fix: change "sats" to "sat" as is defined by nostrmarket ext db

This commit is contained in:
padreug 2025-09-23 23:59:15 +02:00
parent 578cd8f570
commit 2e12315a35

View file

@ -145,20 +145,20 @@ export class NostrmarketAPI extends BaseService {
options: RequestInit = {} options: RequestInit = {}
): Promise<T> { ): Promise<T> {
const url = `${this.baseUrl}/nostrmarket${endpoint}` const url = `${this.baseUrl}/nostrmarket${endpoint}`
const headers: Record<string, string> = { const headers: Record<string, string> = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-API-KEY': walletKey, 'X-API-KEY': walletKey,
} }
// Merge with any additional headers // Merge with any additional headers
if (options.headers) { if (options.headers) {
Object.assign(headers, options.headers) Object.assign(headers, options.headers)
} }
this.debug('NostrmarketAPI request:', { this.debug('NostrmarketAPI request:', {
endpoint, endpoint,
fullUrl: url, fullUrl: url,
method: options.method || 'GET', method: options.method || 'GET',
headers: { headers: {
'Content-Type': headers['Content-Type'], 'Content-Type': headers['Content-Type'],
@ -179,17 +179,17 @@ export class NostrmarketAPI extends BaseService {
statusText: response.statusText, statusText: response.statusText,
errorText errorText
}) })
// If 404, it means no merchant profile exists // If 404, it means no merchant profile exists
if (response.status === 404) { if (response.status === 404) {
return null as T return null as T
} }
// If 403, likely the nostrmarket extension is not enabled for this user // If 403, likely the nostrmarket extension is not enabled for this user
if (response.status === 403) { if (response.status === 403) {
throw new Error(`Access denied: Please ensure the NostrMarket extension is enabled for your LNbits account. Contact your administrator if needed.`) throw new Error(`Access denied: Please ensure the NostrMarket extension is enabled for your LNbits account. Contact your administrator if needed.`)
} }
throw new Error(`NostrmarketAPI request failed: ${response.status} ${response.statusText}`) throw new Error(`NostrmarketAPI request failed: ${response.status} ${response.statusText}`)
} }
@ -208,13 +208,13 @@ export class NostrmarketAPI extends BaseService {
walletInkey, walletInkey,
{ method: 'GET' } { method: 'GET' }
) )
this.debug('Retrieved merchant:', { this.debug('Retrieved merchant:', {
exists: !!merchant, exists: !!merchant,
merchantId: merchant?.id, merchantId: merchant?.id,
active: merchant?.config?.active active: merchant?.config?.active
}) })
return merchant return merchant
} catch (error) { } catch (error) {
this.debug('Failed to get merchant:', error) this.debug('Failed to get merchant:', error)
@ -228,7 +228,7 @@ export class NostrmarketAPI extends BaseService {
* Uses wallet admin key as per the API specification * Uses wallet admin key as per the API specification
*/ */
async createMerchant( async createMerchant(
walletAdminkey: string, walletAdminkey: string,
merchantData: CreateMerchantRequest merchantData: CreateMerchantRequest
): Promise<Merchant> { ): Promise<Merchant> {
const merchant = await this.request<Merchant>( const merchant = await this.request<Merchant>(
@ -239,9 +239,9 @@ export class NostrmarketAPI extends BaseService {
body: JSON.stringify(merchantData), body: JSON.stringify(merchantData),
} }
) )
this.debug('Created merchant:', { merchantId: merchant.id }) this.debug('Created merchant:', { merchantId: merchant.id })
return merchant return merchant
} }
@ -255,9 +255,9 @@ export class NostrmarketAPI extends BaseService {
walletInkey, walletInkey,
{ method: 'GET' } { method: 'GET' }
) )
this.debug('Retrieved stalls:', { count: stalls?.length || 0 }) this.debug('Retrieved stalls:', { count: stalls?.length || 0 })
return stalls || [] return stalls || []
} catch (error) { } catch (error) {
this.debug('Failed to get stalls:', error) this.debug('Failed to get stalls:', error)
@ -280,9 +280,9 @@ export class NostrmarketAPI extends BaseService {
body: JSON.stringify(stallData), body: JSON.stringify(stallData),
} }
) )
this.debug('Created stall:', { stallId: stall.id }) this.debug('Created stall:', { stallId: stall.id })
return stall return stall
} }
@ -296,9 +296,9 @@ export class NostrmarketAPI extends BaseService {
walletInkey, walletInkey,
{ method: 'GET' } { method: 'GET' }
) )
this.debug('Retrieved zones:', { count: zones?.length || 0 }) this.debug('Retrieved zones:', { count: zones?.length || 0 })
return zones || [] return zones || []
} catch (error) { } catch (error) {
this.debug('Failed to get zones:', error) this.debug('Failed to get zones:', error)
@ -321,9 +321,9 @@ export class NostrmarketAPI extends BaseService {
body: JSON.stringify(zoneData), body: JSON.stringify(zoneData),
} }
) )
this.debug('Created zone:', { zoneId: zone.id, zoneName: zone.name }) this.debug('Created zone:', { zoneId: zone.id, zoneName: zone.name })
return zone return zone
} }
@ -331,22 +331,22 @@ export class NostrmarketAPI extends BaseService {
* Get available currencies * Get available currencies
*/ */
async getCurrencies(): Promise<string[]> { async getCurrencies(): Promise<string[]> {
const baseCurrencies = ['sats'] const baseCurrencies = ['sat']
try { try {
const apiCurrencies = await this.request<string[]>( const apiCurrencies = await this.request<string[]>(
'/api/v1/currencies', '/api/v1/currencies',
'', // No authentication needed for currencies endpoint '', // No authentication needed for currencies endpoint
{ method: 'GET' } { method: 'GET' }
) )
if (apiCurrencies && Array.isArray(apiCurrencies)) { if (apiCurrencies && Array.isArray(apiCurrencies)) {
// Combine base currencies with API currencies, removing duplicates // Combine base currencies with API currencies, removing duplicates
const allCurrencies = [...baseCurrencies, ...apiCurrencies.filter(currency => !baseCurrencies.includes(currency))] const allCurrencies = [...baseCurrencies, ...apiCurrencies.filter(currency => !baseCurrencies.includes(currency))]
this.debug('Retrieved currencies:', { count: allCurrencies.length, currencies: allCurrencies }) this.debug('Retrieved currencies:', { count: allCurrencies.length, currencies: allCurrencies })
return allCurrencies return allCurrencies
} }
this.debug('No API currencies returned, using base currencies only') this.debug('No API currencies returned, using base currencies only')
return baseCurrencies return baseCurrencies
} catch (error) { } catch (error) {
@ -364,13 +364,13 @@ export class NostrmarketAPI extends BaseService {
walletInkey, walletInkey,
{ method: 'GET' } { method: 'GET' }
) )
this.debug('Retrieved products:', { this.debug('Retrieved products:', {
stallId, stallId,
count: products?.length || 0, count: products?.length || 0,
pending pending
}) })
return products || [] return products || []
} }
@ -378,7 +378,7 @@ export class NostrmarketAPI extends BaseService {
* Create a new product * Create a new product
*/ */
async createProduct( async createProduct(
walletAdminkey: string, walletAdminkey: string,
productData: CreateProductRequest productData: CreateProductRequest
): Promise<Product> { ): Promise<Product> {
const product = await this.request<Product>( const product = await this.request<Product>(
@ -389,13 +389,13 @@ export class NostrmarketAPI extends BaseService {
body: JSON.stringify(productData), body: JSON.stringify(productData),
} }
) )
this.debug('Created product:', { this.debug('Created product:', {
productId: product.id, productId: product.id,
productName: product.name, productName: product.name,
stallId: product.stall_id stallId: product.stall_id
}) })
return product return product
} }
@ -403,7 +403,7 @@ export class NostrmarketAPI extends BaseService {
* Update an existing product * Update an existing product
*/ */
async updateProduct( async updateProduct(
walletAdminkey: string, walletAdminkey: string,
productId: string, productId: string,
productData: Product productData: Product
): Promise<Product> { ): Promise<Product> {
@ -415,12 +415,12 @@ export class NostrmarketAPI extends BaseService {
body: JSON.stringify(productData), body: JSON.stringify(productData),
} }
) )
this.debug('Updated product:', { this.debug('Updated product:', {
productId: product.id, productId: product.id,
productName: product.name productName: product.name
}) })
return product return product
} }
@ -434,12 +434,12 @@ export class NostrmarketAPI extends BaseService {
walletInkey, walletInkey,
{ method: 'GET' } { method: 'GET' }
) )
this.debug('Retrieved product:', { this.debug('Retrieved product:', {
productId: product?.id, productId: product?.id,
productName: product?.name productName: product?.name
}) })
return product return product
} catch (error) { } catch (error) {
this.debug('Failed to get product:', error) this.debug('Failed to get product:', error)
@ -456,7 +456,7 @@ export class NostrmarketAPI extends BaseService {
walletAdminkey, walletAdminkey,
{ method: 'DELETE' } { method: 'DELETE' }
) )
this.debug('Deleted product:', { productId }) this.debug('Deleted product:', { productId })
} }
} }