@cimplify/sdk 0.89.0 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/advanced.d.mts +3 -3
- package/dist/advanced.d.ts +3 -3
- package/dist/advanced.js +20 -20
- package/dist/advanced.mjs +1 -1
- package/dist/{chunk-JHJTXAPS.js → chunk-3MBMIEWT.js} +4 -4
- package/dist/{chunk-DENWOZEA.mjs → chunk-3XD2FVP4.mjs} +163 -43
- package/dist/{chunk-M4ALCELT.mjs → chunk-54H2YYIW.mjs} +2 -2
- package/dist/{chunk-T2CJ67QV.js → chunk-DCRN67NO.js} +201 -78
- package/dist/{chunk-T7Z25EY4.js → chunk-HKN3YG76.js} +84 -0
- package/dist/{chunk-GHFDYM5K.js → chunk-IVJEUGWF.js} +10 -1
- package/dist/{chunk-ROBTTS3Q.js → chunk-OAHSF542.js} +40 -1
- package/dist/{chunk-APBLFZ2I.mjs → chunk-PYBFTMHI.mjs} +40 -1
- package/dist/{chunk-OZDDHSIB.mjs → chunk-RRBY35TJ.mjs} +80 -1
- package/dist/{chunk-ZU4ZRYUR.mjs → chunk-T7LDBZZZ.mjs} +10 -1
- package/dist/chunk-U4MW6PYU.mjs +23 -0
- package/dist/chunk-XREIZ56K.js +26 -0
- package/dist/{client-CqZgdUtw.d.ts → client-BQbSKlHS.d.mts} +165 -11
- package/dist/{client-CAY2NbRG.d.mts → client-Bw4HtLP1.d.mts} +2 -2
- package/dist/{client-D8ZFs-sq.d.mts → client-CeW3acve.d.ts} +165 -11
- package/dist/{client-CUbwb6Om.d.ts → client-Otzv_rgP.d.ts} +2 -2
- package/dist/{index-CmWOz9bi.d.mts → index-CmIboQjl.d.mts} +3 -3
- package/dist/{index-Bc5qUxAt.d.ts → index-DgoRwz8l.d.ts} +3 -3
- package/dist/index.d.mts +49 -7
- package/dist/index.d.ts +49 -7
- package/dist/index.js +109 -82
- package/dist/index.mjs +11 -5
- package/dist/mock/cli.mjs +61 -1
- package/dist/mock/library.js +61 -1
- package/dist/mock/library.mjs +61 -1
- package/dist/mock/msw.js +61 -1
- package/dist/mock/msw.mjs +61 -1
- package/dist/{payment-Dcgb9n1n.d.mts → payment-BFtLqiG2.d.mts} +1 -1
- package/dist/{payment-Xq0WDZXh.d.ts → payment-Cq8FT1B6.d.ts} +1 -1
- package/dist/{price-DAAjKgAp.d.ts → price-DaFXT-Lr.d.ts} +1 -1
- package/dist/{price--Ma_WO5_.d.mts → price-DleDWk_s.d.mts} +1 -1
- package/dist/{product-BakHcsP2.d.ts → product-bZ8G5Z8D.d.mts} +95 -2
- package/dist/{product-BakHcsP2.d.mts → product-bZ8G5Z8D.d.ts} +95 -2
- package/dist/react.d.mts +471 -8
- package/dist/react.d.ts +471 -8
- package/dist/react.js +2787 -402
- package/dist/react.mjs +2699 -337
- package/dist/{server-Bk_hlefX.d.mts → server-D-iK-bNt.d.mts} +8 -1
- package/dist/{server-Bei5lBrc.d.ts → server-DwsY9hlX.d.ts} +8 -1
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +7 -7
- package/dist/server.mjs +2 -2
- package/dist/styles.css +1 -1
- package/dist/testing/msw.d.mts +2 -2
- package/dist/testing/msw.d.ts +2 -2
- package/dist/testing/msw.js +3 -2
- package/dist/testing/msw.mjs +2 -1
- package/dist/testing/suite.d.mts +6 -6
- package/dist/testing/suite.d.ts +6 -6
- package/dist/testing/suite.js +24 -23
- package/dist/testing/suite.mjs +5 -4
- package/dist/testing.d.mts +5 -5
- package/dist/testing.d.ts +5 -5
- package/dist/testing.js +80 -79
- package/dist/testing.mjs +6 -5
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/package.json +4 -1
- package/registry/booking-page.json +1 -1
- package/registry/chat-widget.json +1 -1
- package/registry/customer-input-fields.json +1 -1
- package/registry/date-slot-picker.json +1 -1
- package/registry/product-customizer.json +1 -1
- package/registry/rental-service-card.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkIVJEUGWF_js = require('./chunk-IVJEUGWF.js');
|
|
4
4
|
var chunkAETVRBKI_js = require('./chunk-AETVRBKI.js');
|
|
5
5
|
|
|
6
6
|
// src/store-credit.ts
|
|
@@ -13,7 +13,7 @@ var StoreCreditQueries = class {
|
|
|
13
13
|
* currency. Requires a signed-in customer; returns an error otherwise.
|
|
14
14
|
*/
|
|
15
15
|
async balance() {
|
|
16
|
-
return
|
|
16
|
+
return chunkIVJEUGWF_js.safe(this.client.get("/api/v1/store-credit/balance"));
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -95,7 +95,7 @@ var ActivityService = class {
|
|
|
95
95
|
this.sendEvents([event]);
|
|
96
96
|
}
|
|
97
97
|
async getState() {
|
|
98
|
-
return
|
|
98
|
+
return chunkIVJEUGWF_js.safe(this.client.get("/api/v1/activity/state"));
|
|
99
99
|
}
|
|
100
100
|
async getRecommendations(options) {
|
|
101
101
|
const params = new URLSearchParams();
|
|
@@ -103,10 +103,10 @@ var ActivityService = class {
|
|
|
103
103
|
if (options?.limit) params.set("limit", String(options.limit));
|
|
104
104
|
const query = params.toString();
|
|
105
105
|
const path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
|
|
106
|
-
return
|
|
106
|
+
return chunkIVJEUGWF_js.safe(this.client.get(path));
|
|
107
107
|
}
|
|
108
108
|
async dismissMessage(code) {
|
|
109
|
-
return
|
|
109
|
+
return chunkIVJEUGWF_js.safe(
|
|
110
110
|
this.client.post("/api/v1/activity/messages/dismiss", { code })
|
|
111
111
|
);
|
|
112
112
|
}
|
|
@@ -142,16 +142,16 @@ var SubscriptionService = class {
|
|
|
142
142
|
this.client = client;
|
|
143
143
|
}
|
|
144
144
|
async list() {
|
|
145
|
-
return
|
|
145
|
+
return chunkIVJEUGWF_js.safe(this.client.get("/api/v1/subscriptions"));
|
|
146
146
|
}
|
|
147
147
|
async get(id) {
|
|
148
148
|
const encodedId = encodeURIComponent(id);
|
|
149
|
-
return
|
|
149
|
+
return chunkIVJEUGWF_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
|
|
150
150
|
}
|
|
151
151
|
async cancel(id, reason, opts) {
|
|
152
152
|
const encodedId = encodeURIComponent(id);
|
|
153
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
154
|
-
return
|
|
153
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkIVJEUGWF_js.generateIdempotencyKey();
|
|
154
|
+
return chunkIVJEUGWF_js.safe(
|
|
155
155
|
this.client.post(
|
|
156
156
|
`/api/v1/subscriptions/${encodedId}/cancel`,
|
|
157
157
|
{ reason },
|
|
@@ -161,20 +161,20 @@ var SubscriptionService = class {
|
|
|
161
161
|
}
|
|
162
162
|
async pause(id) {
|
|
163
163
|
const encodedId = encodeURIComponent(id);
|
|
164
|
-
return
|
|
164
|
+
return chunkIVJEUGWF_js.safe(
|
|
165
165
|
this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
async resume(id) {
|
|
169
169
|
const encodedId = encodeURIComponent(id);
|
|
170
|
-
return
|
|
170
|
+
return chunkIVJEUGWF_js.safe(
|
|
171
171
|
this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
174
|
async skipNextRenewal(id, opts) {
|
|
175
175
|
const encodedId = encodeURIComponent(id);
|
|
176
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
177
|
-
return
|
|
176
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkIVJEUGWF_js.generateIdempotencyKey();
|
|
177
|
+
return chunkIVJEUGWF_js.safe(
|
|
178
178
|
this.client.post(
|
|
179
179
|
`/api/v1/subscriptions/${encodedId}/skip`,
|
|
180
180
|
void 0,
|
|
@@ -190,8 +190,8 @@ var UploadService = class {
|
|
|
190
190
|
this.client = client;
|
|
191
191
|
}
|
|
192
192
|
async init(filename, contentType, sizeBytes, opts) {
|
|
193
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
194
|
-
return
|
|
193
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkIVJEUGWF_js.generateIdempotencyKey();
|
|
194
|
+
return chunkIVJEUGWF_js.safe(
|
|
195
195
|
this.client.post(
|
|
196
196
|
"/api/v1/uploads/init",
|
|
197
197
|
{
|
|
@@ -204,7 +204,7 @@ var UploadService = class {
|
|
|
204
204
|
);
|
|
205
205
|
}
|
|
206
206
|
async confirm(uploadId) {
|
|
207
|
-
return
|
|
207
|
+
return chunkIVJEUGWF_js.safe(
|
|
208
208
|
this.client.post("/api/v1/uploads/confirm", {
|
|
209
209
|
upload_id: uploadId
|
|
210
210
|
})
|
|
@@ -250,7 +250,7 @@ var PlacesService = class {
|
|
|
250
250
|
this.client = client;
|
|
251
251
|
}
|
|
252
252
|
async autocomplete(input, sessionToken) {
|
|
253
|
-
return
|
|
253
|
+
return chunkIVJEUGWF_js.safe(
|
|
254
254
|
this.client.post("/api/v1/places/autocomplete", {
|
|
255
255
|
input,
|
|
256
256
|
sessionToken
|
|
@@ -258,7 +258,7 @@ var PlacesService = class {
|
|
|
258
258
|
);
|
|
259
259
|
}
|
|
260
260
|
async details(placeId, sessionToken) {
|
|
261
|
-
return
|
|
261
|
+
return chunkIVJEUGWF_js.safe(
|
|
262
262
|
this.client.post("/api/v1/places/details", {
|
|
263
263
|
place_id: placeId,
|
|
264
264
|
sessionToken
|
|
@@ -277,7 +277,7 @@ var DeliveryService = class {
|
|
|
277
277
|
params.set("dropoff_lat", String(dropoffLat));
|
|
278
278
|
params.set("dropoff_lng", String(dropoffLng));
|
|
279
279
|
if (country) params.set("country", country);
|
|
280
|
-
return
|
|
280
|
+
return chunkIVJEUGWF_js.safe(
|
|
281
281
|
this.client.get(`/api/v1/delivery/fee?${params.toString()}`)
|
|
282
282
|
);
|
|
283
283
|
}
|
|
@@ -289,21 +289,112 @@ var DeliveryService = class {
|
|
|
289
289
|
params.set("dropoff_lng", String(dropoffLng));
|
|
290
290
|
if (opts?.country) params.set("country", opts.country);
|
|
291
291
|
if (opts?.orderValue != null) params.set("order_value", String(opts.orderValue));
|
|
292
|
-
return
|
|
292
|
+
return chunkIVJEUGWF_js.safe(
|
|
293
293
|
this.client.get(`/api/v1/delivery/options?${params.toString()}`)
|
|
294
294
|
);
|
|
295
295
|
}
|
|
296
296
|
};
|
|
297
297
|
|
|
298
|
+
// src/internal/events.ts
|
|
299
|
+
var MUTATION_ERROR = "mutation:error";
|
|
300
|
+
var AUTH_TOKEN_CHANGED = "auth:token-changed";
|
|
301
|
+
var SESSION_CLAIMED = "session:claimed";
|
|
302
|
+
var SESSION_CLEARED = "session:cleared";
|
|
303
|
+
function createClientEvents() {
|
|
304
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
305
|
+
return {
|
|
306
|
+
on(name, listener) {
|
|
307
|
+
let set = listeners.get(name);
|
|
308
|
+
if (!set) {
|
|
309
|
+
set = /* @__PURE__ */ new Set();
|
|
310
|
+
listeners.set(name, set);
|
|
311
|
+
}
|
|
312
|
+
set.add(listener);
|
|
313
|
+
return () => {
|
|
314
|
+
set?.delete(listener);
|
|
315
|
+
};
|
|
316
|
+
},
|
|
317
|
+
off(name, listener) {
|
|
318
|
+
listeners.get(name)?.delete(listener);
|
|
319
|
+
},
|
|
320
|
+
emit(name, payload) {
|
|
321
|
+
const set = listeners.get(name);
|
|
322
|
+
if (!set) return;
|
|
323
|
+
const snapshot = Array.from(set);
|
|
324
|
+
for (const listener of snapshot) {
|
|
325
|
+
try {
|
|
326
|
+
listener(payload);
|
|
327
|
+
} catch (err2) {
|
|
328
|
+
console.error(`[Cimplify] event listener for "${name}" threw:`, err2);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
298
335
|
// src/support.ts
|
|
299
336
|
var SupportService = class {
|
|
300
337
|
constructor(client) {
|
|
301
338
|
this.client = client;
|
|
339
|
+
this.claimInFlight = null;
|
|
340
|
+
this.lastClaimedAccessToken = null;
|
|
341
|
+
this.claimedName = null;
|
|
342
|
+
this.client.events.on(SESSION_CLEARED, () => {
|
|
343
|
+
this.lastClaimedAccessToken = null;
|
|
344
|
+
this.claimedName = null;
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/** The verified customer this session's conversation was claimed for, null while anonymous. */
|
|
348
|
+
get claimedCustomerName() {
|
|
349
|
+
return this.claimedName;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Claim the anonymous session for the verified Link identity: the server
|
|
353
|
+
* verifies the access token, rotates the session token (adopted here, so
|
|
354
|
+
* every subsequent request rides the bound session), folds the guest cart
|
|
355
|
+
* in, and adopts or merges the widget conversation.
|
|
356
|
+
*
|
|
357
|
+
* Idempotent and single-flight: concurrent calls share one request, and a
|
|
358
|
+
* token already claimed by this instance short-circuits without a network
|
|
359
|
+
* round trip. Emits `session:claimed` on the client's event channel.
|
|
360
|
+
*/
|
|
361
|
+
async claimConversation() {
|
|
362
|
+
const accessToken = this.client.getAccessToken();
|
|
363
|
+
if (!accessToken) {
|
|
364
|
+
return chunkIVJEUGWF_js.err(new chunkAETVRBKI_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
365
|
+
}
|
|
366
|
+
if (this.claimInFlight) return this.claimInFlight;
|
|
367
|
+
if (this.lastClaimedAccessToken === accessToken) {
|
|
368
|
+
return chunkIVJEUGWF_js.err(new chunkAETVRBKI_js.CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
369
|
+
}
|
|
370
|
+
this.claimInFlight = (async () => {
|
|
371
|
+
const result = await chunkIVJEUGWF_js.safe(
|
|
372
|
+
this.client.post("/api/v1/support/conversation/claim", {
|
|
373
|
+
access_token: accessToken
|
|
374
|
+
})
|
|
375
|
+
);
|
|
376
|
+
if (result.ok) {
|
|
377
|
+
this.lastClaimedAccessToken = accessToken;
|
|
378
|
+
this.claimedName = result.value.customer_name || null;
|
|
379
|
+
this.client.adoptSessionToken(result.value.session_token);
|
|
380
|
+
this.client.events.emit(SESSION_CLAIMED, {
|
|
381
|
+
sessionToken: result.value.session_token,
|
|
382
|
+
threadId: result.value.thread_id ?? null,
|
|
383
|
+
customerName: result.value.customer_name
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
return result;
|
|
387
|
+
})();
|
|
388
|
+
try {
|
|
389
|
+
return await this.claimInFlight;
|
|
390
|
+
} finally {
|
|
391
|
+
this.claimInFlight = null;
|
|
392
|
+
}
|
|
302
393
|
}
|
|
303
394
|
/** Open (or resume) the customer's widget conversation. */
|
|
304
395
|
async openConversation(opts) {
|
|
305
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
306
|
-
return
|
|
396
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkIVJEUGWF_js.generateIdempotencyKey();
|
|
397
|
+
return chunkIVJEUGWF_js.safe(
|
|
307
398
|
this.client.post("/api/v1/support/conversation", void 0, {
|
|
308
399
|
idempotencyKey
|
|
309
400
|
})
|
|
@@ -314,61 +405,59 @@ var SupportService = class {
|
|
|
314
405
|
*
|
|
315
406
|
* The idempotency key doubles as the message `client_id`: the backend
|
|
316
407
|
* dedupes on it, so client retries of the same send never insert twice.
|
|
408
|
+
* `replyToMessageId` quotes another message by its `ChatMessage.id`; the
|
|
409
|
+
* server resolves it thread-scoped and echoes the quote as `reply_to`.
|
|
317
410
|
*/
|
|
318
411
|
async sendMessage(content, opts) {
|
|
319
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
320
|
-
return
|
|
412
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkIVJEUGWF_js.generateIdempotencyKey();
|
|
413
|
+
return chunkIVJEUGWF_js.safe(
|
|
321
414
|
this.client.post(
|
|
322
415
|
"/api/v1/support/conversation/messages",
|
|
323
|
-
{
|
|
416
|
+
{
|
|
417
|
+
content,
|
|
418
|
+
client_id: idempotencyKey,
|
|
419
|
+
reply_to_message_id: opts?.replyToMessageId,
|
|
420
|
+
upload_ids: opts?.attachments?.map((a) => a.upload_id)
|
|
421
|
+
},
|
|
324
422
|
{ idempotencyKey }
|
|
325
423
|
)
|
|
326
424
|
);
|
|
327
425
|
}
|
|
328
|
-
/**
|
|
426
|
+
/**
|
|
427
|
+
* Poll for messages. `after` pages forward (live updates); `before` pages
|
|
428
|
+
* backward for scrollback into older history.
|
|
429
|
+
*/
|
|
329
430
|
async getMessages(options = {}) {
|
|
330
431
|
const params = new URLSearchParams();
|
|
331
432
|
if (options.after) params.set("after", options.after);
|
|
433
|
+
if (options.before) params.set("before", options.before);
|
|
332
434
|
if (options.limit) params.set("limit", String(options.limit));
|
|
333
435
|
const query = params.toString();
|
|
334
436
|
const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
|
|
335
|
-
return
|
|
437
|
+
return chunkIVJEUGWF_js.safe(this.client.get(path));
|
|
438
|
+
}
|
|
439
|
+
/** React to a message in the active conversation by its `ChatMessage.id`. */
|
|
440
|
+
async reactToMessage(messageId, emoji) {
|
|
441
|
+
return chunkIVJEUGWF_js.safe(
|
|
442
|
+
this.client.post(
|
|
443
|
+
`/api/v1/support/conversation/messages/${messageId}/reactions`,
|
|
444
|
+
{ emoji }
|
|
445
|
+
)
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
/** Ask for a person: flags the thread for the merchant's inbox. */
|
|
449
|
+
async requestHuman(opts) {
|
|
450
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkIVJEUGWF_js.generateIdempotencyKey();
|
|
451
|
+
return chunkIVJEUGWF_js.safe(
|
|
452
|
+
this.client.post(
|
|
453
|
+
"/api/v1/support/conversation/handoff",
|
|
454
|
+
void 0,
|
|
455
|
+
{ idempotencyKey }
|
|
456
|
+
)
|
|
457
|
+
);
|
|
336
458
|
}
|
|
337
459
|
};
|
|
338
460
|
|
|
339
|
-
// src/internal/events.ts
|
|
340
|
-
function createClientEvents() {
|
|
341
|
-
const listeners = /* @__PURE__ */ new Map();
|
|
342
|
-
return {
|
|
343
|
-
on(name, listener) {
|
|
344
|
-
let set = listeners.get(name);
|
|
345
|
-
if (!set) {
|
|
346
|
-
set = /* @__PURE__ */ new Set();
|
|
347
|
-
listeners.set(name, set);
|
|
348
|
-
}
|
|
349
|
-
set.add(listener);
|
|
350
|
-
return () => {
|
|
351
|
-
set?.delete(listener);
|
|
352
|
-
};
|
|
353
|
-
},
|
|
354
|
-
off(name, listener) {
|
|
355
|
-
listeners.get(name)?.delete(listener);
|
|
356
|
-
},
|
|
357
|
-
emit(name, payload) {
|
|
358
|
-
const set = listeners.get(name);
|
|
359
|
-
if (!set) return;
|
|
360
|
-
const snapshot = Array.from(set);
|
|
361
|
-
for (const listener of snapshot) {
|
|
362
|
-
try {
|
|
363
|
-
listener(payload);
|
|
364
|
-
} catch (err) {
|
|
365
|
-
console.error(`[Cimplify] event listener for "${name}" threw:`, err);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
|
|
372
461
|
// src/client.ts
|
|
373
462
|
var SESSION_TOKEN_STORAGE_KEY = "cimplify_session_token";
|
|
374
463
|
var ORDER_TOKEN_PREFIX = "cimplify_ot_";
|
|
@@ -548,6 +637,28 @@ var CimplifyClient = class {
|
|
|
548
637
|
newToken: token,
|
|
549
638
|
source: "manual"
|
|
550
639
|
});
|
|
640
|
+
this.events.emit(AUTH_TOKEN_CHANGED, { token });
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Zero-UI claim: a freshly verified customer identity (OTP verify, silent
|
|
644
|
+
* refresh restore) binds the anonymous session so the conversation, cart
|
|
645
|
+
* and orders survive a cleared browser. Best-effort by design — a failed
|
|
646
|
+
* claim leaves the session anonymous, exactly as it was. Called by the
|
|
647
|
+
* auth flows, never by the raw token setter.
|
|
648
|
+
*/
|
|
649
|
+
autoClaimChatIdentity() {
|
|
650
|
+
if (typeof window === "undefined" || !this.sessionToken || !this.accessToken) return;
|
|
651
|
+
void this.support.claimConversation();
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Adopt a server-rotated session token (claim flow). The old token stays
|
|
655
|
+
* in flight-safe use until the next request; the storage swap makes the
|
|
656
|
+
* rotation durable across reloads.
|
|
657
|
+
*/
|
|
658
|
+
adoptSessionToken(token) {
|
|
659
|
+
if (!token || token === this.sessionToken) return;
|
|
660
|
+
this.sessionToken = token;
|
|
661
|
+
this.saveSessionToken(token);
|
|
551
662
|
}
|
|
552
663
|
clearSession() {
|
|
553
664
|
const previous = this.accessToken;
|
|
@@ -562,6 +673,8 @@ var CimplifyClient = class {
|
|
|
562
673
|
newToken: null,
|
|
563
674
|
source: "clear"
|
|
564
675
|
});
|
|
676
|
+
this.events.emit(AUTH_TOKEN_CHANGED, { token: null });
|
|
677
|
+
this.events.emit(SESSION_CLEARED, {});
|
|
565
678
|
}
|
|
566
679
|
setOrderToken(orderId, token) {
|
|
567
680
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
@@ -660,9 +773,16 @@ var CimplifyClient = class {
|
|
|
660
773
|
async authedFetch(url, options) {
|
|
661
774
|
return this.resilientFetch(url, options);
|
|
662
775
|
}
|
|
776
|
+
// Storage guards: even the `window.localStorage` property access throws in
|
|
777
|
+
// some sandboxed iframes and strict private-browsing modes. These run in the
|
|
778
|
+
// constructor at module load, so a throw would white-screen the whole app —
|
|
779
|
+
// fall back to an in-memory session token instead.
|
|
663
780
|
loadSessionToken() {
|
|
664
|
-
|
|
665
|
-
|
|
781
|
+
try {
|
|
782
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
783
|
+
return localStorage.getItem(SESSION_TOKEN_STORAGE_KEY);
|
|
784
|
+
}
|
|
785
|
+
} catch {
|
|
666
786
|
}
|
|
667
787
|
return null;
|
|
668
788
|
}
|
|
@@ -676,7 +796,7 @@ var CimplifyClient = class {
|
|
|
676
796
|
* every visitor to one session, so SSR keeps the lazy server-minted flow.
|
|
677
797
|
*/
|
|
678
798
|
mintSessionToken() {
|
|
679
|
-
if (typeof window === "undefined"
|
|
799
|
+
if (typeof window === "undefined") {
|
|
680
800
|
return null;
|
|
681
801
|
}
|
|
682
802
|
const token = generateSessionToken();
|
|
@@ -684,11 +804,11 @@ var CimplifyClient = class {
|
|
|
684
804
|
return token;
|
|
685
805
|
}
|
|
686
806
|
saveSessionToken(token) {
|
|
687
|
-
|
|
688
|
-
|
|
807
|
+
try {
|
|
808
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
689
809
|
localStorage.setItem(SESSION_TOKEN_STORAGE_KEY, token);
|
|
690
|
-
} catch {
|
|
691
810
|
}
|
|
811
|
+
} catch {
|
|
692
812
|
}
|
|
693
813
|
}
|
|
694
814
|
captureSessionToken(response) {
|
|
@@ -961,25 +1081,25 @@ var CimplifyClient = class {
|
|
|
961
1081
|
}
|
|
962
1082
|
get catalogue() {
|
|
963
1083
|
if (!this._catalogue) {
|
|
964
|
-
this._catalogue = new
|
|
1084
|
+
this._catalogue = new chunkIVJEUGWF_js.CatalogueQueries(this);
|
|
965
1085
|
}
|
|
966
1086
|
return this._catalogue;
|
|
967
1087
|
}
|
|
968
1088
|
get cart() {
|
|
969
1089
|
if (!this._cart) {
|
|
970
|
-
this._cart = new
|
|
1090
|
+
this._cart = new chunkIVJEUGWF_js.CartOperations(this);
|
|
971
1091
|
}
|
|
972
1092
|
return this._cart;
|
|
973
1093
|
}
|
|
974
1094
|
get checkout() {
|
|
975
1095
|
if (!this._checkout) {
|
|
976
|
-
this._checkout = new
|
|
1096
|
+
this._checkout = new chunkIVJEUGWF_js.CheckoutService(this);
|
|
977
1097
|
}
|
|
978
1098
|
return this._checkout;
|
|
979
1099
|
}
|
|
980
1100
|
get orders() {
|
|
981
1101
|
if (!this._orders) {
|
|
982
|
-
this._orders = new
|
|
1102
|
+
this._orders = new chunkIVJEUGWF_js.OrderQueries(this);
|
|
983
1103
|
}
|
|
984
1104
|
return this._orders;
|
|
985
1105
|
}
|
|
@@ -1009,43 +1129,43 @@ var CimplifyClient = class {
|
|
|
1009
1129
|
}
|
|
1010
1130
|
get link() {
|
|
1011
1131
|
if (!this._link) {
|
|
1012
|
-
this._link = new
|
|
1132
|
+
this._link = new chunkIVJEUGWF_js.LinkService(this);
|
|
1013
1133
|
}
|
|
1014
1134
|
return this._link;
|
|
1015
1135
|
}
|
|
1016
1136
|
get auth() {
|
|
1017
1137
|
if (!this._auth) {
|
|
1018
|
-
this._auth = new
|
|
1138
|
+
this._auth = new chunkIVJEUGWF_js.AuthService(this);
|
|
1019
1139
|
}
|
|
1020
1140
|
return this._auth;
|
|
1021
1141
|
}
|
|
1022
1142
|
get business() {
|
|
1023
1143
|
if (!this._business) {
|
|
1024
|
-
this._business = new
|
|
1144
|
+
this._business = new chunkIVJEUGWF_js.BusinessService(this);
|
|
1025
1145
|
}
|
|
1026
1146
|
return this._business;
|
|
1027
1147
|
}
|
|
1028
1148
|
get inventory() {
|
|
1029
1149
|
if (!this._inventory) {
|
|
1030
|
-
this._inventory = new
|
|
1150
|
+
this._inventory = new chunkIVJEUGWF_js.InventoryService(this);
|
|
1031
1151
|
}
|
|
1032
1152
|
return this._inventory;
|
|
1033
1153
|
}
|
|
1034
1154
|
get scheduling() {
|
|
1035
1155
|
if (!this._scheduling) {
|
|
1036
|
-
this._scheduling = new
|
|
1156
|
+
this._scheduling = new chunkIVJEUGWF_js.SchedulingService(this);
|
|
1037
1157
|
}
|
|
1038
1158
|
return this._scheduling;
|
|
1039
1159
|
}
|
|
1040
1160
|
get lite() {
|
|
1041
1161
|
if (!this._lite) {
|
|
1042
|
-
this._lite = new
|
|
1162
|
+
this._lite = new chunkIVJEUGWF_js.LiteService(this);
|
|
1043
1163
|
}
|
|
1044
1164
|
return this._lite;
|
|
1045
1165
|
}
|
|
1046
1166
|
get fx() {
|
|
1047
1167
|
if (!this._fx) {
|
|
1048
|
-
this._fx = new
|
|
1168
|
+
this._fx = new chunkIVJEUGWF_js.FxService(this);
|
|
1049
1169
|
}
|
|
1050
1170
|
return this._fx;
|
|
1051
1171
|
}
|
|
@@ -1080,7 +1200,7 @@ var CimplifyClient = class {
|
|
|
1080
1200
|
if (businessId) {
|
|
1081
1201
|
this.setBusinessId(businessId);
|
|
1082
1202
|
}
|
|
1083
|
-
return
|
|
1203
|
+
return chunkIVJEUGWF_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
|
|
1084
1204
|
}
|
|
1085
1205
|
};
|
|
1086
1206
|
function createCimplifyClient(config = {}) {
|
|
@@ -1090,7 +1210,10 @@ function createCimplifyClient(config = {}) {
|
|
|
1090
1210
|
exports.ActivityService = ActivityService;
|
|
1091
1211
|
exports.CimplifyClient = CimplifyClient;
|
|
1092
1212
|
exports.DeliveryService = DeliveryService;
|
|
1213
|
+
exports.MUTATION_ERROR = MUTATION_ERROR;
|
|
1093
1214
|
exports.PlacesService = PlacesService;
|
|
1215
|
+
exports.SESSION_CLAIMED = SESSION_CLAIMED;
|
|
1216
|
+
exports.SESSION_CLEARED = SESSION_CLEARED;
|
|
1094
1217
|
exports.StoreCreditQueries = StoreCreditQueries;
|
|
1095
1218
|
exports.SubscriptionService = SubscriptionService;
|
|
1096
1219
|
exports.SupportService = SupportService;
|
|
@@ -74,6 +74,85 @@ function getVariantDisplayName(variant, productName) {
|
|
|
74
74
|
return productName || (variant.is_default ? "Default" : "Option");
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// src/utils/price-basis.ts
|
|
78
|
+
var MULTI_DAY_UNITS = /* @__PURE__ */ new Set([
|
|
79
|
+
"days",
|
|
80
|
+
"nights",
|
|
81
|
+
"weeks",
|
|
82
|
+
"months",
|
|
83
|
+
"years"
|
|
84
|
+
]);
|
|
85
|
+
var PERIOD_LABELS = {
|
|
86
|
+
minutes: "session",
|
|
87
|
+
hours: "session",
|
|
88
|
+
days: "day",
|
|
89
|
+
nights: "night",
|
|
90
|
+
weeks: "week",
|
|
91
|
+
months: "month",
|
|
92
|
+
years: "year"
|
|
93
|
+
};
|
|
94
|
+
function isMultiDayService(product) {
|
|
95
|
+
if ((product.type || "product") !== "service") return false;
|
|
96
|
+
if (product.scheduling_mode) return product.scheduling_mode === "multi_day";
|
|
97
|
+
return product.duration_unit != null && MULTI_DAY_UNITS.has(product.duration_unit);
|
|
98
|
+
}
|
|
99
|
+
function priceBasisLabel(product) {
|
|
100
|
+
if ((product.type || "product") !== "service") return null;
|
|
101
|
+
const basis = product.price_basis ?? (isMultiDayService(product) ? "per_duration_unit" : null);
|
|
102
|
+
if (basis === null || basis === "flat") return null;
|
|
103
|
+
if (basis === "per_person") return "person";
|
|
104
|
+
return PERIOD_LABELS[product.duration_unit ?? "nights"];
|
|
105
|
+
}
|
|
106
|
+
var DAY_MS = 864e5;
|
|
107
|
+
function utcDateParts(iso) {
|
|
108
|
+
const date = new Date(iso);
|
|
109
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
110
|
+
return { year: date.getUTCFullYear(), month: date.getUTCMonth() + 1, day: date.getUTCDate() };
|
|
111
|
+
}
|
|
112
|
+
function stayPeriods(scheduledStart, scheduledEnd, durationUnit) {
|
|
113
|
+
const start = utcDateParts(scheduledStart);
|
|
114
|
+
const end = utcDateParts(scheduledEnd);
|
|
115
|
+
if (!start || !end) return 1;
|
|
116
|
+
const days = Math.max(
|
|
117
|
+
1,
|
|
118
|
+
Math.round(
|
|
119
|
+
(Date.UTC(end.year, end.month - 1, end.day) - Date.UTC(start.year, start.month - 1, start.day)) / DAY_MS
|
|
120
|
+
)
|
|
121
|
+
);
|
|
122
|
+
switch (durationUnit) {
|
|
123
|
+
case "weeks":
|
|
124
|
+
return Math.max(1, Math.ceil(days / 7));
|
|
125
|
+
case "months": {
|
|
126
|
+
let months = (end.year - start.year) * 12 + (end.month - start.month);
|
|
127
|
+
if (end.day > start.day) months += 1;
|
|
128
|
+
return Math.max(1, months);
|
|
129
|
+
}
|
|
130
|
+
case "years": {
|
|
131
|
+
let years = end.year - start.year;
|
|
132
|
+
if (end.month > start.month || end.month === start.month && end.day > start.day) {
|
|
133
|
+
years += 1;
|
|
134
|
+
}
|
|
135
|
+
return Math.max(1, years);
|
|
136
|
+
}
|
|
137
|
+
default:
|
|
138
|
+
return days;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function stayLength(scheduledStart, scheduledEnd, durationUnit) {
|
|
142
|
+
const periods = stayPeriods(scheduledStart, scheduledEnd, durationUnit);
|
|
143
|
+
const label = PERIOD_LABELS[durationUnit ?? "nights"];
|
|
144
|
+
return `${periods} ${label}${periods === 1 ? "" : "s"}`;
|
|
145
|
+
}
|
|
146
|
+
function serviceBillingMultiplier(product, selection) {
|
|
147
|
+
if ((product.type || "product") !== "service") return null;
|
|
148
|
+
const basis = product.price_basis ?? (isMultiDayService(product) ? "per_duration_unit" : "per_person");
|
|
149
|
+
const units = Math.max(1, selection.units ?? 1);
|
|
150
|
+
if (basis === "flat") return units;
|
|
151
|
+
if (basis === "per_person") return Math.max(1, selection.quantity) * units;
|
|
152
|
+
const periods = selection.scheduledStart && selection.scheduledEnd ? stayPeriods(selection.scheduledStart, selection.scheduledEnd, product.duration_unit) : 1;
|
|
153
|
+
return periods * units;
|
|
154
|
+
}
|
|
155
|
+
|
|
77
156
|
// src/types/product.ts
|
|
78
157
|
var PRODUCT_TYPE = {
|
|
79
158
|
Product: "product",
|
|
@@ -174,4 +253,9 @@ exports.allGalleryImages = allGalleryImages;
|
|
|
174
253
|
exports.assetUrl = assetUrl;
|
|
175
254
|
exports.getVariantDisplayName = getVariantDisplayName;
|
|
176
255
|
exports.isCimplifyAsset = isCimplifyAsset;
|
|
256
|
+
exports.isMultiDayService = isMultiDayService;
|
|
257
|
+
exports.priceBasisLabel = priceBasisLabel;
|
|
177
258
|
exports.resolveGallery = resolveGallery;
|
|
259
|
+
exports.serviceBillingMultiplier = serviceBillingMultiplier;
|
|
260
|
+
exports.stayLength = stayLength;
|
|
261
|
+
exports.stayPeriods = stayPeriods;
|
|
@@ -1673,7 +1673,10 @@ var CheckoutService = class {
|
|
|
1673
1673
|
idempotency_key: data.idempotency_key || generateIdempotencyKey(),
|
|
1674
1674
|
metadata: data.metadata,
|
|
1675
1675
|
pay_currency: data.pay_currency,
|
|
1676
|
-
fx_quote_id: data.fx_quote_id
|
|
1676
|
+
fx_quote_id: data.fx_quote_id,
|
|
1677
|
+
use_store_credit: data.use_store_credit,
|
|
1678
|
+
voucher_code: data.voucher_code,
|
|
1679
|
+
pay_deposit: data.pay_deposit
|
|
1677
1680
|
};
|
|
1678
1681
|
const baseCurrency = chunkAETVRBKI_js.currencyCode(
|
|
1679
1682
|
(cart.pricing.currency || checkoutData.pay_currency || "GHS").toUpperCase()
|
|
@@ -1804,6 +1807,7 @@ var LinkService = class {
|
|
|
1804
1807
|
);
|
|
1805
1808
|
if (result.ok && result.value.session_token) {
|
|
1806
1809
|
this.client.setAccessToken(result.value.session_token);
|
|
1810
|
+
this.client.autoClaimChatIdentity();
|
|
1807
1811
|
}
|
|
1808
1812
|
return result;
|
|
1809
1813
|
}
|
|
@@ -1815,6 +1819,7 @@ var LinkService = class {
|
|
|
1815
1819
|
);
|
|
1816
1820
|
if (result.ok && result.value.session_token) {
|
|
1817
1821
|
this.client.setAccessToken(result.value.session_token);
|
|
1822
|
+
this.client.autoClaimChatIdentity();
|
|
1818
1823
|
}
|
|
1819
1824
|
return result;
|
|
1820
1825
|
}
|
|
@@ -2000,6 +2005,7 @@ var AuthService = class {
|
|
|
2000
2005
|
);
|
|
2001
2006
|
if (result.ok && result.value.session_token) {
|
|
2002
2007
|
this.client.setAccessToken(result.value.session_token);
|
|
2008
|
+
this.client.autoClaimChatIdentity();
|
|
2003
2009
|
}
|
|
2004
2010
|
return result;
|
|
2005
2011
|
}
|
|
@@ -2153,6 +2159,7 @@ var SchedulingService = class {
|
|
|
2153
2159
|
service_id: input.service_id,
|
|
2154
2160
|
date: input.date,
|
|
2155
2161
|
participant_count: input.participant_count,
|
|
2162
|
+
units: input.units,
|
|
2156
2163
|
variant_id: input.variant_id
|
|
2157
2164
|
});
|
|
2158
2165
|
return safe(this.client.get(path));
|
|
@@ -2173,6 +2180,7 @@ var SchedulingService = class {
|
|
|
2173
2180
|
end_date: params.end_date,
|
|
2174
2181
|
location_id: params.location_id,
|
|
2175
2182
|
participant_count: params.participant_count,
|
|
2183
|
+
units: params.units,
|
|
2176
2184
|
variant_id: params.variant_id
|
|
2177
2185
|
});
|
|
2178
2186
|
return safe(this.client.get(path));
|
|
@@ -3145,6 +3153,7 @@ var CimplifyElements = class {
|
|
|
3145
3153
|
this.accessToken = token;
|
|
3146
3154
|
this.accountId = decodeJwtSub(token);
|
|
3147
3155
|
this.client.setAccessToken(token);
|
|
3156
|
+
this.client.autoClaimChatIdentity();
|
|
3148
3157
|
await this.hydrateCustomerData();
|
|
3149
3158
|
return {
|
|
3150
3159
|
accountId: this.accountId ?? "",
|