@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/README.md +8 -8
- package/dist/errors/index.d.ts +105 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +536 -89
- package/dist/index.mjs +512 -85
- package/dist/modules/invoices.d.ts +1 -1
- package/dist/modules/invoices.d.ts.map +1 -1
- package/dist/modules/payments.d.ts +9 -34
- package/dist/modules/payments.d.ts.map +1 -1
- package/dist/modules/products.d.ts +2 -2
- package/dist/types/common.d.ts +197 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/enhanced-payment.d.ts +311 -0
- package/dist/types/enhanced-payment.d.ts.map +1 -0
- package/dist/types/enhanced-product.d.ts +299 -0
- package/dist/types/enhanced-product.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -9
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/invoice.d.ts +2 -2
- package/dist/types/invoice.d.ts.map +1 -1
- package/dist/types/payment.d.ts +2 -32
- package/dist/types/payment.d.ts.map +1 -1
- package/dist/types/product.d.ts +3 -3
- package/dist/types/product.d.ts.map +1 -1
- package/dist/types/public.d.ts +1 -1
- package/dist/types/public.d.ts.map +1 -1
- package/dist/types/streaming-payments.d.ts +173 -0
- package/dist/types/streaming-payments.d.ts.map +1 -0
- package/dist/types/token.d.ts +16 -17
- package/dist/types/token.d.ts.map +1 -1
- package/dist/utils/debug.d.ts +75 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/package.json +19 -16
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ const beep = new BeepClient({
|
|
|
87
87
|
|
|
88
88
|
### Server-Side Making Money
|
|
89
89
|
|
|
90
|
-
Let's say you want to charge someone 5
|
|
90
|
+
Let's say you want to charge someone 5 USDC for a pack of 100 magic crystals in your game. Here's the complete server-side flow:
|
|
91
91
|
|
|
92
92
|
#### The Server-Side Payment Flow
|
|
93
93
|
|
|
@@ -110,7 +110,7 @@ Seriously, all _you_ need to worry about is step 1. We handle 2-7 because we're
|
|
|
110
110
|
const invoiceDetails = {
|
|
111
111
|
description: 'A pack of 100 magic crystals',
|
|
112
112
|
amount: '5.00',
|
|
113
|
-
token: SupportedToken.
|
|
113
|
+
token: SupportedToken.USDC,
|
|
114
114
|
payerType: 'customer_wallet' as const,
|
|
115
115
|
};
|
|
116
116
|
|
|
@@ -142,7 +142,7 @@ try {
|
|
|
142
142
|
```typescript
|
|
143
143
|
const invoice = await beep.invoices.createInvoice({
|
|
144
144
|
amount: '19.99',
|
|
145
|
-
token: SupportedToken.
|
|
145
|
+
token: SupportedToken.USDC,
|
|
146
146
|
description: 'VIP Battle Pass',
|
|
147
147
|
payerType: 'customer_wallet',
|
|
148
148
|
});
|
|
@@ -155,7 +155,7 @@ const invoice = await beep.invoices.createInvoice({
|
|
|
155
155
|
const product = await beep.products.createProduct({
|
|
156
156
|
name: 'Magic Sword',
|
|
157
157
|
price: '9.99',
|
|
158
|
-
token: SupportedToken.
|
|
158
|
+
token: SupportedToken.USDC,
|
|
159
159
|
isSubscription: false,
|
|
160
160
|
});
|
|
161
161
|
|
|
@@ -334,7 +334,7 @@ Clean token enum instead of remembering addresses:
|
|
|
334
334
|
```typescript
|
|
335
335
|
import { SupportedToken } from '@beep-it/sdk-core';
|
|
336
336
|
|
|
337
|
-
const token = SupportedToken.
|
|
337
|
+
const token = SupportedToken.USDC; // Much cleaner!
|
|
338
338
|
```
|
|
339
339
|
|
|
340
340
|
### `TokenUtils`
|
|
@@ -345,13 +345,13 @@ Advanced token utilities:
|
|
|
345
345
|
import { TokenUtils, SupportedToken } from '@beep-it/sdk-core';
|
|
346
346
|
|
|
347
347
|
// Get the address from a token enum
|
|
348
|
-
const address = TokenUtils.getTokenAddress(SupportedToken.
|
|
348
|
+
const address = TokenUtils.getTokenAddress(SupportedToken.USDC);
|
|
349
349
|
|
|
350
350
|
// Check if we support a token
|
|
351
|
-
const isSupported = TokenUtils.isTokenSupported(SupportedToken.
|
|
351
|
+
const isSupported = TokenUtils.isTokenSupported(SupportedToken.USDC);
|
|
352
352
|
|
|
353
353
|
// Get a token enum from an address (reverse lookup)
|
|
354
|
-
const token = TokenUtils.getTokenFromAddress('
|
|
354
|
+
const token = TokenUtils.getTokenFromAddress('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyB7u6T');
|
|
355
355
|
```
|
|
356
356
|
|
|
357
357
|
---
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Enhanced error handling for the BEEP SDK
|
|
3
|
+
* Provides typed, semantic errors with proper error codes and context
|
|
4
|
+
*/
|
|
5
|
+
export declare enum BeepErrorCode {
|
|
6
|
+
INVALID_API_KEY = "BEEP_1001",
|
|
7
|
+
MISSING_API_KEY = "BEEP_1002",
|
|
8
|
+
UNAUTHORIZED = "BEEP_1003",
|
|
9
|
+
INVALID_PUBLISHABLE_KEY = "BEEP_1004",
|
|
10
|
+
NETWORK_ERROR = "BEEP_2001",
|
|
11
|
+
TIMEOUT = "BEEP_2002",
|
|
12
|
+
SERVER_ERROR = "BEEP_2003",
|
|
13
|
+
PAYMENT_FAILED = "BEEP_3001",
|
|
14
|
+
PAYMENT_EXPIRED = "BEEP_3002",
|
|
15
|
+
PAYMENT_NOT_FOUND = "BEEP_3003",
|
|
16
|
+
INSUFFICIENT_FUNDS = "BEEP_3004",
|
|
17
|
+
PAYMENT_ALREADY_PROCESSED = "BEEP_3005",
|
|
18
|
+
INVOICE_NOT_FOUND = "BEEP_4001",
|
|
19
|
+
INVOICE_EXPIRED = "BEEP_4002",
|
|
20
|
+
INVOICE_ALREADY_PAID = "BEEP_4003",
|
|
21
|
+
INVALID_PARAMETER = "BEEP_5001",
|
|
22
|
+
MISSING_PARAMETER = "BEEP_5002",
|
|
23
|
+
INVALID_AMOUNT = "BEEP_5003",
|
|
24
|
+
INVALID_TOKEN = "BEEP_5004",
|
|
25
|
+
RATE_LIMIT_EXCEEDED = "BEEP_6001",
|
|
26
|
+
UNKNOWN_ERROR = "BEEP_9999"
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for creating a BeepError
|
|
30
|
+
*/
|
|
31
|
+
export interface BeepErrorOptions {
|
|
32
|
+
code: BeepErrorCode;
|
|
33
|
+
statusCode?: number;
|
|
34
|
+
details?: Record<string, any>;
|
|
35
|
+
requestId?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Base error class for all BEEP SDK errors
|
|
39
|
+
* Provides structured error information for better debugging and handling
|
|
40
|
+
*/
|
|
41
|
+
export declare class BeepError extends Error {
|
|
42
|
+
readonly code: BeepErrorCode;
|
|
43
|
+
readonly statusCode?: number;
|
|
44
|
+
readonly details?: Record<string, any>;
|
|
45
|
+
readonly timestamp: Date;
|
|
46
|
+
readonly requestId?: string;
|
|
47
|
+
constructor(message: string, options: BeepErrorOptions);
|
|
48
|
+
/**
|
|
49
|
+
* Returns a user-friendly error message
|
|
50
|
+
*/
|
|
51
|
+
getUserMessage(): string;
|
|
52
|
+
/**
|
|
53
|
+
* Returns a JSON representation of the error for logging
|
|
54
|
+
*/
|
|
55
|
+
toJSON(): Record<string, any>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options for specialized error classes
|
|
59
|
+
*/
|
|
60
|
+
export interface SpecializedErrorOptions {
|
|
61
|
+
code?: BeepErrorCode;
|
|
62
|
+
details?: Record<string, any>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Authentication error - thrown when API key is invalid or missing
|
|
66
|
+
*/
|
|
67
|
+
export declare class BeepAuthenticationError extends BeepError {
|
|
68
|
+
constructor(message: string, options?: SpecializedErrorOptions);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validation error - thrown when request parameters are invalid
|
|
72
|
+
*/
|
|
73
|
+
export declare class BeepValidationError extends BeepError {
|
|
74
|
+
constructor(message: string, options?: SpecializedErrorOptions);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Payment error - thrown when payment operations fail
|
|
78
|
+
*/
|
|
79
|
+
export declare class BeepPaymentError extends BeepError {
|
|
80
|
+
constructor(message: string, options?: SpecializedErrorOptions);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Network error - thrown when network operations fail
|
|
84
|
+
*/
|
|
85
|
+
export declare class BeepNetworkError extends BeepError {
|
|
86
|
+
constructor(message: string, options?: SpecializedErrorOptions);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Options for rate limit error
|
|
90
|
+
*/
|
|
91
|
+
export interface RateLimitErrorOptions extends SpecializedErrorOptions {
|
|
92
|
+
retryAfter?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Rate limit error - thrown when API rate limits are exceeded
|
|
96
|
+
*/
|
|
97
|
+
export declare class BeepRateLimitError extends BeepError {
|
|
98
|
+
readonly retryAfter?: number;
|
|
99
|
+
constructor(message: string, options?: RateLimitErrorOptions);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Utility function to create appropriate error from axios error response
|
|
103
|
+
*/
|
|
104
|
+
export declare function createBeepErrorFromAxios(error: any): BeepError;
|
|
105
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oBAAY,aAAa;IAEvB,eAAe,cAAc;IAC7B,eAAe,cAAc;IAC7B,YAAY,cAAc;IAC1B,uBAAuB,cAAc;IAGrC,aAAa,cAAc;IAC3B,OAAO,cAAc;IACrB,YAAY,cAAc;IAG1B,cAAc,cAAc;IAC5B,eAAe,cAAc;IAC7B,iBAAiB,cAAc;IAC/B,kBAAkB,cAAc;IAChC,yBAAyB,cAAc;IAGvC,iBA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AQ,SAAS;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B;CAQnE;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B;CAOnE;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;IAC/C,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAExB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;CASjE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,CA4F9D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { PaymentsModule } from './modules/payments';
|
|
|
7
7
|
import { ProductsModule } from './modules/products';
|
|
8
8
|
import { WidgetModule } from './modules/widget';
|
|
9
9
|
import { UserModule } from './modules/user';
|
|
10
|
+
import { BeepDebugOptions } from './utils/debug';
|
|
10
11
|
/**
|
|
11
12
|
* Configuration options for initializing the BeepClient
|
|
12
13
|
*/
|
|
@@ -18,6 +19,8 @@ export interface BeepClientOptions {
|
|
|
18
19
|
* @default 'https://api.justbeep.it'
|
|
19
20
|
*/
|
|
20
21
|
serverUrl?: string;
|
|
22
|
+
/** Debug options for enhanced developer experience */
|
|
23
|
+
debug?: BeepDebugOptions;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* The main BEEP SDK client for server-side applications using secret API keys
|
|
@@ -43,7 +46,7 @@ export interface BeepClientOptions {
|
|
|
43
46
|
* // Create a payment request
|
|
44
47
|
* const payment = await beep.requestPayment({
|
|
45
48
|
* amount: 10.00,
|
|
46
|
-
* token: SupportedToken.
|
|
49
|
+
* token: SupportedToken.USDC,
|
|
47
50
|
* description: 'Premium subscription'
|
|
48
51
|
* });
|
|
49
52
|
*
|
|
@@ -57,6 +60,7 @@ export interface BeepClientOptions {
|
|
|
57
60
|
*/
|
|
58
61
|
export declare class BeepClient {
|
|
59
62
|
private client;
|
|
63
|
+
private debugger;
|
|
60
64
|
/** Access to product management functionality (server-side only) */
|
|
61
65
|
readonly products: ProductsModule;
|
|
62
66
|
/** Access to invoice management functionality (server-side only) */
|
|
@@ -90,7 +94,7 @@ export declare class BeepClient {
|
|
|
90
94
|
* const res = await beep.payments.createPayout({
|
|
91
95
|
* amount: '1000000', // 1.0 USDC with 6 decimals
|
|
92
96
|
* destinationWalletAddress: 'DEST_ADDRESS',
|
|
93
|
-
* chain: '
|
|
97
|
+
* chain: 'SUI',
|
|
94
98
|
* token: 'USDC',
|
|
95
99
|
* });
|
|
96
100
|
*/
|
|
@@ -179,4 +183,6 @@ export declare class BeepPublicClient {
|
|
|
179
183
|
constructor(options: BeepPublicClientOptions);
|
|
180
184
|
}
|
|
181
185
|
export type { PublicPaymentSessionRequest, PublicPaymentSessionResponse, PublicPaymentStatusResponse, EphemeralItem, } from './types/public';
|
|
186
|
+
export * from './errors';
|
|
187
|
+
export * from './types';
|
|
182
188
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH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