@beep-it/sdk-core 0.1.2-beta.3 → 0.1.2
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 +238 -228
- package/dist/index.d.ts +6 -98
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -298
- package/dist/index.mjs +10 -298
- package/dist/modules/payments.d.ts +11 -196
- package/dist/modules/payments.d.ts.map +1 -1
- package/dist/modules/widget.d.ts +0 -15
- package/dist/modules/widget.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/payment.d.ts +0 -211
- package/dist/types/payment.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,24 +19,14 @@ export interface BeepClientOptions {
|
|
|
19
19
|
serverUrl?: string;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* The main BEEP SDK client for
|
|
23
|
-
*
|
|
24
|
-
* **Use this client for:**
|
|
25
|
-
* - Server-side applications (Node.js, Express, Next.js API routes)
|
|
26
|
-
* - Backend services that can safely store secret API keys
|
|
27
|
-
* - Full payment processing capabilities including streaming payments
|
|
28
|
-
* - Administrative operations like product and invoice management
|
|
29
|
-
*
|
|
30
|
-
* **Security Note:** Never use BeepClient in client-side code (browsers) as it
|
|
31
|
-
* requires secret API keys that should not be exposed publicly.
|
|
22
|
+
* The main BEEP SDK client for interacting with the BEEP API
|
|
32
23
|
*
|
|
33
24
|
* @example
|
|
34
25
|
* ```typescript
|
|
35
26
|
* import { BeepClient, SupportedToken } from '@beep-it/sdk-core';
|
|
36
27
|
*
|
|
37
|
-
* // Only use this server-side with secret API keys
|
|
38
28
|
* const beep = new BeepClient({
|
|
39
|
-
* apiKey: '
|
|
29
|
+
* apiKey: 'your_api_key_here'
|
|
40
30
|
* });
|
|
41
31
|
*
|
|
42
32
|
* // Create a payment request
|
|
@@ -45,27 +35,15 @@ export interface BeepClientOptions {
|
|
|
45
35
|
* token: SupportedToken.USDT,
|
|
46
36
|
* description: 'Premium subscription'
|
|
47
37
|
* });
|
|
48
|
-
*
|
|
49
|
-
* // Issue streaming payments (BeepClient only)
|
|
50
|
-
* const streamingSession = await beep.payments.issuePayment({
|
|
51
|
-
* apiKey: 'your_secret_api_key',
|
|
52
|
-
* assetChunks: [{ assetId: 'video-content', quantity: 1 }],
|
|
53
|
-
* payingMerchantId: 'merchant_id'
|
|
54
|
-
* });
|
|
55
38
|
* ```
|
|
56
39
|
*/
|
|
57
40
|
export declare class BeepClient {
|
|
58
41
|
private client;
|
|
59
|
-
/** Access to product management functionality
|
|
42
|
+
/** Access to product management functionality */
|
|
60
43
|
readonly products: ProductsModule;
|
|
61
|
-
/** Access to invoice management functionality
|
|
44
|
+
/** Access to invoice management functionality */
|
|
62
45
|
readonly invoices: InvoicesModule;
|
|
63
|
-
/**
|
|
64
|
-
* Access to payment processing functionality including streaming payments
|
|
65
|
-
*
|
|
66
|
-
* **Note:** Streaming payment methods (issuePayment, startStreaming, pauseStreaming,
|
|
67
|
-
* stopStreaming) are only available with BeepClient and secret API keys.
|
|
68
|
-
*/
|
|
46
|
+
/** Access to payment processing functionality */
|
|
69
47
|
readonly payments: PaymentsModule;
|
|
70
48
|
/**
|
|
71
49
|
* Creates a new BEEP client instance
|
|
@@ -74,23 +52,6 @@ export declare class BeepClient {
|
|
|
74
52
|
* @throws {Error} When API key is missing or invalid
|
|
75
53
|
*/
|
|
76
54
|
constructor(options: BeepClientOptions);
|
|
77
|
-
/**
|
|
78
|
-
* Initiate a payout from your treasury wallet to an external address.
|
|
79
|
-
* Requires a secret API key (server-side only).
|
|
80
|
-
*
|
|
81
|
-
* Notes:
|
|
82
|
-
* - Do not pass walletId. The server derives the wallet based on your API key's merchant and requested chain.
|
|
83
|
-
* - amount must be in smallest units for the token (e.g., 6‑decimals USDC amount as an integer string).
|
|
84
|
-
* - This endpoint responds immediately with acceptance/rejection. Actual transfer executes asynchronously after funds are reserved.
|
|
85
|
-
*
|
|
86
|
-
* Example:
|
|
87
|
-
* const res = await beep.payments.createPayout({
|
|
88
|
-
* amount: '1000000', // 1.0 USDC with 6 decimals
|
|
89
|
-
* destinationWalletAddress: 'DEST_ADDRESS',
|
|
90
|
-
* chain: 'SOLANA',
|
|
91
|
-
* token: 'USDC',
|
|
92
|
-
* });
|
|
93
|
-
*/
|
|
94
55
|
/**
|
|
95
56
|
* Checks the health status of the BEEP API server
|
|
96
57
|
*
|
|
@@ -116,63 +77,10 @@ export interface BeepPublicClientOptions {
|
|
|
116
77
|
/** Optional server URL override */
|
|
117
78
|
serverUrl?: string;
|
|
118
79
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Browser-safe BEEP client for frontend applications using publishable keys
|
|
121
|
-
*
|
|
122
|
-
* **Use this client for:**
|
|
123
|
-
* - Frontend applications (React, Vue, vanilla JavaScript)
|
|
124
|
-
* - Browser-based code where secret keys cannot be safely stored
|
|
125
|
-
* - Widget-based payment sessions with ephemeral items
|
|
126
|
-
* - Client-side payment status polling
|
|
127
|
-
*
|
|
128
|
-
* **Limitations compared to BeepClient:**
|
|
129
|
-
* - Cannot access streaming payment methods (issuePayment, startStreaming, etc.)
|
|
130
|
-
* - Cannot manage products or invoices directly
|
|
131
|
-
* - Limited to public widget endpoints only
|
|
132
|
-
* - No access to administrative functions
|
|
133
|
-
*
|
|
134
|
-
* **Security:** Uses publishable keys which are safe to expose in client-side code.
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* import { BeepPublicClient } from '@beep-it/sdk-core';
|
|
139
|
-
*
|
|
140
|
-
* // Safe to use in browsers with publishable keys
|
|
141
|
-
* const publicBeep = new BeepPublicClient({
|
|
142
|
-
* publishableKey: 'beep_pk_your_publishable_key_here' // Safe to expose
|
|
143
|
-
* });
|
|
144
|
-
*
|
|
145
|
-
* // Create payment sessions with mixed assets
|
|
146
|
-
* const session = await publicBeep.widget.createPaymentSession({
|
|
147
|
-
* assets: [
|
|
148
|
-
* { assetId: 'existing-product-uuid', quantity: 1 },
|
|
149
|
-
* { name: 'Custom Item', price: '12.50', quantity: 1 }
|
|
150
|
-
* ],
|
|
151
|
-
* paymentLabel: 'My Store'
|
|
152
|
-
* });
|
|
153
|
-
*
|
|
154
|
-
* // Poll for payment completion
|
|
155
|
-
* const { paid } = await publicBeep.widget.waitForPaid({
|
|
156
|
-
* referenceKey: session.referenceKey
|
|
157
|
-
* });
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
80
|
export declare class BeepPublicClient {
|
|
161
81
|
private client;
|
|
162
|
-
/**
|
|
163
|
-
* Access to public widget endpoints for payment sessions
|
|
164
|
-
*
|
|
165
|
-
* **Note:** This is the only module available in BeepPublicClient.
|
|
166
|
-
* Streaming payments, product management, and administrative functions
|
|
167
|
-
* are only available in BeepClient with secret API keys.
|
|
168
|
-
*/
|
|
82
|
+
/** Access to public widget endpoints */
|
|
169
83
|
readonly widget: WidgetModule;
|
|
170
|
-
/**
|
|
171
|
-
* Creates a new BEEP public client instance for browser use
|
|
172
|
-
*
|
|
173
|
-
* @param options - Configuration options including publishable key
|
|
174
|
-
* @throws {Error} When publishable key is missing or invalid
|
|
175
|
-
*/
|
|
176
84
|
constructor(options: BeepPublicClientOptions);
|
|
177
85
|
}
|
|
178
86
|
export type { PublicPaymentSessionRequest, PublicPaymentSessionResponse, PublicPaymentStatusResponse, EphemeralItem, } from './types/public';
|
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;AAEhD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED
|
|
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;AAEhD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAgB;IAE9B,iDAAiD;IACjD,SAAgB,QAAQ,EAAE,cAAc,CAAC;IAEzC,iDAAiD;IACjD,SAAgB,QAAQ,EAAE,cAAc,CAAC;IAEzC,iDAAiD;IACjD,SAAgB,QAAQ,EAAE,cAAc,CAAC;IAEzC;;;;;OAKG;gBACS,OAAO,EAAE,iBAAiB;IAmBtC;;;;;;;;;;;OAWG;IACU,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;CAW5C;AAOD,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGpG,YAAY,EACV,0BAA0B,EAC1B,+BAA+B,EAC/B,oBAAoB,EACpB,OAAO,EACP,aAAa,EACb,SAAS,GACV,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,oBAAoB,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG3F,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3D,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAM5C,MAAM,WAAW,uBAAuB;IACtC,mEAAmE;IACnE,cAAc,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAgB;IAC9B,wCAAwC;IACxC,SAAgB,MAAM,EAAE,YAAY,CAAC;gBAEzB,OAAO,EAAE,uBAAuB;CAe7C;AAED,YAAY,EACV,2BAA2B,EAC3B,4BAA4B,EAC5B,2BAA2B,EAC3B,aAAa,GACd,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -237,116 +237,22 @@ var PaymentsModule = class {
|
|
|
237
237
|
this.client = client;
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
|
-
*
|
|
241
|
-
* Requires a secret API key (server-side only).
|
|
242
|
-
*
|
|
243
|
-
* Notes:
|
|
244
|
-
* - Do not pass walletId. The server derives the wallet based on your API key's merchant and requested chain.
|
|
245
|
-
* - amount must be in smallest units for the token (e.g., 6‑decimals USDC amount as an integer string).
|
|
246
|
-
* - This endpoint responds immediately with acceptance/rejection. Actual transfer executes asynchronously after funds are reserved.
|
|
247
|
-
*
|
|
248
|
-
* Example:
|
|
249
|
-
* const res = await beep.payments.createPayout({
|
|
250
|
-
* amount: '1000000', // 1.0 USDC with 6 decimals
|
|
251
|
-
* destinationWalletAddress: 'DEST_ADDRESS',
|
|
252
|
-
* chain: 'SOLANA',
|
|
253
|
-
* token: 'USDC',
|
|
254
|
-
* });
|
|
255
|
-
*/
|
|
256
|
-
async createPayout(params) {
|
|
257
|
-
const { data } = await this.client.post("/v1/payouts", params);
|
|
258
|
-
return data;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Waits for a payment to complete by polling the 402 endpoint using a reference key.
|
|
262
|
-
* The request is considered complete when the response no longer includes `referenceKey`.
|
|
263
|
-
*/
|
|
264
|
-
async waitForPaymentCompletion(options) {
|
|
265
|
-
const baseIntervalMs = options.intervalMs ?? 15e3;
|
|
266
|
-
let currentIntervalMs = baseIntervalMs;
|
|
267
|
-
const timeoutMs = options.timeoutMs ?? 5 * 6e4;
|
|
268
|
-
const deadline = Date.now() + timeoutMs;
|
|
269
|
-
let last = null;
|
|
270
|
-
while (true) {
|
|
271
|
-
if (options.signal?.aborted) {
|
|
272
|
-
return { paid: false, last };
|
|
273
|
-
}
|
|
274
|
-
try {
|
|
275
|
-
try {
|
|
276
|
-
const resp = await this.client.post(
|
|
277
|
-
`/v1/payment/request-payment`,
|
|
278
|
-
{
|
|
279
|
-
assets: options.assets,
|
|
280
|
-
paymentReference: options.paymentReference,
|
|
281
|
-
paymentLabel: options.paymentLabel,
|
|
282
|
-
generateQrCode: false
|
|
283
|
-
}
|
|
284
|
-
);
|
|
285
|
-
last = resp.data.data;
|
|
286
|
-
} catch (err) {
|
|
287
|
-
const ax = err;
|
|
288
|
-
const status = ax.response?.status;
|
|
289
|
-
if (status === 402) {
|
|
290
|
-
last = ax.response?.data?.data ?? null;
|
|
291
|
-
} else {
|
|
292
|
-
if (status && [400, 401, 403, 404, 422].includes(status)) {
|
|
293
|
-
options.onError?.(err);
|
|
294
|
-
return { paid: false, last };
|
|
295
|
-
}
|
|
296
|
-
options.onError?.(err);
|
|
297
|
-
currentIntervalMs = Math.min(Math.ceil(currentIntervalMs * 1.5), 6e4);
|
|
298
|
-
last = last ?? null;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
options.onUpdate?.(last);
|
|
302
|
-
if (last?.status === "expired" /* EXPIRED */ || last?.status === "failed" /* FAILED */) {
|
|
303
|
-
return { paid: false, last };
|
|
304
|
-
}
|
|
305
|
-
const paid = !last?.referenceKey;
|
|
306
|
-
if (paid) return { paid: true, last };
|
|
307
|
-
currentIntervalMs = baseIntervalMs;
|
|
308
|
-
} catch (e) {
|
|
309
|
-
options.onError?.(e);
|
|
310
|
-
currentIntervalMs = Math.min(Math.ceil(currentIntervalMs * 1.5), 6e4);
|
|
311
|
-
}
|
|
312
|
-
if (Date.now() >= deadline) return { paid: false, last };
|
|
313
|
-
await new Promise((r) => setTimeout(r, currentIntervalMs));
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Creates a payment request for purchasing assets using a two‑phase 402 flow.
|
|
318
|
-
*
|
|
319
|
-
* Phase 1 – Request payment (no paymentReference):
|
|
320
|
-
* - Server responds with HTTP 402 Payment Required and a payload containing:
|
|
321
|
-
* referenceKey, paymentUrl (Solana Pay), optional qrCode, amount, expiresAt, status.
|
|
322
|
-
* - The SDK normalizes this by returning the payload (even when status code is 402).
|
|
323
|
-
* - The caller must instruct the user to pay via their wallet using paymentUrl/qrCode.
|
|
324
|
-
*
|
|
325
|
-
* Phase 2 – Check/complete payment (with paymentReference):
|
|
326
|
-
* - Call again with the same assets and paymentReference returned in Phase 1.
|
|
327
|
-
* - If payment is still pending, server may again provide the referenceKey (or return 402).
|
|
328
|
-
* - When payment is complete, server will return success (no referenceKey required). In this SDK
|
|
329
|
-
* we consider the payment complete when the response does NOT include referenceKey.
|
|
240
|
+
* Creates a payment request for purchasing assets
|
|
330
241
|
*
|
|
331
242
|
* @param input - Parameters for the asset purchase request
|
|
332
|
-
* @returns
|
|
243
|
+
* @returns Promise that resolves to payment request data, or null if validation fails
|
|
333
244
|
*
|
|
334
245
|
* @example
|
|
335
|
-
*
|
|
336
|
-
* const
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* paymentLabel: 'My Store'
|
|
246
|
+
* ```typescript
|
|
247
|
+
* const payment = await beep.payments.requestAndPurchaseAsset({
|
|
248
|
+
* paymentReference: 'premium_subscription_123',
|
|
249
|
+
* assetIds: ['asset_1', 'asset_2']
|
|
340
250
|
* });
|
|
341
|
-
* // Show req.paymentUrl/req.qrCode to user; req.referenceKey identifies this payment.
|
|
342
251
|
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
* generateQrCode: false
|
|
348
|
-
* });
|
|
349
|
-
* const isPaid = !check?.referenceKey; // When no referenceKey is returned, payment is complete
|
|
252
|
+
* if (payment) {
|
|
253
|
+
* console.log('Payment URL:', payment.paymentUrl);
|
|
254
|
+
* }
|
|
255
|
+
* ```
|
|
350
256
|
*/
|
|
351
257
|
async requestAndPurchaseAsset(input) {
|
|
352
258
|
if (!input.paymentReference && !input.assets?.length) {
|
|
@@ -412,143 +318,6 @@ var PaymentsModule = class {
|
|
|
412
318
|
throw new Error(`Failed to sign solana transaction: ${errorMessage}`);
|
|
413
319
|
}
|
|
414
320
|
}
|
|
415
|
-
// --- Streaming Payment Methods ---
|
|
416
|
-
// Note: These methods are ONLY available with BeepClient (secret API keys)
|
|
417
|
-
// They do NOT work with BeepPublicClient (publishable keys)
|
|
418
|
-
/**
|
|
419
|
-
* Issues a payment request for streaming charges with specified asset chunks
|
|
420
|
-
*
|
|
421
|
-
* Creates a new streaming payment session that can be started, paused, and stopped.
|
|
422
|
-
* This is the first step in setting up automatic billing for ongoing services or
|
|
423
|
-
* consumption-based pricing.
|
|
424
|
-
*
|
|
425
|
-
* **Important Security Note**: This method requires a secret API key and is only
|
|
426
|
-
* available when using `BeepClient`. It will NOT work with `BeepPublicClient` or
|
|
427
|
-
* publishable keys for security reasons.
|
|
428
|
-
*
|
|
429
|
-
* @param payload - Payment request details including assets and merchant information
|
|
430
|
-
* @returns Promise resolving to payment session identifiers
|
|
431
|
-
* @throws {Error} When the request fails or authentication is invalid
|
|
432
|
-
*
|
|
433
|
-
* @example
|
|
434
|
-
* ```typescript
|
|
435
|
-
* // Only works with BeepClient (server-side)
|
|
436
|
-
* const beep = new BeepClient({ apiKey: 'your_secret_api_key' });
|
|
437
|
-
*
|
|
438
|
-
* const paymentSession = await beep.payments.issuePayment({
|
|
439
|
-
* apiKey: 'your_secret_api_key',
|
|
440
|
-
* assetChunks: [
|
|
441
|
-
* { assetId: 'video-streaming-uuid', quantity: 1 },
|
|
442
|
-
* { assetId: 'api-calls-uuid', quantity: 100 }
|
|
443
|
-
* ],
|
|
444
|
-
* payingMerchantId: 'merchant_who_will_be_charged',
|
|
445
|
-
* invoiceId: 'optional_existing_invoice_uuid'
|
|
446
|
-
* });
|
|
447
|
-
*
|
|
448
|
-
* console.log('Payment session created:', paymentSession.referenceKey);
|
|
449
|
-
* console.log('Invoice ID for management:', paymentSession.invoiceId);
|
|
450
|
-
* ```
|
|
451
|
-
*/
|
|
452
|
-
async issuePayment(payload) {
|
|
453
|
-
const response = await this.client.post(
|
|
454
|
-
"/v1/invoices/issue-payment",
|
|
455
|
-
payload
|
|
456
|
-
);
|
|
457
|
-
return response.data;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Starts an active streaming session and begins charging for asset usage
|
|
461
|
-
*
|
|
462
|
-
* Activates a previously issued payment request and begins billing the specified
|
|
463
|
-
* merchant according to the streaming payment configuration. Once started, charges
|
|
464
|
-
* will accumulate based on actual usage.
|
|
465
|
-
*
|
|
466
|
-
* **Important Security Note**: This method requires a secret API key and is only
|
|
467
|
-
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
468
|
-
*
|
|
469
|
-
* @param payload - Streaming session start details
|
|
470
|
-
* @returns Promise resolving to confirmation of the started session
|
|
471
|
-
* @throws {Error} When the invoice is invalid or already active
|
|
472
|
-
*
|
|
473
|
-
* @example
|
|
474
|
-
* ```typescript
|
|
475
|
-
* // Start billing for the streaming session
|
|
476
|
-
* const result = await beep.payments.startStreaming({
|
|
477
|
-
* apiKey: 'your_secret_api_key',
|
|
478
|
-
* invoiceId: 'invoice_uuid_from_issuePayment'
|
|
479
|
-
* });
|
|
480
|
-
*
|
|
481
|
-
* console.log('Streaming started for invoice:', result.invoiceId);
|
|
482
|
-
* // Charges will now accumulate based on usage
|
|
483
|
-
* ```
|
|
484
|
-
*/
|
|
485
|
-
async startStreaming(payload) {
|
|
486
|
-
const response = await this.client.post("/v1/invoices/start", payload);
|
|
487
|
-
return response.data;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Temporarily pauses an active streaming session without terminating it
|
|
491
|
-
*
|
|
492
|
-
* Halts billing for a streaming session while keeping the session alive for later resumption.
|
|
493
|
-
* This is useful for temporary service interruptions or when you want to control billing
|
|
494
|
-
* periods precisely.
|
|
495
|
-
*
|
|
496
|
-
* **Important Security Note**: This method requires a secret API key and is only
|
|
497
|
-
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
498
|
-
*
|
|
499
|
-
* @param payload - Streaming session pause details
|
|
500
|
-
* @returns Promise resolving to pause operation result
|
|
501
|
-
* @throws {Error} When the invoice is not in a valid state for pausing
|
|
502
|
-
*
|
|
503
|
-
* @example
|
|
504
|
-
* ```typescript
|
|
505
|
-
* // Temporarily pause billing (can be resumed later)
|
|
506
|
-
* const result = await beep.payments.pauseStreaming({
|
|
507
|
-
* apiKey: 'your_secret_api_key',
|
|
508
|
-
* invoiceId: 'active_streaming_invoice_uuid'
|
|
509
|
-
* });
|
|
510
|
-
*
|
|
511
|
-
* if (result.success) {
|
|
512
|
-
* console.log('Streaming paused - no new charges will accumulate');
|
|
513
|
-
* // Use startStreaming() again to resume
|
|
514
|
-
* }
|
|
515
|
-
* ```
|
|
516
|
-
*/
|
|
517
|
-
async pauseStreaming(payload) {
|
|
518
|
-
const response = await this.client.post("/v1/invoices/pause", payload);
|
|
519
|
-
return response.data;
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Permanently stops a streaming session and finalizes all charges
|
|
523
|
-
*
|
|
524
|
-
* Terminates a streaming session completely, finalizing all accumulated charges.
|
|
525
|
-
* This action cannot be undone - the session cannot be restarted after stopping.
|
|
526
|
-
* Use this when you're completely finished with a service or want to close out billing.
|
|
527
|
-
*
|
|
528
|
-
* **Important Security Note**: This method requires a secret API key and is only
|
|
529
|
-
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
530
|
-
*
|
|
531
|
-
* @param payload - Streaming session stop details
|
|
532
|
-
* @returns Promise resolving to final session details and reference keys
|
|
533
|
-
* @throws {Error} When the invoice cannot be stopped or doesn't exist
|
|
534
|
-
*
|
|
535
|
-
* @example
|
|
536
|
-
* ```typescript
|
|
537
|
-
* // Permanently stop and finalize the streaming session
|
|
538
|
-
* const result = await beep.payments.stopStreaming({
|
|
539
|
-
* apiKey: 'your_secret_api_key',
|
|
540
|
-
* invoiceId: 'active_streaming_invoice_uuid'
|
|
541
|
-
* });
|
|
542
|
-
*
|
|
543
|
-
* console.log('Session permanently stopped:', result.invoiceId);
|
|
544
|
-
* console.log('All reference keys for records:', result.referenceKeys);
|
|
545
|
-
* // Session cannot be restarted after this point
|
|
546
|
-
* ```
|
|
547
|
-
*/
|
|
548
|
-
async stopStreaming(payload) {
|
|
549
|
-
const response = await this.client.post("/v1/invoices/stop", payload);
|
|
550
|
-
return response.data;
|
|
551
|
-
}
|
|
552
321
|
};
|
|
553
322
|
|
|
554
323
|
// src/modules/products.ts
|
|
@@ -717,39 +486,6 @@ var WidgetModule = class {
|
|
|
717
486
|
);
|
|
718
487
|
return res.data;
|
|
719
488
|
}
|
|
720
|
-
/**
|
|
721
|
-
* Waits for payment completion by polling the public status endpoint until paid or timeout.
|
|
722
|
-
* Designed for browser/public usage (no secret keys).
|
|
723
|
-
*/
|
|
724
|
-
async waitForPaid(options) {
|
|
725
|
-
const baseIntervalMs = options.intervalMs ?? 15e3;
|
|
726
|
-
let currentIntervalMs = baseIntervalMs;
|
|
727
|
-
const timeoutMs = options.timeoutMs ?? 5 * 6e4;
|
|
728
|
-
const deadline = Date.now() + timeoutMs;
|
|
729
|
-
let last;
|
|
730
|
-
while (true) {
|
|
731
|
-
if (options.signal?.aborted) return { paid: false, last };
|
|
732
|
-
try {
|
|
733
|
-
const res = await this.client.get(
|
|
734
|
-
`/v1/widget/payment-status/${encodeURIComponent(options.referenceKey)}`
|
|
735
|
-
);
|
|
736
|
-
last = res.data;
|
|
737
|
-
options.onUpdate?.(last);
|
|
738
|
-
if (last?.paid) return { paid: true, last };
|
|
739
|
-
currentIntervalMs = baseIntervalMs;
|
|
740
|
-
} catch (err) {
|
|
741
|
-
options.onError?.(err);
|
|
742
|
-
const ax = err;
|
|
743
|
-
const status = ax.response?.status;
|
|
744
|
-
if (status && [400, 401, 403, 404, 422].includes(status)) {
|
|
745
|
-
return { paid: false, last };
|
|
746
|
-
}
|
|
747
|
-
currentIntervalMs = Math.min(Math.ceil(currentIntervalMs * 1.5), 6e4);
|
|
748
|
-
}
|
|
749
|
-
if (Date.now() >= deadline) return { paid: false, last };
|
|
750
|
-
await new Promise((r) => setTimeout(r, currentIntervalMs));
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
489
|
};
|
|
754
490
|
|
|
755
491
|
// src/index.ts
|
|
@@ -776,24 +512,6 @@ var BeepClient = class {
|
|
|
776
512
|
this.invoices = new InvoicesModule(this.client);
|
|
777
513
|
this.payments = new PaymentsModule(this.client);
|
|
778
514
|
}
|
|
779
|
-
/**
|
|
780
|
-
* Initiate a payout from your treasury wallet to an external address.
|
|
781
|
-
* Requires a secret API key (server-side only).
|
|
782
|
-
*
|
|
783
|
-
* Notes:
|
|
784
|
-
* - Do not pass walletId. The server derives the wallet based on your API key's merchant and requested chain.
|
|
785
|
-
* - amount must be in smallest units for the token (e.g., 6‑decimals USDC amount as an integer string).
|
|
786
|
-
* - This endpoint responds immediately with acceptance/rejection. Actual transfer executes asynchronously after funds are reserved.
|
|
787
|
-
*
|
|
788
|
-
* Example:
|
|
789
|
-
* const res = await beep.payments.createPayout({
|
|
790
|
-
* amount: '1000000', // 1.0 USDC with 6 decimals
|
|
791
|
-
* destinationWalletAddress: 'DEST_ADDRESS',
|
|
792
|
-
* chain: 'SOLANA',
|
|
793
|
-
* token: 'USDC',
|
|
794
|
-
* });
|
|
795
|
-
*/
|
|
796
|
-
// Deprecated: use beep.payments.createPayout()
|
|
797
515
|
/**
|
|
798
516
|
* Checks the health status of the BEEP API server
|
|
799
517
|
*
|
|
@@ -819,12 +537,6 @@ var BeepClient = class {
|
|
|
819
537
|
}
|
|
820
538
|
};
|
|
821
539
|
var BeepPublicClient = class {
|
|
822
|
-
/**
|
|
823
|
-
* Creates a new BEEP public client instance for browser use
|
|
824
|
-
*
|
|
825
|
-
* @param options - Configuration options including publishable key
|
|
826
|
-
* @throws {Error} When publishable key is missing or invalid
|
|
827
|
-
*/
|
|
828
540
|
constructor(options) {
|
|
829
541
|
if (!options.publishableKey) {
|
|
830
542
|
throw new Error("publishableKey is required to initialize BeepPublicClient");
|