@beep-it/sdk-core 0.1.7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,50 +1,65 @@
1
1
  // src/index.ts
2
2
  import axios from "axios";
3
3
 
4
+ // src/types/invoice.ts
5
+ var InvoiceStatus = /* @__PURE__ */ ((InvoiceStatus2) => {
6
+ InvoiceStatus2["PENDING"] = "pending";
7
+ InvoiceStatus2["PAID"] = "paid";
8
+ InvoiceStatus2["CONFIRMED"] = "confirmed";
9
+ InvoiceStatus2["EXPIRED"] = "expired";
10
+ InvoiceStatus2["FAILED"] = "failed";
11
+ return InvoiceStatus2;
12
+ })(InvoiceStatus || {});
13
+
14
+ // src/types/payment.ts
15
+ var PayoutStatus = /* @__PURE__ */ ((PayoutStatus2) => {
16
+ PayoutStatus2["PENDING"] = "PENDING";
17
+ PayoutStatus2["IN_PROGRESS"] = "IN_PROGRESS";
18
+ PayoutStatus2["COMPLETED"] = "COMPLETED";
19
+ PayoutStatus2["FAILED"] = "FAILED";
20
+ PayoutStatus2["CANCELED"] = "CANCELED";
21
+ return PayoutStatus2;
22
+ })(PayoutStatus || {});
23
+
4
24
  // src/types/token.ts
5
25
  var SupportedToken = /* @__PURE__ */ ((SupportedToken3) => {
6
26
  SupportedToken3["USDC"] = "USDC";
7
- SupportedToken3["USDT"] = "USDT";
8
27
  return SupportedToken3;
9
28
  })(SupportedToken || {});
10
29
  var TOKEN_ADDRESSES = {
11
- ["USDC" /* USDC */]: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyB7u6T",
12
- // USDC mint address
13
- ["USDT" /* USDT */]: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
14
- // USDT mint address
30
+ ["USDC" /* USDC */]: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyB7u6T"
31
+ // USDC token address
15
32
  };
16
33
  var TOKEN_DECIMALS = {
17
- ["USDC" /* USDC */]: 6,
34
+ ["USDC" /* USDC */]: 6
18
35
  // USDC uses 6 decimal places
19
- ["USDT" /* USDT */]: 6
20
- // USDT uses 6 decimal places
21
36
  };
22
37
  var TokenUtils = class {
23
38
  /**
24
- * Retrieves the SPL token address for a supported token
39
+ * Retrieves the token address for a supported token
25
40
  *
26
41
  * @param token - The supported token enum value
27
- * @returns The corresponding SPL token address on Solana
42
+ * @returns The corresponding token address on SUI
28
43
  *
29
44
  * @example
30
45
  * ```typescript
31
- * const address = TokenUtils.getTokenAddress(SupportedToken.USDT);
32
- * console.log(address); // 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'
46
+ * const address = TokenUtils.getTokenAddress(SupportedToken.USDC);
47
+ * console.log(address); // 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyB7u6T'
33
48
  * ```
34
49
  */
35
50
  static getTokenAddress(token) {
36
51
  return TOKEN_ADDRESSES[token];
37
52
  }
38
53
  /**
39
- * Performs reverse lookup to find token enum from SPL address
54
+ * Performs reverse lookup to find token enum from token address
40
55
  *
41
- * @param address - The SPL token address to look up
56
+ * @param address - The token address to look up
42
57
  * @returns The corresponding SupportedToken enum value, or null if not found
43
58
  *
44
59
  * @example
45
60
  * ```typescript
46
- * const token = TokenUtils.getTokenFromAddress('Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB');
47
- * console.log(token); // SupportedToken.USDT
61
+ * const token = TokenUtils.getTokenFromAddress('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyB7u6T');
62
+ * console.log(token); // SupportedToken.USDC
48
63
  * ```
49
64
  */
50
65
  static getTokenFromAddress(address) {
@@ -78,7 +93,7 @@ var TokenUtils = class {
78
93
  *
79
94
  * @example
80
95
  * ```typescript
81
- * const userInput = 'USDT';
96
+ * const userInput = 'USDC';
82
97
  * if (TokenUtils.isTokenSupported(userInput)) {
83
98
  * // userInput is now typed as SupportedToken
84
99
  * const address = TokenUtils.getTokenAddress(userInput);
@@ -91,7 +106,7 @@ var TokenUtils = class {
91
106
  /**
92
107
  * Returns the default token for operations when no token is specified
93
108
  *
94
- * @returns The default SupportedToken (currently USDT)
109
+ * @returns The default SupportedToken (currently USDC)
95
110
  *
96
111
  * @example
97
112
  * ```typescript
@@ -104,6 +119,53 @@ var TokenUtils = class {
104
119
  }
105
120
  };
106
121
 
122
+ // src/types/common.ts
123
+ var BlockchainNetwork = /* @__PURE__ */ ((BlockchainNetwork2) => {
124
+ BlockchainNetwork2["SUI"] = "SUI";
125
+ BlockchainNetwork2["SOLANA"] = "SOLANA";
126
+ return BlockchainNetwork2;
127
+ })(BlockchainNetwork || {});
128
+ var SortOrder = /* @__PURE__ */ ((SortOrder2) => {
129
+ SortOrder2["ASC"] = "asc";
130
+ SortOrder2["DESC"] = "desc";
131
+ return SortOrder2;
132
+ })(SortOrder || {});
133
+ var EntityStatus = /* @__PURE__ */ ((EntityStatus2) => {
134
+ EntityStatus2["ACTIVE"] = "active";
135
+ EntityStatus2["INACTIVE"] = "inactive";
136
+ EntityStatus2["PENDING"] = "pending";
137
+ EntityStatus2["DELETED"] = "deleted";
138
+ EntityStatus2["ARCHIVED"] = "archived";
139
+ return EntityStatus2;
140
+ })(EntityStatus || {});
141
+ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
142
+ WebhookEventType2["PAYMENT_COMPLETED"] = "payment.completed";
143
+ WebhookEventType2["PAYMENT_FAILED"] = "payment.failed";
144
+ WebhookEventType2["INVOICE_PAID"] = "invoice.paid";
145
+ WebhookEventType2["INVOICE_EXPIRED"] = "invoice.expired";
146
+ WebhookEventType2["PRODUCT_CREATED"] = "product.created";
147
+ WebhookEventType2["PRODUCT_UPDATED"] = "product.updated";
148
+ WebhookEventType2["SUBSCRIPTION_ACTIVATED"] = "subscription.activated";
149
+ WebhookEventType2["SUBSCRIPTION_CANCELLED"] = "subscription.cancelled";
150
+ return WebhookEventType2;
151
+ })(WebhookEventType || {});
152
+ function isUUID(value) {
153
+ if (typeof value !== "string") return false;
154
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
155
+ return uuidRegex.test(value);
156
+ }
157
+ function isMoneyAmount(value) {
158
+ if (typeof value !== "string") return false;
159
+ const moneyRegex = /^\d+(\.\d{1,2})?$/;
160
+ return moneyRegex.test(value);
161
+ }
162
+ function formatMoneyAmount(amount, decimals = 2) {
163
+ return amount.toFixed(decimals);
164
+ }
165
+ function parseMoneyAmount(amount) {
166
+ return parseFloat(amount);
167
+ }
168
+
107
169
  // src/modules/invoices.ts
108
170
  var InvoicesModule = class {
109
171
  constructor(client) {
@@ -112,11 +174,11 @@ var InvoicesModule = class {
112
174
  /**
113
175
  * Creates a new invoice for payment processing
114
176
  * Supports both product-based invoices (linked to existing products) and custom invoices
115
- *
177
+ *
116
178
  * @param payload - Invoice creation parameters (product-based or custom)
117
179
  * @returns Promise that resolves to the created invoice
118
180
  * @throws {Error} When invoice creation fails
119
- *
181
+ *
120
182
  * @example
121
183
  * ```typescript
122
184
  * // Create invoice from existing product
@@ -124,12 +186,12 @@ var InvoicesModule = class {
124
186
  * productId: 'prod_123',
125
187
  * payerType: 'customer_wallet'
126
188
  * });
127
- *
189
+ *
128
190
  * // Create custom invoice
129
191
  * const customInvoice = await beep.invoices.createInvoice({
130
192
  * description: 'Consulting services',
131
193
  * amount: '100.00',
132
- * token: SupportedToken.USDT,
194
+ * token: SupportedToken.USDC,
133
195
  * payerType: 'customer_wallet'
134
196
  * });
135
197
  * ```
@@ -137,18 +199,20 @@ var InvoicesModule = class {
137
199
  async createInvoice(payload) {
138
200
  const requestPayload = { ...payload };
139
201
  if ("token" in requestPayload && !("splTokenAddress" in requestPayload)) {
140
- requestPayload.splTokenAddress = TokenUtils.getTokenAddress(requestPayload.token);
202
+ requestPayload.splTokenAddress = TokenUtils.getTokenAddress(
203
+ requestPayload.token
204
+ );
141
205
  }
142
206
  const response = await this.client.post("/v1/invoices", requestPayload);
143
207
  return response.data;
144
208
  }
145
209
  /**
146
210
  * Retrieves a specific invoice by its ID
147
- *
211
+ *
148
212
  * @param invoiceId - The unique identifier of the invoice to retrieve
149
213
  * @returns Promise that resolves to the invoice details
150
214
  * @throws {Error} When the invoice is not found or retrieval fails
151
- *
215
+ *
152
216
  * @example
153
217
  * ```typescript
154
218
  * const invoice = await beep.invoices.getInvoice('inv_123abc456def');
@@ -162,10 +226,10 @@ var InvoicesModule = class {
162
226
  }
163
227
  /**
164
228
  * Retrieves all invoices for the current merchant
165
- *
229
+ *
166
230
  * @returns Promise that resolves to an array of invoices
167
231
  * @throws {Error} When invoice retrieval fails
168
- *
232
+ *
169
233
  * @example
170
234
  * ```typescript
171
235
  * const invoices = await beep.invoices.listInvoices();
@@ -179,13 +243,13 @@ var InvoicesModule = class {
179
243
  }
180
244
  /**
181
245
  * Deletes an existing invoice
182
- *
246
+ *
183
247
  * @param invoiceId - The unique identifier of the invoice to delete
184
248
  * @returns Promise that resolves when the invoice is successfully deleted
185
249
  * @throws {Error} When the invoice is not found or deletion fails
186
- *
250
+ *
187
251
  * @remarks Once deleted, an invoice cannot be recovered. Use with caution.
188
- *
252
+ *
189
253
  * @example
190
254
  * ```typescript
191
255
  * await beep.invoices.deleteInvoice('inv_123abc456def');
@@ -208,14 +272,16 @@ var PaymentsModule = class {
208
272
  *
209
273
  * Notes:
210
274
  * - Do not pass walletId. The server derives the wallet based on your API key's merchant and requested chain.
211
- * - amount must be in smallest units for the token (e.g., 6‑decimals USDC amount as an integer string).
275
+ * - amount is a human-readable decimal string (e.g., "1.0" for 1 USDC, "0.5" for 0.5 SUI).
276
+ * The server converts to the token's base units internally.
277
+ * - Minimum: 0.01 per transaction. Maximum: 100,000 per transaction.
212
278
  * - This endpoint responds immediately with acceptance/rejection. Actual transfer executes asynchronously after funds are reserved.
213
279
  *
214
280
  * Example:
215
281
  * const res = await beep.payments.createPayout({
216
- * amount: '1000000', // 1.0 USDC with 6 decimals
282
+ * amount: '1.50', // 1.50 USDC (human-readable)
217
283
  * destinationWalletAddress: 'DEST_ADDRESS',
218
- * chain: 'SOLANA',
284
+ * chain: 'SUI',
219
285
  * token: 'USDC',
220
286
  * });
221
287
  */
@@ -284,7 +350,7 @@ var PaymentsModule = class {
284
350
  *
285
351
  * Phase 1 – Request payment (no paymentReference):
286
352
  * - Server responds with HTTP 402 Payment Required and a payload containing:
287
- * referenceKey, paymentUrl (Solana Pay), optional qrCode, amount, expiresAt, status.
353
+ * referenceKey, paymentUrl, optional qrCode, amount, expiresAt, status.
288
354
  * - The SDK normalizes this by returning the payload (even when status code is 402).
289
355
  * - The caller must instruct the user to pay via their wallet using paymentUrl/qrCode.
290
356
  *
@@ -333,51 +399,6 @@ var PaymentsModule = class {
333
399
  return null;
334
400
  }
335
401
  }
336
- /**
337
- * Signs a Solana transaction for direct blockchain payment processing
338
- *
339
- * @param input - Transaction parameters including addresses, amounts, and token details
340
- * @returns Promise that resolves to signed transaction data
341
- * @throws {Error} When transaction signing fails or required fields are missing
342
- *
343
- * @example
344
- * ```typescript
345
- * try {
346
- * const signedTx = await beep.payments.signSolanaTransaction({
347
- * senderAddress: 'sender_wallet_address',
348
- * recipientAddress: 'recipient_wallet_address',
349
- * tokenMintAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
350
- * amount: 1000000, // 1.0 USDT in base units
351
- * decimals: 6
352
- * });
353
- *
354
- * if (signedTx) {
355
- * console.log('Transaction ready for broadcast:', signedTx.signedTransaction);
356
- * }
357
- * } catch (error) {
358
- * console.error('Transaction signing failed:', error);
359
- * }
360
- * ```
361
- */
362
- async signSolanaTransaction(input) {
363
- if (!input.senderAddress || !input.recipientAddress || !input.tokenMintAddress || !input.amount || !input.decimals) {
364
- console.error("Missing required fields");
365
- return null;
366
- }
367
- try {
368
- const response = await this.client.post(
369
- "/v1/payment/sign-solana-transaction",
370
- input
371
- );
372
- if (!response.data || !response.data.data) {
373
- throw new Error("No data returned from solana transaction signing");
374
- }
375
- return response.data.data;
376
- } catch (error) {
377
- const errorMessage = error instanceof Error ? error.message : String(error);
378
- throw new Error(`Failed to sign solana transaction: ${errorMessage}`);
379
- }
380
- }
381
402
  // --- Streaming Payment Methods ---
382
403
  // Note: These methods are ONLY available with BeepClient (secret API keys)
383
404
  // They do NOT work with BeepPublicClient (publishable keys)
@@ -543,7 +564,7 @@ var ProductsModule = class {
543
564
  * name: 'Premium License',
544
565
  * description: 'Lifetime access to premium features',
545
566
  * price: '99.99',
546
- * token: SupportedToken.USDT,
567
+ * token: SupportedToken.USDC,
547
568
  * isSubscription: false
548
569
  * });
549
570
  *
@@ -552,7 +573,7 @@ var ProductsModule = class {
552
573
  * name: 'Monthly Pro Plan',
553
574
  * description: 'Monthly subscription with full access',
554
575
  * price: '19.99',
555
- * token: SupportedToken.USDT,
576
+ * token: SupportedToken.USDC,
556
577
  * isSubscription: true
557
578
  * });
558
579
  * ```
@@ -771,6 +792,381 @@ var UserModule = class {
771
792
  }
772
793
  };
773
794
 
795
+ // src/errors/index.ts
796
+ var BeepErrorCode = /* @__PURE__ */ ((BeepErrorCode2) => {
797
+ BeepErrorCode2["INVALID_API_KEY"] = "BEEP_1001";
798
+ BeepErrorCode2["MISSING_API_KEY"] = "BEEP_1002";
799
+ BeepErrorCode2["UNAUTHORIZED"] = "BEEP_1003";
800
+ BeepErrorCode2["INVALID_PUBLISHABLE_KEY"] = "BEEP_1004";
801
+ BeepErrorCode2["NETWORK_ERROR"] = "BEEP_2001";
802
+ BeepErrorCode2["TIMEOUT"] = "BEEP_2002";
803
+ BeepErrorCode2["SERVER_ERROR"] = "BEEP_2003";
804
+ BeepErrorCode2["PAYMENT_FAILED"] = "BEEP_3001";
805
+ BeepErrorCode2["PAYMENT_EXPIRED"] = "BEEP_3002";
806
+ BeepErrorCode2["PAYMENT_NOT_FOUND"] = "BEEP_3003";
807
+ BeepErrorCode2["INSUFFICIENT_FUNDS"] = "BEEP_3004";
808
+ BeepErrorCode2["PAYMENT_ALREADY_PROCESSED"] = "BEEP_3005";
809
+ BeepErrorCode2["INVOICE_NOT_FOUND"] = "BEEP_4001";
810
+ BeepErrorCode2["INVOICE_EXPIRED"] = "BEEP_4002";
811
+ BeepErrorCode2["INVOICE_ALREADY_PAID"] = "BEEP_4003";
812
+ BeepErrorCode2["INVALID_PARAMETER"] = "BEEP_5001";
813
+ BeepErrorCode2["MISSING_PARAMETER"] = "BEEP_5002";
814
+ BeepErrorCode2["INVALID_AMOUNT"] = "BEEP_5003";
815
+ BeepErrorCode2["INVALID_TOKEN"] = "BEEP_5004";
816
+ BeepErrorCode2["RATE_LIMIT_EXCEEDED"] = "BEEP_6001";
817
+ BeepErrorCode2["UNKNOWN_ERROR"] = "BEEP_9999";
818
+ return BeepErrorCode2;
819
+ })(BeepErrorCode || {});
820
+ var BeepError = class _BeepError extends Error {
821
+ constructor(message, options) {
822
+ super(message);
823
+ this.name = "BeepError";
824
+ this.code = options.code;
825
+ this.statusCode = options.statusCode;
826
+ this.details = options.details;
827
+ this.timestamp = /* @__PURE__ */ new Date();
828
+ this.requestId = options.requestId;
829
+ if (Error.captureStackTrace) {
830
+ Error.captureStackTrace(this, _BeepError);
831
+ }
832
+ }
833
+ /**
834
+ * Returns a user-friendly error message
835
+ */
836
+ getUserMessage() {
837
+ switch (this.code) {
838
+ case "BEEP_1001" /* INVALID_API_KEY */:
839
+ return "The API key provided is invalid. Please check your credentials.";
840
+ case "BEEP_1002" /* MISSING_API_KEY */:
841
+ return "No API key provided. Please provide a valid API key.";
842
+ case "BEEP_2001" /* NETWORK_ERROR */:
843
+ return "Unable to connect to BEEP servers. Please check your internet connection.";
844
+ case "BEEP_3002" /* PAYMENT_EXPIRED */:
845
+ return "This payment request has expired. Please create a new one.";
846
+ case "BEEP_3004" /* INSUFFICIENT_FUNDS */:
847
+ return "Insufficient funds to complete this transaction.";
848
+ case "BEEP_6001" /* RATE_LIMIT_EXCEEDED */:
849
+ return "Too many requests. Please try again later.";
850
+ default:
851
+ return this.message || "An unexpected error occurred.";
852
+ }
853
+ }
854
+ /**
855
+ * Returns a JSON representation of the error for logging
856
+ */
857
+ toJSON() {
858
+ return {
859
+ name: this.name,
860
+ message: this.message,
861
+ code: this.code,
862
+ statusCode: this.statusCode,
863
+ details: this.details,
864
+ timestamp: this.timestamp,
865
+ requestId: this.requestId,
866
+ stack: this.stack
867
+ };
868
+ }
869
+ };
870
+ var BeepAuthenticationError = class extends BeepError {
871
+ constructor(message, options = {}) {
872
+ super(message, {
873
+ code: options.code ?? "BEEP_1003" /* UNAUTHORIZED */,
874
+ statusCode: 401,
875
+ details: options.details
876
+ });
877
+ this.name = "BeepAuthenticationError";
878
+ }
879
+ };
880
+ var BeepValidationError = class extends BeepError {
881
+ constructor(message, options = {}) {
882
+ super(message, {
883
+ code: options.code ?? "BEEP_5001" /* INVALID_PARAMETER */,
884
+ statusCode: 400,
885
+ details: options.details
886
+ });
887
+ this.name = "BeepValidationError";
888
+ }
889
+ };
890
+ var BeepPaymentError = class extends BeepError {
891
+ constructor(message, options = {}) {
892
+ super(message, {
893
+ code: options.code ?? "BEEP_3001" /* PAYMENT_FAILED */,
894
+ statusCode: 402,
895
+ details: options.details
896
+ });
897
+ this.name = "BeepPaymentError";
898
+ }
899
+ };
900
+ var BeepNetworkError = class extends BeepError {
901
+ constructor(message, options = {}) {
902
+ super(message, {
903
+ code: options.code ?? "BEEP_2001" /* NETWORK_ERROR */,
904
+ details: options.details
905
+ });
906
+ this.name = "BeepNetworkError";
907
+ }
908
+ };
909
+ var BeepRateLimitError = class extends BeepError {
910
+ constructor(message, options = {}) {
911
+ super(message, {
912
+ code: "BEEP_6001" /* RATE_LIMIT_EXCEEDED */,
913
+ statusCode: 429,
914
+ details: options.details
915
+ });
916
+ this.name = "BeepRateLimitError";
917
+ this.retryAfter = options.retryAfter;
918
+ }
919
+ };
920
+ function createBeepErrorFromAxios(error) {
921
+ const response = error.response;
922
+ const requestId = response?.headers?.["x-request-id"];
923
+ if (!response) {
924
+ return new BeepNetworkError(error.message || "Network connection failed", {
925
+ code: "BEEP_2001" /* NETWORK_ERROR */,
926
+ details: { originalError: error }
927
+ });
928
+ }
929
+ const status = response.status;
930
+ const data = response.data;
931
+ const message = data?.message || data?.error || error.message;
932
+ switch (status) {
933
+ case 401:
934
+ return new BeepAuthenticationError(message, {
935
+ code: "BEEP_1003" /* UNAUTHORIZED */,
936
+ details: { response: data }
937
+ });
938
+ case 400: {
939
+ if (message.toLowerCase().includes("api key")) {
940
+ return new BeepAuthenticationError(message, {
941
+ code: "BEEP_1001" /* INVALID_API_KEY */,
942
+ details: { response: data }
943
+ });
944
+ }
945
+ return new BeepValidationError(message, {
946
+ code: "BEEP_5001" /* INVALID_PARAMETER */,
947
+ details: { response: data, fields: data?.fields }
948
+ });
949
+ }
950
+ case 402:
951
+ return new BeepPaymentError(message, {
952
+ code: "BEEP_3001" /* PAYMENT_FAILED */,
953
+ details: { response: data }
954
+ });
955
+ case 404: {
956
+ if (message.toLowerCase().includes("invoice")) {
957
+ return new BeepError(message, {
958
+ code: "BEEP_4001" /* INVOICE_NOT_FOUND */,
959
+ statusCode: 404,
960
+ details: { response: data },
961
+ requestId
962
+ });
963
+ }
964
+ if (message.toLowerCase().includes("payment")) {
965
+ return new BeepError(message, {
966
+ code: "BEEP_3003" /* PAYMENT_NOT_FOUND */,
967
+ statusCode: 404,
968
+ details: { response: data },
969
+ requestId
970
+ });
971
+ }
972
+ break;
973
+ }
974
+ case 429: {
975
+ const retryAfter = response.headers?.["retry-after"];
976
+ return new BeepRateLimitError(message, {
977
+ retryAfter: retryAfter ? parseInt(retryAfter) : void 0,
978
+ details: { response: data }
979
+ });
980
+ }
981
+ case 500:
982
+ case 502:
983
+ case 503:
984
+ case 504:
985
+ return new BeepError(message, {
986
+ code: "BEEP_2003" /* SERVER_ERROR */,
987
+ statusCode: status,
988
+ details: { response: data },
989
+ requestId
990
+ });
991
+ }
992
+ return new BeepError(message, {
993
+ code: "BEEP_9999" /* UNKNOWN_ERROR */,
994
+ statusCode: status,
995
+ details: { response: data },
996
+ requestId
997
+ });
998
+ }
999
+
1000
+ // src/utils/debug.ts
1001
+ var defaultLogger = (options) => {
1002
+ const { level, message, data } = options;
1003
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
1004
+ const prefix = `[BEEP SDK ${level}] ${timestamp}`;
1005
+ switch (level) {
1006
+ case "error":
1007
+ console.error(prefix, message, data);
1008
+ break;
1009
+ case "warn":
1010
+ console.warn(prefix, message, data);
1011
+ break;
1012
+ case "info":
1013
+ console.info(prefix, message, data);
1014
+ break;
1015
+ case "debug":
1016
+ console.debug(prefix, message, data);
1017
+ break;
1018
+ default:
1019
+ console.log(prefix, message, data);
1020
+ }
1021
+ };
1022
+ var BeepDebugger = class {
1023
+ constructor(options = {}) {
1024
+ this.options = options;
1025
+ this.logger = options.logger || defaultLogger;
1026
+ }
1027
+ /**
1028
+ * Log an error with context
1029
+ */
1030
+ error(message, error) {
1031
+ if (error instanceof BeepError) {
1032
+ this.logger({
1033
+ level: "error",
1034
+ message,
1035
+ data: {
1036
+ code: error.code,
1037
+ statusCode: error.statusCode,
1038
+ details: error.details,
1039
+ requestId: error.requestId,
1040
+ userMessage: error.getUserMessage()
1041
+ }
1042
+ });
1043
+ } else {
1044
+ this.logger({ level: "error", message, data: error });
1045
+ }
1046
+ }
1047
+ /**
1048
+ * Log a warning
1049
+ */
1050
+ warn(message, data) {
1051
+ this.logger({ level: "warn", message, data });
1052
+ }
1053
+ /**
1054
+ * Log info message
1055
+ */
1056
+ info(message, data) {
1057
+ if (this.options.debug) {
1058
+ this.logger({ level: "info", message, data });
1059
+ }
1060
+ }
1061
+ /**
1062
+ * Log debug message
1063
+ */
1064
+ debug(message, data) {
1065
+ if (this.options.debug) {
1066
+ this.logger({ level: "debug", message, data });
1067
+ }
1068
+ }
1069
+ /**
1070
+ * Log API request
1071
+ */
1072
+ logRequest(options) {
1073
+ if (this.options.logRequests && this.options.debug) {
1074
+ const { method, url, data } = options;
1075
+ this.logger({
1076
+ level: "debug",
1077
+ message: `API Request: ${method} ${url}`,
1078
+ data: {
1079
+ method,
1080
+ url,
1081
+ data: this.sanitizeData(data)
1082
+ }
1083
+ });
1084
+ }
1085
+ }
1086
+ /**
1087
+ * Log API response
1088
+ */
1089
+ logResponse(options) {
1090
+ if (this.options.logResponses && this.options.debug) {
1091
+ const { method, url, status, data } = options;
1092
+ this.logger({
1093
+ level: "debug",
1094
+ message: `API Response: ${method} ${url} (${status})`,
1095
+ data: {
1096
+ method,
1097
+ url,
1098
+ status,
1099
+ data: this.sanitizeData(data)
1100
+ }
1101
+ });
1102
+ }
1103
+ }
1104
+ /**
1105
+ * Sanitize sensitive data before logging
1106
+ */
1107
+ sanitizeData(data) {
1108
+ if (!data) return data;
1109
+ const sensitiveFields = ["apiKey", "api_key", "authorization", "password", "secret"];
1110
+ if (typeof data === "string") {
1111
+ return data;
1112
+ }
1113
+ if (Array.isArray(data)) {
1114
+ return data.map((item) => this.sanitizeData(item));
1115
+ }
1116
+ if (typeof data === "object") {
1117
+ const sanitized = {};
1118
+ for (const [key, value] of Object.entries(data)) {
1119
+ if (sensitiveFields.some((field) => key.toLowerCase().includes(field))) {
1120
+ sanitized[key] = "[REDACTED]";
1121
+ } else {
1122
+ sanitized[key] = this.sanitizeData(value);
1123
+ }
1124
+ }
1125
+ return sanitized;
1126
+ }
1127
+ return data;
1128
+ }
1129
+ };
1130
+ function createDebugInterceptors(axios2, beepDebugger) {
1131
+ axios2.interceptors.request.use(
1132
+ (config) => {
1133
+ beepDebugger.logRequest({
1134
+ method: config.method?.toUpperCase() || "GET",
1135
+ url: config.url || "",
1136
+ data: config.data
1137
+ });
1138
+ return config;
1139
+ },
1140
+ (error) => {
1141
+ beepDebugger.error("Request interceptor error", error);
1142
+ return Promise.reject(error);
1143
+ }
1144
+ );
1145
+ axios2.interceptors.response.use(
1146
+ (response) => {
1147
+ beepDebugger.logResponse({
1148
+ method: response.config.method?.toUpperCase() || "GET",
1149
+ url: response.config.url || "",
1150
+ status: response.status,
1151
+ data: response.data
1152
+ });
1153
+ return response;
1154
+ },
1155
+ (error) => {
1156
+ if (error.response) {
1157
+ beepDebugger.logResponse({
1158
+ method: error.config?.method?.toUpperCase() || "GET",
1159
+ url: error.config?.url || "",
1160
+ status: error.response.status,
1161
+ data: error.response.data
1162
+ });
1163
+ }
1164
+ beepDebugger.error("API Error", error);
1165
+ return Promise.reject(error);
1166
+ }
1167
+ );
1168
+ }
1169
+
774
1170
  // src/index.ts
775
1171
  var BeepClient = class {
776
1172
  /**
@@ -781,8 +1177,11 @@ var BeepClient = class {
781
1177
  */
782
1178
  constructor(options) {
783
1179
  if (!options.apiKey) {
784
- throw new Error("API key is required to initialize BeepClient");
1180
+ throw new BeepAuthenticationError("API key is required to initialize BeepClient", {
1181
+ code: "BEEP_1002" /* MISSING_API_KEY */
1182
+ });
785
1183
  }
1184
+ this.debugger = new BeepDebugger(options.debug);
786
1185
  this.client = axios.create({
787
1186
  baseURL: options.serverUrl || "https://api.justbeep.it",
788
1187
  headers: {
@@ -791,6 +1190,9 @@ var BeepClient = class {
791
1190
  "X-Beep-Client": "beep-sdk"
792
1191
  }
793
1192
  });
1193
+ if (options.debug?.debug) {
1194
+ createDebugInterceptors(this.client, this.debugger);
1195
+ }
794
1196
  this.products = new ProductsModule(this.client);
795
1197
  this.invoices = new InvoicesModule(this.client);
796
1198
  this.payments = new PaymentsModule(this.client);
@@ -809,7 +1211,7 @@ var BeepClient = class {
809
1211
  * const res = await beep.payments.createPayout({
810
1212
  * amount: '1000000', // 1.0 USDC with 6 decimals
811
1213
  * destinationWalletAddress: 'DEST_ADDRESS',
812
- * chain: 'SOLANA',
1214
+ * chain: 'SUI',
813
1215
  * token: 'USDC',
814
1216
  * });
815
1217
  */
@@ -847,7 +1249,12 @@ var BeepPublicClient = class {
847
1249
  */
848
1250
  constructor(options) {
849
1251
  if (!options.publishableKey) {
850
- throw new Error("publishableKey is required to initialize BeepPublicClient");
1252
+ throw new BeepAuthenticationError(
1253
+ "publishableKey is required to initialize BeepPublicClient",
1254
+ {
1255
+ code: "BEEP_1002" /* MISSING_API_KEY */
1256
+ }
1257
+ );
851
1258
  }
852
1259
  this.client = axios.create({
853
1260
  baseURL: options.serverUrl || "https://api.justbeep.it",
@@ -861,8 +1268,28 @@ var BeepPublicClient = class {
861
1268
  }
862
1269
  };
863
1270
  export {
1271
+ BeepAuthenticationError,
864
1272
  BeepClient,
1273
+ BeepError,
1274
+ BeepErrorCode,
1275
+ BeepNetworkError,
1276
+ BeepPaymentError,
865
1277
  BeepPublicClient,
1278
+ BeepRateLimitError,
1279
+ BeepValidationError,
1280
+ BlockchainNetwork,
1281
+ EntityStatus,
1282
+ InvoiceStatus,
1283
+ PayoutStatus,
1284
+ SortOrder,
866
1285
  SupportedToken,
867
- TokenUtils
1286
+ TOKEN_ADDRESSES,
1287
+ TOKEN_DECIMALS,
1288
+ TokenUtils,
1289
+ WebhookEventType,
1290
+ createBeepErrorFromAxios,
1291
+ formatMoneyAmount,
1292
+ isMoneyAmount,
1293
+ isUUID,
1294
+ parseMoneyAmount
868
1295
  };