@hyperscale0/sdk 1.0.123

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/client.js ADDED
@@ -0,0 +1,823 @@
1
+ // Generated from core/contracts operation descriptors. Do not edit.
2
+ const routes = {
3
+ "account.balance.retrieve": {
4
+ "method": "GET",
5
+ "path": "/v1/accounts/{accountId}/balance",
6
+ "pathParams": [
7
+ "accountId"
8
+ ],
9
+ "idempotency": "not_required"
10
+ },
11
+ "account.close": {
12
+ "method": "POST",
13
+ "path": "/v1/accounts/{accountId}/close",
14
+ "pathParams": [
15
+ "accountId"
16
+ ],
17
+ "idempotency": "required"
18
+ },
19
+ "account.create": {
20
+ "method": "POST",
21
+ "path": "/v1/accounts",
22
+ "pathParams": [],
23
+ "idempotency": "required"
24
+ },
25
+ "account.freeze": {
26
+ "method": "POST",
27
+ "path": "/v1/accounts/{accountId}/freeze",
28
+ "pathParams": [
29
+ "accountId"
30
+ ],
31
+ "idempotency": "required"
32
+ },
33
+ "account.hold.list": {
34
+ "method": "GET",
35
+ "path": "/v1/accounts/{accountId}/holds",
36
+ "pathParams": [
37
+ "accountId"
38
+ ],
39
+ "idempotency": "not_required"
40
+ },
41
+ "account.hold.retrieve": {
42
+ "method": "GET",
43
+ "path": "/v1/accounts/{accountId}/holds/{transferId}",
44
+ "pathParams": [
45
+ "accountId",
46
+ "transferId"
47
+ ],
48
+ "idempotency": "not_required"
49
+ },
50
+ "account.list": {
51
+ "method": "GET",
52
+ "path": "/v1/accounts",
53
+ "pathParams": [],
54
+ "idempotency": "not_required"
55
+ },
56
+ "account.retrieve": {
57
+ "method": "GET",
58
+ "path": "/v1/accounts/{accountId}",
59
+ "pathParams": [
60
+ "accountId"
61
+ ],
62
+ "idempotency": "not_required"
63
+ },
64
+ "account.statement.export": {
65
+ "method": "GET",
66
+ "path": "/v1/accounts/{accountId}/statements/{period}/export",
67
+ "pathParams": [
68
+ "accountId",
69
+ "period"
70
+ ],
71
+ "idempotency": "not_required"
72
+ },
73
+ "account.statement.retrieve": {
74
+ "method": "GET",
75
+ "path": "/v1/accounts/{accountId}/statements/{period}",
76
+ "pathParams": [
77
+ "accountId",
78
+ "period"
79
+ ],
80
+ "idempotency": "not_required"
81
+ },
82
+ "account.unfreeze": {
83
+ "method": "POST",
84
+ "path": "/v1/accounts/{accountId}/unfreeze",
85
+ "pathParams": [
86
+ "accountId"
87
+ ],
88
+ "idempotency": "required"
89
+ },
90
+ "activity.list": {
91
+ "method": "GET",
92
+ "path": "/v1/activity",
93
+ "pathParams": [],
94
+ "idempotency": "not_required"
95
+ },
96
+ "audit_event.list": {
97
+ "method": "GET",
98
+ "path": "/v1/audit-events",
99
+ "pathParams": [],
100
+ "idempotency": "not_required"
101
+ },
102
+ "audit_event.retrieve": {
103
+ "method": "GET",
104
+ "path": "/v1/audit-events/{auditEventId}",
105
+ "pathParams": [
106
+ "auditEventId"
107
+ ],
108
+ "idempotency": "not_required"
109
+ },
110
+ "consent.list": {
111
+ "method": "GET",
112
+ "path": "/v1/consents",
113
+ "pathParams": [],
114
+ "idempotency": "not_required"
115
+ },
116
+ "consent.retrieve": {
117
+ "method": "GET",
118
+ "path": "/v1/consents/{consentId}",
119
+ "pathParams": [
120
+ "consentId"
121
+ ],
122
+ "idempotency": "not_required"
123
+ },
124
+ "consent.revoke": {
125
+ "method": "POST",
126
+ "path": "/v1/consents/{consentId}/revoke",
127
+ "pathParams": [
128
+ "consentId"
129
+ ],
130
+ "idempotency": "required"
131
+ },
132
+ "customer_access.close": {
133
+ "method": "POST",
134
+ "path": "/v1/customer-access/{customerAccessId}/close",
135
+ "pathParams": [
136
+ "customerAccessId"
137
+ ],
138
+ "idempotency": "required"
139
+ },
140
+ "customer_access.list": {
141
+ "method": "GET",
142
+ "path": "/v1/customer-access",
143
+ "pathParams": [],
144
+ "idempotency": "not_required"
145
+ },
146
+ "customer_access.reactivate": {
147
+ "method": "POST",
148
+ "path": "/v1/customer-access/{customerAccessId}/reactivate",
149
+ "pathParams": [
150
+ "customerAccessId"
151
+ ],
152
+ "idempotency": "required"
153
+ },
154
+ "customer_access.retrieve": {
155
+ "method": "GET",
156
+ "path": "/v1/customer-access/{customerAccessId}",
157
+ "pathParams": [
158
+ "customerAccessId"
159
+ ],
160
+ "idempotency": "not_required"
161
+ },
162
+ "customer_access.suspend": {
163
+ "method": "POST",
164
+ "path": "/v1/customer-access/{customerAccessId}/suspend",
165
+ "pathParams": [
166
+ "customerAccessId"
167
+ ],
168
+ "idempotency": "required"
169
+ },
170
+ "customer.create": {
171
+ "method": "POST",
172
+ "path": "/v1/customers",
173
+ "pathParams": [],
174
+ "idempotency": "required"
175
+ },
176
+ "customer.list": {
177
+ "method": "GET",
178
+ "path": "/v1/customers",
179
+ "pathParams": [],
180
+ "idempotency": "not_required"
181
+ },
182
+ "customer.login": {
183
+ "method": "POST",
184
+ "path": "/v1/customer-identity/login",
185
+ "pathParams": [],
186
+ "idempotency": "required"
187
+ },
188
+ "customer.logout": {
189
+ "method": "POST",
190
+ "path": "/v1/customer-identity/logout",
191
+ "pathParams": [],
192
+ "idempotency": "required"
193
+ },
194
+ "customer.retrieve": {
195
+ "method": "GET",
196
+ "path": "/v1/customers/{customerId}",
197
+ "pathParams": [
198
+ "customerId"
199
+ ],
200
+ "idempotency": "not_required"
201
+ },
202
+ "customer.session.revoke": {
203
+ "method": "POST",
204
+ "path": "/v1/customer-identity/sessions/{customerSessionId}/revoke",
205
+ "pathParams": [
206
+ "customerSessionId"
207
+ ],
208
+ "idempotency": "required"
209
+ },
210
+ "customer.signup": {
211
+ "method": "POST",
212
+ "path": "/v1/customer-identity/signup",
213
+ "pathParams": [],
214
+ "idempotency": "required"
215
+ },
216
+ "developer.log.list": {
217
+ "method": "GET",
218
+ "path": "/v1/developer-logs",
219
+ "pathParams": [],
220
+ "idempotency": "not_required"
221
+ },
222
+ "developer.log.retrieve": {
223
+ "method": "GET",
224
+ "path": "/v1/developer-logs/{operationId}",
225
+ "pathParams": [
226
+ "operationId"
227
+ ],
228
+ "idempotency": "not_required"
229
+ },
230
+ "event.list": {
231
+ "method": "GET",
232
+ "path": "/v1/events",
233
+ "pathParams": [],
234
+ "idempotency": "not_required"
235
+ },
236
+ "event.retrieve": {
237
+ "method": "GET",
238
+ "path": "/v1/events/{eventId}",
239
+ "pathParams": [
240
+ "eventId"
241
+ ],
242
+ "idempotency": "not_required"
243
+ },
244
+ "extension.list": {
245
+ "method": "GET",
246
+ "path": "/v1/extensions",
247
+ "pathParams": [],
248
+ "idempotency": "not_required"
249
+ },
250
+ "internal_transfer.list": {
251
+ "method": "GET",
252
+ "path": "/v1/internal-transfers",
253
+ "pathParams": [],
254
+ "idempotency": "not_required"
255
+ },
256
+ "internal_transfer.retrieve": {
257
+ "method": "GET",
258
+ "path": "/v1/internal-transfers/{transferId}",
259
+ "pathParams": [
260
+ "transferId"
261
+ ],
262
+ "idempotency": "not_required"
263
+ },
264
+ "operation.list": {
265
+ "method": "GET",
266
+ "path": "/v1/operations",
267
+ "pathParams": [],
268
+ "idempotency": "not_required"
269
+ },
270
+ "operation.retrieve": {
271
+ "method": "GET",
272
+ "path": "/v1/operations/{operationId}",
273
+ "pathParams": [
274
+ "operationId"
275
+ ],
276
+ "idempotency": "not_required"
277
+ },
278
+ "payment_reminder.delivery.retrieve": {
279
+ "method": "GET",
280
+ "path": "/v1/products/{productId}/payment-reminders/{operationId}",
281
+ "pathParams": [
282
+ "productId",
283
+ "operationId"
284
+ ],
285
+ "idempotency": "not_required"
286
+ },
287
+ "product.actions.list": {
288
+ "method": "GET",
289
+ "path": "/v1/products/{productId}/actions",
290
+ "pathParams": [
291
+ "productId"
292
+ ],
293
+ "idempotency": "not_required"
294
+ },
295
+ "product.activation.retrieve": {
296
+ "method": "GET",
297
+ "path": "/v1/products/{productId}/activation",
298
+ "pathParams": [
299
+ "productId"
300
+ ],
301
+ "idempotency": "not_required"
302
+ },
303
+ "product.balance_sheet.retrieve": {
304
+ "method": "GET",
305
+ "path": "/v1/products/{productId}/balance-sheet",
306
+ "pathParams": [
307
+ "productId"
308
+ ],
309
+ "idempotency": "not_required"
310
+ },
311
+ "product.blocks.summary": {
312
+ "method": "GET",
313
+ "path": "/v1/products/{productId}/blocks/summary",
314
+ "pathParams": [
315
+ "productId"
316
+ ],
317
+ "idempotency": "not_required"
318
+ },
319
+ "product.connections.retrieve": {
320
+ "method": "GET",
321
+ "path": "/v1/products/{productId}/connections",
322
+ "pathParams": [
323
+ "productId"
324
+ ],
325
+ "idempotency": "not_required"
326
+ },
327
+ "product.earn.rate.list": {
328
+ "method": "GET",
329
+ "path": "/v1/products/{productId}/earn-rates",
330
+ "pathParams": [
331
+ "productId"
332
+ ],
333
+ "idempotency": "not_required"
334
+ },
335
+ "product.earnings.settle": {
336
+ "method": "POST",
337
+ "path": "/v1/products/{productId}/earnings/settlements",
338
+ "pathParams": [
339
+ "productId"
340
+ ],
341
+ "idempotency": "required"
342
+ },
343
+ "product.economic_snapshot.retrieve": {
344
+ "method": "GET",
345
+ "path": "/v1/products/{productId}/economic-snapshot",
346
+ "pathParams": [
347
+ "productId"
348
+ ],
349
+ "idempotency": "not_required"
350
+ },
351
+ "product.guidance.retrieve": {
352
+ "method": "GET",
353
+ "path": "/v1/products/{productId}/guidance",
354
+ "pathParams": [
355
+ "productId"
356
+ ],
357
+ "idempotency": "not_required"
358
+ },
359
+ "product.instruments.list": {
360
+ "method": "GET",
361
+ "path": "/v1/products/{productId}/instruments",
362
+ "pathParams": [
363
+ "productId"
364
+ ],
365
+ "idempotency": "not_required"
366
+ },
367
+ "product.list": {
368
+ "method": "GET",
369
+ "path": "/v1/products",
370
+ "pathParams": [],
371
+ "idempotency": "not_required"
372
+ },
373
+ "product.margin.retrieve": {
374
+ "method": "GET",
375
+ "path": "/v1/products/{productId}/margin",
376
+ "pathParams": [
377
+ "productId"
378
+ ],
379
+ "idempotency": "not_required"
380
+ },
381
+ "product.objects.actions": {
382
+ "method": "GET",
383
+ "path": "/v1/products/{productId}/objects/{kind}/{objectId}/actions",
384
+ "pathParams": [
385
+ "productId",
386
+ "kind",
387
+ "objectId"
388
+ ],
389
+ "idempotency": "not_required"
390
+ },
391
+ "product.objects.agreements.evidence.list": {
392
+ "method": "GET",
393
+ "path": "/v1/products/{productId}/objects/{kind}/{objectId}/agreements/{instanceId}/evidence",
394
+ "pathParams": [
395
+ "productId",
396
+ "kind",
397
+ "objectId",
398
+ "instanceId"
399
+ ],
400
+ "idempotency": "not_required"
401
+ },
402
+ "product.objects.agreements.list": {
403
+ "method": "GET",
404
+ "path": "/v1/products/{productId}/objects/{kind}/{objectId}/agreements",
405
+ "pathParams": [
406
+ "productId",
407
+ "kind",
408
+ "objectId"
409
+ ],
410
+ "idempotency": "not_required"
411
+ },
412
+ "product.objects.create": {
413
+ "method": "POST",
414
+ "path": "/v1/products/{productId}/objects/{kind}",
415
+ "pathParams": [
416
+ "productId",
417
+ "kind"
418
+ ],
419
+ "idempotency": "required"
420
+ },
421
+ "product.objects.discover": {
422
+ "method": "GET",
423
+ "path": "/v1/products/{productId}/objects",
424
+ "pathParams": [
425
+ "productId"
426
+ ],
427
+ "idempotency": "not_required"
428
+ },
429
+ "product.objects.execute": {
430
+ "method": "POST",
431
+ "path": "/v1/products/{productId}/objects/{kind}/{objectId}/actions/{action}",
432
+ "pathParams": [
433
+ "productId",
434
+ "kind",
435
+ "objectId",
436
+ "action"
437
+ ],
438
+ "idempotency": "required"
439
+ },
440
+ "product.objects.list": {
441
+ "method": "GET",
442
+ "path": "/v1/products/{productId}/objects/{kind}",
443
+ "pathParams": [
444
+ "productId",
445
+ "kind"
446
+ ],
447
+ "idempotency": "not_required"
448
+ },
449
+ "product.objects.preview": {
450
+ "method": "POST",
451
+ "path": "/v1/products/{productId}/objects/{kind}/{objectId}/actions/{action}/preview",
452
+ "pathParams": [
453
+ "productId",
454
+ "kind",
455
+ "objectId",
456
+ "action"
457
+ ],
458
+ "idempotency": "not_required"
459
+ },
460
+ "product.objects.retrieve": {
461
+ "method": "GET",
462
+ "path": "/v1/products/{productId}/objects/{kind}/{objectId}",
463
+ "pathParams": [
464
+ "productId",
465
+ "kind",
466
+ "objectId"
467
+ ],
468
+ "idempotency": "not_required"
469
+ },
470
+ "product.objects.timeline.list": {
471
+ "method": "GET",
472
+ "path": "/v1/products/{productId}/objects/{kind}/{objectId}/timeline",
473
+ "pathParams": [
474
+ "productId",
475
+ "kind",
476
+ "objectId"
477
+ ],
478
+ "idempotency": "not_required"
479
+ },
480
+ "product.operation_set.retrieve": {
481
+ "method": "GET",
482
+ "path": "/v1/products/{productId}/operation-set",
483
+ "pathParams": [
484
+ "productId"
485
+ ],
486
+ "idempotency": "not_required"
487
+ },
488
+ "product.retrieve": {
489
+ "method": "GET",
490
+ "path": "/v1/products/{productId}",
491
+ "pathParams": [
492
+ "productId"
493
+ ],
494
+ "idempotency": "not_required"
495
+ },
496
+ "product.schedule.list": {
497
+ "method": "GET",
498
+ "path": "/v1/products/{productId}/schedule",
499
+ "pathParams": [
500
+ "productId"
501
+ ],
502
+ "idempotency": "not_required"
503
+ },
504
+ "product.treasury.retrieve": {
505
+ "method": "GET",
506
+ "path": "/v1/products/{productId}/treasury",
507
+ "pathParams": [
508
+ "productId"
509
+ ],
510
+ "idempotency": "not_required"
511
+ },
512
+ "product.work.list": {
513
+ "method": "GET",
514
+ "path": "/v1/products/{productId}/work",
515
+ "pathParams": [
516
+ "productId"
517
+ ],
518
+ "idempotency": "not_required"
519
+ },
520
+ "receipt.list": {
521
+ "method": "GET",
522
+ "path": "/v1/receipts",
523
+ "pathParams": [],
524
+ "idempotency": "not_required"
525
+ },
526
+ "receipt.retrieve": {
527
+ "method": "GET",
528
+ "path": "/v1/receipts/{receiptId}",
529
+ "pathParams": [
530
+ "receiptId"
531
+ ],
532
+ "idempotency": "not_required"
533
+ },
534
+ "sandbox.account.fund": {
535
+ "method": "POST",
536
+ "path": "/v1/sandbox/account-funding",
537
+ "pathParams": [],
538
+ "idempotency": "required"
539
+ },
540
+ "sandbox.clock.advance": {
541
+ "method": "POST",
542
+ "path": "/v1/sandbox/clock/advance",
543
+ "pathParams": [],
544
+ "idempotency": "required"
545
+ },
546
+ "sandbox.clock.retrieve": {
547
+ "method": "GET",
548
+ "path": "/v1/products/{productId}/sandbox-clock",
549
+ "pathParams": [
550
+ "productId"
551
+ ],
552
+ "idempotency": "not_required"
553
+ },
554
+ "sandbox.customer_access.activate": {
555
+ "method": "POST",
556
+ "path": "/v1/sandbox/customer-access/{customerAccessId}/activate",
557
+ "pathParams": [
558
+ "customerAccessId"
559
+ ],
560
+ "idempotency": "required"
561
+ },
562
+ "sandbox.platform.fire": {
563
+ "method": "POST",
564
+ "path": "/v1/sandbox/platform/fire",
565
+ "pathParams": [],
566
+ "idempotency": "required"
567
+ },
568
+ "transfer_return.create": {
569
+ "method": "POST",
570
+ "path": "/v1/transfer-returns",
571
+ "pathParams": [],
572
+ "idempotency": "required"
573
+ },
574
+ "usage_record.list": {
575
+ "method": "GET",
576
+ "path": "/v1/usage-records",
577
+ "pathParams": [],
578
+ "idempotency": "not_required"
579
+ },
580
+ "usage_record.retrieve": {
581
+ "method": "GET",
582
+ "path": "/v1/usage-records/{usageRecordId}",
583
+ "pathParams": [
584
+ "usageRecordId"
585
+ ],
586
+ "idempotency": "not_required"
587
+ },
588
+ "usage.statement": {
589
+ "method": "GET",
590
+ "path": "/v1/usage/statement",
591
+ "pathParams": [],
592
+ "idempotency": "not_required"
593
+ },
594
+ "webhook.delivery.list": {
595
+ "method": "GET",
596
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}/deliveries",
597
+ "pathParams": [
598
+ "webhookEndpointId"
599
+ ],
600
+ "idempotency": "not_required"
601
+ },
602
+ "webhook.delivery.resend": {
603
+ "method": "POST",
604
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}/deliveries/{webhookDeliveryId}/resend",
605
+ "pathParams": [
606
+ "webhookEndpointId",
607
+ "webhookDeliveryId"
608
+ ],
609
+ "idempotency": "required"
610
+ },
611
+ "webhook.endpoint.create": {
612
+ "method": "POST",
613
+ "path": "/v1/webhook-endpoints",
614
+ "pathParams": [],
615
+ "idempotency": "required"
616
+ },
617
+ "webhook.endpoint.delete": {
618
+ "method": "POST",
619
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}/delete",
620
+ "pathParams": [
621
+ "webhookEndpointId"
622
+ ],
623
+ "idempotency": "required"
624
+ },
625
+ "webhook.endpoint.disable": {
626
+ "method": "POST",
627
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}/disable",
628
+ "pathParams": [
629
+ "webhookEndpointId"
630
+ ],
631
+ "idempotency": "required"
632
+ },
633
+ "webhook.endpoint.enable": {
634
+ "method": "POST",
635
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}/enable",
636
+ "pathParams": [
637
+ "webhookEndpointId"
638
+ ],
639
+ "idempotency": "required"
640
+ },
641
+ "webhook.endpoint.list": {
642
+ "method": "GET",
643
+ "path": "/v1/webhook-endpoints",
644
+ "pathParams": [],
645
+ "idempotency": "not_required"
646
+ },
647
+ "webhook.endpoint.recover": {
648
+ "method": "POST",
649
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}/recover",
650
+ "pathParams": [
651
+ "webhookEndpointId"
652
+ ],
653
+ "idempotency": "required"
654
+ },
655
+ "webhook.endpoint.retrieve": {
656
+ "method": "GET",
657
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}",
658
+ "pathParams": [
659
+ "webhookEndpointId"
660
+ ],
661
+ "idempotency": "not_required"
662
+ },
663
+ "webhook.endpoint.secret.rotate": {
664
+ "method": "POST",
665
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}/secret/rotate",
666
+ "pathParams": [
667
+ "webhookEndpointId"
668
+ ],
669
+ "idempotency": "required"
670
+ },
671
+ "webhook.endpoint.update": {
672
+ "method": "PATCH",
673
+ "path": "/v1/webhook-endpoints/{webhookEndpointId}",
674
+ "pathParams": [
675
+ "webhookEndpointId"
676
+ ],
677
+ "idempotency": "required"
678
+ },
679
+ "webhook.event.catalog": {
680
+ "method": "GET",
681
+ "path": "/v1/products/{productId}/webhook-event-catalog",
682
+ "pathParams": [
683
+ "productId"
684
+ ],
685
+ "idempotency": "not_required"
686
+ }
687
+ };
688
+
689
+ export function createClient({
690
+ apiKey,
691
+ sessionToken,
692
+ productId,
693
+ baseUrl = "https://hyperscale0.ai",
694
+ environment = "sandbox",
695
+ turnstileToken,
696
+ }) {
697
+ if (!apiKey === !sessionToken || !productId)
698
+ throw new Error("Choose one API key or session token and a Product");
699
+ const credential = sessionToken ?? apiKey;
700
+ const origin = new URL(baseUrl);
701
+ if (
702
+ origin.origin !== baseUrl ||
703
+ (origin.protocol !== "https:" &&
704
+ !["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname))
705
+ ) {
706
+ throw new Error(
707
+ "baseUrl must be an HTTPS origin or a loopback HTTP origin",
708
+ );
709
+ }
710
+ if (!["sandbox", "live"].includes(environment))
711
+ throw new Error("environment must be sandbox or live");
712
+ async function request(path, input, idempotencyKey, method, extraHeaders) {
713
+ const httpMethod = method ?? (input === undefined ? "GET" : "POST");
714
+ const response = await fetch(new URL(path, origin), {
715
+ method: httpMethod,
716
+ headers: {
717
+ authorization: `Bearer ${credential}`,
718
+ "x-hyperscale-environment": environment,
719
+ ...(input === undefined ? {} : { "content-type": "application/json" }),
720
+ ...(idempotencyKey ? { "idempotency-key": idempotencyKey } : {}),
721
+ ...extraHeaders,
722
+ },
723
+ ...(input === undefined ? {} : { body: JSON.stringify(input) }),
724
+ redirect: "error",
725
+ signal: AbortSignal.timeout(30_000),
726
+ });
727
+ const result = await response.json();
728
+ if (!response.ok) {
729
+ const error = new Error(
730
+ `Hyperscale request failed with HTTP ${response.status}`,
731
+ );
732
+ error.status = response.status;
733
+ error.code = result?.error?.code;
734
+ error.details = result?.error?.details;
735
+ error.requestId = response.headers.get("x-request-id");
736
+ throw error;
737
+ }
738
+ return result;
739
+ }
740
+ const productPath = `/v1/products/${encodeURIComponent(productId)}`;
741
+ const actionPath = sessionToken
742
+ ? `${productPath}/operations`
743
+ : "/v1/operations";
744
+ return {
745
+ rehearse: (name, { idempotencyKey } = {}) => {
746
+ if (!sessionToken || !idempotencyKey)
747
+ throw new Error(
748
+ "rehearse requires a tenant session and idempotency key",
749
+ );
750
+ return request(
751
+ "/v1/sandbox/rehearsals",
752
+ { productId, name },
753
+ idempotencyKey,
754
+ );
755
+ },
756
+ reminderDelivery: (operationId) =>
757
+ request(
758
+ `${productPath}/payment-reminders/${encodeURIComponent(operationId)}`,
759
+ ),
760
+ discover: () => request(`${productPath}/objects`),
761
+ call: (name, input = {}, options = {}) => {
762
+ const route = routes[name];
763
+ if (!route) throw new Error(`Unknown operation: ${name}`);
764
+ const remaining = { ...input };
765
+ const path = route.path.replace(/\{([^}]+)\}/g, (_, param) => {
766
+ let value = remaining[param];
767
+ if (value === undefined && param === "productId") {
768
+ value = productId;
769
+ }
770
+ if (value === undefined || value === null) {
771
+ throw new Error(`${name} requires ${param} in input`);
772
+ }
773
+ delete remaining[param];
774
+ return encodeURIComponent(String(value));
775
+ });
776
+ const extraHeaders = { ...(options.headers ?? {}) };
777
+ const turnstile = options.turnstileToken ?? turnstileToken;
778
+ if (turnstile) {
779
+ extraHeaders["x-turnstile-token"] ??= turnstile;
780
+ }
781
+ if (route.method === "GET") {
782
+ const params = new URLSearchParams();
783
+ for (const [key, value] of Object.entries(remaining)) {
784
+ if (value === undefined || value === null) continue;
785
+ params.set(
786
+ key,
787
+ typeof value === "string" ? value : JSON.stringify(value),
788
+ );
789
+ }
790
+ const query = params.toString();
791
+ const targetPath = query ? `${path}?${query}` : path;
792
+ return request(
793
+ targetPath,
794
+ undefined,
795
+ options.idempotencyKey,
796
+ route.method,
797
+ extraHeaders,
798
+ );
799
+ }
800
+ return request(
801
+ path,
802
+ remaining,
803
+ options.idempotencyKey,
804
+ route.method,
805
+ extraHeaders,
806
+ );
807
+ },
808
+ instruments: () => request(`${productPath}/instruments`),
809
+ actions: (instrument) =>
810
+ request(
811
+ `${productPath}/actions${instrument ? `?instrument=${encodeURIComponent(instrument)}` : ""}`,
812
+ ),
813
+ act: (name, input, { idempotencyKey } = {}) => {
814
+ if (!idempotencyKey)
815
+ throw new Error("act requires an idempotencyKey for safe retries");
816
+ return request(
817
+ `${actionPath}/${encodeURIComponent(name)}`,
818
+ input,
819
+ idempotencyKey,
820
+ );
821
+ },
822
+ };
823
+ }