@cimplify/sdk 0.102.0 → 0.103.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/advanced.d.mts +3 -3
- package/dist/advanced.d.ts +3 -3
- package/dist/advanced.js +23 -22
- package/dist/advanced.mjs +4 -3
- package/dist/{chunk-DCMXUKDQ.mjs → chunk-C2JSNJUC.mjs} +404 -95
- package/dist/chunk-CNN7Z2IP.js +125 -0
- package/dist/{chunk-DKLHCZ5M.mjs → chunk-GERXZQSX.mjs} +487 -11
- package/dist/chunk-GOHSXBKW.mjs +105 -0
- package/dist/{chunk-4KNFBPV2.mjs → chunk-H7ACMHM3.mjs} +32 -14
- package/dist/{chunk-Z3K2D3TE.mjs → chunk-J6PNHDHL.mjs} +453 -483
- package/dist/{chunk-NIOUSKQQ.js → chunk-JG5CQNCB.js} +5 -0
- package/dist/{chunk-YER7DIOM.js → chunk-JSWJ4XDE.js} +471 -519
- package/dist/{chunk-DLW3RWRK.mjs → chunk-M4URVKHE.mjs} +46 -12
- package/dist/{chunk-WMEC5JWN.js → chunk-NNG6IFFX.js} +50 -13
- package/dist/{chunk-LOWSMGRT.js → chunk-QOWPGS7Z.js} +34 -16
- package/dist/{chunk-YDA46OZ6.js → chunk-R6OLQ33I.js} +560 -80
- package/dist/{chunk-EAZGA7LD.js → chunk-VIL6IQCG.js} +406 -97
- package/dist/{chunk-O3YUHLZL.mjs → chunk-VNPEYLB2.mjs} +5 -0
- package/dist/{client-B40KFazg.d.ts → client-BfpNjJ_a.d.mts} +90 -299
- package/dist/{client-BizGfqB7.d.mts → client-DHBwvh7U.d.ts} +90 -299
- package/dist/{client-BdErclfU.d.mts → client-DpqRobY9.d.mts} +2 -2
- package/dist/{client-nsiMwuC1.d.ts → client-Dqg2mc-7.d.ts} +2 -2
- package/dist/{index-DpmnI__D.d.mts → index-C8uDqLwJ.d.ts} +14 -4
- package/dist/{index-nEyXWIyR.d.ts → index-e2y6AK70.d.mts} +14 -4
- package/dist/index.d.mts +81 -8
- package/dist/index.d.ts +81 -8
- package/dist/index.js +202 -169
- package/dist/index.mjs +6 -5
- package/dist/link-cuNVYc2s.d.mts +297 -0
- package/dist/link-cuNVYc2s.d.ts +297 -0
- package/dist/mock/cli.mjs +410 -94
- package/dist/mock/library.js +410 -94
- package/dist/mock/library.mjs +410 -94
- package/dist/mock/msw.js +410 -94
- package/dist/mock/msw.mjs +410 -94
- package/dist/{product-Byf0unSy.d.mts → payment-H5LoIvXU.d.mts} +189 -7
- package/dist/{product-Byf0unSy.d.ts → payment-H5LoIvXU.d.ts} +189 -7
- package/dist/{price-CS4E5zLS.d.mts → price-BvePgDXe.d.mts} +1 -1
- package/dist/{price-BstChV9a.d.ts → price-C2RqscMY.d.ts} +1 -1
- package/dist/react.d.mts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +141 -140
- package/dist/react.mjs +5 -4
- package/dist/{server-DqbZh8Bk.d.mts → server-C7FyLdrz.d.mts} +11 -9
- package/dist/{server-Cj40R2ZD.d.ts → server-DoXIpSd7.d.ts} +11 -9
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +11 -10
- package/dist/server.mjs +5 -4
- package/dist/testing/msw.d.mts +2 -2
- package/dist/testing/msw.d.ts +2 -2
- package/dist/testing/msw.js +4 -3
- package/dist/testing/msw.mjs +3 -2
- package/dist/testing/suite.d.mts +6 -6
- package/dist/testing/suite.d.ts +6 -6
- package/dist/testing/suite.js +26 -25
- package/dist/testing/suite.mjs +7 -6
- package/dist/testing.d.mts +154 -55
- package/dist/testing.d.ts +154 -55
- package/dist/testing.js +83 -82
- package/dist/testing.mjs +8 -7
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/dist/utils.js +37 -29
- package/dist/utils.mjs +2 -2
- package/package.json +7 -1
- package/dist/payment-l0rkieEQ.d.mts +0 -113
- package/dist/payment-vzNnIi1n.d.ts +0 -113
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkJSWJ4XDE_js = require('./chunk-JSWJ4XDE.js');
|
|
4
|
+
var chunkJG5CQNCB_js = require('./chunk-JG5CQNCB.js');
|
|
5
5
|
|
|
6
6
|
// src/store-credit.ts
|
|
7
7
|
var StoreCreditQueries = class {
|
|
@@ -13,7 +13,7 @@ var StoreCreditQueries = class {
|
|
|
13
13
|
* currency. Requires a signed-in customer; returns an error otherwise.
|
|
14
14
|
*/
|
|
15
15
|
async balance() {
|
|
16
|
-
return
|
|
16
|
+
return chunkJSWJ4XDE_js.safe(this.client.get("/api/v1/store-credit/balance"));
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -262,7 +262,7 @@ var ActivityService = class {
|
|
|
262
262
|
this.sendEvents([event]);
|
|
263
263
|
}
|
|
264
264
|
async getState() {
|
|
265
|
-
return
|
|
265
|
+
return chunkJSWJ4XDE_js.safe(this.client.get("/api/v1/activity/state"));
|
|
266
266
|
}
|
|
267
267
|
async getRecommendations(options) {
|
|
268
268
|
const params = new URLSearchParams();
|
|
@@ -270,10 +270,10 @@ var ActivityService = class {
|
|
|
270
270
|
if (options?.limit) params.set("limit", String(options.limit));
|
|
271
271
|
const query = params.toString();
|
|
272
272
|
const path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
|
|
273
|
-
return
|
|
273
|
+
return chunkJSWJ4XDE_js.safe(this.client.get(path));
|
|
274
274
|
}
|
|
275
275
|
async dismissMessage(code) {
|
|
276
|
-
return
|
|
276
|
+
return chunkJSWJ4XDE_js.safe(
|
|
277
277
|
this.client.post("/api/v1/activity/messages/dismiss", { code })
|
|
278
278
|
);
|
|
279
279
|
}
|
|
@@ -369,16 +369,16 @@ var SubscriptionService = class {
|
|
|
369
369
|
this.client = client;
|
|
370
370
|
}
|
|
371
371
|
async list() {
|
|
372
|
-
return
|
|
372
|
+
return chunkJSWJ4XDE_js.safe(this.client.get("/api/v1/subscriptions"));
|
|
373
373
|
}
|
|
374
374
|
async get(id) {
|
|
375
375
|
const encodedId = encodeURIComponent(id);
|
|
376
|
-
return
|
|
376
|
+
return chunkJSWJ4XDE_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
|
|
377
377
|
}
|
|
378
378
|
async cancel(id, reason, opts) {
|
|
379
379
|
const encodedId = encodeURIComponent(id);
|
|
380
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
381
|
-
return
|
|
380
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
|
|
381
|
+
return chunkJSWJ4XDE_js.safe(
|
|
382
382
|
this.client.post(
|
|
383
383
|
`/api/v1/subscriptions/${encodedId}/cancel`,
|
|
384
384
|
{ reason },
|
|
@@ -388,20 +388,20 @@ var SubscriptionService = class {
|
|
|
388
388
|
}
|
|
389
389
|
async pause(id) {
|
|
390
390
|
const encodedId = encodeURIComponent(id);
|
|
391
|
-
return
|
|
391
|
+
return chunkJSWJ4XDE_js.safe(
|
|
392
392
|
this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
|
|
393
393
|
);
|
|
394
394
|
}
|
|
395
395
|
async resume(id) {
|
|
396
396
|
const encodedId = encodeURIComponent(id);
|
|
397
|
-
return
|
|
397
|
+
return chunkJSWJ4XDE_js.safe(
|
|
398
398
|
this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
|
|
399
399
|
);
|
|
400
400
|
}
|
|
401
401
|
async skipNextRenewal(id, opts) {
|
|
402
402
|
const encodedId = encodeURIComponent(id);
|
|
403
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
404
|
-
return
|
|
403
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
|
|
404
|
+
return chunkJSWJ4XDE_js.safe(
|
|
405
405
|
this.client.post(
|
|
406
406
|
`/api/v1/subscriptions/${encodedId}/skip`,
|
|
407
407
|
void 0,
|
|
@@ -417,8 +417,8 @@ var UploadService = class {
|
|
|
417
417
|
this.client = client;
|
|
418
418
|
}
|
|
419
419
|
async init(filename, contentType, sizeBytes, opts) {
|
|
420
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
421
|
-
return
|
|
420
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
|
|
421
|
+
return chunkJSWJ4XDE_js.safe(
|
|
422
422
|
this.client.post(
|
|
423
423
|
"/api/v1/uploads/init",
|
|
424
424
|
{
|
|
@@ -431,7 +431,7 @@ var UploadService = class {
|
|
|
431
431
|
);
|
|
432
432
|
}
|
|
433
433
|
async confirm(uploadId) {
|
|
434
|
-
return
|
|
434
|
+
return chunkJSWJ4XDE_js.safe(
|
|
435
435
|
this.client.post("/api/v1/uploads/confirm", {
|
|
436
436
|
upload_id: uploadId
|
|
437
437
|
})
|
|
@@ -450,7 +450,7 @@ var UploadService = class {
|
|
|
450
450
|
if (!uploadResponse.ok) {
|
|
451
451
|
return {
|
|
452
452
|
ok: false,
|
|
453
|
-
error: new
|
|
453
|
+
error: new chunkJG5CQNCB_js.CimplifyError(
|
|
454
454
|
"UPLOAD_FAILED",
|
|
455
455
|
`Upload failed with status ${uploadResponse.status}`,
|
|
456
456
|
true
|
|
@@ -460,7 +460,7 @@ var UploadService = class {
|
|
|
460
460
|
} catch (error) {
|
|
461
461
|
return {
|
|
462
462
|
ok: false,
|
|
463
|
-
error: new
|
|
463
|
+
error: new chunkJG5CQNCB_js.CimplifyError(
|
|
464
464
|
"UPLOAD_FAILED",
|
|
465
465
|
error instanceof Error ? error.message : "Upload failed",
|
|
466
466
|
true
|
|
@@ -477,7 +477,7 @@ var PlacesService = class {
|
|
|
477
477
|
this.client = client;
|
|
478
478
|
}
|
|
479
479
|
async autocomplete(input, sessionToken) {
|
|
480
|
-
return
|
|
480
|
+
return chunkJSWJ4XDE_js.safe(
|
|
481
481
|
this.client.post("/api/v1/places/autocomplete", {
|
|
482
482
|
input,
|
|
483
483
|
sessionToken
|
|
@@ -485,7 +485,7 @@ var PlacesService = class {
|
|
|
485
485
|
);
|
|
486
486
|
}
|
|
487
487
|
async details(placeId, sessionToken) {
|
|
488
|
-
return
|
|
488
|
+
return chunkJSWJ4XDE_js.safe(
|
|
489
489
|
this.client.post("/api/v1/places/details", {
|
|
490
490
|
place_id: placeId,
|
|
491
491
|
sessionToken
|
|
@@ -504,7 +504,7 @@ var DeliveryService = class {
|
|
|
504
504
|
params.set("dropoff_lat", String(dropoffLat));
|
|
505
505
|
params.set("dropoff_lng", String(dropoffLng));
|
|
506
506
|
if (country) params.set("country", country);
|
|
507
|
-
return
|
|
507
|
+
return chunkJSWJ4XDE_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
|
|
508
508
|
}
|
|
509
509
|
async getOptions(queryOrLatitude, longitude, legacyOptions) {
|
|
510
510
|
const query = typeof queryOrLatitude === "number" ? {
|
|
@@ -518,7 +518,7 @@ var DeliveryService = class {
|
|
|
518
518
|
if (query.country) params.set("country", query.country);
|
|
519
519
|
if (query.currency) params.set("currency", query.currency);
|
|
520
520
|
if (query.orderValue != null) params.set("order_value", String(query.orderValue));
|
|
521
|
-
return
|
|
521
|
+
return chunkJSWJ4XDE_js.safe(
|
|
522
522
|
this.client.get(`/api/v1/delivery/options?${params.toString()}`)
|
|
523
523
|
);
|
|
524
524
|
}
|
|
@@ -595,7 +595,7 @@ var SupportService = class {
|
|
|
595
595
|
async claimConversation() {
|
|
596
596
|
const accessToken = this.client.getAccessToken();
|
|
597
597
|
if (!accessToken) {
|
|
598
|
-
return
|
|
598
|
+
return chunkJSWJ4XDE_js.err(new chunkJG5CQNCB_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
599
599
|
}
|
|
600
600
|
if (this.claimInFlight) {
|
|
601
601
|
if (this.claimInFlightToken === accessToken) return this.claimInFlight;
|
|
@@ -603,12 +603,12 @@ var SupportService = class {
|
|
|
603
603
|
return this.claimConversation();
|
|
604
604
|
}
|
|
605
605
|
if (this.lastClaimedAccessToken === accessToken) {
|
|
606
|
-
return
|
|
606
|
+
return chunkJSWJ4XDE_js.err(new chunkJG5CQNCB_js.CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
607
607
|
}
|
|
608
608
|
const epoch = this.client.getSessionEpoch();
|
|
609
609
|
this.claimInFlightToken = accessToken;
|
|
610
610
|
this.claimInFlight = (async () => {
|
|
611
|
-
const result = await
|
|
611
|
+
const result = await chunkJSWJ4XDE_js.safe(
|
|
612
612
|
this.client.post(
|
|
613
613
|
"/api/v1/support/conversation/claim",
|
|
614
614
|
{ access_token: accessToken },
|
|
@@ -617,8 +617,8 @@ var SupportService = class {
|
|
|
617
617
|
);
|
|
618
618
|
if (result.ok) {
|
|
619
619
|
if (this.client.getSessionEpoch() !== epoch) {
|
|
620
|
-
return
|
|
621
|
-
new
|
|
620
|
+
return chunkJSWJ4XDE_js.err(
|
|
621
|
+
new chunkJG5CQNCB_js.CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
622
622
|
);
|
|
623
623
|
}
|
|
624
624
|
this.lastClaimedAccessToken = accessToken;
|
|
@@ -646,20 +646,20 @@ var SupportService = class {
|
|
|
646
646
|
* the inbox with empty threads.
|
|
647
647
|
*/
|
|
648
648
|
async peekConversation() {
|
|
649
|
-
const result = await
|
|
649
|
+
const result = await chunkJSWJ4XDE_js.safe(
|
|
650
650
|
this.client.get("/api/v1/support/conversation")
|
|
651
651
|
);
|
|
652
652
|
if (!result.ok) return result;
|
|
653
|
-
if (!result.value.conversation) return
|
|
654
|
-
return
|
|
653
|
+
if (!result.value.conversation) return chunkJSWJ4XDE_js.ok(null);
|
|
654
|
+
return chunkJSWJ4XDE_js.ok({
|
|
655
655
|
conversation: result.value.conversation,
|
|
656
656
|
messages: result.value.messages
|
|
657
657
|
});
|
|
658
658
|
}
|
|
659
659
|
/** Open (or resume) the customer's widget conversation. */
|
|
660
660
|
async openConversation(opts) {
|
|
661
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
662
|
-
return
|
|
661
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
|
|
662
|
+
return chunkJSWJ4XDE_js.safe(
|
|
663
663
|
this.client.post("/api/v1/support/conversation", void 0, {
|
|
664
664
|
idempotencyKey
|
|
665
665
|
})
|
|
@@ -674,8 +674,8 @@ var SupportService = class {
|
|
|
674
674
|
* server resolves it thread-scoped and echoes the quote as `reply_to`.
|
|
675
675
|
*/
|
|
676
676
|
async sendMessage(content, opts) {
|
|
677
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
678
|
-
return
|
|
677
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
|
|
678
|
+
return chunkJSWJ4XDE_js.safe(
|
|
679
679
|
this.client.post(
|
|
680
680
|
"/api/v1/support/conversation/messages",
|
|
681
681
|
{
|
|
@@ -699,11 +699,11 @@ var SupportService = class {
|
|
|
699
699
|
if (options.limit) params.set("limit", String(options.limit));
|
|
700
700
|
const query = params.toString();
|
|
701
701
|
const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
|
|
702
|
-
return
|
|
702
|
+
return chunkJSWJ4XDE_js.safe(this.client.get(path));
|
|
703
703
|
}
|
|
704
704
|
/** React to a message in the active conversation by its `ChatMessage.id`. */
|
|
705
705
|
async reactToMessage(messageId, emoji) {
|
|
706
|
-
return
|
|
706
|
+
return chunkJSWJ4XDE_js.safe(
|
|
707
707
|
this.client.post(
|
|
708
708
|
`/api/v1/support/conversation/messages/${messageId}/reactions`,
|
|
709
709
|
{ emoji }
|
|
@@ -712,8 +712,8 @@ var SupportService = class {
|
|
|
712
712
|
}
|
|
713
713
|
/** Ask for a person: flags the thread for the merchant's inbox. */
|
|
714
714
|
async requestHuman(opts) {
|
|
715
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
716
|
-
return
|
|
715
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
|
|
716
|
+
return chunkJSWJ4XDE_js.safe(
|
|
717
717
|
this.client.post(
|
|
718
718
|
"/api/v1/support/conversation/handoff",
|
|
719
719
|
void 0,
|
|
@@ -723,6 +723,453 @@ var SupportService = class {
|
|
|
723
723
|
}
|
|
724
724
|
};
|
|
725
725
|
|
|
726
|
+
// src/payment-authorization/providers/paystack.ts
|
|
727
|
+
async function openPaystackPopup(options, signal) {
|
|
728
|
+
if (typeof window === "undefined") {
|
|
729
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
730
|
+
}
|
|
731
|
+
let PaystackPop;
|
|
732
|
+
try {
|
|
733
|
+
const imported = await import('@paystack/inline-js');
|
|
734
|
+
PaystackPop = imported.default;
|
|
735
|
+
} catch {
|
|
736
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
737
|
+
}
|
|
738
|
+
return new Promise((resolve) => {
|
|
739
|
+
let settled = false;
|
|
740
|
+
let providerStarted = false;
|
|
741
|
+
const resolveOnce = (result) => {
|
|
742
|
+
if (settled) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
settled = true;
|
|
746
|
+
if (signal) {
|
|
747
|
+
signal.removeEventListener("abort", onAbort);
|
|
748
|
+
}
|
|
749
|
+
resolve(result);
|
|
750
|
+
};
|
|
751
|
+
const onAbort = () => {
|
|
752
|
+
resolveOnce({
|
|
753
|
+
success: false,
|
|
754
|
+
// Once Paystack owns the transaction, cancellation is ambiguous. The
|
|
755
|
+
// adapter converts this into submitted so Cimplify polling decides.
|
|
756
|
+
error: providerStarted ? "SUBMISSION_UNKNOWN" : "CANCELLED"
|
|
757
|
+
});
|
|
758
|
+
};
|
|
759
|
+
if (signal?.aborted) {
|
|
760
|
+
resolveOnce({ success: false, error: "CANCELLED" });
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (signal) {
|
|
764
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
765
|
+
}
|
|
766
|
+
try {
|
|
767
|
+
const popup = new PaystackPop();
|
|
768
|
+
popup.newTransaction({
|
|
769
|
+
key: options.key,
|
|
770
|
+
email: options.email,
|
|
771
|
+
amount: options.amount,
|
|
772
|
+
currency: options.currency,
|
|
773
|
+
reference: options.reference,
|
|
774
|
+
accessCode: options.accessCode,
|
|
775
|
+
onSuccess: (transaction) => {
|
|
776
|
+
resolveOnce({
|
|
777
|
+
success: true,
|
|
778
|
+
reference: transaction.reference ?? options.reference
|
|
779
|
+
});
|
|
780
|
+
},
|
|
781
|
+
onCancel: () => {
|
|
782
|
+
resolveOnce({ success: false, error: "PAYMENT_CANCELLED" });
|
|
783
|
+
},
|
|
784
|
+
onError: (error) => {
|
|
785
|
+
resolveOnce({
|
|
786
|
+
success: false,
|
|
787
|
+
error: error?.message || "PAYMENT_FAILED"
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
providerStarted = true;
|
|
792
|
+
} catch {
|
|
793
|
+
resolveOnce({ success: false, error: "POPUP_BLOCKED" });
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
var PaystackAuthorizationAdapter = class {
|
|
798
|
+
constructor(openPopup = openPaystackPopup) {
|
|
799
|
+
this.openPopup = openPopup;
|
|
800
|
+
this.provider = "paystack";
|
|
801
|
+
}
|
|
802
|
+
async authorize(context) {
|
|
803
|
+
const result = await this.openPopup(
|
|
804
|
+
{
|
|
805
|
+
key: context.action.public_key,
|
|
806
|
+
email: context.email,
|
|
807
|
+
accessCode: context.action.client_secret,
|
|
808
|
+
reference: context.reference || context.action.client_secret,
|
|
809
|
+
currency: context.currency
|
|
810
|
+
},
|
|
811
|
+
context.signal
|
|
812
|
+
);
|
|
813
|
+
if (result.success) {
|
|
814
|
+
return { status: "submitted", reference: result.reference || context.reference };
|
|
815
|
+
}
|
|
816
|
+
if (result.error === "SUBMISSION_UNKNOWN") {
|
|
817
|
+
return { status: "submitted", reference: context.reference };
|
|
818
|
+
}
|
|
819
|
+
if (!result.error || result.error === "CANCELLED" || result.error === "PAYMENT_CANCELLED") {
|
|
820
|
+
return { status: "cancelled" };
|
|
821
|
+
}
|
|
822
|
+
if (result.error === "POPUP_BLOCKED") {
|
|
823
|
+
return {
|
|
824
|
+
status: "failed",
|
|
825
|
+
code: "POPUP_BLOCKED",
|
|
826
|
+
message: "Unable to open the Paystack payment popup. Please allow popups and try again.",
|
|
827
|
+
recoverable: true
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
if (result.error === "PROVIDER_UNAVAILABLE") {
|
|
831
|
+
return {
|
|
832
|
+
status: "failed",
|
|
833
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
834
|
+
message: "Paystack is unavailable in this environment.",
|
|
835
|
+
recoverable: false
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
return {
|
|
839
|
+
status: "failed",
|
|
840
|
+
code: "PAYMENT_FAILED",
|
|
841
|
+
message: result.error || "Paystack payment could not be submitted.",
|
|
842
|
+
recoverable: true
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
// src/payment-authorization/providers/stripe.ts
|
|
848
|
+
async function loadStripeFromPeer(publicKey) {
|
|
849
|
+
try {
|
|
850
|
+
const imported = await import('@stripe/stripe-js');
|
|
851
|
+
return imported.loadStripe ? imported.loadStripe(publicKey) : null;
|
|
852
|
+
} catch {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
function createStripeModal() {
|
|
857
|
+
if (typeof document === "undefined" || !document.body) return null;
|
|
858
|
+
const previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
859
|
+
const root = document.createElement("div");
|
|
860
|
+
root.setAttribute("role", "dialog");
|
|
861
|
+
root.setAttribute("aria-modal", "true");
|
|
862
|
+
root.setAttribute("aria-label", "Secure card payment");
|
|
863
|
+
Object.assign(root.style, {
|
|
864
|
+
position: "fixed",
|
|
865
|
+
inset: "0",
|
|
866
|
+
zIndex: "2147483647",
|
|
867
|
+
display: "grid",
|
|
868
|
+
placeItems: "center",
|
|
869
|
+
padding: "16px",
|
|
870
|
+
background: "rgba(15, 23, 42, 0.58)"
|
|
871
|
+
});
|
|
872
|
+
const form = document.createElement("form");
|
|
873
|
+
Object.assign(form.style, {
|
|
874
|
+
width: "min(100%, 480px)",
|
|
875
|
+
maxHeight: "calc(100vh - 32px)",
|
|
876
|
+
overflow: "auto",
|
|
877
|
+
borderRadius: "12px",
|
|
878
|
+
padding: "24px",
|
|
879
|
+
background: "#fff",
|
|
880
|
+
boxShadow: "0 24px 80px rgba(15, 23, 42, 0.32)"
|
|
881
|
+
});
|
|
882
|
+
const title = document.createElement("h2");
|
|
883
|
+
title.textContent = "Complete card payment";
|
|
884
|
+
Object.assign(title.style, { margin: "0 0 18px", font: "600 18px/1.4 system-ui" });
|
|
885
|
+
const paymentMount = document.createElement("div");
|
|
886
|
+
paymentMount.setAttribute("data-cimplify-stripe-payment-element", "");
|
|
887
|
+
const error = document.createElement("p");
|
|
888
|
+
error.setAttribute("role", "alert");
|
|
889
|
+
Object.assign(error.style, {
|
|
890
|
+
minHeight: "20px",
|
|
891
|
+
margin: "14px 0 0",
|
|
892
|
+
color: "#b91c1c",
|
|
893
|
+
font: "14px/1.4 system-ui"
|
|
894
|
+
});
|
|
895
|
+
const actions = document.createElement("div");
|
|
896
|
+
Object.assign(actions.style, {
|
|
897
|
+
display: "flex",
|
|
898
|
+
justifyContent: "flex-end",
|
|
899
|
+
gap: "10px",
|
|
900
|
+
marginTop: "18px"
|
|
901
|
+
});
|
|
902
|
+
const cancelButton = document.createElement("button");
|
|
903
|
+
cancelButton.type = "button";
|
|
904
|
+
cancelButton.textContent = "Cancel";
|
|
905
|
+
Object.assign(cancelButton.style, {
|
|
906
|
+
border: "1px solid #cbd5e1",
|
|
907
|
+
borderRadius: "8px",
|
|
908
|
+
padding: "10px 16px",
|
|
909
|
+
background: "#fff",
|
|
910
|
+
color: "#0f172a",
|
|
911
|
+
cursor: "pointer"
|
|
912
|
+
});
|
|
913
|
+
const submitButton = document.createElement("button");
|
|
914
|
+
submitButton.type = "submit";
|
|
915
|
+
submitButton.textContent = "Pay securely";
|
|
916
|
+
Object.assign(submitButton.style, {
|
|
917
|
+
border: "0",
|
|
918
|
+
borderRadius: "8px",
|
|
919
|
+
padding: "10px 16px",
|
|
920
|
+
background: "#0f172a",
|
|
921
|
+
color: "#fff",
|
|
922
|
+
cursor: "pointer"
|
|
923
|
+
});
|
|
924
|
+
actions.append(cancelButton, submitButton);
|
|
925
|
+
form.append(title, paymentMount, error, actions);
|
|
926
|
+
root.append(form);
|
|
927
|
+
document.body.append(root);
|
|
928
|
+
cancelButton.focus();
|
|
929
|
+
return { root, form, paymentMount, submitButton, cancelButton, error, previousFocus };
|
|
930
|
+
}
|
|
931
|
+
function stripeFailure(error) {
|
|
932
|
+
const message = error?.message || "Stripe could not authorize this payment.";
|
|
933
|
+
if (error?.code === "payment_intent_authentication_failure" || error?.type === "invalid_request_error") {
|
|
934
|
+
return {
|
|
935
|
+
status: "failed",
|
|
936
|
+
code: "AUTHORIZATION_FAILED",
|
|
937
|
+
message,
|
|
938
|
+
recoverable: true
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
return { status: "failed", code: "PAYMENT_FAILED", message, recoverable: true };
|
|
942
|
+
}
|
|
943
|
+
var StripeAuthorizationAdapter = class {
|
|
944
|
+
constructor(loadStripe = loadStripeFromPeer) {
|
|
945
|
+
this.loadStripe = loadStripe;
|
|
946
|
+
this.provider = "stripe";
|
|
947
|
+
}
|
|
948
|
+
async authorize(context) {
|
|
949
|
+
if (typeof window === "undefined" || typeof document === "undefined" || context.signal?.aborted) {
|
|
950
|
+
return context.signal?.aborted ? { status: "cancelled" } : {
|
|
951
|
+
status: "failed",
|
|
952
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
953
|
+
message: "Stripe Payment Element is unavailable in this environment.",
|
|
954
|
+
recoverable: false
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
let stripe;
|
|
958
|
+
try {
|
|
959
|
+
stripe = await this.loadStripe(context.action.public_key);
|
|
960
|
+
} catch (error) {
|
|
961
|
+
return {
|
|
962
|
+
status: "failed",
|
|
963
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
964
|
+
message: error instanceof Error ? error.message : "Stripe.js could not be loaded.",
|
|
965
|
+
recoverable: true
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
if (context.signal?.aborted) {
|
|
969
|
+
return { status: "cancelled" };
|
|
970
|
+
}
|
|
971
|
+
if (!stripe) {
|
|
972
|
+
return {
|
|
973
|
+
status: "failed",
|
|
974
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
975
|
+
message: "Stripe.js could not be loaded.",
|
|
976
|
+
recoverable: false
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
const modal = createStripeModal();
|
|
980
|
+
if (!modal) {
|
|
981
|
+
return {
|
|
982
|
+
status: "failed",
|
|
983
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
984
|
+
message: "Stripe Payment Element could not be mounted.",
|
|
985
|
+
recoverable: false
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
let paymentElement;
|
|
989
|
+
let elements;
|
|
990
|
+
try {
|
|
991
|
+
elements = stripe.elements({ clientSecret: context.action.client_secret });
|
|
992
|
+
paymentElement = elements.create("payment");
|
|
993
|
+
paymentElement.mount(modal.paymentMount);
|
|
994
|
+
} catch {
|
|
995
|
+
modal.root.remove();
|
|
996
|
+
modal.previousFocus?.focus();
|
|
997
|
+
return {
|
|
998
|
+
status: "failed",
|
|
999
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
1000
|
+
message: "Stripe Payment Element could not be initialized.",
|
|
1001
|
+
recoverable: false
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
if (context.signal?.aborted) {
|
|
1005
|
+
if (paymentElement.destroy) paymentElement.destroy();
|
|
1006
|
+
else paymentElement.unmount?.();
|
|
1007
|
+
modal.root.remove();
|
|
1008
|
+
modal.previousFocus?.focus();
|
|
1009
|
+
return { status: "cancelled" };
|
|
1010
|
+
}
|
|
1011
|
+
return new Promise((resolve) => {
|
|
1012
|
+
let settled = false;
|
|
1013
|
+
let submitting = false;
|
|
1014
|
+
let confirmationStarted = false;
|
|
1015
|
+
const cleanup = () => {
|
|
1016
|
+
context.signal?.removeEventListener("abort", onAbort);
|
|
1017
|
+
modal.form.removeEventListener("submit", onSubmit);
|
|
1018
|
+
modal.cancelButton.removeEventListener("click", onCancel);
|
|
1019
|
+
if (paymentElement.destroy) paymentElement.destroy();
|
|
1020
|
+
else paymentElement.unmount?.();
|
|
1021
|
+
modal.root.remove();
|
|
1022
|
+
modal.previousFocus?.focus();
|
|
1023
|
+
};
|
|
1024
|
+
const settle = (outcome) => {
|
|
1025
|
+
if (settled) return;
|
|
1026
|
+
settled = true;
|
|
1027
|
+
cleanup();
|
|
1028
|
+
resolve(outcome);
|
|
1029
|
+
};
|
|
1030
|
+
const onAbort = () => {
|
|
1031
|
+
if (confirmationStarted) {
|
|
1032
|
+
settle({ status: "submitted", reference: context.reference });
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
settle({ status: "cancelled" });
|
|
1036
|
+
};
|
|
1037
|
+
const onCancel = () => {
|
|
1038
|
+
if (!confirmationStarted) settle({ status: "cancelled" });
|
|
1039
|
+
};
|
|
1040
|
+
const onSubmit = async (event) => {
|
|
1041
|
+
event.preventDefault();
|
|
1042
|
+
if (submitting || settled) return;
|
|
1043
|
+
submitting = true;
|
|
1044
|
+
modal.submitButton.disabled = true;
|
|
1045
|
+
modal.error.textContent = "";
|
|
1046
|
+
try {
|
|
1047
|
+
const validation = elements.submit ? await elements.submit() : {};
|
|
1048
|
+
if (validation.error) {
|
|
1049
|
+
modal.error.textContent = validation.error.message || "Check your payment details.";
|
|
1050
|
+
submitting = false;
|
|
1051
|
+
modal.submitButton.disabled = false;
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
if (settled || context.signal?.aborted) {
|
|
1055
|
+
settle({ status: "cancelled" });
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
confirmationStarted = true;
|
|
1059
|
+
modal.cancelButton.disabled = true;
|
|
1060
|
+
const confirmation = await stripe.confirmPayment({
|
|
1061
|
+
elements,
|
|
1062
|
+
confirmParams: { return_url: context.returnUrl || window.location.href },
|
|
1063
|
+
redirect: "if_required"
|
|
1064
|
+
});
|
|
1065
|
+
if (settled) return;
|
|
1066
|
+
if (confirmation.error) {
|
|
1067
|
+
settle(stripeFailure(confirmation.error));
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
settle({
|
|
1071
|
+
status: "submitted",
|
|
1072
|
+
reference: confirmation.paymentIntent?.id || context.reference
|
|
1073
|
+
});
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
if (confirmationStarted) {
|
|
1076
|
+
settle({ status: "submitted", reference: context.reference });
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
settle(
|
|
1080
|
+
stripeFailure({
|
|
1081
|
+
message: error instanceof Error ? error.message : "Stripe confirmation failed."
|
|
1082
|
+
})
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
modal.form.addEventListener("submit", onSubmit);
|
|
1087
|
+
modal.cancelButton.addEventListener("click", onCancel);
|
|
1088
|
+
context.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1089
|
+
paymentElement.on?.("escape", onCancel);
|
|
1090
|
+
paymentElement.on?.("loaderror", (event) => {
|
|
1091
|
+
if (confirmationStarted) return;
|
|
1092
|
+
settle({
|
|
1093
|
+
status: "failed",
|
|
1094
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
1095
|
+
message: event?.error?.message || "Stripe Payment Element failed to load.",
|
|
1096
|
+
recoverable: true
|
|
1097
|
+
});
|
|
1098
|
+
});
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
// src/payment-authorization/registry.ts
|
|
1104
|
+
function normalizeProvider(provider) {
|
|
1105
|
+
return typeof provider === "string" ? provider.trim().toLowerCase() : "";
|
|
1106
|
+
}
|
|
1107
|
+
var PaymentAuthorizationAdapterRegistry = class {
|
|
1108
|
+
constructor(adapters = []) {
|
|
1109
|
+
this.adapters = /* @__PURE__ */ new Map();
|
|
1110
|
+
for (const adapter of adapters) {
|
|
1111
|
+
this.register(adapter);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
register(adapter) {
|
|
1115
|
+
const provider = normalizeProvider(adapter.provider);
|
|
1116
|
+
if (!provider) {
|
|
1117
|
+
throw new TypeError("Payment authorization adapter provider cannot be empty.");
|
|
1118
|
+
}
|
|
1119
|
+
this.adapters.set(provider, adapter);
|
|
1120
|
+
return this;
|
|
1121
|
+
}
|
|
1122
|
+
unregister(provider) {
|
|
1123
|
+
return this.adapters.delete(normalizeProvider(provider));
|
|
1124
|
+
}
|
|
1125
|
+
get(provider) {
|
|
1126
|
+
return this.adapters.get(normalizeProvider(provider));
|
|
1127
|
+
}
|
|
1128
|
+
supports(provider) {
|
|
1129
|
+
return this.adapters.has(normalizeProvider(provider));
|
|
1130
|
+
}
|
|
1131
|
+
providers() {
|
|
1132
|
+
return [...this.adapters.keys()];
|
|
1133
|
+
}
|
|
1134
|
+
async authorize(action, options) {
|
|
1135
|
+
const provider = normalizeProvider(action.provider);
|
|
1136
|
+
if (!provider) {
|
|
1137
|
+
return {
|
|
1138
|
+
status: "failed",
|
|
1139
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
1140
|
+
message: "Card authorization response did not identify a payment provider.",
|
|
1141
|
+
recoverable: false
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
const adapter = this.adapters.get(provider);
|
|
1145
|
+
if (!adapter) {
|
|
1146
|
+
return {
|
|
1147
|
+
status: "failed",
|
|
1148
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
1149
|
+
message: `Card authorization provider '${provider}' is not supported by this SDK client.`,
|
|
1150
|
+
recoverable: false
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
try {
|
|
1154
|
+
const normalizedAction = action.provider === provider ? action : { ...action, provider };
|
|
1155
|
+
return await adapter.authorize({ ...options, action: normalizedAction });
|
|
1156
|
+
} catch (error) {
|
|
1157
|
+
return {
|
|
1158
|
+
status: "failed",
|
|
1159
|
+
code: "PAYMENT_FAILED",
|
|
1160
|
+
message: error instanceof Error ? error.message : `Card authorization provider '${provider}' failed unexpectedly.`,
|
|
1161
|
+
recoverable: true
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
function createDefaultPaymentAuthorizationAdapterRegistry() {
|
|
1167
|
+
return new PaymentAuthorizationAdapterRegistry([
|
|
1168
|
+
new PaystackAuthorizationAdapter(),
|
|
1169
|
+
new StripeAuthorizationAdapter()
|
|
1170
|
+
]);
|
|
1171
|
+
}
|
|
1172
|
+
|
|
726
1173
|
// src/client.ts
|
|
727
1174
|
var SESSION_TOKEN_STORAGE_KEY = "cimplify_session_token";
|
|
728
1175
|
var SESSION_SYNC_STORAGE_KEY = "cimplify_session_sync";
|
|
@@ -774,16 +1221,16 @@ function isRetryable(error) {
|
|
|
774
1221
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
775
1222
|
return true;
|
|
776
1223
|
}
|
|
777
|
-
if (error instanceof
|
|
1224
|
+
if (error instanceof chunkJG5CQNCB_js.CimplifyError) {
|
|
778
1225
|
return error.retryable;
|
|
779
1226
|
}
|
|
780
1227
|
return false;
|
|
781
1228
|
}
|
|
782
1229
|
function toNetworkError(error, isTestMode) {
|
|
783
1230
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
784
|
-
return
|
|
785
|
-
new
|
|
786
|
-
|
|
1231
|
+
return chunkJG5CQNCB_js.enrichError(
|
|
1232
|
+
new chunkJG5CQNCB_js.CimplifyError(
|
|
1233
|
+
chunkJG5CQNCB_js.ErrorCode.TIMEOUT,
|
|
787
1234
|
"Request timed out. Please check your connection and try again.",
|
|
788
1235
|
true
|
|
789
1236
|
),
|
|
@@ -791,21 +1238,21 @@ function toNetworkError(error, isTestMode) {
|
|
|
791
1238
|
);
|
|
792
1239
|
}
|
|
793
1240
|
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
794
|
-
return
|
|
795
|
-
new
|
|
796
|
-
|
|
1241
|
+
return chunkJG5CQNCB_js.enrichError(
|
|
1242
|
+
new chunkJG5CQNCB_js.CimplifyError(
|
|
1243
|
+
chunkJG5CQNCB_js.ErrorCode.NETWORK_ERROR,
|
|
797
1244
|
"Network error. Please check your internet connection.",
|
|
798
1245
|
true
|
|
799
1246
|
),
|
|
800
1247
|
{ isTestMode }
|
|
801
1248
|
);
|
|
802
1249
|
}
|
|
803
|
-
if (error instanceof
|
|
804
|
-
return
|
|
1250
|
+
if (error instanceof chunkJG5CQNCB_js.CimplifyError) {
|
|
1251
|
+
return chunkJG5CQNCB_js.enrichError(error, { isTestMode });
|
|
805
1252
|
}
|
|
806
|
-
return
|
|
807
|
-
new
|
|
808
|
-
|
|
1253
|
+
return chunkJG5CQNCB_js.enrichError(
|
|
1254
|
+
new chunkJG5CQNCB_js.CimplifyError(
|
|
1255
|
+
chunkJG5CQNCB_js.ErrorCode.UNKNOWN_ERROR,
|
|
809
1256
|
error instanceof Error ? error.message : "An unknown error occurred",
|
|
810
1257
|
false
|
|
811
1258
|
),
|
|
@@ -847,6 +1294,7 @@ var CimplifyClient = class {
|
|
|
847
1294
|
this.context = {};
|
|
848
1295
|
this.businessId = null;
|
|
849
1296
|
this.businessIdResolvePromise = null;
|
|
1297
|
+
this.publicKeyEpoch = 0;
|
|
850
1298
|
this.inflightRequests = /* @__PURE__ */ new Map();
|
|
851
1299
|
/**
|
|
852
1300
|
* App-level event channel. Subscribe to surface mutation rollbacks, outbox
|
|
@@ -865,6 +1313,7 @@ var CimplifyClient = class {
|
|
|
865
1313
|
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
866
1314
|
this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
|
|
867
1315
|
this.hooks = config.hooks ?? {};
|
|
1316
|
+
this.authorizationAdapters = config.authorizationAdapterRegistry ?? createDefaultPaymentAuthorizationAdapterRegistry();
|
|
868
1317
|
this.fetchImpl = (config.fetch ?? globalThis.fetch).bind(globalThis);
|
|
869
1318
|
this.sessionToken = this.loadSessionToken() ?? this.mintSessionToken();
|
|
870
1319
|
this.watchCrossTabSession();
|
|
@@ -1081,10 +1530,18 @@ var CimplifyClient = class {
|
|
|
1081
1530
|
// X-API-Key and the business can't be resolved.
|
|
1082
1531
|
setPublicKey(publicKey) {
|
|
1083
1532
|
const normalized = publicKey.trim();
|
|
1084
|
-
if (
|
|
1085
|
-
return;
|
|
1086
|
-
}
|
|
1533
|
+
if (normalized === this.publicKey) return;
|
|
1087
1534
|
this.publicKey = normalized;
|
|
1535
|
+
this.publicKeyEpoch += 1;
|
|
1536
|
+
this.businessId = null;
|
|
1537
|
+
this.businessIdResolvePromise = null;
|
|
1538
|
+
this.inflightRequests.clear();
|
|
1539
|
+
this._activity?.resetSession();
|
|
1540
|
+
delete this.context.location_id;
|
|
1541
|
+
if (this.accessToken !== null) {
|
|
1542
|
+
this.setAccessToken(null);
|
|
1543
|
+
}
|
|
1544
|
+
this.events.emit(SESSION_CLEARED, {});
|
|
1088
1545
|
}
|
|
1089
1546
|
getBusinessId() {
|
|
1090
1547
|
return this.businessId;
|
|
@@ -1096,22 +1553,33 @@ var CimplifyClient = class {
|
|
|
1096
1553
|
if (this.businessIdResolvePromise) {
|
|
1097
1554
|
return this.businessIdResolvePromise;
|
|
1098
1555
|
}
|
|
1099
|
-
|
|
1556
|
+
const publicKeyEpoch = this.publicKeyEpoch;
|
|
1557
|
+
const resolution = (async () => {
|
|
1100
1558
|
const result = await this.business.getInfo();
|
|
1101
1559
|
if (!result.ok || !result.value?.id) {
|
|
1102
|
-
throw new
|
|
1103
|
-
|
|
1560
|
+
throw new chunkJG5CQNCB_js.CimplifyError(
|
|
1561
|
+
chunkJG5CQNCB_js.ErrorCode.NOT_FOUND,
|
|
1104
1562
|
"Unable to resolve business ID from the current public key.",
|
|
1105
1563
|
true
|
|
1106
1564
|
);
|
|
1107
1565
|
}
|
|
1566
|
+
if (this.publicKeyEpoch !== publicKeyEpoch) {
|
|
1567
|
+
throw new chunkJG5CQNCB_js.CimplifyError(
|
|
1568
|
+
chunkJG5CQNCB_js.ErrorCode.TENANT_CONTEXT_CHANGED,
|
|
1569
|
+
"The storefront tenant changed while resolving its business identity.",
|
|
1570
|
+
true
|
|
1571
|
+
);
|
|
1572
|
+
}
|
|
1108
1573
|
this.businessId = result.value.id;
|
|
1109
1574
|
return result.value.id;
|
|
1110
1575
|
})();
|
|
1576
|
+
this.businessIdResolvePromise = resolution;
|
|
1111
1577
|
try {
|
|
1112
|
-
return await
|
|
1578
|
+
return await resolution;
|
|
1113
1579
|
} finally {
|
|
1114
|
-
this.businessIdResolvePromise
|
|
1580
|
+
if (this.businessIdResolvePromise === resolution) {
|
|
1581
|
+
this.businessIdResolvePromise = null;
|
|
1582
|
+
}
|
|
1115
1583
|
}
|
|
1116
1584
|
}
|
|
1117
1585
|
async authedFetch(url, options, timeoutMs) {
|
|
@@ -1240,7 +1708,7 @@ var CimplifyClient = class {
|
|
|
1240
1708
|
if (response.status >= 400 && response.status < 500) {
|
|
1241
1709
|
this.hooks.onRequestError?.({
|
|
1242
1710
|
...context,
|
|
1243
|
-
error: new
|
|
1711
|
+
error: new chunkJG5CQNCB_js.CimplifyError(
|
|
1244
1712
|
`HTTP_${response.status}`,
|
|
1245
1713
|
`Request failed with status ${response.status}`,
|
|
1246
1714
|
false
|
|
@@ -1266,7 +1734,7 @@ var CimplifyClient = class {
|
|
|
1266
1734
|
}
|
|
1267
1735
|
this.hooks.onRequestError?.({
|
|
1268
1736
|
...context,
|
|
1269
|
-
error: new
|
|
1737
|
+
error: new chunkJG5CQNCB_js.CimplifyError(
|
|
1270
1738
|
"SERVER_ERROR",
|
|
1271
1739
|
`Server error ${response.status} after ${retryCount} retries`,
|
|
1272
1740
|
false
|
|
@@ -1314,7 +1782,13 @@ var CimplifyClient = class {
|
|
|
1314
1782
|
}
|
|
1315
1783
|
getDedupeKey(type, payload, cacheOptions) {
|
|
1316
1784
|
const cacheKey = cacheOptions ? `|${JSON.stringify(cacheOptions)}` : "";
|
|
1317
|
-
|
|
1785
|
+
const identityKey = JSON.stringify([
|
|
1786
|
+
this.publicKey.trim(),
|
|
1787
|
+
this.publicKeyEpoch,
|
|
1788
|
+
this.sessionEpoch,
|
|
1789
|
+
this.context.location_id ?? null
|
|
1790
|
+
]);
|
|
1791
|
+
return `${type}:${identityKey}:${JSON.stringify(payload)}${cacheKey}`;
|
|
1318
1792
|
}
|
|
1319
1793
|
async deduplicatedRequest(key, requestFn) {
|
|
1320
1794
|
const existing = this.inflightRequests.get(key);
|
|
@@ -1322,7 +1796,9 @@ var CimplifyClient = class {
|
|
|
1322
1796
|
return existing;
|
|
1323
1797
|
}
|
|
1324
1798
|
const request = requestFn().finally(() => {
|
|
1325
|
-
this.inflightRequests.
|
|
1799
|
+
if (this.inflightRequests.get(key) === request) {
|
|
1800
|
+
this.inflightRequests.delete(key);
|
|
1801
|
+
}
|
|
1326
1802
|
});
|
|
1327
1803
|
this.inflightRequests.set(key, request);
|
|
1328
1804
|
return request;
|
|
@@ -1418,12 +1894,12 @@ var CimplifyClient = class {
|
|
|
1418
1894
|
const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
|
|
1419
1895
|
if (errorCode === "IDEMPOTENCY_MISMATCH") {
|
|
1420
1896
|
const originalCreatedAt = typeof json.error === "object" && json.error?.original_created_at || "";
|
|
1421
|
-
throw new
|
|
1897
|
+
throw new chunkJG5CQNCB_js.IdempotencyMismatchError(errorMessage, originalCreatedAt);
|
|
1422
1898
|
}
|
|
1423
|
-
const error =
|
|
1899
|
+
const error = chunkJG5CQNCB_js.enrichError(new chunkJG5CQNCB_js.CimplifyError(errorCode, errorMessage, retryable), {
|
|
1424
1900
|
isTestMode: this.isTestMode()
|
|
1425
1901
|
});
|
|
1426
|
-
if ((response.status === 401 || error.code ===
|
|
1902
|
+
if ((response.status === 401 || error.code === chunkJG5CQNCB_js.ErrorCode.UNAUTHORIZED) && this.accessToken) {
|
|
1427
1903
|
console.warn(
|
|
1428
1904
|
"[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
|
|
1429
1905
|
);
|
|
@@ -1431,8 +1907,8 @@ var CimplifyClient = class {
|
|
|
1431
1907
|
throw error;
|
|
1432
1908
|
}
|
|
1433
1909
|
if (json?.success === false || json?.error?.code || json?.error?.message) {
|
|
1434
|
-
const error =
|
|
1435
|
-
new
|
|
1910
|
+
const error = chunkJG5CQNCB_js.enrichError(
|
|
1911
|
+
new chunkJG5CQNCB_js.CimplifyError(
|
|
1436
1912
|
json.error?.code || "API_ERROR",
|
|
1437
1913
|
json.error?.message || "An error occurred",
|
|
1438
1914
|
json.error?.retryable || false
|
|
@@ -1448,25 +1924,25 @@ var CimplifyClient = class {
|
|
|
1448
1924
|
}
|
|
1449
1925
|
get catalogue() {
|
|
1450
1926
|
if (!this._catalogue) {
|
|
1451
|
-
this._catalogue = new
|
|
1927
|
+
this._catalogue = new chunkJSWJ4XDE_js.CatalogueQueries(this);
|
|
1452
1928
|
}
|
|
1453
1929
|
return this._catalogue;
|
|
1454
1930
|
}
|
|
1455
1931
|
get cart() {
|
|
1456
1932
|
if (!this._cart) {
|
|
1457
|
-
this._cart = new
|
|
1933
|
+
this._cart = new chunkJSWJ4XDE_js.CartOperations(this);
|
|
1458
1934
|
}
|
|
1459
1935
|
return this._cart;
|
|
1460
1936
|
}
|
|
1461
1937
|
get checkout() {
|
|
1462
1938
|
if (!this._checkout) {
|
|
1463
|
-
this._checkout = new
|
|
1939
|
+
this._checkout = new chunkJSWJ4XDE_js.CheckoutService(this);
|
|
1464
1940
|
}
|
|
1465
1941
|
return this._checkout;
|
|
1466
1942
|
}
|
|
1467
1943
|
get orders() {
|
|
1468
1944
|
if (!this._orders) {
|
|
1469
|
-
this._orders = new
|
|
1945
|
+
this._orders = new chunkJSWJ4XDE_js.OrderQueries(this);
|
|
1470
1946
|
}
|
|
1471
1947
|
return this._orders;
|
|
1472
1948
|
}
|
|
@@ -1496,43 +1972,43 @@ var CimplifyClient = class {
|
|
|
1496
1972
|
}
|
|
1497
1973
|
get link() {
|
|
1498
1974
|
if (!this._link) {
|
|
1499
|
-
this._link = new
|
|
1975
|
+
this._link = new chunkJSWJ4XDE_js.LinkService(this);
|
|
1500
1976
|
}
|
|
1501
1977
|
return this._link;
|
|
1502
1978
|
}
|
|
1503
1979
|
get auth() {
|
|
1504
1980
|
if (!this._auth) {
|
|
1505
|
-
this._auth = new
|
|
1981
|
+
this._auth = new chunkJSWJ4XDE_js.AuthService(this);
|
|
1506
1982
|
}
|
|
1507
1983
|
return this._auth;
|
|
1508
1984
|
}
|
|
1509
1985
|
get business() {
|
|
1510
1986
|
if (!this._business) {
|
|
1511
|
-
this._business = new
|
|
1987
|
+
this._business = new chunkJSWJ4XDE_js.BusinessService(this);
|
|
1512
1988
|
}
|
|
1513
1989
|
return this._business;
|
|
1514
1990
|
}
|
|
1515
1991
|
get inventory() {
|
|
1516
1992
|
if (!this._inventory) {
|
|
1517
|
-
this._inventory = new
|
|
1993
|
+
this._inventory = new chunkJSWJ4XDE_js.InventoryService(this);
|
|
1518
1994
|
}
|
|
1519
1995
|
return this._inventory;
|
|
1520
1996
|
}
|
|
1521
1997
|
get scheduling() {
|
|
1522
1998
|
if (!this._scheduling) {
|
|
1523
|
-
this._scheduling = new
|
|
1999
|
+
this._scheduling = new chunkJSWJ4XDE_js.SchedulingService(this);
|
|
1524
2000
|
}
|
|
1525
2001
|
return this._scheduling;
|
|
1526
2002
|
}
|
|
1527
2003
|
get lite() {
|
|
1528
2004
|
if (!this._lite) {
|
|
1529
|
-
this._lite = new
|
|
2005
|
+
this._lite = new chunkJSWJ4XDE_js.LiteService(this);
|
|
1530
2006
|
}
|
|
1531
2007
|
return this._lite;
|
|
1532
2008
|
}
|
|
1533
2009
|
get fx() {
|
|
1534
2010
|
if (!this._fx) {
|
|
1535
|
-
this._fx = new
|
|
2011
|
+
this._fx = new chunkJSWJ4XDE_js.FxService(this);
|
|
1536
2012
|
}
|
|
1537
2013
|
return this._fx;
|
|
1538
2014
|
}
|
|
@@ -1567,7 +2043,7 @@ var CimplifyClient = class {
|
|
|
1567
2043
|
if (businessId) {
|
|
1568
2044
|
this.setBusinessId(businessId);
|
|
1569
2045
|
}
|
|
1570
|
-
return
|
|
2046
|
+
return chunkJSWJ4XDE_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
|
|
1571
2047
|
}
|
|
1572
2048
|
};
|
|
1573
2049
|
function createCimplifyClient(config = {}) {
|
|
@@ -1579,11 +2055,15 @@ exports.ActivityService = ActivityService;
|
|
|
1579
2055
|
exports.CimplifyClient = CimplifyClient;
|
|
1580
2056
|
exports.DeliveryService = DeliveryService;
|
|
1581
2057
|
exports.MUTATION_ERROR = MUTATION_ERROR;
|
|
2058
|
+
exports.PaymentAuthorizationAdapterRegistry = PaymentAuthorizationAdapterRegistry;
|
|
2059
|
+
exports.PaystackAuthorizationAdapter = PaystackAuthorizationAdapter;
|
|
1582
2060
|
exports.PlacesService = PlacesService;
|
|
1583
2061
|
exports.SESSION_CLAIMED = SESSION_CLAIMED;
|
|
1584
2062
|
exports.SESSION_CLEARED = SESSION_CLEARED;
|
|
1585
2063
|
exports.StoreCreditQueries = StoreCreditQueries;
|
|
2064
|
+
exports.StripeAuthorizationAdapter = StripeAuthorizationAdapter;
|
|
1586
2065
|
exports.SubscriptionService = SubscriptionService;
|
|
1587
2066
|
exports.SupportService = SupportService;
|
|
1588
2067
|
exports.UploadService = UploadService;
|
|
1589
2068
|
exports.createCimplifyClient = createCimplifyClient;
|
|
2069
|
+
exports.createDefaultPaymentAuthorizationAdapterRegistry = createDefaultPaymentAuthorizationAdapterRegistry;
|