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