@cimplify/sdk 0.110.2 → 0.111.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/CHANGELOG.md +54 -0
- package/README.md +18 -0
- package/dist/advanced.d.mts +4 -4
- package/dist/advanced.d.ts +4 -4
- package/dist/advanced.js +22 -22
- package/dist/advanced.mjs +3 -3
- package/dist/{catalogue-OTuS5zp-.d.ts → catalogue-1QcoGDO6.d.ts} +2 -2
- package/dist/{catalogue-CPTMyBUz.d.mts → catalogue-FdFQiWrU.d.mts} +2 -2
- package/dist/{chunk-SYEO2WV4.mjs → chunk-42JTCWIE.mjs} +3 -3
- package/dist/{chunk-OMTVH334.js → chunk-6QANXRUM.js} +203 -186
- package/dist/{chunk-6ETDAU62.mjs → chunk-B45X3HPO.mjs} +98 -39
- package/dist/{chunk-MKIJQL5Q.js → chunk-CJVEJPIG.js} +69 -69
- package/dist/{chunk-Q2Y3VMKH.js → chunk-ETZDIISN.js} +151 -151
- package/dist/{chunk-GCKWKLZF.mjs → chunk-FT6GFYJL.mjs} +17 -3
- package/dist/{chunk-A36JRXXH.mjs → chunk-KWZHIPRN.mjs} +26 -9
- package/dist/{chunk-SNNEOS5Z.js → chunk-MHDUUSG6.js} +75 -75
- package/dist/{chunk-UCR5HRYM.js → chunk-NFXCKTE2.js} +17 -3
- package/dist/{chunk-DFZWHNRG.js → chunk-QOCHWR4V.js} +105 -42
- package/dist/{chunk-IZDWAL53.mjs → chunk-UJDQQTBS.mjs} +8 -8
- package/dist/{chunk-BTUSVHIE.mjs → chunk-WLSU5QJT.mjs} +2 -2
- package/dist/{client-dqOhP9Nc.d.ts → client-CChON4-x.d.ts} +2 -2
- package/dist/{client-CX_WR0-J.d.mts → client-EeuGm5gj.d.mts} +2 -2
- package/dist/{elements-DdsRig-2.d.mts → elements-ss9xZgRg.d.mts} +27 -1
- package/dist/{elements-DdsRig-2.d.ts → elements-ss9xZgRg.d.ts} +27 -1
- package/dist/index-BB2gjVvA.d.mts +153 -0
- package/dist/index-BEfmBDAH.d.ts +153 -0
- package/dist/{index-B98Xac8e.d.ts → index-DQK8sTfu.d.ts} +2 -2
- package/dist/{index-DbAN_VQE.d.mts → index-DSVkhRmW.d.mts} +2 -2
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +189 -177
- package/dist/index.mjs +8 -8
- package/dist/mock/cli.mjs +25 -10
- package/dist/mock/library.js +25 -10
- package/dist/mock/library.mjs +25 -10
- package/dist/mock/msw.js +25 -10
- package/dist/mock/msw.mjs +25 -10
- package/dist/{price-BOzexBww.d.mts → price-B-w4PwHm.d.mts} +1 -1
- package/dist/{price-C1h9sPxE.d.ts → price-BEvQFNJv.d.ts} +1 -1
- package/dist/react.d.mts +23 -15
- package/dist/react.d.ts +23 -15
- package/dist/react.js +254 -237
- package/dist/react.mjs +128 -111
- package/dist/{scheduling-D2ajXpMC.d.ts → scheduling-D9WwOxbo.d.ts} +1 -1
- package/dist/{scheduling-DSRbbaZb.d.mts → scheduling-DDmrYCr-.d.mts} +1 -1
- package/dist/{server-D29IIuDV.d.ts → server-BiKwxvnf.d.ts} +2 -2
- package/dist/{server-DQMWPnc8.d.mts → server-DPdtl2dd.d.mts} +2 -2
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +10 -10
- package/dist/server.mjs +4 -4
- package/dist/styles.css +1 -1
- package/dist/testing/msw.d.mts +3 -3
- package/dist/testing/msw.d.ts +3 -3
- package/dist/testing/msw.js +3 -3
- package/dist/testing/msw.mjs +2 -2
- package/dist/testing/suite.d.mts +6 -6
- package/dist/testing/suite.d.ts +6 -6
- package/dist/testing/suite.js +25 -25
- package/dist/testing/suite.mjs +6 -6
- package/dist/testing.d.mts +5 -5
- package/dist/testing.d.ts +5 -5
- package/dist/testing.js +117 -117
- package/dist/testing.mjs +7 -7
- package/dist/utils.d.mts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +44 -32
- package/dist/utils.mjs +2 -2
- package/package.json +5 -3
- package/registry/cart-summary.json +1 -1
- package/registry/chat-widget.json +1 -1
- package/registry/price.json +1 -1
- package/registry/product-customizer.json +1 -1
- package/registry/search-input.json +1 -1
- package/dist/index-6gkHMGAq.d.mts +0 -86
- package/dist/index-B_ByTtIT.d.ts +0 -86
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkWOF3AD3J_js = require('./chunk-WOF3AD3J.js');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var chunk6QANXRUM_js = require('./chunk-6QANXRUM.js');
|
|
5
|
+
var chunkNFXCKTE2_js = require('./chunk-NFXCKTE2.js');
|
|
6
6
|
var sha2_js = require('@noble/hashes/sha2.js');
|
|
7
7
|
|
|
8
8
|
// src/types/observability.ts
|
|
@@ -14,12 +14,12 @@ var SESSION_CHANGE_SOURCE = {
|
|
|
14
14
|
|
|
15
15
|
// src/utils/purchase-intent-resolver.ts
|
|
16
16
|
var DEFAULT_POLL_INTERVAL_MS = 3e3, DEFAULT_MAX_POLL_ATTEMPTS = 60, DEFAULT_MAX_ACTION_STEPS = 4, DEFAULT_MAX_TERMS_REVIEW_STEPS = 4, DEFAULT_DEADLINE_MS = (3e3) * (60), TRANSIENT_RETRY_BASE_MS = 1e3, TRANSIENT_RETRY_MAX_MS = 8e3, HTTP_SERVER_ERROR_PREFIX = "HTTP_5", TRANSIENT_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
chunkNFXCKTE2_js.ErrorCode.NETWORK_ERROR,
|
|
18
|
+
chunkNFXCKTE2_js.ErrorCode.TIMEOUT,
|
|
19
|
+
chunkNFXCKTE2_js.ErrorCode.SERVER_ERROR
|
|
20
20
|
]), PROVIDER_OWNED_ACTIONS = /* @__PURE__ */ new Set([
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.REDIRECT_REQUIRED,
|
|
22
|
+
chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.CARD_POPUP_REQUIRED
|
|
23
23
|
]);
|
|
24
24
|
function nonnegativeInteger(value, fallback) {
|
|
25
25
|
return value === void 0 || !Number.isFinite(value) ? fallback : Math.max(0, Math.floor(value));
|
|
@@ -60,52 +60,52 @@ var PurchaseIntentResolver = class {
|
|
|
60
60
|
options.maxTermsReviewSteps,
|
|
61
61
|
(4)
|
|
62
62
|
), deadline = this.now() + nonnegativeInteger(options.deadlineMs, DEFAULT_DEADLINE_MS), request = options.confirmation, pollAttempts = 0, actionSteps = 0, termsReviewSteps = 0, transientAttempts = 0, lastResponse = null, handedOverAction = null, requestOptions = { signal: options.signal, timeoutMs: options.requestTimeoutMs };
|
|
63
|
-
this.ensureActive(options.signal), this.notify(options,
|
|
64
|
-
let responseResult = options.initialResponse ?
|
|
63
|
+
this.ensureActive(options.signal), this.notify(options, chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLVE_STATUS.CONFIRMING);
|
|
64
|
+
let responseResult = options.initialResponse ? chunk6QANXRUM_js.ok(options.initialResponse) : await this.confirmation.confirm(intentId, request, requestOptions);
|
|
65
65
|
for (; ; ) {
|
|
66
66
|
if (this.ensureActive(options.signal), !responseResult.ok) {
|
|
67
67
|
let remaining = deadline - this.now();
|
|
68
68
|
if (!isTransientPurchaseIntentError(responseResult.error) || remaining <= 0)
|
|
69
|
-
return remaining <= 0 && lastResponse?.status ===
|
|
70
|
-
transientAttempts += 1, this.notify(options,
|
|
69
|
+
return remaining <= 0 && lastResponse?.status === chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.COLLECTION_PROCESSING ? chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.TIMED_OUT, response: lastResponse }) : responseResult;
|
|
70
|
+
transientAttempts += 1, this.notify(options, chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLVE_STATUS.RECONNECTING, lastResponse ?? void 0), await this.wait(Math.min(transientRetryDelay(transientAttempts), remaining), options.signal), responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
71
71
|
continue;
|
|
72
72
|
}
|
|
73
73
|
transientAttempts = 0;
|
|
74
74
|
let response = responseResult.value;
|
|
75
75
|
switch (lastResponse = response, response.status) {
|
|
76
|
-
case
|
|
77
|
-
return this.notify(options,
|
|
78
|
-
case
|
|
79
|
-
return this.notify(options,
|
|
80
|
-
case
|
|
81
|
-
return this.notify(options,
|
|
82
|
-
case
|
|
76
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.ORDER_CREATED:
|
|
77
|
+
return this.notify(options, chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLVE_STATUS.COMPLETED, response), chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.COMPLETED, response });
|
|
78
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.PAYMENT_FAILED:
|
|
79
|
+
return this.notify(options, chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLVE_STATUS.FAILED, response), chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.FAILED, response });
|
|
80
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.PAYMENT_OUTCOME_UNKNOWN:
|
|
81
|
+
return this.notify(options, chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLVE_STATUS.OUTCOME_UNKNOWN, response), chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.OUTCOME_UNKNOWN, response });
|
|
82
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.COLLECTION_PROCESSING:
|
|
83
83
|
if (pollAttempts >= maxPollAttempts)
|
|
84
|
-
return
|
|
85
|
-
pollAttempts += 1, this.notify(options,
|
|
84
|
+
return chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.TIMED_OUT, response });
|
|
85
|
+
pollAttempts += 1, this.notify(options, chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLVE_STATUS.POLLING, response), await this.wait(pollIntervalMs, options.signal), responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
86
86
|
continue;
|
|
87
|
-
case
|
|
88
|
-
case
|
|
89
|
-
case
|
|
90
|
-
this.notify(options,
|
|
87
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.REDIRECT_REQUIRED:
|
|
88
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.CARD_POPUP_REQUIRED:
|
|
89
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.AUTHORIZATION_REQUIRED: {
|
|
90
|
+
this.notify(options, chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLVE_STATUS.AWAITING_ACTION, response);
|
|
91
91
|
let actionKey = `${response.attempt_id}:${response.status}`;
|
|
92
92
|
if (actionKey === handedOverAction) {
|
|
93
93
|
if (pollAttempts >= maxPollAttempts)
|
|
94
|
-
return
|
|
94
|
+
return chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.ACTION_REQUIRED, response });
|
|
95
95
|
pollAttempts += 1, await this.wait(pollIntervalMs, options.signal), responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
96
96
|
continue;
|
|
97
97
|
}
|
|
98
98
|
if (!options.onActionRequired || actionSteps >= maxActionSteps)
|
|
99
|
-
return
|
|
99
|
+
return chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.ACTION_REQUIRED, response });
|
|
100
100
|
actionSteps += 1;
|
|
101
101
|
let decision = await options.onActionRequired(response);
|
|
102
|
-
if (decision ===
|
|
103
|
-
return
|
|
104
|
-
if (typeof decision == "object" && decision.kind ===
|
|
102
|
+
if (decision === chunkNFXCKTE2_js.PURCHASE_INTENT_ACTION_DECISION.STOP)
|
|
103
|
+
return chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.ACTION_REQUIRED, response });
|
|
104
|
+
if (typeof decision == "object" && decision.kind === chunkNFXCKTE2_js.PURCHASE_INTENT_ACTION_DECISION.SUBMIT) {
|
|
105
105
|
if (!this.confirmation.submitAction)
|
|
106
|
-
return
|
|
107
|
-
new
|
|
108
|
-
|
|
106
|
+
return chunk6QANXRUM_js.err(
|
|
107
|
+
new chunkNFXCKTE2_js.CimplifyError(
|
|
108
|
+
chunkNFXCKTE2_js.PURCHASE_INTENT_ERROR_CODE.ACTION_UNSUPPORTED,
|
|
109
109
|
"This confirmation transport cannot submit purchase-intent actions.",
|
|
110
110
|
false
|
|
111
111
|
)
|
|
@@ -118,10 +118,10 @@ var PurchaseIntentResolver = class {
|
|
|
118
118
|
);
|
|
119
119
|
continue;
|
|
120
120
|
}
|
|
121
|
-
if (decision !==
|
|
122
|
-
return
|
|
123
|
-
new
|
|
124
|
-
|
|
121
|
+
if (decision !== chunkNFXCKTE2_js.PURCHASE_INTENT_ACTION_DECISION.CONTINUE)
|
|
122
|
+
return chunk6QANXRUM_js.err(
|
|
123
|
+
new chunkNFXCKTE2_js.CimplifyError(
|
|
124
|
+
chunkNFXCKTE2_js.PURCHASE_INTENT_ERROR_CODE.ACTION_UNSUPPORTED,
|
|
125
125
|
"The action callback returned an unsupported decision.",
|
|
126
126
|
false
|
|
127
127
|
)
|
|
@@ -129,24 +129,24 @@ var PurchaseIntentResolver = class {
|
|
|
129
129
|
PROVIDER_OWNED_ACTIONS.has(response.status) && (handedOverAction = actionKey), await this.wait(pollIntervalMs, options.signal), responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
|
-
case
|
|
133
|
-
if (this.notify(options,
|
|
134
|
-
return
|
|
132
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.TERMS_CHANGED: {
|
|
133
|
+
if (this.notify(options, chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLVE_STATUS.REVIEWING_TERMS, response), !options.onTermsChanged || termsReviewSteps >= maxTermsReviewSteps)
|
|
134
|
+
return chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
135
135
|
termsReviewSteps += 1;
|
|
136
136
|
let replacementRequest = await options.onTermsChanged(response);
|
|
137
137
|
if (!replacementRequest)
|
|
138
|
-
return
|
|
138
|
+
return chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
139
139
|
request = replacementRequest, responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
140
140
|
continue;
|
|
141
141
|
}
|
|
142
|
-
case
|
|
143
|
-
case
|
|
144
|
-
case
|
|
145
|
-
return
|
|
142
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.SELECTION_UNAVAILABLE:
|
|
143
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.OFFER_ENDED:
|
|
144
|
+
case chunkNFXCKTE2_js.PURCHASE_INTENT_CONFIRM_STATUS.SOURCE_UNAVAILABLE:
|
|
145
|
+
return chunk6QANXRUM_js.ok({ kind: chunkNFXCKTE2_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
146
146
|
default:
|
|
147
|
-
return
|
|
148
|
-
new
|
|
149
|
-
|
|
147
|
+
return chunk6QANXRUM_js.err(
|
|
148
|
+
new chunkNFXCKTE2_js.CimplifyError(
|
|
149
|
+
chunkNFXCKTE2_js.PURCHASE_INTENT_ERROR_CODE.ACTION_UNSUPPORTED,
|
|
150
150
|
"The payment returned a status this checkout does not understand.",
|
|
151
151
|
false
|
|
152
152
|
)
|
|
@@ -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 chunk6QANXRUM_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 chunk6QANXRUM_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
|
let request = {
|
|
213
213
|
expected_intent_revision: expectedRevision
|
|
214
214
|
};
|
|
215
|
-
return
|
|
215
|
+
return chunk6QANXRUM_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 chunk6QANXRUM_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
|
let normalizedAttemptId = attemptId.trim();
|
|
241
241
|
if (!normalizedAttemptId) throw new TypeError("attemptId must not be empty");
|
|
242
|
-
return
|
|
242
|
+
return chunk6QANXRUM_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,
|
|
@@ -269,7 +269,7 @@ var PurchaseIntentService = class {
|
|
|
269
269
|
this.sessionPath = hostedSessionPath(sessionId), this.resolver = new PurchaseIntentResolver({ confirmation: this });
|
|
270
270
|
}
|
|
271
271
|
prepare(request, options) {
|
|
272
|
-
return
|
|
272
|
+
return chunk6QANXRUM_js.safe(
|
|
273
273
|
this.transport.post(
|
|
274
274
|
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.PREPARE}`,
|
|
275
275
|
request,
|
|
@@ -282,7 +282,7 @@ var PurchaseIntentService = class {
|
|
|
282
282
|
);
|
|
283
283
|
}
|
|
284
284
|
confirm(_intentId, request, options) {
|
|
285
|
-
return
|
|
285
|
+
return chunk6QANXRUM_js.safe(
|
|
286
286
|
this.transport.post(
|
|
287
287
|
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.CONFIRM}`,
|
|
288
288
|
request,
|
|
@@ -295,7 +295,7 @@ var PurchaseIntentService = class {
|
|
|
295
295
|
);
|
|
296
296
|
}
|
|
297
297
|
replay(options) {
|
|
298
|
-
return
|
|
298
|
+
return chunk6QANXRUM_js.safe(
|
|
299
299
|
this.transport.get(
|
|
300
300
|
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.REPLAY}`,
|
|
301
301
|
{
|
|
@@ -308,7 +308,7 @@ var PurchaseIntentService = class {
|
|
|
308
308
|
submitAction(_intentId, attemptId, request, options) {
|
|
309
309
|
let normalized = attemptId.trim();
|
|
310
310
|
if (!normalized) throw new TypeError("attemptId must not be empty");
|
|
311
|
-
return
|
|
311
|
+
return chunk6QANXRUM_js.safe(
|
|
312
312
|
this.transport.post(
|
|
313
313
|
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.ATTEMPTS}/${encodeURIComponent(normalized)}/${PURCHASE_INTENT_ROUTE.ACTIONS}`,
|
|
314
314
|
request,
|
|
@@ -334,7 +334,7 @@ var StoreCreditQueries = class {
|
|
|
334
334
|
* currency. Requires a signed-in customer; returns an error otherwise.
|
|
335
335
|
*/
|
|
336
336
|
async balance() {
|
|
337
|
-
return
|
|
337
|
+
return chunk6QANXRUM_js.safe(this.client.get("/api/v1/store-credit/balance"));
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
340
|
|
|
@@ -617,16 +617,16 @@ var ActivityService = class {
|
|
|
617
617
|
this.sendEvents([event]);
|
|
618
618
|
}
|
|
619
619
|
async getState() {
|
|
620
|
-
return
|
|
620
|
+
return chunk6QANXRUM_js.safe(this.client.get("/api/v1/activity/state"));
|
|
621
621
|
}
|
|
622
622
|
async getRecommendations(options) {
|
|
623
623
|
let params = new URLSearchParams();
|
|
624
624
|
options?.location_id && params.set("location_id", options.location_id), options?.limit && params.set("limit", String(options.limit));
|
|
625
625
|
let query = params.toString(), path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
|
|
626
|
-
return
|
|
626
|
+
return chunk6QANXRUM_js.safe(this.client.get(path));
|
|
627
627
|
}
|
|
628
628
|
async dismissMessage(code) {
|
|
629
|
-
return
|
|
629
|
+
return chunk6QANXRUM_js.safe(
|
|
630
630
|
this.client.post("/api/v1/activity/messages/dismiss", { code })
|
|
631
631
|
);
|
|
632
632
|
}
|
|
@@ -719,15 +719,15 @@ var SubscriptionService = class {
|
|
|
719
719
|
this.client = client;
|
|
720
720
|
}
|
|
721
721
|
async list() {
|
|
722
|
-
return
|
|
722
|
+
return chunk6QANXRUM_js.safe(this.client.get("/api/v1/subscriptions"));
|
|
723
723
|
}
|
|
724
724
|
async get(id) {
|
|
725
725
|
let encodedId = encodeURIComponent(id);
|
|
726
|
-
return
|
|
726
|
+
return chunk6QANXRUM_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
|
|
727
727
|
}
|
|
728
728
|
async cancel(id, reason, opts) {
|
|
729
|
-
let encodedId = encodeURIComponent(id), idempotencyKey = opts?.idempotencyKey ??
|
|
730
|
-
return
|
|
729
|
+
let encodedId = encodeURIComponent(id), idempotencyKey = opts?.idempotencyKey ?? chunk6QANXRUM_js.generateIdempotencyKey();
|
|
730
|
+
return chunk6QANXRUM_js.safe(
|
|
731
731
|
this.client.post(
|
|
732
732
|
`/api/v1/subscriptions/${encodedId}/cancel`,
|
|
733
733
|
{ reason },
|
|
@@ -737,19 +737,19 @@ var SubscriptionService = class {
|
|
|
737
737
|
}
|
|
738
738
|
async pause(id) {
|
|
739
739
|
let encodedId = encodeURIComponent(id);
|
|
740
|
-
return
|
|
740
|
+
return chunk6QANXRUM_js.safe(
|
|
741
741
|
this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
|
|
742
742
|
);
|
|
743
743
|
}
|
|
744
744
|
async resume(id) {
|
|
745
745
|
let encodedId = encodeURIComponent(id);
|
|
746
|
-
return
|
|
746
|
+
return chunk6QANXRUM_js.safe(
|
|
747
747
|
this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
|
|
748
748
|
);
|
|
749
749
|
}
|
|
750
750
|
async skipNextRenewal(id, opts) {
|
|
751
|
-
let encodedId = encodeURIComponent(id), idempotencyKey = opts?.idempotencyKey ??
|
|
752
|
-
return
|
|
751
|
+
let encodedId = encodeURIComponent(id), idempotencyKey = opts?.idempotencyKey ?? chunk6QANXRUM_js.generateIdempotencyKey();
|
|
752
|
+
return chunk6QANXRUM_js.safe(
|
|
753
753
|
this.client.post(
|
|
754
754
|
`/api/v1/subscriptions/${encodedId}/skip`,
|
|
755
755
|
void 0,
|
|
@@ -777,8 +777,8 @@ var UploadService = class {
|
|
|
777
777
|
* `CONTENT_SHA256_HEADER`; without it the server hashes the stored bytes.
|
|
778
778
|
*/
|
|
779
779
|
async init(filename, contentType2, sizeBytes, opts) {
|
|
780
|
-
let idempotencyKey = opts?.idempotencyKey ??
|
|
781
|
-
return
|
|
780
|
+
let idempotencyKey = opts?.idempotencyKey ?? chunk6QANXRUM_js.generateIdempotencyKey();
|
|
781
|
+
return chunk6QANXRUM_js.safe(
|
|
782
782
|
this.client.post(
|
|
783
783
|
"/api/v1/uploads/init",
|
|
784
784
|
{
|
|
@@ -792,7 +792,7 @@ var UploadService = class {
|
|
|
792
792
|
);
|
|
793
793
|
}
|
|
794
794
|
async confirm(uploadId) {
|
|
795
|
-
return
|
|
795
|
+
return chunk6QANXRUM_js.safe(
|
|
796
796
|
this.client.post("/api/v1/uploads/confirm", {
|
|
797
797
|
upload_id: uploadId
|
|
798
798
|
})
|
|
@@ -811,7 +811,7 @@ var UploadService = class {
|
|
|
811
811
|
if (!uploadResponse.ok)
|
|
812
812
|
return {
|
|
813
813
|
ok: !1,
|
|
814
|
-
error: new
|
|
814
|
+
error: new chunkNFXCKTE2_js.CimplifyError(
|
|
815
815
|
"UPLOAD_FAILED",
|
|
816
816
|
`Upload failed with status ${uploadResponse.status}`,
|
|
817
817
|
!0
|
|
@@ -820,7 +820,7 @@ var UploadService = class {
|
|
|
820
820
|
} catch (error) {
|
|
821
821
|
return {
|
|
822
822
|
ok: false,
|
|
823
|
-
error: new
|
|
823
|
+
error: new chunkNFXCKTE2_js.CimplifyError(
|
|
824
824
|
"UPLOAD_FAILED",
|
|
825
825
|
error instanceof Error ? error.message : "Upload failed",
|
|
826
826
|
true
|
|
@@ -838,7 +838,7 @@ var PlacesService = class {
|
|
|
838
838
|
}
|
|
839
839
|
/** `country` (ISO alpha-2) biases results; absent, the store's own country. */
|
|
840
840
|
async autocomplete(input, sessionToken, country) {
|
|
841
|
-
return
|
|
841
|
+
return chunk6QANXRUM_js.safe(
|
|
842
842
|
this.client.post("/api/v1/places/autocomplete", {
|
|
843
843
|
input,
|
|
844
844
|
sessionToken,
|
|
@@ -851,7 +851,7 @@ var PlacesService = class {
|
|
|
851
851
|
* the autocomplete used. Absent, the store's own country.
|
|
852
852
|
*/
|
|
853
853
|
async details(placeId, sessionToken, country) {
|
|
854
|
-
return
|
|
854
|
+
return chunk6QANXRUM_js.safe(
|
|
855
855
|
this.client.post("/api/v1/places/details", {
|
|
856
856
|
place_id: placeId,
|
|
857
857
|
sessionToken,
|
|
@@ -868,7 +868,7 @@ var DeliveryService = class {
|
|
|
868
868
|
}
|
|
869
869
|
async getFee(dropoffLat, dropoffLng, country) {
|
|
870
870
|
let params = new URLSearchParams();
|
|
871
|
-
return params.set("dropoff_lat", String(dropoffLat)), params.set("dropoff_lng", String(dropoffLng)), country && params.set("country", country),
|
|
871
|
+
return params.set("dropoff_lat", String(dropoffLat)), params.set("dropoff_lng", String(dropoffLng)), country && params.set("country", country), chunk6QANXRUM_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
|
|
872
872
|
}
|
|
873
873
|
async getOptions(queryOrLatitude, longitude, legacyOptions) {
|
|
874
874
|
let query = typeof queryOrLatitude == "number" ? {
|
|
@@ -876,7 +876,7 @@ var DeliveryService = class {
|
|
|
876
876
|
dropoffLat: queryOrLatitude,
|
|
877
877
|
dropoffLng: longitude
|
|
878
878
|
} : queryOrLatitude ?? {}, params = new URLSearchParams();
|
|
879
|
-
return query.dropoffLat != null && params.set("dropoff_lat", String(query.dropoffLat)), query.dropoffLng != null && params.set("dropoff_lng", String(query.dropoffLng)), query.country && params.set("country", query.country), query.currency && params.set("currency", query.currency), query.orderValue != null && params.set("order_value", String(query.orderValue)),
|
|
879
|
+
return query.dropoffLat != null && params.set("dropoff_lat", String(query.dropoffLat)), query.dropoffLng != null && params.set("dropoff_lng", String(query.dropoffLng)), query.country && params.set("country", query.country), query.currency && params.set("currency", query.currency), query.orderValue != null && params.set("order_value", String(query.orderValue)), chunk6QANXRUM_js.safe(
|
|
880
880
|
this.client.get(`/api/v1/delivery/options?${params.toString()}`)
|
|
881
881
|
);
|
|
882
882
|
}
|
|
@@ -963,14 +963,14 @@ var SupportService = class {
|
|
|
963
963
|
* contact values, account ids, and message bodies.
|
|
964
964
|
*/
|
|
965
965
|
async claimExternalChats() {
|
|
966
|
-
return this.client.getAccessToken() ?
|
|
966
|
+
return this.client.getAccessToken() ? chunk6QANXRUM_js.safe(
|
|
967
967
|
(async () => {
|
|
968
968
|
let businessId = await this.client.resolveBusinessId();
|
|
969
969
|
return this.client.post("/v1/me/chats/external-claims", {
|
|
970
970
|
business_id: businessId
|
|
971
971
|
});
|
|
972
972
|
})()
|
|
973
|
-
) :
|
|
973
|
+
) : chunk6QANXRUM_js.err(new chunkNFXCKTE2_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
974
974
|
}
|
|
975
975
|
/**
|
|
976
976
|
* Peek at the conversation without creating one: resolves the existing
|
|
@@ -978,22 +978,22 @@ var SupportService = class {
|
|
|
978
978
|
* the inbox with empty threads.
|
|
979
979
|
*/
|
|
980
980
|
async peekConversation() {
|
|
981
|
-
let result = await
|
|
981
|
+
let result = await chunk6QANXRUM_js.safe(
|
|
982
982
|
this.client.get("/api/v1/support/conversation")
|
|
983
983
|
);
|
|
984
|
-
return result.ok ? result.value.conversation ?
|
|
984
|
+
return result.ok ? result.value.conversation ? chunk6QANXRUM_js.ok({
|
|
985
985
|
conversation: result.value.conversation,
|
|
986
986
|
messages: chatMessagesFromWire(result.value.messages)
|
|
987
|
-
}) :
|
|
987
|
+
}) : chunk6QANXRUM_js.ok(null) : result;
|
|
988
988
|
}
|
|
989
989
|
/** Open (or resume) the customer's widget conversation. */
|
|
990
990
|
async openConversation(opts) {
|
|
991
|
-
let idempotencyKey = opts?.idempotencyKey ??
|
|
991
|
+
let idempotencyKey = opts?.idempotencyKey ?? chunk6QANXRUM_js.generateIdempotencyKey(), result = await chunk6QANXRUM_js.safe(
|
|
992
992
|
this.client.post("/api/v1/support/conversation", void 0, {
|
|
993
993
|
idempotencyKey
|
|
994
994
|
})
|
|
995
995
|
);
|
|
996
|
-
return result.ok ?
|
|
996
|
+
return result.ok ? chunk6QANXRUM_js.ok({
|
|
997
997
|
conversation: result.value.conversation,
|
|
998
998
|
messages: chatMessagesFromWire(result.value.messages)
|
|
999
999
|
}) : result;
|
|
@@ -1007,7 +1007,7 @@ var SupportService = class {
|
|
|
1007
1007
|
* server resolves it thread-scoped and echoes the quote as `reply_to`.
|
|
1008
1008
|
*/
|
|
1009
1009
|
async sendMessage(content, opts) {
|
|
1010
|
-
let idempotencyKey = opts?.idempotencyKey ??
|
|
1010
|
+
let idempotencyKey = opts?.idempotencyKey ?? chunk6QANXRUM_js.generateIdempotencyKey(), result = await chunk6QANXRUM_js.safe(
|
|
1011
1011
|
this.client.post(
|
|
1012
1012
|
"/api/v1/support/conversation/messages",
|
|
1013
1013
|
{
|
|
@@ -1019,7 +1019,7 @@ var SupportService = class {
|
|
|
1019
1019
|
{ idempotencyKey }
|
|
1020
1020
|
)
|
|
1021
1021
|
);
|
|
1022
|
-
return result.ok ?
|
|
1022
|
+
return result.ok ? chunk6QANXRUM_js.ok(chatMessageFromWire(result.value.message)) : result;
|
|
1023
1023
|
}
|
|
1024
1024
|
/**
|
|
1025
1025
|
* Poll for messages. `after` pages forward (live updates); `before` pages
|
|
@@ -1028,24 +1028,24 @@ var SupportService = class {
|
|
|
1028
1028
|
async getMessages(options = {}) {
|
|
1029
1029
|
let params = new URLSearchParams();
|
|
1030
1030
|
options.afterSequence !== void 0 && params.set("after_sequence", String(options.afterSequence)), options.beforeSequence !== void 0 && params.set("before_sequence", String(options.beforeSequence)), options.limit && params.set("limit", String(options.limit));
|
|
1031
|
-
let query = params.toString(), path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages", result = await
|
|
1032
|
-
return result.ok ?
|
|
1031
|
+
let query = params.toString(), path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages", result = await chunk6QANXRUM_js.safe(this.client.get(path));
|
|
1032
|
+
return result.ok ? chunk6QANXRUM_js.ok(chatMessagesFromWire(result.value)) : result;
|
|
1033
1033
|
}
|
|
1034
1034
|
/** React to a message in the active conversation by its `ChatMessage.id`. */
|
|
1035
1035
|
async reactToMessage(messageId, emoji) {
|
|
1036
|
-
let clientId =
|
|
1036
|
+
let clientId = chunk6QANXRUM_js.generateIdempotencyKey(), result = await chunk6QANXRUM_js.safe(
|
|
1037
1037
|
this.client.post(
|
|
1038
1038
|
`/api/v1/support/conversation/messages/${messageId}/reactions`,
|
|
1039
1039
|
{ emoji, client_id: clientId },
|
|
1040
1040
|
{ idempotencyKey: clientId }
|
|
1041
1041
|
)
|
|
1042
1042
|
);
|
|
1043
|
-
return result.ok ?
|
|
1043
|
+
return result.ok ? chunk6QANXRUM_js.ok(chatMessageFromWire(result.value.message)) : result;
|
|
1044
1044
|
}
|
|
1045
1045
|
/** Ask for a person: flags the thread for the merchant's inbox. */
|
|
1046
1046
|
async requestHuman(opts) {
|
|
1047
|
-
let idempotencyKey = opts?.idempotencyKey ??
|
|
1048
|
-
return
|
|
1047
|
+
let idempotencyKey = opts?.idempotencyKey ?? chunk6QANXRUM_js.generateIdempotencyKey();
|
|
1048
|
+
return chunk6QANXRUM_js.safe(
|
|
1049
1049
|
this.client.post(
|
|
1050
1050
|
"/api/v1/support/conversation/handoff",
|
|
1051
1051
|
void 0,
|
|
@@ -1063,9 +1063,9 @@ var CLAIM_TIMEOUT_MS = 15e3, CLAIM_PATH = "/api/v1/auth/session/claim", SessionS
|
|
|
1063
1063
|
this.claimInFlightToken = null;
|
|
1064
1064
|
this.lastClaimedAccessToken = null;
|
|
1065
1065
|
this.claimedName = null;
|
|
1066
|
-
this.client.events.on(
|
|
1066
|
+
this.client.events.on(chunk6QANXRUM_js.SESSION_CLEARED, () => {
|
|
1067
1067
|
this.lastClaimedAccessToken = null, this.claimedName = null;
|
|
1068
|
-
}), this.client.events.on(
|
|
1068
|
+
}), this.client.events.on(chunk6QANXRUM_js.SESSION_CLAIMED, (event) => {
|
|
1069
1069
|
event.customerName && (this.claimedName = event.customerName);
|
|
1070
1070
|
});
|
|
1071
1071
|
}
|
|
@@ -1076,7 +1076,7 @@ var CLAIM_TIMEOUT_MS = 15e3, CLAIM_PATH = "/api/v1/auth/session/claim", SessionS
|
|
|
1076
1076
|
/** Adopt a session another holder already bound, for this bearer or, with
|
|
1077
1077
|
* `null`, for a bearer this client never holds (the checkout element). */
|
|
1078
1078
|
adopt(accessToken, session) {
|
|
1079
|
-
this.lastClaimedAccessToken = accessToken, this.claimedName = session.customerName || null, this.client.adoptSessionToken(session.sessionToken), this.client.publishSessionClaimed(this.claimedName), this.client.events.emit(
|
|
1079
|
+
this.lastClaimedAccessToken = accessToken, this.claimedName = session.customerName || null, this.client.adoptSessionToken(session.sessionToken), this.client.publishSessionClaimed(this.claimedName), this.client.events.emit(chunk6QANXRUM_js.SESSION_CLAIMED, session);
|
|
1080
1080
|
}
|
|
1081
1081
|
/**
|
|
1082
1082
|
* Bind the anonymous session to the verified Link identity in one server
|
|
@@ -1093,14 +1093,14 @@ var CLAIM_TIMEOUT_MS = 15e3, CLAIM_PATH = "/api/v1/auth/session/claim", SessionS
|
|
|
1093
1093
|
async claim() {
|
|
1094
1094
|
let accessToken = this.client.getAccessToken();
|
|
1095
1095
|
if (!accessToken)
|
|
1096
|
-
return
|
|
1096
|
+
return chunk6QANXRUM_js.err(new chunkNFXCKTE2_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1097
1097
|
if (this.claimInFlight)
|
|
1098
1098
|
return this.claimInFlightToken === accessToken ? this.claimInFlight : (await this.claimInFlight, this.claim());
|
|
1099
1099
|
if (this.lastClaimedAccessToken === accessToken)
|
|
1100
|
-
return
|
|
1100
|
+
return chunk6QANXRUM_js.err(new chunkNFXCKTE2_js.CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
1101
1101
|
let epoch = this.client.getSessionEpoch();
|
|
1102
1102
|
this.claimInFlightToken = accessToken, this.claimInFlight = (async () => {
|
|
1103
|
-
let result = await
|
|
1103
|
+
let result = await chunk6QANXRUM_js.safe(
|
|
1104
1104
|
this.client.post(
|
|
1105
1105
|
CLAIM_PATH,
|
|
1106
1106
|
{ access_token: accessToken },
|
|
@@ -1109,8 +1109,8 @@ var CLAIM_TIMEOUT_MS = 15e3, CLAIM_PATH = "/api/v1/auth/session/claim", SessionS
|
|
|
1109
1109
|
);
|
|
1110
1110
|
if (result.ok) {
|
|
1111
1111
|
if (this.client.getSessionEpoch() !== epoch)
|
|
1112
|
-
return
|
|
1113
|
-
new
|
|
1112
|
+
return chunk6QANXRUM_js.err(
|
|
1113
|
+
new chunkNFXCKTE2_js.CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
1114
1114
|
);
|
|
1115
1115
|
this.adopt(accessToken, {
|
|
1116
1116
|
sessionToken: result.value.session_token,
|
|
@@ -1213,11 +1213,11 @@ function subscribeCrossTabSession(notify) {
|
|
|
1213
1213
|
// src/client.ts
|
|
1214
1214
|
var SESSION_TOKEN_STORAGE_KEY = "cimplify_session_token", ORDER_TOKEN_PREFIX = "cimplify_ot_", SESSION_TOKEN_HEADER = "x-session-token", LOCATION_ID_QUERY_PARAMETER = "location_id", ORDER_TOKEN_TTL_MS = 1440 * 60 * 1e3, DEFAULT_TIMEOUT_MS = 5e3, HTTP_SERVER_ERROR_STATUS = 500, HTTP_TOO_MANY_REQUESTS = 429, HTTP_SERVICE_UNAVAILABLE = 503, RETRY_AFTER_HEADER = "Retry-After", DEFAULT_MAX_RETRIES = 3, DEFAULT_RETRY_DELAY_MS = 1e3, MAX_RETRY_AFTER_MS = 3e4;
|
|
1215
1215
|
function sleep(ms, signal) {
|
|
1216
|
-
return signal?.aborted ? Promise.reject(new
|
|
1216
|
+
return signal?.aborted ? Promise.reject(new chunkNFXCKTE2_js.CimplifyError(chunkNFXCKTE2_js.ErrorCode.CANCELLED, "Request was cancelled.", true)) : new Promise((resolve, reject) => {
|
|
1217
1217
|
let timer = setTimeout(() => {
|
|
1218
1218
|
signal?.removeEventListener("abort", onAbort), resolve();
|
|
1219
1219
|
}, ms), onAbort = () => {
|
|
1220
|
-
clearTimeout(timer), reject(new
|
|
1220
|
+
clearTimeout(timer), reject(new chunkNFXCKTE2_js.CimplifyError(chunkNFXCKTE2_js.ErrorCode.CANCELLED, "Request was cancelled.", true));
|
|
1221
1221
|
};
|
|
1222
1222
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1223
1223
|
});
|
|
@@ -1259,26 +1259,26 @@ function generateSessionToken() {
|
|
|
1259
1259
|
});
|
|
1260
1260
|
}
|
|
1261
1261
|
function isRetryable(error) {
|
|
1262
|
-
return error instanceof TypeError && error.message.includes("fetch") || error instanceof DOMException && error.name === "AbortError" ? true : error instanceof
|
|
1262
|
+
return error instanceof TypeError && error.message.includes("fetch") || error instanceof DOMException && error.name === "AbortError" ? true : error instanceof chunkNFXCKTE2_js.CimplifyError ? error.retryable : false;
|
|
1263
1263
|
}
|
|
1264
1264
|
function toNetworkError(error, isTestMode) {
|
|
1265
|
-
return error instanceof DOMException && error.name === "AbortError" ?
|
|
1266
|
-
new
|
|
1267
|
-
|
|
1265
|
+
return error instanceof DOMException && error.name === "AbortError" ? chunkNFXCKTE2_js.enrichError(
|
|
1266
|
+
new chunkNFXCKTE2_js.CimplifyError(
|
|
1267
|
+
chunkNFXCKTE2_js.ErrorCode.TIMEOUT,
|
|
1268
1268
|
"Request timed out. Please check your connection and try again.",
|
|
1269
1269
|
true
|
|
1270
1270
|
),
|
|
1271
1271
|
{ isTestMode }
|
|
1272
|
-
) : error instanceof TypeError && error.message.includes("fetch") ?
|
|
1273
|
-
new
|
|
1274
|
-
|
|
1272
|
+
) : error instanceof TypeError && error.message.includes("fetch") ? chunkNFXCKTE2_js.enrichError(
|
|
1273
|
+
new chunkNFXCKTE2_js.CimplifyError(
|
|
1274
|
+
chunkNFXCKTE2_js.ErrorCode.NETWORK_ERROR,
|
|
1275
1275
|
"Network error. Please check your internet connection.",
|
|
1276
1276
|
true
|
|
1277
1277
|
),
|
|
1278
1278
|
{ isTestMode }
|
|
1279
|
-
) : error instanceof
|
|
1280
|
-
new
|
|
1281
|
-
|
|
1279
|
+
) : error instanceof chunkNFXCKTE2_js.CimplifyError ? chunkNFXCKTE2_js.enrichError(error, { isTestMode }) : chunkNFXCKTE2_js.enrichError(
|
|
1280
|
+
new chunkNFXCKTE2_js.CimplifyError(
|
|
1281
|
+
chunkNFXCKTE2_js.ErrorCode.UNKNOWN_ERROR,
|
|
1282
1282
|
error instanceof Error ? error.message : "An unknown error occurred",
|
|
1283
1283
|
false
|
|
1284
1284
|
),
|
|
@@ -1329,11 +1329,11 @@ var CimplifyClient = class {
|
|
|
1329
1329
|
* Sentry, analytics, etc.). The SDK emits but never auto-consumes — the
|
|
1330
1330
|
* consumer decides how to react.
|
|
1331
1331
|
*/
|
|
1332
|
-
this.events =
|
|
1332
|
+
this.events = chunk6QANXRUM_js.createClientEvents();
|
|
1333
1333
|
this.stopPageViewTracking = null;
|
|
1334
1334
|
this.publicKey = config.publicKey || getEnvPublicKey() || "";
|
|
1335
1335
|
let urls = deriveUrls();
|
|
1336
|
-
this.baseUrl = config.baseUrl ? normalizeUrl(config.baseUrl) : urls.baseUrl, this.linkApiUrl = config.linkApiUrl ? normalizeUrl(config.linkApiUrl) : urls.linkApiUrl, this.credentials = config.credentials || "include", this.timeout = config.timeout ?? (5e3), this.maxRetries = config.maxRetries ?? (3), this.retryDelay = config.retryDelay ?? (1e3), this.hooks = config.hooks ?? {}, this.authorizationAdapters = config.authorizationAdapterRegistry ??
|
|
1336
|
+
this.baseUrl = config.baseUrl ? normalizeUrl(config.baseUrl) : urls.baseUrl, this.linkApiUrl = config.linkApiUrl ? normalizeUrl(config.linkApiUrl) : urls.linkApiUrl, this.credentials = config.credentials || "include", this.timeout = config.timeout ?? (5e3), this.maxRetries = config.maxRetries ?? (3), this.retryDelay = config.retryDelay ?? (1e3), this.hooks = config.hooks ?? {}, this.authorizationAdapters = config.authorizationAdapterRegistry ?? chunk6QANXRUM_js.createDefaultPaymentAuthorizationAdapterRegistry(), this.fetchImpl = (config.fetch ?? globalThis.fetch).bind(globalThis), this.sessionToken = this.loadSessionToken() ?? this.mintSessionToken();
|
|
1337
1337
|
let persistedSessionSync = this.loadSessionSyncPayload();
|
|
1338
1338
|
persistedSessionSync && this.observeSessionSync(persistedSessionSync), this.stopCrossTabSessionWatch = subscribeCrossTabSession((payload) => {
|
|
1339
1339
|
this.applyCrossTabSession(payload);
|
|
@@ -1378,7 +1378,7 @@ var CimplifyClient = class {
|
|
|
1378
1378
|
previousToken: previous,
|
|
1379
1379
|
newToken: token,
|
|
1380
1380
|
source: SESSION_CHANGE_SOURCE.MANUAL
|
|
1381
|
-
}), this.events.emit(
|
|
1381
|
+
}), this.events.emit(chunk6QANXRUM_js.AUTH_TOKEN_CHANGED, { token });
|
|
1382
1382
|
}
|
|
1383
1383
|
/**
|
|
1384
1384
|
* Zero-UI claim: a freshly verified customer identity (OTP verify, silent
|
|
@@ -1410,7 +1410,7 @@ var CimplifyClient = class {
|
|
|
1410
1410
|
previousToken: previous,
|
|
1411
1411
|
newToken: null,
|
|
1412
1412
|
source: SESSION_CHANGE_SOURCE.CLEAR
|
|
1413
|
-
}), this.events.emit(
|
|
1413
|
+
}), this.events.emit(chunk6QANXRUM_js.AUTH_TOKEN_CHANGED, { token: null }), this.events.emit(chunk6QANXRUM_js.SESSION_CLEARED, {});
|
|
1414
1414
|
}
|
|
1415
1415
|
getSessionEpoch() {
|
|
1416
1416
|
return this.sessionEpoch;
|
|
@@ -1456,12 +1456,12 @@ var CimplifyClient = class {
|
|
|
1456
1456
|
publishLocalSessionSync(envelope);
|
|
1457
1457
|
}
|
|
1458
1458
|
applyCrossTabSession(payload) {
|
|
1459
|
-
this.observeSessionSync(payload) && payload.token !== this.sessionToken && (payload.type === "claimed" ? (this.sessionToken = payload.token, this.sessionEpoch++, this.events.emit(
|
|
1459
|
+
this.observeSessionSync(payload) && payload.token !== this.sessionToken && (payload.type === "claimed" ? (this.sessionToken = payload.token, this.sessionEpoch++, this.events.emit(chunk6QANXRUM_js.SESSION_CLAIMED, {
|
|
1460
1460
|
sessionToken: payload.token,
|
|
1461
1461
|
customerName: payload.name ?? "",
|
|
1462
1462
|
customer: null,
|
|
1463
1463
|
cart: null
|
|
1464
|
-
})) : (this.accessToken = null, this._activity?.resetSession(), this.sessionToken = payload.token, this.sessionEpoch++, this.events.emit(
|
|
1464
|
+
})) : (this.accessToken = null, this._activity?.resetSession(), this.sessionToken = payload.token, this.sessionEpoch++, this.events.emit(chunk6QANXRUM_js.AUTH_TOKEN_CHANGED, { token: null }), this.events.emit(chunk6QANXRUM_js.SESSION_CLEARED, {})));
|
|
1465
1465
|
}
|
|
1466
1466
|
observeSessionSync(payload) {
|
|
1467
1467
|
if (payload.at < this.latestSessionSyncAt) return false;
|
|
@@ -1522,7 +1522,7 @@ var CimplifyClient = class {
|
|
|
1522
1522
|
let normalized = publicKey.trim();
|
|
1523
1523
|
if (normalized === this.publicKey) return;
|
|
1524
1524
|
let restartPageViewTracking = this.stopPageViewTracking !== null;
|
|
1525
|
-
restartPageViewTracking && this.stopTrackingPageViews(), this.publicKey = normalized, this.publicKeyEpoch += 1, this.businessId = null, this.businessIdResolvePromise = null, this.inflightRequests.clear(), this._activity?.resetForStorefrontIdentityChange(), delete this.context.location_id, this.accessToken !== null && this.setAccessToken(null), this.events.emit(
|
|
1525
|
+
restartPageViewTracking && this.stopTrackingPageViews(), this.publicKey = normalized, this.publicKeyEpoch += 1, this.businessId = null, this.businessIdResolvePromise = null, this.inflightRequests.clear(), this._activity?.resetForStorefrontIdentityChange(), delete this.context.location_id, this.accessToken !== null && this.setAccessToken(null), this.events.emit(chunk6QANXRUM_js.SESSION_CLEARED, {}), restartPageViewTracking && (this.stopPageViewTracking = this.activity.autoTrackPageViews());
|
|
1526
1526
|
}
|
|
1527
1527
|
getBusinessId() {
|
|
1528
1528
|
return this.businessId;
|
|
@@ -1535,14 +1535,14 @@ var CimplifyClient = class {
|
|
|
1535
1535
|
let publicKeyEpoch = this.publicKeyEpoch, resolution = (async () => {
|
|
1536
1536
|
let result = await this.business.getInfo();
|
|
1537
1537
|
if (!result.ok || !result.value?.id)
|
|
1538
|
-
throw new
|
|
1539
|
-
|
|
1538
|
+
throw new chunkNFXCKTE2_js.CimplifyError(
|
|
1539
|
+
chunkNFXCKTE2_js.ErrorCode.NOT_FOUND,
|
|
1540
1540
|
"Unable to resolve business ID from the current public key.",
|
|
1541
1541
|
true
|
|
1542
1542
|
);
|
|
1543
1543
|
if (this.publicKeyEpoch !== publicKeyEpoch)
|
|
1544
|
-
throw new
|
|
1545
|
-
|
|
1544
|
+
throw new chunkNFXCKTE2_js.CimplifyError(
|
|
1545
|
+
chunkNFXCKTE2_js.ErrorCode.TENANT_CONTEXT_CHANGED,
|
|
1546
1546
|
"The storefront tenant changed while resolving its business identity.",
|
|
1547
1547
|
true
|
|
1548
1548
|
);
|
|
@@ -1637,7 +1637,7 @@ var CimplifyClient = class {
|
|
|
1637
1637
|
for (let attempt = 0; attempt <= maxRetries; attempt++)
|
|
1638
1638
|
try {
|
|
1639
1639
|
if (signal?.aborted)
|
|
1640
|
-
throw new
|
|
1640
|
+
throw new chunkNFXCKTE2_js.CimplifyError(chunkNFXCKTE2_js.ErrorCode.CANCELLED, "Request was cancelled.", !0);
|
|
1641
1641
|
let controller = new AbortController(), timeoutId = setTimeout(() => controller.abort(), timeoutMs ?? this.timeout), onAbort = () => controller.abort();
|
|
1642
1642
|
signal?.addEventListener("abort", onAbort, { once: !0 });
|
|
1643
1643
|
let response;
|
|
@@ -1669,7 +1669,7 @@ var CimplifyClient = class {
|
|
|
1669
1669
|
if (response.status >= 400 && response.status < 500)
|
|
1670
1670
|
return this.hooks.onRequestError?.({
|
|
1671
1671
|
...context,
|
|
1672
|
-
error: new
|
|
1672
|
+
error: new chunkNFXCKTE2_js.CimplifyError(
|
|
1673
1673
|
`HTTP_${response.status}`,
|
|
1674
1674
|
`Request failed with status ${response.status}`,
|
|
1675
1675
|
!1
|
|
@@ -1692,8 +1692,8 @@ var CimplifyClient = class {
|
|
|
1692
1692
|
}
|
|
1693
1693
|
return this.hooks.onRequestError?.({
|
|
1694
1694
|
...context,
|
|
1695
|
-
error: new
|
|
1696
|
-
|
|
1695
|
+
error: new chunkNFXCKTE2_js.CimplifyError(
|
|
1696
|
+
chunkNFXCKTE2_js.ErrorCode.SERVER_ERROR,
|
|
1697
1697
|
`Server error ${response.status} after ${retryCount} retries`,
|
|
1698
1698
|
!1
|
|
1699
1699
|
),
|
|
@@ -1704,7 +1704,7 @@ var CimplifyClient = class {
|
|
|
1704
1704
|
}), response;
|
|
1705
1705
|
} catch (error) {
|
|
1706
1706
|
if (lastError = error, signal?.aborted)
|
|
1707
|
-
throw new
|
|
1707
|
+
throw new chunkNFXCKTE2_js.CimplifyError(chunkNFXCKTE2_js.ErrorCode.CANCELLED, "Request was cancelled.", true);
|
|
1708
1708
|
let networkError = toNetworkError(error, this.isTestMode()), errorRetryable = isRetryable(error);
|
|
1709
1709
|
if (!errorRetryable || attempt >= maxRetries)
|
|
1710
1710
|
throw this.hooks.onRequestError?.({
|
|
@@ -1868,9 +1868,9 @@ var CimplifyClient = class {
|
|
|
1868
1868
|
try {
|
|
1869
1869
|
json = await response.json();
|
|
1870
1870
|
} catch {
|
|
1871
|
-
throw
|
|
1872
|
-
new
|
|
1873
|
-
serverFailure ?
|
|
1871
|
+
throw chunkNFXCKTE2_js.enrichError(
|
|
1872
|
+
new chunkNFXCKTE2_js.CimplifyError(
|
|
1873
|
+
serverFailure ? chunkNFXCKTE2_js.ErrorCode.SERVER_ERROR : chunkNFXCKTE2_js.ErrorCode.API_ERROR,
|
|
1874
1874
|
serverFailure ? "The service is temporarily unavailable." : "The service returned an unreadable response.",
|
|
1875
1875
|
serverFailure
|
|
1876
1876
|
),
|
|
@@ -1878,26 +1878,26 @@ var CimplifyClient = class {
|
|
|
1878
1878
|
);
|
|
1879
1879
|
}
|
|
1880
1880
|
if (!response.ok) {
|
|
1881
|
-
let errorCode = typeof json.error == "object" && json.error?.error_code || typeof json.error == "object" && json.error?.code ||
|
|
1882
|
-
if (errorCode ===
|
|
1881
|
+
let errorCode = typeof json.error == "object" && json.error?.error_code || typeof json.error == "object" && json.error?.code || chunkNFXCKTE2_js.ErrorCode.API_ERROR, 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", retryable = typeof json.error == "object" && typeof json.error?.retryable == "boolean" ? json.error.retryable : serverFailure;
|
|
1882
|
+
if (errorCode === chunkNFXCKTE2_js.ErrorCode.IDEMPOTENCY_MISMATCH) {
|
|
1883
1883
|
let originalCreatedAt = typeof json.error == "object" && json.error?.original_created_at || "";
|
|
1884
|
-
throw new
|
|
1884
|
+
throw new chunkNFXCKTE2_js.IdempotencyMismatchError(errorMessage, originalCreatedAt);
|
|
1885
1885
|
}
|
|
1886
|
-
let error =
|
|
1886
|
+
let error = chunkNFXCKTE2_js.enrichError(new chunkNFXCKTE2_js.CimplifyError(errorCode, errorMessage, retryable), {
|
|
1887
1887
|
isTestMode: this.isTestMode()
|
|
1888
1888
|
});
|
|
1889
1889
|
if (response.status === (429)) {
|
|
1890
1890
|
let retryAfterMs = retryAfterDelayMs(response.headers.get(RETRY_AFTER_HEADER));
|
|
1891
1891
|
retryAfterMs !== null && (error.retryAfterMs = retryAfterMs);
|
|
1892
1892
|
}
|
|
1893
|
-
throw (response.status === 401 || error.code ===
|
|
1893
|
+
throw (response.status === 401 || error.code === chunkNFXCKTE2_js.ErrorCode.UNAUTHORIZED) && this.accessToken && console.warn(
|
|
1894
1894
|
"[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
|
|
1895
1895
|
), error;
|
|
1896
1896
|
}
|
|
1897
1897
|
if (json?.success === false || json?.error?.code || json?.error?.message)
|
|
1898
|
-
throw
|
|
1899
|
-
new
|
|
1900
|
-
json.error?.code ||
|
|
1898
|
+
throw chunkNFXCKTE2_js.enrichError(
|
|
1899
|
+
new chunkNFXCKTE2_js.CimplifyError(
|
|
1900
|
+
json.error?.code || chunkNFXCKTE2_js.ErrorCode.API_ERROR,
|
|
1901
1901
|
json.error?.message || "An error occurred",
|
|
1902
1902
|
json.error?.retryable || false
|
|
1903
1903
|
),
|
|
@@ -1906,19 +1906,19 @@ var CimplifyClient = class {
|
|
|
1906
1906
|
return json?.data !== void 0 ? json.data : json;
|
|
1907
1907
|
}
|
|
1908
1908
|
get catalogue() {
|
|
1909
|
-
return this._catalogue || (this._catalogue = new
|
|
1909
|
+
return this._catalogue || (this._catalogue = new chunk6QANXRUM_js.CatalogueQueries(this)), this._catalogue;
|
|
1910
1910
|
}
|
|
1911
1911
|
get cart() {
|
|
1912
|
-
return this._cart || (this._cart = new
|
|
1912
|
+
return this._cart || (this._cart = new chunk6QANXRUM_js.CartOperations(this)), this._cart;
|
|
1913
1913
|
}
|
|
1914
1914
|
get checkout() {
|
|
1915
|
-
return this._checkout || (this._checkout = new
|
|
1915
|
+
return this._checkout || (this._checkout = new chunk6QANXRUM_js.CheckoutService(this)), this._checkout;
|
|
1916
1916
|
}
|
|
1917
1917
|
get purchaseIntents() {
|
|
1918
1918
|
return this._purchaseIntents || (this._purchaseIntents = new PurchaseIntentService(this)), this._purchaseIntents;
|
|
1919
1919
|
}
|
|
1920
1920
|
get orders() {
|
|
1921
|
-
return this._orders || (this._orders = new
|
|
1921
|
+
return this._orders || (this._orders = new chunk6QANXRUM_js.OrderQueries(this)), this._orders;
|
|
1922
1922
|
}
|
|
1923
1923
|
get storeCredit() {
|
|
1924
1924
|
return this._storeCredit || (this._storeCredit = new StoreCreditQueries(this)), this._storeCredit;
|
|
@@ -1933,25 +1933,25 @@ var CimplifyClient = class {
|
|
|
1933
1933
|
return this._places || (this._places = new PlacesService(this)), this._places;
|
|
1934
1934
|
}
|
|
1935
1935
|
get link() {
|
|
1936
|
-
return this._link || (this._link = new
|
|
1936
|
+
return this._link || (this._link = new chunk6QANXRUM_js.LinkService(this)), this._link;
|
|
1937
1937
|
}
|
|
1938
1938
|
get auth() {
|
|
1939
|
-
return this._auth || (this._auth = new
|
|
1939
|
+
return this._auth || (this._auth = new chunk6QANXRUM_js.AuthService(this)), this._auth;
|
|
1940
1940
|
}
|
|
1941
1941
|
get business() {
|
|
1942
|
-
return this._business || (this._business = new
|
|
1942
|
+
return this._business || (this._business = new chunk6QANXRUM_js.BusinessService(this)), this._business;
|
|
1943
1943
|
}
|
|
1944
1944
|
get inventory() {
|
|
1945
|
-
return this._inventory || (this._inventory = new
|
|
1945
|
+
return this._inventory || (this._inventory = new chunk6QANXRUM_js.InventoryService(this)), this._inventory;
|
|
1946
1946
|
}
|
|
1947
1947
|
get scheduling() {
|
|
1948
|
-
return this._scheduling || (this._scheduling = new
|
|
1948
|
+
return this._scheduling || (this._scheduling = new chunk6QANXRUM_js.SchedulingService(this)), this._scheduling;
|
|
1949
1949
|
}
|
|
1950
1950
|
get lite() {
|
|
1951
|
-
return this._lite || (this._lite = new
|
|
1951
|
+
return this._lite || (this._lite = new chunk6QANXRUM_js.LiteService(this)), this._lite;
|
|
1952
1952
|
}
|
|
1953
1953
|
get fx() {
|
|
1954
|
-
return this._fx || (this._fx = new
|
|
1954
|
+
return this._fx || (this._fx = new chunk6QANXRUM_js.FxService(this)), this._fx;
|
|
1955
1955
|
}
|
|
1956
1956
|
get activity() {
|
|
1957
1957
|
return this._activity || (this._activity = new ActivityService(this)), this._activity;
|
|
@@ -1972,7 +1972,7 @@ var CimplifyClient = class {
|
|
|
1972
1972
|
return `${protocol}//${host}${path}${query ? `?${query}` : ""}`;
|
|
1973
1973
|
}
|
|
1974
1974
|
elements(businessId, options) {
|
|
1975
|
-
return businessId && this.setBusinessId(businessId),
|
|
1975
|
+
return businessId && this.setBusinessId(businessId), chunk6QANXRUM_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
|
|
1976
1976
|
}
|
|
1977
1977
|
};
|
|
1978
1978
|
function createCimplifyClient(config = {}) {
|