@cimplify/sdk 0.106.2 → 0.107.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/advanced.d.mts +3 -3
- package/dist/advanced.d.ts +3 -3
- package/dist/advanced.js +22 -22
- package/dist/advanced.mjs +3 -3
- package/dist/{catalogue-CVKH9faR.d.mts → catalogue-AmW4XjaN.d.ts} +45 -38
- package/dist/{catalogue-ChBjPPME.d.ts → catalogue-rWd71Xi-.d.mts} +45 -38
- package/dist/{chunk-AVXA4F6G.js → chunk-ANT574FD.js} +29 -0
- package/dist/{chunk-BCLGREHS.js → chunk-CEML2737.js} +245 -219
- package/dist/{chunk-NYDVVNZI.mjs → chunk-JRGK3NXR.mjs} +1 -1
- package/dist/{chunk-NJYR6GGM.mjs → chunk-KG3WT4PR.mjs} +29 -1
- package/dist/{chunk-4VTFTLH7.mjs → chunk-NZMU7UUA.mjs} +3 -3
- package/dist/{chunk-B7JH5D3J.js → chunk-ONII7K3T.js} +262 -303
- package/dist/{chunk-T3MXI7JD.mjs → chunk-OTPLI3JY.mjs} +87 -128
- package/dist/{chunk-LJAZ7H4I.mjs → chunk-T4OU77DM.mjs} +108 -83
- package/dist/{chunk-7O2BBPDM.js → chunk-THSYGWUA.js} +70 -70
- package/dist/{chunk-NJK3THWT.js → chunk-UVRPC2P7.js} +90 -62
- package/dist/{chunk-UYFTOIFW.js → chunk-V32BCG7M.js} +6 -6
- package/dist/{chunk-L4XKIMUO.mjs → chunk-XBL3TMPC.mjs} +31 -3
- package/dist/{client-BfKFK7cn.d.mts → client-DlTJ2hUM.d.mts} +2 -2
- package/dist/{client-DoczTJbs.d.ts → client-ni-CfOSO.d.ts} +2 -2
- package/dist/{checkout-XoV4HNg2.d.mts → elements-BF1Y4aOi.d.mts} +575 -502
- package/dist/{checkout-XoV4HNg2.d.ts → elements-BF1Y4aOi.d.ts} +575 -502
- package/dist/{index-DweR60Cv.d.ts → index-CZ0bJm6k.d.ts} +2 -2
- package/dist/{index-DRMBo26v.d.mts → index-DML_W635.d.mts} +2 -2
- package/dist/{index-Dn6xCpDe.d.ts → index-DU7vffby.d.ts} +2 -2
- package/dist/{index-DEUorPUO.d.mts → index-DopYJKDL.d.mts} +2 -2
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +159 -151
- package/dist/index.mjs +5 -5
- package/dist/mock/cli.mjs +33 -2
- package/dist/mock/library.js +33 -2
- package/dist/mock/library.mjs +33 -2
- package/dist/mock/msw.js +33 -2
- package/dist/mock/msw.mjs +33 -2
- package/dist/{price-De-sxcuj.d.ts → price-B5t2mpsE.d.ts} +1 -1
- package/dist/{price-CUGIYRtD.d.mts → price-DI_U5oXU.d.mts} +1 -1
- package/dist/react.d.mts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +154 -154
- package/dist/react.mjs +7 -7
- package/dist/{server-7soMMUgP.d.ts → server-BItJAUTD.d.ts} +1 -1
- package/dist/{server-DDEJ7e9s.d.mts → server-Dq70vD7z.d.mts} +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/server.js +10 -10
- package/dist/server.mjs +4 -4
- package/dist/testing/msw.d.mts +2 -2
- package/dist/testing/msw.d.ts +2 -2
- package/dist/testing/msw.js +3 -3
- package/dist/testing/msw.mjs +2 -2
- package/dist/testing/suite.d.mts +5 -5
- package/dist/testing/suite.d.ts +5 -5
- package/dist/testing/suite.js +26 -26
- package/dist/testing/suite.mjs +6 -6
- package/dist/testing.d.mts +4 -4
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +118 -118
- package/dist/testing.mjs +7 -7
- package/dist/utils.d.mts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +32 -32
- package/dist/utils.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkXREIZ56K_js = require('./chunk-XREIZ56K.js');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var chunkONII7K3T_js = require('./chunk-ONII7K3T.js');
|
|
5
|
+
var chunkANT574FD_js = require('./chunk-ANT574FD.js');
|
|
6
6
|
|
|
7
7
|
// src/types/observability.ts
|
|
8
8
|
var SESSION_CHANGE_SOURCE = {
|
|
@@ -65,47 +65,47 @@ var PurchaseIntentResolver = class {
|
|
|
65
65
|
let termsReviewSteps = 0;
|
|
66
66
|
const requestOptions = { signal: options.signal, timeoutMs: options.requestTimeoutMs };
|
|
67
67
|
this.ensureActive(options.signal);
|
|
68
|
-
this.notify(options,
|
|
69
|
-
let responseResult = options.initialResponse ?
|
|
68
|
+
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.CONFIRMING);
|
|
69
|
+
let responseResult = options.initialResponse ? chunkONII7K3T_js.ok(options.initialResponse) : await this.confirmation.confirm(intentId, request, requestOptions);
|
|
70
70
|
while (responseResult.ok) {
|
|
71
71
|
this.ensureActive(options.signal);
|
|
72
72
|
const response = responseResult.value;
|
|
73
73
|
switch (response.status) {
|
|
74
|
-
case
|
|
75
|
-
this.notify(options,
|
|
76
|
-
return
|
|
77
|
-
case
|
|
78
|
-
this.notify(options,
|
|
79
|
-
return
|
|
80
|
-
case
|
|
81
|
-
this.notify(options,
|
|
82
|
-
return
|
|
83
|
-
case
|
|
74
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.ORDER_CREATED:
|
|
75
|
+
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.COMPLETED, response);
|
|
76
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.COMPLETED, response });
|
|
77
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.PAYMENT_FAILED:
|
|
78
|
+
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.FAILED, response);
|
|
79
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.FAILED, response });
|
|
80
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.PAYMENT_OUTCOME_UNKNOWN:
|
|
81
|
+
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.OUTCOME_UNKNOWN, response);
|
|
82
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.OUTCOME_UNKNOWN, response });
|
|
83
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.COLLECTION_PROCESSING:
|
|
84
84
|
if (pollAttempts >= maxPollAttempts) {
|
|
85
|
-
return
|
|
85
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.TIMED_OUT, response });
|
|
86
86
|
}
|
|
87
87
|
pollAttempts += 1;
|
|
88
|
-
this.notify(options,
|
|
88
|
+
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.POLLING, response);
|
|
89
89
|
await this.wait(pollIntervalMs, options.signal);
|
|
90
90
|
responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
91
91
|
continue;
|
|
92
|
-
case
|
|
93
|
-
case
|
|
94
|
-
case
|
|
95
|
-
this.notify(options,
|
|
92
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.REDIRECT_REQUIRED:
|
|
93
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.CARD_POPUP_REQUIRED:
|
|
94
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.AUTHORIZATION_REQUIRED: {
|
|
95
|
+
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.AWAITING_ACTION, response);
|
|
96
96
|
if (!options.onActionRequired || actionSteps >= maxActionSteps) {
|
|
97
|
-
return
|
|
97
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.ACTION_REQUIRED, response });
|
|
98
98
|
}
|
|
99
99
|
actionSteps += 1;
|
|
100
100
|
const decision = await options.onActionRequired(response);
|
|
101
|
-
if (decision ===
|
|
102
|
-
return
|
|
101
|
+
if (decision === chunkANT574FD_js.PURCHASE_INTENT_ACTION_DECISION.STOP) {
|
|
102
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.ACTION_REQUIRED, response });
|
|
103
103
|
}
|
|
104
|
-
if (typeof decision === "object" && decision.kind ===
|
|
104
|
+
if (typeof decision === "object" && decision.kind === chunkANT574FD_js.PURCHASE_INTENT_ACTION_DECISION.SUBMIT) {
|
|
105
105
|
if (!this.confirmation.submitAction) {
|
|
106
|
-
return
|
|
107
|
-
new
|
|
108
|
-
|
|
106
|
+
return chunkONII7K3T_js.err(
|
|
107
|
+
new chunkANT574FD_js.CimplifyError(
|
|
108
|
+
chunkANT574FD_js.PURCHASE_INTENT_ERROR_CODE.ACTION_UNSUPPORTED,
|
|
109
109
|
"This confirmation transport cannot submit purchase-intent actions.",
|
|
110
110
|
false
|
|
111
111
|
)
|
|
@@ -119,10 +119,10 @@ var PurchaseIntentResolver = class {
|
|
|
119
119
|
);
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
122
|
-
if (decision !==
|
|
123
|
-
return
|
|
124
|
-
new
|
|
125
|
-
|
|
122
|
+
if (decision !== chunkANT574FD_js.PURCHASE_INTENT_ACTION_DECISION.CONTINUE) {
|
|
123
|
+
return chunkONII7K3T_js.err(
|
|
124
|
+
new chunkANT574FD_js.CimplifyError(
|
|
125
|
+
chunkANT574FD_js.PURCHASE_INTENT_ERROR_CODE.ACTION_UNSUPPORTED,
|
|
126
126
|
"The action callback returned an unsupported decision.",
|
|
127
127
|
false
|
|
128
128
|
)
|
|
@@ -132,24 +132,24 @@ var PurchaseIntentResolver = class {
|
|
|
132
132
|
responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
133
133
|
continue;
|
|
134
134
|
}
|
|
135
|
-
case
|
|
136
|
-
this.notify(options,
|
|
135
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.TERMS_CHANGED: {
|
|
136
|
+
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.REVIEWING_TERMS, response);
|
|
137
137
|
if (!options.onTermsChanged || termsReviewSteps >= maxTermsReviewSteps) {
|
|
138
|
-
return
|
|
138
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
139
139
|
}
|
|
140
140
|
termsReviewSteps += 1;
|
|
141
141
|
const replacementRequest = await options.onTermsChanged(response);
|
|
142
142
|
if (!replacementRequest) {
|
|
143
|
-
return
|
|
143
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
144
144
|
}
|
|
145
145
|
request = replacementRequest;
|
|
146
146
|
responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
149
|
-
case
|
|
150
|
-
case
|
|
151
|
-
case
|
|
152
|
-
return
|
|
149
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.SELECTION_UNAVAILABLE:
|
|
150
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.OFFER_ENDED:
|
|
151
|
+
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.SOURCE_UNAVAILABLE:
|
|
152
|
+
return chunkONII7K3T_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
return responseResult;
|
|
@@ -192,7 +192,7 @@ var PurchaseIntentService = class {
|
|
|
192
192
|
this.resolver = new PurchaseIntentResolver({ confirmation: this });
|
|
193
193
|
}
|
|
194
194
|
mint(request, options) {
|
|
195
|
-
return
|
|
195
|
+
return chunkONII7K3T_js.safe(
|
|
196
196
|
this.transport.post(PURCHASE_INTENT_ROUTE.DIRECT_COLLECTION, request, {
|
|
197
197
|
idempotencyKey: request.client_intent_key,
|
|
198
198
|
signal: options?.signal,
|
|
@@ -201,7 +201,7 @@ var PurchaseIntentService = class {
|
|
|
201
201
|
);
|
|
202
202
|
}
|
|
203
203
|
get(intentId, options) {
|
|
204
|
-
return
|
|
204
|
+
return chunkONII7K3T_js.safe(
|
|
205
205
|
this.transport.get(this.intentPath(intentId), {
|
|
206
206
|
signal: options?.signal,
|
|
207
207
|
timeoutMs: options?.timeoutMs
|
|
@@ -212,7 +212,7 @@ var PurchaseIntentService = class {
|
|
|
212
212
|
const request = {
|
|
213
213
|
expected_intent_revision: expectedRevision
|
|
214
214
|
};
|
|
215
|
-
return
|
|
215
|
+
return chunkONII7K3T_js.safe(
|
|
216
216
|
this.transport.post(
|
|
217
217
|
`${this.intentPath(intentId)}/${PURCHASE_INTENT_ROUTE.REFRESH}`,
|
|
218
218
|
request,
|
|
@@ -224,7 +224,7 @@ var PurchaseIntentService = class {
|
|
|
224
224
|
);
|
|
225
225
|
}
|
|
226
226
|
confirm(intentId, request, options) {
|
|
227
|
-
return
|
|
227
|
+
return chunkONII7K3T_js.safe(
|
|
228
228
|
this.transport.post(
|
|
229
229
|
`${this.intentPath(intentId)}/${PURCHASE_INTENT_ROUTE.CONFIRM}`,
|
|
230
230
|
request,
|
|
@@ -239,7 +239,7 @@ var PurchaseIntentService = class {
|
|
|
239
239
|
submitAction(intentId, attemptId, request, options) {
|
|
240
240
|
const normalizedAttemptId = attemptId.trim();
|
|
241
241
|
if (!normalizedAttemptId) throw new TypeError("attemptId must not be empty");
|
|
242
|
-
return
|
|
242
|
+
return chunkONII7K3T_js.safe(
|
|
243
243
|
this.transport.post(
|
|
244
244
|
`${this.intentPath(intentId)}/${PURCHASE_INTENT_ROUTE.ATTEMPTS}/${encodeURIComponent(normalizedAttemptId)}/${PURCHASE_INTENT_ROUTE.ACTIONS}`,
|
|
245
245
|
request,
|
|
@@ -271,7 +271,7 @@ var HostedPurchaseIntentService = class {
|
|
|
271
271
|
this.resolver = new PurchaseIntentResolver({ confirmation: this });
|
|
272
272
|
}
|
|
273
273
|
prepare(request, options) {
|
|
274
|
-
return
|
|
274
|
+
return chunkONII7K3T_js.safe(
|
|
275
275
|
this.transport.post(
|
|
276
276
|
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.PREPARE}`,
|
|
277
277
|
request,
|
|
@@ -284,7 +284,7 @@ var HostedPurchaseIntentService = class {
|
|
|
284
284
|
);
|
|
285
285
|
}
|
|
286
286
|
confirm(_intentId, request, options) {
|
|
287
|
-
return
|
|
287
|
+
return chunkONII7K3T_js.safe(
|
|
288
288
|
this.transport.post(
|
|
289
289
|
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.CONFIRM}`,
|
|
290
290
|
request,
|
|
@@ -297,7 +297,7 @@ var HostedPurchaseIntentService = class {
|
|
|
297
297
|
);
|
|
298
298
|
}
|
|
299
299
|
replay(options) {
|
|
300
|
-
return
|
|
300
|
+
return chunkONII7K3T_js.safe(
|
|
301
301
|
this.transport.get(
|
|
302
302
|
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.REPLAY}`,
|
|
303
303
|
{
|
|
@@ -310,7 +310,7 @@ var HostedPurchaseIntentService = class {
|
|
|
310
310
|
submitAction(_intentId, attemptId, request, options) {
|
|
311
311
|
const normalized = attemptId.trim();
|
|
312
312
|
if (!normalized) throw new TypeError("attemptId must not be empty");
|
|
313
|
-
return
|
|
313
|
+
return chunkONII7K3T_js.safe(
|
|
314
314
|
this.transport.post(
|
|
315
315
|
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.ATTEMPTS}/${encodeURIComponent(normalized)}/${PURCHASE_INTENT_ROUTE.ACTIONS}`,
|
|
316
316
|
request,
|
|
@@ -336,7 +336,7 @@ var StoreCreditQueries = class {
|
|
|
336
336
|
* currency. Requires a signed-in customer; returns an error otherwise.
|
|
337
337
|
*/
|
|
338
338
|
async balance() {
|
|
339
|
-
return
|
|
339
|
+
return chunkONII7K3T_js.safe(this.client.get("/api/v1/store-credit/balance"));
|
|
340
340
|
}
|
|
341
341
|
};
|
|
342
342
|
|
|
@@ -712,7 +712,7 @@ var ActivityService = class {
|
|
|
712
712
|
this.sendEvents([event]);
|
|
713
713
|
}
|
|
714
714
|
async getState() {
|
|
715
|
-
return
|
|
715
|
+
return chunkONII7K3T_js.safe(this.client.get("/api/v1/activity/state"));
|
|
716
716
|
}
|
|
717
717
|
async getRecommendations(options) {
|
|
718
718
|
const params = new URLSearchParams();
|
|
@@ -720,10 +720,10 @@ var ActivityService = class {
|
|
|
720
720
|
if (options?.limit) params.set("limit", String(options.limit));
|
|
721
721
|
const query = params.toString();
|
|
722
722
|
const path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
|
|
723
|
-
return
|
|
723
|
+
return chunkONII7K3T_js.safe(this.client.get(path));
|
|
724
724
|
}
|
|
725
725
|
async dismissMessage(code) {
|
|
726
|
-
return
|
|
726
|
+
return chunkONII7K3T_js.safe(
|
|
727
727
|
this.client.post("/api/v1/activity/messages/dismiss", { code })
|
|
728
728
|
);
|
|
729
729
|
}
|
|
@@ -743,7 +743,11 @@ var ActivityService = class {
|
|
|
743
743
|
void this.postEvents(events, session ?? this.sessions.beginEvent()).catch(() => {
|
|
744
744
|
});
|
|
745
745
|
}
|
|
746
|
+
hasStorefrontIdentity() {
|
|
747
|
+
return this.client.getPublicKey().trim().length > 0;
|
|
748
|
+
}
|
|
746
749
|
async postEvents(events, session) {
|
|
750
|
+
if (!this.hasStorefrontIdentity()) return;
|
|
747
751
|
const generation = this.captureGeneration();
|
|
748
752
|
await this.bootstrapSession(session, false, generation);
|
|
749
753
|
if (!this.isCurrentGeneration(generation)) return;
|
|
@@ -758,6 +762,7 @@ var ActivityService = class {
|
|
|
758
762
|
);
|
|
759
763
|
}
|
|
760
764
|
bootstrapSession(session, force = false, generation = this.captureGeneration()) {
|
|
765
|
+
if (!this.hasStorefrontIdentity()) return Promise.resolve();
|
|
761
766
|
if (!force && !session.requiresBootstrap) return Promise.resolve();
|
|
762
767
|
if (!force && this.bootstrapRequest?.sessionId === session.id && sameActivityGeneration(this.bootstrapRequest.generation, generation)) {
|
|
763
768
|
return this.bootstrapRequest.promise;
|
|
@@ -829,16 +834,16 @@ var SubscriptionService = class {
|
|
|
829
834
|
this.client = client;
|
|
830
835
|
}
|
|
831
836
|
async list() {
|
|
832
|
-
return
|
|
837
|
+
return chunkONII7K3T_js.safe(this.client.get("/api/v1/subscriptions"));
|
|
833
838
|
}
|
|
834
839
|
async get(id) {
|
|
835
840
|
const encodedId = encodeURIComponent(id);
|
|
836
|
-
return
|
|
841
|
+
return chunkONII7K3T_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
|
|
837
842
|
}
|
|
838
843
|
async cancel(id, reason, opts) {
|
|
839
844
|
const encodedId = encodeURIComponent(id);
|
|
840
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
841
|
-
return
|
|
845
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkONII7K3T_js.generateIdempotencyKey();
|
|
846
|
+
return chunkONII7K3T_js.safe(
|
|
842
847
|
this.client.post(
|
|
843
848
|
`/api/v1/subscriptions/${encodedId}/cancel`,
|
|
844
849
|
{ reason },
|
|
@@ -848,20 +853,20 @@ var SubscriptionService = class {
|
|
|
848
853
|
}
|
|
849
854
|
async pause(id) {
|
|
850
855
|
const encodedId = encodeURIComponent(id);
|
|
851
|
-
return
|
|
856
|
+
return chunkONII7K3T_js.safe(
|
|
852
857
|
this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
|
|
853
858
|
);
|
|
854
859
|
}
|
|
855
860
|
async resume(id) {
|
|
856
861
|
const encodedId = encodeURIComponent(id);
|
|
857
|
-
return
|
|
862
|
+
return chunkONII7K3T_js.safe(
|
|
858
863
|
this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
|
|
859
864
|
);
|
|
860
865
|
}
|
|
861
866
|
async skipNextRenewal(id, opts) {
|
|
862
867
|
const encodedId = encodeURIComponent(id);
|
|
863
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
864
|
-
return
|
|
868
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkONII7K3T_js.generateIdempotencyKey();
|
|
869
|
+
return chunkONII7K3T_js.safe(
|
|
865
870
|
this.client.post(
|
|
866
871
|
`/api/v1/subscriptions/${encodedId}/skip`,
|
|
867
872
|
void 0,
|
|
@@ -877,8 +882,8 @@ var UploadService = class {
|
|
|
877
882
|
this.client = client;
|
|
878
883
|
}
|
|
879
884
|
async init(filename, contentType2, sizeBytes, opts) {
|
|
880
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
881
|
-
return
|
|
885
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkONII7K3T_js.generateIdempotencyKey();
|
|
886
|
+
return chunkONII7K3T_js.safe(
|
|
882
887
|
this.client.post(
|
|
883
888
|
"/api/v1/uploads/init",
|
|
884
889
|
{
|
|
@@ -891,7 +896,7 @@ var UploadService = class {
|
|
|
891
896
|
);
|
|
892
897
|
}
|
|
893
898
|
async confirm(uploadId) {
|
|
894
|
-
return
|
|
899
|
+
return chunkONII7K3T_js.safe(
|
|
895
900
|
this.client.post("/api/v1/uploads/confirm", {
|
|
896
901
|
upload_id: uploadId
|
|
897
902
|
})
|
|
@@ -910,7 +915,7 @@ var UploadService = class {
|
|
|
910
915
|
if (!uploadResponse.ok) {
|
|
911
916
|
return {
|
|
912
917
|
ok: false,
|
|
913
|
-
error: new
|
|
918
|
+
error: new chunkANT574FD_js.CimplifyError(
|
|
914
919
|
"UPLOAD_FAILED",
|
|
915
920
|
`Upload failed with status ${uploadResponse.status}`,
|
|
916
921
|
true
|
|
@@ -920,7 +925,7 @@ var UploadService = class {
|
|
|
920
925
|
} catch (error) {
|
|
921
926
|
return {
|
|
922
927
|
ok: false,
|
|
923
|
-
error: new
|
|
928
|
+
error: new chunkANT574FD_js.CimplifyError(
|
|
924
929
|
"UPLOAD_FAILED",
|
|
925
930
|
error instanceof Error ? error.message : "Upload failed",
|
|
926
931
|
true
|
|
@@ -937,7 +942,7 @@ var PlacesService = class {
|
|
|
937
942
|
this.client = client;
|
|
938
943
|
}
|
|
939
944
|
async autocomplete(input, sessionToken) {
|
|
940
|
-
return
|
|
945
|
+
return chunkONII7K3T_js.safe(
|
|
941
946
|
this.client.post("/api/v1/places/autocomplete", {
|
|
942
947
|
input,
|
|
943
948
|
sessionToken
|
|
@@ -945,7 +950,7 @@ var PlacesService = class {
|
|
|
945
950
|
);
|
|
946
951
|
}
|
|
947
952
|
async details(placeId, sessionToken) {
|
|
948
|
-
return
|
|
953
|
+
return chunkONII7K3T_js.safe(
|
|
949
954
|
this.client.post("/api/v1/places/details", {
|
|
950
955
|
place_id: placeId,
|
|
951
956
|
sessionToken
|
|
@@ -964,7 +969,7 @@ var DeliveryService = class {
|
|
|
964
969
|
params.set("dropoff_lat", String(dropoffLat));
|
|
965
970
|
params.set("dropoff_lng", String(dropoffLng));
|
|
966
971
|
if (country) params.set("country", country);
|
|
967
|
-
return
|
|
972
|
+
return chunkONII7K3T_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
|
|
968
973
|
}
|
|
969
974
|
async getOptions(queryOrLatitude, longitude, legacyOptions) {
|
|
970
975
|
const query = typeof queryOrLatitude === "number" ? {
|
|
@@ -978,7 +983,7 @@ var DeliveryService = class {
|
|
|
978
983
|
if (query.country) params.set("country", query.country);
|
|
979
984
|
if (query.currency) params.set("currency", query.currency);
|
|
980
985
|
if (query.orderValue != null) params.set("order_value", String(query.orderValue));
|
|
981
|
-
return
|
|
986
|
+
return chunkONII7K3T_js.safe(
|
|
982
987
|
this.client.get(`/api/v1/delivery/options?${params.toString()}`)
|
|
983
988
|
);
|
|
984
989
|
}
|
|
@@ -1078,85 +1083,9 @@ function chatRealtimeUpdateFromWire(envelope) {
|
|
|
1078
1083
|
}
|
|
1079
1084
|
|
|
1080
1085
|
// src/support.ts
|
|
1081
|
-
var CLAIM_TIMEOUT_MS = 15e3;
|
|
1082
1086
|
var SupportService = class {
|
|
1083
1087
|
constructor(client) {
|
|
1084
1088
|
this.client = client;
|
|
1085
|
-
this.claimInFlight = null;
|
|
1086
|
-
this.claimInFlightToken = null;
|
|
1087
|
-
this.lastClaimedAccessToken = null;
|
|
1088
|
-
this.claimedName = null;
|
|
1089
|
-
this.client.events.on(chunkB7JH5D3J_js.SESSION_CLEARED, () => {
|
|
1090
|
-
this.lastClaimedAccessToken = null;
|
|
1091
|
-
this.claimedName = null;
|
|
1092
|
-
});
|
|
1093
|
-
this.client.events.on(chunkB7JH5D3J_js.SESSION_CLAIMED, (event) => {
|
|
1094
|
-
if (event.customerName) this.claimedName = event.customerName;
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
/** The verified customer this session's conversation was claimed for, null while anonymous. */
|
|
1098
|
-
get claimedCustomerName() {
|
|
1099
|
-
return this.claimedName;
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
* Claim the anonymous session for the verified Link identity: the server
|
|
1103
|
-
* verifies the access token, rotates the session token (adopted here, so
|
|
1104
|
-
* every subsequent request rides the bound session), folds the guest cart
|
|
1105
|
-
* in, and opens or reuses the account's canonical direct Chat thread.
|
|
1106
|
-
*
|
|
1107
|
-
* Idempotent and single-flight: concurrent calls share one request, and a
|
|
1108
|
-
* token already claimed by this instance short-circuits without a network
|
|
1109
|
-
* round trip. A session already bound to another Link account is rejected
|
|
1110
|
-
* rather than transferring that account's cart. Emits `session:claimed` on
|
|
1111
|
-
* the client's event channel.
|
|
1112
|
-
*/
|
|
1113
|
-
async claimConversation() {
|
|
1114
|
-
const accessToken = this.client.getAccessToken();
|
|
1115
|
-
if (!accessToken) {
|
|
1116
|
-
return chunkB7JH5D3J_js.err(new chunkAVXA4F6G_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1117
|
-
}
|
|
1118
|
-
if (this.claimInFlight) {
|
|
1119
|
-
if (this.claimInFlightToken === accessToken) return this.claimInFlight;
|
|
1120
|
-
await this.claimInFlight;
|
|
1121
|
-
return this.claimConversation();
|
|
1122
|
-
}
|
|
1123
|
-
if (this.lastClaimedAccessToken === accessToken) {
|
|
1124
|
-
return chunkB7JH5D3J_js.err(new chunkAVXA4F6G_js.CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
1125
|
-
}
|
|
1126
|
-
const epoch = this.client.getSessionEpoch();
|
|
1127
|
-
this.claimInFlightToken = accessToken;
|
|
1128
|
-
this.claimInFlight = (async () => {
|
|
1129
|
-
const result = await chunkB7JH5D3J_js.safe(
|
|
1130
|
-
this.client.post(
|
|
1131
|
-
"/api/v1/support/conversation/claim",
|
|
1132
|
-
{ access_token: accessToken },
|
|
1133
|
-
{ timeoutMs: CLAIM_TIMEOUT_MS }
|
|
1134
|
-
)
|
|
1135
|
-
);
|
|
1136
|
-
if (result.ok) {
|
|
1137
|
-
if (this.client.getSessionEpoch() !== epoch) {
|
|
1138
|
-
return chunkB7JH5D3J_js.err(
|
|
1139
|
-
new chunkAVXA4F6G_js.CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
1140
|
-
);
|
|
1141
|
-
}
|
|
1142
|
-
this.lastClaimedAccessToken = accessToken;
|
|
1143
|
-
this.claimedName = result.value.customer_name || null;
|
|
1144
|
-
this.client.adoptSessionToken(result.value.session_token);
|
|
1145
|
-
this.client.publishSessionClaimed(this.claimedName);
|
|
1146
|
-
this.client.events.emit(chunkB7JH5D3J_js.SESSION_CLAIMED, {
|
|
1147
|
-
sessionToken: result.value.session_token,
|
|
1148
|
-
threadId: result.value.thread.id,
|
|
1149
|
-
customerName: result.value.customer_name
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
return result;
|
|
1153
|
-
})();
|
|
1154
|
-
try {
|
|
1155
|
-
return await this.claimInFlight;
|
|
1156
|
-
} finally {
|
|
1157
|
-
this.claimInFlight = null;
|
|
1158
|
-
this.claimInFlightToken = null;
|
|
1159
|
-
}
|
|
1160
1089
|
}
|
|
1161
1090
|
/**
|
|
1162
1091
|
* Retry verified external-history discovery for the current storefront.
|
|
@@ -1166,9 +1095,9 @@ var SupportService = class {
|
|
|
1166
1095
|
*/
|
|
1167
1096
|
async claimExternalChats() {
|
|
1168
1097
|
if (!this.client.getAccessToken()) {
|
|
1169
|
-
return
|
|
1098
|
+
return chunkONII7K3T_js.err(new chunkANT574FD_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1170
1099
|
}
|
|
1171
|
-
return
|
|
1100
|
+
return chunkONII7K3T_js.safe(
|
|
1172
1101
|
(async () => {
|
|
1173
1102
|
const businessId = await this.client.resolveBusinessId();
|
|
1174
1103
|
return this.client.post("/v1/me/chats/external-claims", {
|
|
@@ -1183,26 +1112,26 @@ var SupportService = class {
|
|
|
1183
1112
|
* the inbox with empty threads.
|
|
1184
1113
|
*/
|
|
1185
1114
|
async peekConversation() {
|
|
1186
|
-
const result = await
|
|
1115
|
+
const result = await chunkONII7K3T_js.safe(
|
|
1187
1116
|
this.client.get("/api/v1/support/conversation")
|
|
1188
1117
|
);
|
|
1189
1118
|
if (!result.ok) return result;
|
|
1190
|
-
if (!result.value.conversation) return
|
|
1191
|
-
return
|
|
1119
|
+
if (!result.value.conversation) return chunkONII7K3T_js.ok(null);
|
|
1120
|
+
return chunkONII7K3T_js.ok({
|
|
1192
1121
|
conversation: result.value.conversation,
|
|
1193
1122
|
messages: chatMessagesFromWire(result.value.messages)
|
|
1194
1123
|
});
|
|
1195
1124
|
}
|
|
1196
1125
|
/** Open (or resume) the customer's widget conversation. */
|
|
1197
1126
|
async openConversation(opts) {
|
|
1198
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
1199
|
-
const result = await
|
|
1127
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkONII7K3T_js.generateIdempotencyKey();
|
|
1128
|
+
const result = await chunkONII7K3T_js.safe(
|
|
1200
1129
|
this.client.post("/api/v1/support/conversation", void 0, {
|
|
1201
1130
|
idempotencyKey
|
|
1202
1131
|
})
|
|
1203
1132
|
);
|
|
1204
1133
|
if (!result.ok) return result;
|
|
1205
|
-
return
|
|
1134
|
+
return chunkONII7K3T_js.ok({
|
|
1206
1135
|
conversation: result.value.conversation,
|
|
1207
1136
|
messages: chatMessagesFromWire(result.value.messages)
|
|
1208
1137
|
});
|
|
@@ -1216,8 +1145,8 @@ var SupportService = class {
|
|
|
1216
1145
|
* server resolves it thread-scoped and echoes the quote as `reply_to`.
|
|
1217
1146
|
*/
|
|
1218
1147
|
async sendMessage(content, opts) {
|
|
1219
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
1220
|
-
const result = await
|
|
1148
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkONII7K3T_js.generateIdempotencyKey();
|
|
1149
|
+
const result = await chunkONII7K3T_js.safe(
|
|
1221
1150
|
this.client.post(
|
|
1222
1151
|
"/api/v1/support/conversation/messages",
|
|
1223
1152
|
{
|
|
@@ -1229,7 +1158,7 @@ var SupportService = class {
|
|
|
1229
1158
|
{ idempotencyKey }
|
|
1230
1159
|
)
|
|
1231
1160
|
);
|
|
1232
|
-
return result.ok ?
|
|
1161
|
+
return result.ok ? chunkONII7K3T_js.ok(chatMessageFromWire(result.value.message)) : result;
|
|
1233
1162
|
}
|
|
1234
1163
|
/**
|
|
1235
1164
|
* Poll for messages. `after` pages forward (live updates); `before` pages
|
|
@@ -1244,25 +1173,25 @@ var SupportService = class {
|
|
|
1244
1173
|
if (options.limit) params.set("limit", String(options.limit));
|
|
1245
1174
|
const query = params.toString();
|
|
1246
1175
|
const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
|
|
1247
|
-
const result = await
|
|
1248
|
-
return result.ok ?
|
|
1176
|
+
const result = await chunkONII7K3T_js.safe(this.client.get(path));
|
|
1177
|
+
return result.ok ? chunkONII7K3T_js.ok(chatMessagesFromWire(result.value)) : result;
|
|
1249
1178
|
}
|
|
1250
1179
|
/** React to a message in the active conversation by its `ChatMessage.id`. */
|
|
1251
1180
|
async reactToMessage(messageId, emoji) {
|
|
1252
|
-
const clientId =
|
|
1253
|
-
const result = await
|
|
1181
|
+
const clientId = chunkONII7K3T_js.generateIdempotencyKey();
|
|
1182
|
+
const result = await chunkONII7K3T_js.safe(
|
|
1254
1183
|
this.client.post(
|
|
1255
1184
|
`/api/v1/support/conversation/messages/${messageId}/reactions`,
|
|
1256
1185
|
{ emoji, client_id: clientId },
|
|
1257
1186
|
{ idempotencyKey: clientId }
|
|
1258
1187
|
)
|
|
1259
1188
|
);
|
|
1260
|
-
return result.ok ?
|
|
1189
|
+
return result.ok ? chunkONII7K3T_js.ok(chatMessageFromWire(result.value.message)) : result;
|
|
1261
1190
|
}
|
|
1262
1191
|
/** Ask for a person: flags the thread for the merchant's inbox. */
|
|
1263
1192
|
async requestHuman(opts) {
|
|
1264
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
1265
|
-
return
|
|
1193
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkONII7K3T_js.generateIdempotencyKey();
|
|
1194
|
+
return chunkONII7K3T_js.safe(
|
|
1266
1195
|
this.client.post(
|
|
1267
1196
|
"/api/v1/support/conversation/handoff",
|
|
1268
1197
|
void 0,
|
|
@@ -1272,6 +1201,95 @@ var SupportService = class {
|
|
|
1272
1201
|
}
|
|
1273
1202
|
};
|
|
1274
1203
|
|
|
1204
|
+
// src/session.ts
|
|
1205
|
+
var CLAIM_TIMEOUT_MS = 15e3;
|
|
1206
|
+
var CLAIM_PATH = "/api/v1/auth/session/claim";
|
|
1207
|
+
var SessionService = class {
|
|
1208
|
+
constructor(client) {
|
|
1209
|
+
this.client = client;
|
|
1210
|
+
this.claimInFlight = null;
|
|
1211
|
+
this.claimInFlightToken = null;
|
|
1212
|
+
this.lastClaimedAccessToken = null;
|
|
1213
|
+
this.claimedName = null;
|
|
1214
|
+
this.client.events.on(chunkONII7K3T_js.SESSION_CLEARED, () => {
|
|
1215
|
+
this.lastClaimedAccessToken = null;
|
|
1216
|
+
this.claimedName = null;
|
|
1217
|
+
});
|
|
1218
|
+
this.client.events.on(chunkONII7K3T_js.SESSION_CLAIMED, (event) => {
|
|
1219
|
+
if (event.customerName) this.claimedName = event.customerName;
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
/** The verified customer this session is bound to, null while anonymous. */
|
|
1223
|
+
get claimedCustomerName() {
|
|
1224
|
+
return this.claimedName;
|
|
1225
|
+
}
|
|
1226
|
+
/** Adopt a session another holder already bound for this bearer. */
|
|
1227
|
+
adopt(accessToken, session) {
|
|
1228
|
+
this.lastClaimedAccessToken = accessToken;
|
|
1229
|
+
this.claimedName = session.customerName || null;
|
|
1230
|
+
this.client.adoptSessionToken(session.sessionToken);
|
|
1231
|
+
this.client.publishSessionClaimed(this.claimedName);
|
|
1232
|
+
this.client.events.emit(chunkONII7K3T_js.SESSION_CLAIMED, session);
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Bind the anonymous session to the verified Link identity in one server
|
|
1236
|
+
* transaction: verify the bearer, rotate the session token (adopted here),
|
|
1237
|
+
* fold the guest cart under the customer and re-price it. A repeat for the
|
|
1238
|
+
* same account and session returns the same session.
|
|
1239
|
+
*
|
|
1240
|
+
* Idempotent and single-flight: concurrent calls share one request, and a
|
|
1241
|
+
* token already claimed by this instance short-circuits without a network
|
|
1242
|
+
* round trip. A session already bound to another Link account is rejected
|
|
1243
|
+
* rather than transferring that account's cart. Emits `session:claimed` on
|
|
1244
|
+
* the client's event channel.
|
|
1245
|
+
*/
|
|
1246
|
+
async claim() {
|
|
1247
|
+
const accessToken = this.client.getAccessToken();
|
|
1248
|
+
if (!accessToken) {
|
|
1249
|
+
return chunkONII7K3T_js.err(new chunkANT574FD_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1250
|
+
}
|
|
1251
|
+
if (this.claimInFlight) {
|
|
1252
|
+
if (this.claimInFlightToken === accessToken) return this.claimInFlight;
|
|
1253
|
+
await this.claimInFlight;
|
|
1254
|
+
return this.claim();
|
|
1255
|
+
}
|
|
1256
|
+
if (this.lastClaimedAccessToken === accessToken) {
|
|
1257
|
+
return chunkONII7K3T_js.err(new chunkANT574FD_js.CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
1258
|
+
}
|
|
1259
|
+
const epoch = this.client.getSessionEpoch();
|
|
1260
|
+
this.claimInFlightToken = accessToken;
|
|
1261
|
+
this.claimInFlight = (async () => {
|
|
1262
|
+
const result = await chunkONII7K3T_js.safe(
|
|
1263
|
+
this.client.post(
|
|
1264
|
+
CLAIM_PATH,
|
|
1265
|
+
{ access_token: accessToken },
|
|
1266
|
+
{ timeoutMs: CLAIM_TIMEOUT_MS }
|
|
1267
|
+
)
|
|
1268
|
+
);
|
|
1269
|
+
if (result.ok) {
|
|
1270
|
+
if (this.client.getSessionEpoch() !== epoch) {
|
|
1271
|
+
return chunkONII7K3T_js.err(
|
|
1272
|
+
new chunkANT574FD_js.CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
this.adopt(accessToken, {
|
|
1276
|
+
sessionToken: result.value.session_token,
|
|
1277
|
+
customerName: result.value.customer.name,
|
|
1278
|
+
customer: result.value.customer,
|
|
1279
|
+
cart: result.value.cart
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
return result;
|
|
1283
|
+
})();
|
|
1284
|
+
try {
|
|
1285
|
+
return await this.claimInFlight;
|
|
1286
|
+
} finally {
|
|
1287
|
+
this.claimInFlight = null;
|
|
1288
|
+
this.claimInFlightToken = null;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1275
1293
|
// src/internal/cross-tab-session.ts
|
|
1276
1294
|
var CROSS_TAB_SESSION_HUB_KEY = /* @__PURE__ */ Symbol.for("@cimplify/sdk.cross-tab-session-hub");
|
|
1277
1295
|
var SESSION_SYNC_STORAGE_KEY = "cimplify_session_sync";
|
|
@@ -1384,7 +1402,7 @@ var DEFAULT_RETRY_DELAY_MS = 1e3;
|
|
|
1384
1402
|
var MAX_RETRY_AFTER_MS = 3e4;
|
|
1385
1403
|
function sleep(ms, signal) {
|
|
1386
1404
|
if (signal?.aborted) {
|
|
1387
|
-
return Promise.reject(new
|
|
1405
|
+
return Promise.reject(new chunkANT574FD_js.CimplifyError(chunkANT574FD_js.ErrorCode.CANCELLED, "Request was cancelled.", true));
|
|
1388
1406
|
}
|
|
1389
1407
|
return new Promise((resolve, reject) => {
|
|
1390
1408
|
const timer = setTimeout(() => {
|
|
@@ -1393,7 +1411,7 @@ function sleep(ms, signal) {
|
|
|
1393
1411
|
}, ms);
|
|
1394
1412
|
const onAbort = () => {
|
|
1395
1413
|
clearTimeout(timer);
|
|
1396
|
-
reject(new
|
|
1414
|
+
reject(new chunkANT574FD_js.CimplifyError(chunkANT574FD_js.ErrorCode.CANCELLED, "Request was cancelled.", true));
|
|
1397
1415
|
};
|
|
1398
1416
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1399
1417
|
});
|
|
@@ -1451,16 +1469,16 @@ function isRetryable(error) {
|
|
|
1451
1469
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
1452
1470
|
return true;
|
|
1453
1471
|
}
|
|
1454
|
-
if (error instanceof
|
|
1472
|
+
if (error instanceof chunkANT574FD_js.CimplifyError) {
|
|
1455
1473
|
return error.retryable;
|
|
1456
1474
|
}
|
|
1457
1475
|
return false;
|
|
1458
1476
|
}
|
|
1459
1477
|
function toNetworkError(error, isTestMode) {
|
|
1460
1478
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
1461
|
-
return
|
|
1462
|
-
new
|
|
1463
|
-
|
|
1479
|
+
return chunkANT574FD_js.enrichError(
|
|
1480
|
+
new chunkANT574FD_js.CimplifyError(
|
|
1481
|
+
chunkANT574FD_js.ErrorCode.TIMEOUT,
|
|
1464
1482
|
"Request timed out. Please check your connection and try again.",
|
|
1465
1483
|
true
|
|
1466
1484
|
),
|
|
@@ -1468,21 +1486,21 @@ function toNetworkError(error, isTestMode) {
|
|
|
1468
1486
|
);
|
|
1469
1487
|
}
|
|
1470
1488
|
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
1471
|
-
return
|
|
1472
|
-
new
|
|
1473
|
-
|
|
1489
|
+
return chunkANT574FD_js.enrichError(
|
|
1490
|
+
new chunkANT574FD_js.CimplifyError(
|
|
1491
|
+
chunkANT574FD_js.ErrorCode.NETWORK_ERROR,
|
|
1474
1492
|
"Network error. Please check your internet connection.",
|
|
1475
1493
|
true
|
|
1476
1494
|
),
|
|
1477
1495
|
{ isTestMode }
|
|
1478
1496
|
);
|
|
1479
1497
|
}
|
|
1480
|
-
if (error instanceof
|
|
1481
|
-
return
|
|
1498
|
+
if (error instanceof chunkANT574FD_js.CimplifyError) {
|
|
1499
|
+
return chunkANT574FD_js.enrichError(error, { isTestMode });
|
|
1482
1500
|
}
|
|
1483
|
-
return
|
|
1484
|
-
new
|
|
1485
|
-
|
|
1501
|
+
return chunkANT574FD_js.enrichError(
|
|
1502
|
+
new chunkANT574FD_js.CimplifyError(
|
|
1503
|
+
chunkANT574FD_js.ErrorCode.UNKNOWN_ERROR,
|
|
1486
1504
|
error instanceof Error ? error.message : "An unknown error occurred",
|
|
1487
1505
|
false
|
|
1488
1506
|
),
|
|
@@ -1535,7 +1553,7 @@ var CimplifyClient = class {
|
|
|
1535
1553
|
* Sentry, analytics, etc.). The SDK emits but never auto-consumes — the
|
|
1536
1554
|
* consumer decides how to react.
|
|
1537
1555
|
*/
|
|
1538
|
-
this.events =
|
|
1556
|
+
this.events = chunkONII7K3T_js.createClientEvents();
|
|
1539
1557
|
this.stopPageViewTracking = null;
|
|
1540
1558
|
this.publicKey = config.publicKey || getEnvPublicKey() || "";
|
|
1541
1559
|
const urls = deriveUrls();
|
|
@@ -1546,7 +1564,7 @@ var CimplifyClient = class {
|
|
|
1546
1564
|
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1547
1565
|
this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
|
|
1548
1566
|
this.hooks = config.hooks ?? {};
|
|
1549
|
-
this.authorizationAdapters = config.authorizationAdapterRegistry ??
|
|
1567
|
+
this.authorizationAdapters = config.authorizationAdapterRegistry ?? chunkONII7K3T_js.createDefaultPaymentAuthorizationAdapterRegistry();
|
|
1550
1568
|
this.fetchImpl = (config.fetch ?? globalThis.fetch).bind(globalThis);
|
|
1551
1569
|
this.sessionToken = this.loadSessionToken() ?? this.mintSessionToken();
|
|
1552
1570
|
const persistedSessionSync = this.loadSessionSyncPayload();
|
|
@@ -1615,7 +1633,7 @@ var CimplifyClient = class {
|
|
|
1615
1633
|
newToken: token,
|
|
1616
1634
|
source: SESSION_CHANGE_SOURCE.MANUAL
|
|
1617
1635
|
});
|
|
1618
|
-
this.events.emit(
|
|
1636
|
+
this.events.emit(chunkONII7K3T_js.AUTH_TOKEN_CHANGED, { token });
|
|
1619
1637
|
}
|
|
1620
1638
|
/**
|
|
1621
1639
|
* Zero-UI claim: a freshly verified customer identity (OTP verify, silent
|
|
@@ -1625,9 +1643,9 @@ var CimplifyClient = class {
|
|
|
1625
1643
|
* merchant auth flows, never by the raw token setter. Global Link clients
|
|
1626
1644
|
* have no storefront tenant and therefore activate without this step.
|
|
1627
1645
|
*/
|
|
1628
|
-
|
|
1646
|
+
autoClaimSession() {
|
|
1629
1647
|
if (typeof window === "undefined" || !this.sessionToken || !this.accessToken) return;
|
|
1630
|
-
void this.
|
|
1648
|
+
void this.session.claim();
|
|
1631
1649
|
}
|
|
1632
1650
|
/**
|
|
1633
1651
|
* Adopt a server-rotated session token (claim flow). The old token stays
|
|
@@ -1659,8 +1677,8 @@ var CimplifyClient = class {
|
|
|
1659
1677
|
newToken: null,
|
|
1660
1678
|
source: SESSION_CHANGE_SOURCE.CLEAR
|
|
1661
1679
|
});
|
|
1662
|
-
this.events.emit(
|
|
1663
|
-
this.events.emit(
|
|
1680
|
+
this.events.emit(chunkONII7K3T_js.AUTH_TOKEN_CHANGED, { token: null });
|
|
1681
|
+
this.events.emit(chunkONII7K3T_js.SESSION_CLEARED, {});
|
|
1664
1682
|
}
|
|
1665
1683
|
getSessionEpoch() {
|
|
1666
1684
|
return this.sessionEpoch;
|
|
@@ -1713,18 +1731,19 @@ var CimplifyClient = class {
|
|
|
1713
1731
|
if (payload.type === "claimed") {
|
|
1714
1732
|
this.sessionToken = payload.token;
|
|
1715
1733
|
this.sessionEpoch++;
|
|
1716
|
-
this.events.emit(
|
|
1734
|
+
this.events.emit(chunkONII7K3T_js.SESSION_CLAIMED, {
|
|
1717
1735
|
sessionToken: payload.token,
|
|
1718
|
-
|
|
1719
|
-
|
|
1736
|
+
customerName: payload.name ?? "",
|
|
1737
|
+
customer: null,
|
|
1738
|
+
cart: null
|
|
1720
1739
|
});
|
|
1721
1740
|
} else {
|
|
1722
1741
|
this.accessToken = null;
|
|
1723
1742
|
this._activity?.resetSession();
|
|
1724
1743
|
this.sessionToken = payload.token;
|
|
1725
1744
|
this.sessionEpoch++;
|
|
1726
|
-
this.events.emit(
|
|
1727
|
-
this.events.emit(
|
|
1745
|
+
this.events.emit(chunkONII7K3T_js.AUTH_TOKEN_CHANGED, { token: null });
|
|
1746
|
+
this.events.emit(chunkONII7K3T_js.SESSION_CLEARED, {});
|
|
1728
1747
|
}
|
|
1729
1748
|
}
|
|
1730
1749
|
observeSessionSync(payload) {
|
|
@@ -1817,7 +1836,7 @@ var CimplifyClient = class {
|
|
|
1817
1836
|
if (this.accessToken !== null) {
|
|
1818
1837
|
this.setAccessToken(null);
|
|
1819
1838
|
}
|
|
1820
|
-
this.events.emit(
|
|
1839
|
+
this.events.emit(chunkONII7K3T_js.SESSION_CLEARED, {});
|
|
1821
1840
|
if (restartPageViewTracking) {
|
|
1822
1841
|
this.stopPageViewTracking = this.activity.autoTrackPageViews();
|
|
1823
1842
|
}
|
|
@@ -1836,15 +1855,15 @@ var CimplifyClient = class {
|
|
|
1836
1855
|
const resolution = (async () => {
|
|
1837
1856
|
const result = await this.business.getInfo();
|
|
1838
1857
|
if (!result.ok || !result.value?.id) {
|
|
1839
|
-
throw new
|
|
1840
|
-
|
|
1858
|
+
throw new chunkANT574FD_js.CimplifyError(
|
|
1859
|
+
chunkANT574FD_js.ErrorCode.NOT_FOUND,
|
|
1841
1860
|
"Unable to resolve business ID from the current public key.",
|
|
1842
1861
|
true
|
|
1843
1862
|
);
|
|
1844
1863
|
}
|
|
1845
1864
|
if (this.publicKeyEpoch !== publicKeyEpoch) {
|
|
1846
|
-
throw new
|
|
1847
|
-
|
|
1865
|
+
throw new chunkANT574FD_js.CimplifyError(
|
|
1866
|
+
chunkANT574FD_js.ErrorCode.TENANT_CONTEXT_CHANGED,
|
|
1848
1867
|
"The storefront tenant changed while resolving its business identity.",
|
|
1849
1868
|
true
|
|
1850
1869
|
);
|
|
@@ -1969,7 +1988,7 @@ var CimplifyClient = class {
|
|
|
1969
1988
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1970
1989
|
try {
|
|
1971
1990
|
if (signal?.aborted) {
|
|
1972
|
-
throw new
|
|
1991
|
+
throw new chunkANT574FD_js.CimplifyError(chunkANT574FD_js.ErrorCode.CANCELLED, "Request was cancelled.", true);
|
|
1973
1992
|
}
|
|
1974
1993
|
const controller = new AbortController();
|
|
1975
1994
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs ?? this.timeout);
|
|
@@ -2012,7 +2031,7 @@ var CimplifyClient = class {
|
|
|
2012
2031
|
if (response.status >= 400 && response.status < 500) {
|
|
2013
2032
|
this.hooks.onRequestError?.({
|
|
2014
2033
|
...context,
|
|
2015
|
-
error: new
|
|
2034
|
+
error: new chunkANT574FD_js.CimplifyError(
|
|
2016
2035
|
`HTTP_${response.status}`,
|
|
2017
2036
|
`Request failed with status ${response.status}`,
|
|
2018
2037
|
false
|
|
@@ -2038,8 +2057,8 @@ var CimplifyClient = class {
|
|
|
2038
2057
|
}
|
|
2039
2058
|
this.hooks.onRequestError?.({
|
|
2040
2059
|
...context,
|
|
2041
|
-
error: new
|
|
2042
|
-
|
|
2060
|
+
error: new chunkANT574FD_js.CimplifyError(
|
|
2061
|
+
chunkANT574FD_js.ErrorCode.SERVER_ERROR,
|
|
2043
2062
|
`Server error ${response.status} after ${retryCount} retries`,
|
|
2044
2063
|
false
|
|
2045
2064
|
),
|
|
@@ -2052,7 +2071,7 @@ var CimplifyClient = class {
|
|
|
2052
2071
|
} catch (error) {
|
|
2053
2072
|
lastError = error;
|
|
2054
2073
|
if (signal?.aborted) {
|
|
2055
|
-
throw new
|
|
2074
|
+
throw new chunkANT574FD_js.CimplifyError(chunkANT574FD_js.ErrorCode.CANCELLED, "Request was cancelled.", true);
|
|
2056
2075
|
}
|
|
2057
2076
|
const networkError = toNetworkError(error, this.isTestMode());
|
|
2058
2077
|
const errorRetryable = isRetryable(error);
|
|
@@ -2226,17 +2245,17 @@ var CimplifyClient = class {
|
|
|
2226
2245
|
async handleRestResponse(response) {
|
|
2227
2246
|
const json = await response.json();
|
|
2228
2247
|
if (!response.ok) {
|
|
2229
|
-
const errorCode = typeof json.error === "object" && json.error?.error_code || typeof json.error === "object" && json.error?.code ||
|
|
2248
|
+
const errorCode = typeof json.error === "object" && json.error?.error_code || typeof json.error === "object" && json.error?.code || chunkANT574FD_js.ErrorCode.API_ERROR;
|
|
2230
2249
|
const errorMessage = typeof json.error === "object" && json.error?.error_message || typeof json.error === "object" && json.error?.message || typeof json.error === "string" && json.error || typeof json.message === "string" && json.message || "An error occurred";
|
|
2231
2250
|
const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
|
|
2232
|
-
if (errorCode ===
|
|
2251
|
+
if (errorCode === chunkANT574FD_js.ErrorCode.IDEMPOTENCY_MISMATCH) {
|
|
2233
2252
|
const originalCreatedAt = typeof json.error === "object" && json.error?.original_created_at || "";
|
|
2234
|
-
throw new
|
|
2253
|
+
throw new chunkANT574FD_js.IdempotencyMismatchError(errorMessage, originalCreatedAt);
|
|
2235
2254
|
}
|
|
2236
|
-
const error =
|
|
2255
|
+
const error = chunkANT574FD_js.enrichError(new chunkANT574FD_js.CimplifyError(errorCode, errorMessage, retryable), {
|
|
2237
2256
|
isTestMode: this.isTestMode()
|
|
2238
2257
|
});
|
|
2239
|
-
if ((response.status === 401 || error.code ===
|
|
2258
|
+
if ((response.status === 401 || error.code === chunkANT574FD_js.ErrorCode.UNAUTHORIZED) && this.accessToken) {
|
|
2240
2259
|
console.warn(
|
|
2241
2260
|
"[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
|
|
2242
2261
|
);
|
|
@@ -2244,9 +2263,9 @@ var CimplifyClient = class {
|
|
|
2244
2263
|
throw error;
|
|
2245
2264
|
}
|
|
2246
2265
|
if (json?.success === false || json?.error?.code || json?.error?.message) {
|
|
2247
|
-
const error =
|
|
2248
|
-
new
|
|
2249
|
-
json.error?.code ||
|
|
2266
|
+
const error = chunkANT574FD_js.enrichError(
|
|
2267
|
+
new chunkANT574FD_js.CimplifyError(
|
|
2268
|
+
json.error?.code || chunkANT574FD_js.ErrorCode.API_ERROR,
|
|
2250
2269
|
json.error?.message || "An error occurred",
|
|
2251
2270
|
json.error?.retryable || false
|
|
2252
2271
|
),
|
|
@@ -2261,19 +2280,19 @@ var CimplifyClient = class {
|
|
|
2261
2280
|
}
|
|
2262
2281
|
get catalogue() {
|
|
2263
2282
|
if (!this._catalogue) {
|
|
2264
|
-
this._catalogue = new
|
|
2283
|
+
this._catalogue = new chunkONII7K3T_js.CatalogueQueries(this);
|
|
2265
2284
|
}
|
|
2266
2285
|
return this._catalogue;
|
|
2267
2286
|
}
|
|
2268
2287
|
get cart() {
|
|
2269
2288
|
if (!this._cart) {
|
|
2270
|
-
this._cart = new
|
|
2289
|
+
this._cart = new chunkONII7K3T_js.CartOperations(this);
|
|
2271
2290
|
}
|
|
2272
2291
|
return this._cart;
|
|
2273
2292
|
}
|
|
2274
2293
|
get checkout() {
|
|
2275
2294
|
if (!this._checkout) {
|
|
2276
|
-
this._checkout = new
|
|
2295
|
+
this._checkout = new chunkONII7K3T_js.CheckoutService(this);
|
|
2277
2296
|
}
|
|
2278
2297
|
return this._checkout;
|
|
2279
2298
|
}
|
|
@@ -2285,7 +2304,7 @@ var CimplifyClient = class {
|
|
|
2285
2304
|
}
|
|
2286
2305
|
get orders() {
|
|
2287
2306
|
if (!this._orders) {
|
|
2288
|
-
this._orders = new
|
|
2307
|
+
this._orders = new chunkONII7K3T_js.OrderQueries(this);
|
|
2289
2308
|
}
|
|
2290
2309
|
return this._orders;
|
|
2291
2310
|
}
|
|
@@ -2315,43 +2334,43 @@ var CimplifyClient = class {
|
|
|
2315
2334
|
}
|
|
2316
2335
|
get link() {
|
|
2317
2336
|
if (!this._link) {
|
|
2318
|
-
this._link = new
|
|
2337
|
+
this._link = new chunkONII7K3T_js.LinkService(this);
|
|
2319
2338
|
}
|
|
2320
2339
|
return this._link;
|
|
2321
2340
|
}
|
|
2322
2341
|
get auth() {
|
|
2323
2342
|
if (!this._auth) {
|
|
2324
|
-
this._auth = new
|
|
2343
|
+
this._auth = new chunkONII7K3T_js.AuthService(this);
|
|
2325
2344
|
}
|
|
2326
2345
|
return this._auth;
|
|
2327
2346
|
}
|
|
2328
2347
|
get business() {
|
|
2329
2348
|
if (!this._business) {
|
|
2330
|
-
this._business = new
|
|
2349
|
+
this._business = new chunkONII7K3T_js.BusinessService(this);
|
|
2331
2350
|
}
|
|
2332
2351
|
return this._business;
|
|
2333
2352
|
}
|
|
2334
2353
|
get inventory() {
|
|
2335
2354
|
if (!this._inventory) {
|
|
2336
|
-
this._inventory = new
|
|
2355
|
+
this._inventory = new chunkONII7K3T_js.InventoryService(this);
|
|
2337
2356
|
}
|
|
2338
2357
|
return this._inventory;
|
|
2339
2358
|
}
|
|
2340
2359
|
get scheduling() {
|
|
2341
2360
|
if (!this._scheduling) {
|
|
2342
|
-
this._scheduling = new
|
|
2361
|
+
this._scheduling = new chunkONII7K3T_js.SchedulingService(this);
|
|
2343
2362
|
}
|
|
2344
2363
|
return this._scheduling;
|
|
2345
2364
|
}
|
|
2346
2365
|
get lite() {
|
|
2347
2366
|
if (!this._lite) {
|
|
2348
|
-
this._lite = new
|
|
2367
|
+
this._lite = new chunkONII7K3T_js.LiteService(this);
|
|
2349
2368
|
}
|
|
2350
2369
|
return this._lite;
|
|
2351
2370
|
}
|
|
2352
2371
|
get fx() {
|
|
2353
2372
|
if (!this._fx) {
|
|
2354
|
-
this._fx = new
|
|
2373
|
+
this._fx = new chunkONII7K3T_js.FxService(this);
|
|
2355
2374
|
}
|
|
2356
2375
|
return this._fx;
|
|
2357
2376
|
}
|
|
@@ -2373,6 +2392,12 @@ var CimplifyClient = class {
|
|
|
2373
2392
|
}
|
|
2374
2393
|
return this._support;
|
|
2375
2394
|
}
|
|
2395
|
+
get session() {
|
|
2396
|
+
if (!this._session) {
|
|
2397
|
+
this._session = new SessionService(this);
|
|
2398
|
+
}
|
|
2399
|
+
return this._session;
|
|
2400
|
+
}
|
|
2376
2401
|
buildWsUrl(path) {
|
|
2377
2402
|
const protocol = this.baseUrl.startsWith("https") ? "wss:" : "ws:";
|
|
2378
2403
|
const host = this.baseUrl.replace(/^https?:\/\//, "");
|
|
@@ -2386,7 +2411,7 @@ var CimplifyClient = class {
|
|
|
2386
2411
|
if (businessId) {
|
|
2387
2412
|
this.setBusinessId(businessId);
|
|
2388
2413
|
}
|
|
2389
|
-
return
|
|
2414
|
+
return chunkONII7K3T_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
|
|
2390
2415
|
}
|
|
2391
2416
|
};
|
|
2392
2417
|
function createCimplifyClient(config = {}) {
|
|
@@ -2402,6 +2427,7 @@ exports.PlacesService = PlacesService;
|
|
|
2402
2427
|
exports.PurchaseIntentResolver = PurchaseIntentResolver;
|
|
2403
2428
|
exports.PurchaseIntentService = PurchaseIntentService;
|
|
2404
2429
|
exports.SESSION_CHANGE_SOURCE = SESSION_CHANGE_SOURCE;
|
|
2430
|
+
exports.SessionService = SessionService;
|
|
2405
2431
|
exports.StoreCreditQueries = StoreCreditQueries;
|
|
2406
2432
|
exports.SubscriptionService = SubscriptionService;
|
|
2407
2433
|
exports.SupportService = SupportService;
|