@everestan/protocolbanks-sdk 0.0.0-stage → 0.2.1

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 ADDED
@@ -0,0 +1,683 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/payment-link.ts
9
+ var PaymentLink = class {
10
+ constructor(config) {
11
+ this.config = config;
12
+ }
13
+ /**
14
+ * Create a new payment link
15
+ */
16
+ async create(options) {
17
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
18
+ const response = await fetch(`${baseUrl}/api/acquiring/payment-links`, {
19
+ method: "POST",
20
+ headers: {
21
+ "Content-Type": "application/json",
22
+ "X-API-Key": this.config.apiKey
23
+ },
24
+ body: JSON.stringify({
25
+ title: options.title,
26
+ description: options.description,
27
+ amount: options.amount,
28
+ token: options.token || this.config.defaultToken || "USDC",
29
+ recipientAddress: options.recipientAddress,
30
+ amountType: options.amount ? "fixed" : "customer_input",
31
+ redirectUrl: options.redirectUrl,
32
+ expiresAt: options.expiresIn ? new Date(Date.now() + options.expiresIn * 1e3).toISOString() : void 0,
33
+ brandColor: options.branding?.color,
34
+ logoUrl: options.branding?.logoUrl,
35
+ distributeAsset: !!options.assetDistribution,
36
+ assetType: options.assetDistribution?.type,
37
+ assetContractAddress: options.assetDistribution?.contractAddress,
38
+ assetTokenId: options.assetDistribution?.tokenId,
39
+ assetAmount: options.assetDistribution?.amount,
40
+ metadata: options.metadata
41
+ })
42
+ });
43
+ const data = await response.json();
44
+ if (!response.ok || !data.success) {
45
+ return {
46
+ success: false,
47
+ id: "",
48
+ paymentUrl: "",
49
+ status: "failed",
50
+ error: data.error || "Failed to create payment link"
51
+ };
52
+ }
53
+ return {
54
+ success: true,
55
+ id: data.link.link_id,
56
+ paymentUrl: data.paymentUrl,
57
+ shortUrl: data.shortUrl,
58
+ qrCodeData: data.paymentUrl,
59
+ status: "pending"
60
+ };
61
+ }
62
+ /**
63
+ * Get payment link details
64
+ */
65
+ async get(linkId) {
66
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
67
+ const response = await fetch(
68
+ `${baseUrl}/api/acquiring/payment-links?linkId=${linkId}`,
69
+ {
70
+ headers: {
71
+ "X-API-Key": this.config.apiKey
72
+ }
73
+ }
74
+ );
75
+ return response.json();
76
+ }
77
+ /**
78
+ * List all payment links
79
+ */
80
+ async list(merchantId) {
81
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
82
+ const params = merchantId ? `?merchantId=${merchantId}` : "";
83
+ const response = await fetch(
84
+ `${baseUrl}/api/acquiring/payment-links${params}`,
85
+ {
86
+ headers: {
87
+ "X-API-Key": this.config.apiKey
88
+ }
89
+ }
90
+ );
91
+ return response.json();
92
+ }
93
+ /**
94
+ * Update a payment link
95
+ */
96
+ async update(linkId, updates) {
97
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
98
+ const response = await fetch(`${baseUrl}/api/acquiring/payment-links`, {
99
+ method: "PATCH",
100
+ headers: {
101
+ "Content-Type": "application/json",
102
+ "X-API-Key": this.config.apiKey
103
+ },
104
+ body: JSON.stringify({ linkId, ...updates })
105
+ });
106
+ return response.json();
107
+ }
108
+ /**
109
+ * Delete a payment link
110
+ */
111
+ async delete(linkId) {
112
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
113
+ const response = await fetch(
114
+ `${baseUrl}/api/acquiring/payment-links?linkId=${linkId}`,
115
+ {
116
+ method: "DELETE",
117
+ headers: {
118
+ "X-API-Key": this.config.apiKey
119
+ }
120
+ }
121
+ );
122
+ return response.json();
123
+ }
124
+ };
125
+
126
+ // src/invoice.ts
127
+ var Invoice = class {
128
+ constructor(config) {
129
+ this.config = config;
130
+ }
131
+ /**
132
+ * Create a new invoice
133
+ */
134
+ async create(options) {
135
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
136
+ const response = await fetch(`${baseUrl}/api/invoice`, {
137
+ method: "POST",
138
+ headers: {
139
+ "Content-Type": "application/json",
140
+ "X-API-Key": this.config.apiKey
141
+ },
142
+ body: JSON.stringify({
143
+ recipientAddress: options.recipientAddress,
144
+ amount: options.amount,
145
+ token: options.token || this.config.defaultToken || "USDC",
146
+ description: options.description,
147
+ merchantName: options.merchantName,
148
+ amountFiat: options.amountFiat,
149
+ fiatCurrency: options.fiatCurrency,
150
+ expiresIn: (options.expiresInHours || 24) * 60 * 60 * 1e3,
151
+ metadata: {
152
+ ...options.metadata,
153
+ customerName: options.customer?.name,
154
+ customerEmail: options.customer?.email
155
+ }
156
+ })
157
+ });
158
+ const data = await response.json();
159
+ if (!response.ok || !data.success && !data.invoice) {
160
+ return {
161
+ success: false,
162
+ id: "",
163
+ paymentUrl: "",
164
+ status: "failed",
165
+ error: data.error || "Failed to create invoice"
166
+ };
167
+ }
168
+ return {
169
+ success: true,
170
+ id: data.invoice.invoice_id,
171
+ paymentUrl: data.paymentLink,
172
+ qrCodeData: data.qrCodeData,
173
+ status: "pending"
174
+ };
175
+ }
176
+ /**
177
+ * Get invoice details
178
+ */
179
+ async get(invoiceId, signature) {
180
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
181
+ const params = new URLSearchParams({ id: invoiceId });
182
+ if (signature) params.set("sig", signature);
183
+ const response = await fetch(`${baseUrl}/api/invoice?${params.toString()}`, {
184
+ headers: {
185
+ "X-API-Key": this.config.apiKey
186
+ }
187
+ });
188
+ return response.json();
189
+ }
190
+ /**
191
+ * Update invoice status (e.g., after payment)
192
+ */
193
+ async updateStatus(invoiceId, status, txHash, paidBy) {
194
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
195
+ const response = await fetch(`${baseUrl}/api/invoice`, {
196
+ method: "PATCH",
197
+ headers: {
198
+ "Content-Type": "application/json",
199
+ "X-API-Key": this.config.apiKey
200
+ },
201
+ body: JSON.stringify({ invoiceId, status, txHash, paidBy })
202
+ });
203
+ return response.json();
204
+ }
205
+ /**
206
+ * Get printable invoice export URL
207
+ */
208
+ getExportUrl(invoiceId, signature) {
209
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
210
+ const params = new URLSearchParams({ id: invoiceId });
211
+ if (signature) params.set("sig", signature);
212
+ return `${baseUrl}/api/invoice/export?${params.toString()}`;
213
+ }
214
+ /**
215
+ * List invoices for a merchant
216
+ */
217
+ async list(options) {
218
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
219
+ const params = new URLSearchParams();
220
+ if (options?.status) params.set("status", options.status);
221
+ if (options?.limit) params.set("limit", options.limit.toString());
222
+ if (options?.offset) params.set("offset", options.offset.toString());
223
+ const response = await fetch(`${baseUrl}/api/invoice/list?${params.toString()}`, {
224
+ headers: {
225
+ "X-API-Key": this.config.apiKey
226
+ }
227
+ });
228
+ return response.json();
229
+ }
230
+ };
231
+
232
+ // src/checkout.ts
233
+ var Checkout = class {
234
+ constructor(config) {
235
+ this.config = config;
236
+ }
237
+ /**
238
+ * Create a new checkout order
239
+ */
240
+ async create(options) {
241
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
242
+ const response = await fetch(`${baseUrl}/api/acquiring/orders`, {
243
+ method: "POST",
244
+ headers: {
245
+ "Content-Type": "application/json",
246
+ "X-API-Key": this.config.apiKey
247
+ },
248
+ body: JSON.stringify({
249
+ merchant_id: options.merchantId,
250
+ amount: parseFloat(options.amount),
251
+ currency: options.currency || "USD",
252
+ token: options.token || this.config.defaultToken || "USDC",
253
+ notify_url: options.notifyUrl,
254
+ return_url: options.returnUrl,
255
+ metadata: options.metadata
256
+ })
257
+ });
258
+ const data = await response.json();
259
+ if (!response.ok || !data.success) {
260
+ return {
261
+ success: false,
262
+ id: "",
263
+ paymentUrl: "",
264
+ status: "failed",
265
+ error: data.error || "Failed to create checkout"
266
+ };
267
+ }
268
+ const checkoutUrl = `${baseUrl}/checkout?order=${data.order.order_no}`;
269
+ return {
270
+ success: true,
271
+ id: data.order.order_no,
272
+ paymentUrl: checkoutUrl,
273
+ qrCodeData: checkoutUrl,
274
+ status: "pending"
275
+ };
276
+ }
277
+ /**
278
+ * Get order status
279
+ */
280
+ async getStatus(orderNo) {
281
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
282
+ const response = await fetch(`${baseUrl}/api/acquiring/orders/${orderNo}`, {
283
+ headers: {
284
+ "X-API-Key": this.config.apiKey
285
+ }
286
+ });
287
+ return response.json();
288
+ }
289
+ /**
290
+ * List orders for a merchant
291
+ */
292
+ async listOrders(merchantId, options) {
293
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
294
+ const params = new URLSearchParams();
295
+ if (merchantId) params.set("merchantId", merchantId);
296
+ if (options?.limit) params.set("limit", options.limit.toString());
297
+ if (options?.offset) params.set("offset", options.offset.toString());
298
+ const response = await fetch(
299
+ `${baseUrl}/api/acquiring/orders?${params.toString()}`,
300
+ {
301
+ headers: {
302
+ "X-API-Key": this.config.apiKey
303
+ }
304
+ }
305
+ );
306
+ return response.json();
307
+ }
308
+ /**
309
+ * Open checkout in a popup window
310
+ */
311
+ openPopup(options) {
312
+ return new Promise(async (resolve, reject) => {
313
+ try {
314
+ const result = await this.create(options);
315
+ if (!result.success) {
316
+ reject(new Error(result.error || "Failed to create checkout"));
317
+ return;
318
+ }
319
+ const width = 450;
320
+ const height = 700;
321
+ const left = window.screenX + (window.outerWidth - width) / 2;
322
+ const top = window.screenY + (window.outerHeight - height) / 2;
323
+ const popup = window.open(
324
+ result.paymentUrl,
325
+ "protocol-banks-checkout",
326
+ `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
327
+ );
328
+ if (!popup) {
329
+ reject(new Error("Popup blocked. Please allow popups for this site."));
330
+ return;
331
+ }
332
+ const interval = setInterval(() => {
333
+ if (popup.closed) {
334
+ clearInterval(interval);
335
+ this.getStatus(result.id).then((status) => {
336
+ if (status.order?.status === "paid") {
337
+ resolve({
338
+ ...result,
339
+ status: "paid",
340
+ txHash: status.order.tx_hash
341
+ });
342
+ } else {
343
+ resolve({
344
+ ...result,
345
+ status: "cancelled"
346
+ });
347
+ }
348
+ }).catch(() => {
349
+ resolve({ ...result, status: "cancelled" });
350
+ });
351
+ }
352
+ }, 500);
353
+ } catch (error) {
354
+ reject(error);
355
+ }
356
+ });
357
+ }
358
+ };
359
+
360
+ // src/webhook.ts
361
+ var Webhook = class {
362
+ constructor(config) {
363
+ this.config = config;
364
+ }
365
+ /**
366
+ * Verify an incoming webhook signature (server-side only).
367
+ *
368
+ * Use this in your webhook handler to validate that the request
369
+ * came from Protocol Banks.
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * const pb = new ProtocolBanks({ apiKey: 'pk_...' });
374
+ *
375
+ * app.post('/webhook', (req, res) => {
376
+ * const signature = req.headers['x-webhook-signature'];
377
+ * const timestamp = req.headers['x-webhook-timestamp'];
378
+ * const body = JSON.stringify(req.body);
379
+ *
380
+ * if (!pb.webhooks.verify(body, signature, 'whsec_...')) {
381
+ * return res.status(401).send('Invalid signature');
382
+ * }
383
+ *
384
+ * // Process event
385
+ * const event = req.body;
386
+ * console.log('Received event:', event.event);
387
+ * res.status(200).send('OK');
388
+ * });
389
+ * ```
390
+ */
391
+ verify(payload, signature, secret) {
392
+ try {
393
+ const crypto2 = __require("crypto");
394
+ const expectedSignature = crypto2.createHmac("sha256", secret).update(payload).digest("hex");
395
+ if (signature.length !== expectedSignature.length) {
396
+ return false;
397
+ }
398
+ const sigBuffer = Buffer.from(signature, "hex");
399
+ const expectedBuffer = Buffer.from(expectedSignature, "hex");
400
+ if (sigBuffer.length !== expectedBuffer.length) {
401
+ return false;
402
+ }
403
+ return crypto2.timingSafeEqual(sigBuffer, expectedBuffer);
404
+ } catch {
405
+ return this.verifyBrowser(payload, signature, secret);
406
+ }
407
+ }
408
+ /**
409
+ * Browser-compatible signature verification using Web Crypto API
410
+ */
411
+ verifyBrowser(payload, signature, secret) {
412
+ console.warn(
413
+ "Webhook verification in browser is not recommended. Use server-side verification."
414
+ );
415
+ return false;
416
+ }
417
+ /**
418
+ * Async signature verification using Web Crypto API (works in browser and Node.js)
419
+ */
420
+ async verifyAsync(payload, signature, secret) {
421
+ try {
422
+ const crypto2 = __require("crypto");
423
+ const expectedSignature = crypto2.createHmac("sha256", secret).update(payload).digest("hex");
424
+ const sigBuffer = Buffer.from(signature, "hex");
425
+ const expectedBuffer = Buffer.from(expectedSignature, "hex");
426
+ if (sigBuffer.length !== expectedBuffer.length) {
427
+ return false;
428
+ }
429
+ return crypto2.timingSafeEqual(sigBuffer, expectedBuffer);
430
+ } catch {
431
+ const encoder = new TextEncoder();
432
+ const keyData = encoder.encode(secret);
433
+ const payloadData = encoder.encode(payload);
434
+ const key = await crypto.subtle.importKey(
435
+ "raw",
436
+ keyData,
437
+ { name: "HMAC", hash: "SHA-256" },
438
+ false,
439
+ ["sign"]
440
+ );
441
+ const signatureBuffer = await crypto.subtle.sign(
442
+ "HMAC",
443
+ key,
444
+ payloadData
445
+ );
446
+ const expectedHex = Array.from(new Uint8Array(signatureBuffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
447
+ if (signature.length !== expectedHex.length) {
448
+ return false;
449
+ }
450
+ let result = 0;
451
+ for (let i = 0; i < signature.length; i++) {
452
+ result |= signature.charCodeAt(i) ^ expectedHex.charCodeAt(i);
453
+ }
454
+ return result === 0;
455
+ }
456
+ }
457
+ /**
458
+ * Construct a webhook event from a raw request
459
+ */
460
+ constructEvent(payload, signature, secret) {
461
+ if (!this.verify(payload, signature, secret)) {
462
+ throw new Error("Invalid webhook signature");
463
+ }
464
+ const event = JSON.parse(payload);
465
+ return event;
466
+ }
467
+ /**
468
+ * Create a new webhook subscription
469
+ */
470
+ async create(options) {
471
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
472
+ const response = await fetch(`${baseUrl}/api/webhooks`, {
473
+ method: "POST",
474
+ headers: {
475
+ "Content-Type": "application/json",
476
+ "X-API-Key": this.config.apiKey
477
+ },
478
+ body: JSON.stringify(options)
479
+ });
480
+ return response.json();
481
+ }
482
+ /**
483
+ * List webhook subscriptions
484
+ */
485
+ async list() {
486
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
487
+ const response = await fetch(`${baseUrl}/api/webhooks`, {
488
+ headers: {
489
+ "X-API-Key": this.config.apiKey
490
+ }
491
+ });
492
+ return response.json();
493
+ }
494
+ /**
495
+ * Delete a webhook subscription
496
+ */
497
+ async delete(webhookId) {
498
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
499
+ const response = await fetch(`${baseUrl}/api/webhooks/${webhookId}`, {
500
+ method: "DELETE",
501
+ headers: {
502
+ "X-API-Key": this.config.apiKey
503
+ }
504
+ });
505
+ return response.json();
506
+ }
507
+ /**
508
+ * Get recent webhook deliveries
509
+ */
510
+ async getDeliveries(webhookId) {
511
+ const baseUrl = this.config.baseUrl || "https://protocol-banks.vercel.app";
512
+ const response = await fetch(
513
+ `${baseUrl}/api/webhooks/${webhookId}/deliveries`,
514
+ {
515
+ headers: {
516
+ "X-API-Key": this.config.apiKey
517
+ }
518
+ }
519
+ );
520
+ return response.json();
521
+ }
522
+ };
523
+
524
+ // src/agent.ts
525
+ var Agent = class {
526
+ constructor(config) {
527
+ this.config = config;
528
+ }
529
+ baseUrl() {
530
+ return this.config.baseUrl || "https://protocolbanks.com";
531
+ }
532
+ async call(method, path, body) {
533
+ const res = await fetch(`${this.baseUrl()}/api/v1/agent${path}`, {
534
+ method,
535
+ headers: {
536
+ ...body === void 0 ? {} : { "Content-Type": "application/json" },
537
+ Authorization: `Bearer ${this.config.apiKey}`
538
+ },
539
+ ...body === void 0 ? {} : { body: JSON.stringify(body) }
540
+ });
541
+ const json = await res.json().catch(() => ({ error: `HTTP ${res.status}` }));
542
+ return { ...json, status: res.status };
543
+ }
544
+ /** Mode, equity, positions, activity and the key's policy with spentTodayUsd. */
545
+ async state() {
546
+ return this.call("GET", "/state");
547
+ }
548
+ /** Place one order. Executes through the trading-only agent wallet. */
549
+ async order(request) {
550
+ return this.call("POST", "/orders", request);
551
+ }
552
+ /** Validate a payment and return the intent the agent signs itself. */
553
+ async pay(request) {
554
+ return this.call("POST", "/pay", request);
555
+ }
556
+ /** Quote a swap; the agent signs and submits the returned transaction. */
557
+ async swap(request) {
558
+ return this.call("POST", "/swap", request);
559
+ }
560
+ /** Create a pending invoice and get the payer's paymentLink. */
561
+ async invoice(request) {
562
+ return this.call("POST", "/invoice", request);
563
+ }
564
+ /**
565
+ * Read an invoice back with the id and signature from its paymentLink
566
+ * (`/pay?invoice=<id>&sig=<sig>`). A signed invoice answers 403 without sig.
567
+ */
568
+ async invoiceStatus(invoiceId, sig) {
569
+ const query = new URLSearchParams({ id: invoiceId });
570
+ if (sig) query.set("sig", sig);
571
+ const res = await fetch(`${this.baseUrl()}/api/invoice?${query.toString()}`);
572
+ const json = await res.json().catch(() => ({ error: `HTTP ${res.status}` }));
573
+ return { ok: Boolean(json.success), status: res.status, invoice: json.invoice, error: json.error };
574
+ }
575
+ };
576
+
577
+ // src/client.ts
578
+ var ProtocolBanks = class {
579
+ constructor(config) {
580
+ this.config = {
581
+ ...config,
582
+ baseUrl: config.baseUrl || "https://protocolbanks.com",
583
+ defaultToken: config.defaultToken || "USDC"
584
+ };
585
+ this.paymentLinks = new PaymentLink(this.config);
586
+ this.invoices = new Invoice(this.config);
587
+ this.checkout = new Checkout(this.config);
588
+ this.webhooks = new Webhook(this.config);
589
+ this.agent = new Agent(this.config);
590
+ }
591
+ /**
592
+ * Create an embeddable payment iframe
593
+ */
594
+ embed(options) {
595
+ const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container;
596
+ if (!container) {
597
+ throw new Error("Container element not found");
598
+ }
599
+ const params = new URLSearchParams({
600
+ to: options.to,
601
+ token: options.token || this.config.defaultToken
602
+ });
603
+ if (options.amount) params.set("amount", options.amount);
604
+ if (options.merchantName) params.set("merchant", options.merchantName);
605
+ if (options.theme) params.set("theme", options.theme);
606
+ const iframe = document.createElement("iframe");
607
+ iframe.src = `${this.config.baseUrl}/embed/pay?${params.toString()}`;
608
+ iframe.style.width = "100%";
609
+ iframe.style.height = "500px";
610
+ iframe.style.border = "none";
611
+ iframe.style.borderRadius = "12px";
612
+ iframe.allow = "payment";
613
+ const handleMessage = (event) => {
614
+ if (event.origin !== new URL(this.config.baseUrl).origin) return;
615
+ const data = event.data;
616
+ if (data.type === "payment_success" && options.onSuccess) {
617
+ options.onSuccess({
618
+ success: true,
619
+ id: data.txHash || "",
620
+ paymentUrl: "",
621
+ status: "paid",
622
+ txHash: data.txHash
623
+ });
624
+ }
625
+ if (data.type === "payment_error" && options.onError) {
626
+ options.onError(new Error(data.error || "Payment failed"));
627
+ }
628
+ };
629
+ window.addEventListener("message", handleMessage);
630
+ container.appendChild(iframe);
631
+ return {
632
+ destroy: () => {
633
+ window.removeEventListener("message", handleMessage);
634
+ iframe.remove();
635
+ }
636
+ };
637
+ }
638
+ /**
639
+ * Generate a payment URL for direct redirect
640
+ */
641
+ getPaymentUrl(options) {
642
+ const params = new URLSearchParams({
643
+ to: options.to,
644
+ amount: options.amount,
645
+ token: options.token || this.config.defaultToken
646
+ });
647
+ if (options.merchantName) params.set("merchant", options.merchantName);
648
+ return `${this.config.baseUrl}/pay?${params.toString()}`;
649
+ }
650
+ /**
651
+ * Make an authenticated API request
652
+ */
653
+ async request(path, options = {}) {
654
+ const url = `${this.config.baseUrl}/api${path}`;
655
+ const headers = {
656
+ "Content-Type": "application/json",
657
+ "X-API-Key": this.config.apiKey
658
+ };
659
+ if (this.config.apiSecret) {
660
+ headers["X-API-Secret"] = this.config.apiSecret;
661
+ }
662
+ const response = await fetch(url, {
663
+ ...options,
664
+ headers: {
665
+ ...headers,
666
+ ...options.headers
667
+ }
668
+ });
669
+ if (!response.ok) {
670
+ const error = await response.json().catch(() => ({ error: "Request failed" }));
671
+ throw new Error(error.error || `API request failed: ${response.status}`);
672
+ }
673
+ return response.json();
674
+ }
675
+ };
676
+ export {
677
+ Agent,
678
+ Checkout,
679
+ Invoice,
680
+ PaymentLink,
681
+ ProtocolBanks,
682
+ Webhook
683
+ };