@cimplify/sdk 0.100.2 → 0.100.3

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.
Files changed (48) hide show
  1. package/dist/advanced.d.mts +1 -1
  2. package/dist/advanced.d.ts +1 -1
  3. package/dist/advanced.js +20 -20
  4. package/dist/advanced.mjs +1 -1
  5. package/dist/{chunk-IJI7KMTG.js → chunk-CNY2XFN4.js} +255 -74
  6. package/dist/{chunk-TIQLOH2B.mjs → chunk-FFRQNNUQ.mjs} +3 -0
  7. package/dist/{chunk-6JEKKL3M.js → chunk-FWKSBF3F.js} +3 -0
  8. package/dist/{chunk-B2YOCOLH.mjs → chunk-HFTRLRLM.mjs} +2 -2
  9. package/dist/{chunk-QRBBSIAY.js → chunk-KNCW5DI7.js} +4 -4
  10. package/dist/{chunk-YWNJJO2U.mjs → chunk-NOGCGI4J.mjs} +2 -2
  11. package/dist/{chunk-IFAQLFAJ.js → chunk-XCS56XSS.js} +2 -2
  12. package/dist/{chunk-PJUXAUM2.mjs → chunk-XG4DZT4I.mjs} +209 -28
  13. package/dist/{client-C6wb92AD.d.mts → client-BGeSemVv.d.mts} +2 -2
  14. package/dist/{client-LPg_AUUr.d.ts → client-BWdeCgmo.d.ts} +11 -2
  15. package/dist/{client-D8XcrONA.d.mts → client-Bx4NRdl8.d.mts} +11 -2
  16. package/dist/{client-CgXkRu2o.d.ts → client-Cvp8W1r9.d.ts} +2 -2
  17. package/dist/index.d.mts +2 -2
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +69 -69
  20. package/dist/index.mjs +3 -3
  21. package/dist/mock/cli.mjs +2 -2
  22. package/dist/mock/library.js +2 -2
  23. package/dist/mock/library.mjs +2 -2
  24. package/dist/mock/msw.js +2 -2
  25. package/dist/mock/msw.mjs +2 -2
  26. package/dist/react.d.mts +1 -1
  27. package/dist/react.d.ts +1 -1
  28. package/dist/react.js +25 -25
  29. package/dist/react.mjs +2 -2
  30. package/dist/{server--RyVAfPN.d.mts → server-BRJ61o2J.d.mts} +3 -3
  31. package/dist/{server-CNyy47HL.d.ts → server-CXrVYtNo.d.ts} +3 -3
  32. package/dist/server.d.mts +2 -2
  33. package/dist/server.d.ts +2 -2
  34. package/dist/server.js +7 -7
  35. package/dist/server.mjs +2 -2
  36. package/dist/testing/msw.d.mts +1 -1
  37. package/dist/testing/msw.d.ts +1 -1
  38. package/dist/testing/msw.js +2 -2
  39. package/dist/testing/msw.mjs +1 -1
  40. package/dist/testing/suite.d.mts +4 -4
  41. package/dist/testing/suite.d.ts +4 -4
  42. package/dist/testing/suite.js +23 -23
  43. package/dist/testing/suite.mjs +4 -4
  44. package/dist/testing.d.mts +3 -3
  45. package/dist/testing.d.ts +3 -3
  46. package/dist/testing.js +79 -79
  47. package/dist/testing.mjs +5 -5
  48. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk6JEKKL3M_js = require('./chunk-6JEKKL3M.js');
3
+ var chunkFWKSBF3F_js = require('./chunk-FWKSBF3F.js');
4
4
  var chunkNIOUSKQQ_js = require('./chunk-NIOUSKQQ.js');
5
5
 
6
6
  // src/store-credit.ts
@@ -13,38 +13,182 @@ var StoreCreditQueries = class {
13
13
  * currency. Requires a signed-in customer; returns an error otherwise.
14
14
  */
15
15
  async balance() {
16
- return chunk6JEKKL3M_js.safe(this.client.get("/api/v1/store-credit/balance"));
16
+ return chunkFWKSBF3F_js.safe(this.client.get("/api/v1/store-credit/balance"));
17
17
  }
18
18
  };
19
19
 
20
+ // src/internal/analytics-session.ts
21
+ var ANALYTICS_SESSION_IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
22
+ var ANALYTICS_SESSION_STORAGE_KEY = "cimplify_analytics_session";
23
+ var ANALYTICS_SESSION_STATE_VERSION = 1;
24
+ var MICROSECONDS_PER_MILLISECOND = 1e3;
25
+ var MICROSECONDS_PER_SECOND = 1e6;
26
+ var AnalyticsSessionCoordinator = class {
27
+ constructor() {
28
+ this.fallbackState = null;
29
+ }
30
+ beginEvent(nowMs = Date.now()) {
31
+ const state = this.resolveActiveState(nowMs);
32
+ state.lastActivityAtMs = nowMs;
33
+ const occurredAt = reserveOccurredAt(state, nowMs, 1);
34
+ this.write(state);
35
+ return toEventContext(state, occurredAt);
36
+ }
37
+ beginPage(path, nowMs = Date.now()) {
38
+ const existing = this.read();
39
+ const expired = !existing || isExpired(existing, nowMs);
40
+ const state = expired ? newSession(nowMs) : existing;
41
+ const previousPage = expired ? void 0 : durationFor(state.activePage, nowMs);
42
+ state.lastActivityAtMs = nowMs;
43
+ state.activePage = { path, enteredAtMs: nowMs };
44
+ const occurredAt = reserveOccurredAt(state, nowMs, previousPage ? 2 : 1);
45
+ this.write(state);
46
+ return {
47
+ session: toEventContext(state, occurredAt),
48
+ previousPage
49
+ };
50
+ }
51
+ current() {
52
+ const state = this.read();
53
+ if (!state || isExpired(state, Date.now())) return null;
54
+ return toContext(state);
55
+ }
56
+ markBootstrapped(sessionId) {
57
+ const state = this.read();
58
+ if (!state || state.id !== sessionId) return;
59
+ state.bootstrapped = true;
60
+ this.write(state);
61
+ }
62
+ reset() {
63
+ this.fallbackState = null;
64
+ try {
65
+ sessionStorage.removeItem(ANALYTICS_SESSION_STORAGE_KEY);
66
+ } catch {
67
+ }
68
+ }
69
+ resolveActiveState(nowMs) {
70
+ const state = this.read();
71
+ return !state || isExpired(state, nowMs) ? newSession(nowMs) : state;
72
+ }
73
+ read() {
74
+ try {
75
+ const serialized = sessionStorage.getItem(ANALYTICS_SESSION_STORAGE_KEY);
76
+ if (!serialized) return this.fallbackState;
77
+ const state = JSON.parse(serialized);
78
+ if (!isPersistedSession(state)) {
79
+ sessionStorage.removeItem(ANALYTICS_SESSION_STORAGE_KEY);
80
+ return this.fallbackState;
81
+ }
82
+ this.fallbackState = state;
83
+ return state;
84
+ } catch {
85
+ return this.fallbackState;
86
+ }
87
+ }
88
+ write(state) {
89
+ this.fallbackState = state;
90
+ try {
91
+ sessionStorage.setItem(ANALYTICS_SESSION_STORAGE_KEY, JSON.stringify(state));
92
+ } catch {
93
+ }
94
+ }
95
+ };
96
+ function newSession(nowMs) {
97
+ return {
98
+ version: ANALYTICS_SESSION_STATE_VERSION,
99
+ id: generateSessionId(),
100
+ startedAtMs: nowMs,
101
+ lastActivityAtMs: nowMs,
102
+ bootstrapped: false
103
+ };
104
+ }
105
+ function toContext(state) {
106
+ return {
107
+ id: state.id,
108
+ startedAt: new Date(state.startedAtMs).toISOString(),
109
+ requiresBootstrap: !state.bootstrapped
110
+ };
111
+ }
112
+ function toEventContext(state, occurredAtMicros) {
113
+ return {
114
+ ...toContext(state),
115
+ occurredAt: formatEpochMicros(occurredAtMicros)
116
+ };
117
+ }
118
+ function reserveOccurredAt(state, nowMs, eventCount) {
119
+ const wallClockMicros = Math.trunc(nowMs) * MICROSECONDS_PER_MILLISECOND;
120
+ const occurredAtMicros = Math.max(
121
+ wallClockMicros,
122
+ (state.lastOccurredAtMicros ?? wallClockMicros - 1) + 1
123
+ );
124
+ state.lastOccurredAtMicros = occurredAtMicros + eventCount - 1;
125
+ return occurredAtMicros;
126
+ }
127
+ function formatEpochMicros(epochMicros) {
128
+ const epochMillis = Math.floor(epochMicros / MICROSECONDS_PER_MILLISECOND);
129
+ const microsWithinSecond = epochMicros % MICROSECONDS_PER_SECOND;
130
+ const millisecondIso = new Date(epochMillis).toISOString();
131
+ return `${millisecondIso.slice(0, -5)}.${String(microsWithinSecond).padStart(6, "0")}Z`;
132
+ }
133
+ function durationFor(activePage, nowMs) {
134
+ if (!activePage || nowMs < activePage.enteredAtMs) return void 0;
135
+ return {
136
+ path: activePage.path,
137
+ timeOnPageSeconds: Math.floor((nowMs - activePage.enteredAtMs) / 1e3)
138
+ };
139
+ }
140
+ function isExpired(state, nowMs) {
141
+ return nowMs - state.lastActivityAtMs >= ANALYTICS_SESSION_IDLE_TIMEOUT_MS;
142
+ }
143
+ function isPersistedSession(value) {
144
+ if (!value || typeof value !== "object") return false;
145
+ const state = value;
146
+ return state.version === ANALYTICS_SESSION_STATE_VERSION && typeof state.id === "string" && state.id.length > 0 && typeof state.startedAtMs === "number" && Number.isFinite(state.startedAtMs) && typeof state.lastActivityAtMs === "number" && Number.isFinite(state.lastActivityAtMs) && (state.lastOccurredAtMicros === void 0 || typeof state.lastOccurredAtMicros === "number" && Number.isSafeInteger(state.lastOccurredAtMicros)) && typeof state.bootstrapped === "boolean" && (!state.activePage || typeof state.activePage.path === "string" && typeof state.activePage.enteredAtMs === "number" && Number.isFinite(state.activePage.enteredAtMs));
147
+ }
148
+ function generateSessionId() {
149
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
150
+ return crypto.randomUUID();
151
+ }
152
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (character) => {
153
+ const random = Math.random() * 16 | 0;
154
+ const value = character === "x" ? random : random & 3 | 8;
155
+ return value.toString(16);
156
+ });
157
+ }
158
+
20
159
  // src/activity.ts
21
160
  var VISITOR_ID_STORAGE_KEY = "cimplify_visitor_id";
22
- var SESSION_STARTED_STORAGE_KEY = "cimplify_session_started_at";
23
161
  var ActivityService = class {
24
162
  constructor(client) {
25
163
  this.client = client;
164
+ this.sessions = new AnalyticsSessionCoordinator();
165
+ this.bootstrapRequest = null;
26
166
  }
27
167
  /**
28
168
  * Record session start (landing, referrer, UTM, device). Fire-and-forget,
29
- * at most once per tab session; called automatically by the track* methods.
169
+ * at most once per 30-minute-idle analytics session; called automatically
170
+ * by the track* methods.
30
171
  */
31
172
  startSession() {
32
173
  if (typeof window === "undefined") return;
33
- let alreadyStarted = null;
34
- try {
35
- alreadyStarted = sessionStorage.getItem(SESSION_STARTED_STORAGE_KEY);
36
- } catch {
37
- }
38
- if (alreadyStarted) return;
39
- const startedAt = (/* @__PURE__ */ new Date()).toISOString();
40
- try {
41
- sessionStorage.setItem(SESSION_STARTED_STORAGE_KEY, startedAt);
42
- } catch {
43
- }
44
- this.client.post("/api/v1/activity/session", this.buildSessionPayload(startedAt)).catch(() => {
174
+ const session = this.sessions.beginEvent();
175
+ void this.bootstrapSession(session).catch(() => {
176
+ });
177
+ }
178
+ /** Rebind an existing analytics session after the server authenticates a customer. */
179
+ refreshIdentity() {
180
+ if (typeof window === "undefined") return;
181
+ const session = this.sessions.current();
182
+ if (!session) return;
183
+ void this.bootstrapSession(session, true).catch(() => {
45
184
  });
46
185
  }
47
- buildSessionPayload(startedAt) {
186
+ /** A signed-out browser starts a fresh anonymous analytics session. */
187
+ resetSession() {
188
+ this.sessions.reset();
189
+ this.bootstrapRequest = null;
190
+ }
191
+ buildSessionPayload(session) {
48
192
  const params = new URLSearchParams(window.location.search);
49
193
  const utm = (key) => params.get(`utm_${key}`) || void 0;
50
194
  const { visitorId, isNewVisitor } = resolveVisitor();
@@ -54,7 +198,8 @@ var ActivityService = class {
54
198
  } catch {
55
199
  }
56
200
  return {
57
- started_at: startedAt,
201
+ analytics_session_id: session.id,
202
+ started_at: session.startedAt,
58
203
  landing_page: window.location.pathname,
59
204
  landing_url: window.location.href,
60
205
  referrer_url: document.referrer || void 0,
@@ -74,17 +219,28 @@ var ActivityService = class {
74
219
  is_new_visitor: isNewVisitor
75
220
  };
76
221
  }
77
- /** Product/category views imply one; call this for every other page. */
222
+ /** Route-level page view. Product/category interactions are tracked separately. */
78
223
  trackPageView(options = {}) {
79
- this.sendEvents([
80
- {
81
- type: "page_view",
82
- page_path: options.pagePath ?? currentPath(),
83
- page_title: options.pageTitle ?? currentTitle()
84
- }
85
- ]);
224
+ if (typeof window === "undefined") return;
225
+ const pagePath = options.pagePath ?? currentPath() ?? "";
226
+ const transition = this.sessions.beginPage(pagePath);
227
+ const events = [];
228
+ if (transition.previousPage) {
229
+ events.push({
230
+ type: "page_duration",
231
+ page_path: transition.previousPage.path,
232
+ time_on_page: transition.previousPage.timeOnPageSeconds
233
+ });
234
+ }
235
+ events.push({
236
+ type: "page_view",
237
+ page_path: pagePath,
238
+ page_title: options.pageTitle ?? currentTitle()
239
+ });
240
+ this.sendEvents(events, transition.session);
86
241
  }
87
242
  trackProductView(productId, options = {}) {
243
+ if (typeof window === "undefined") return;
88
244
  const event = {
89
245
  type: "product_view",
90
246
  product_id: productId,
@@ -96,6 +252,7 @@ var ActivityService = class {
96
252
  this.sendEvents([event]);
97
253
  }
98
254
  trackCategoryView(categoryId, options = {}) {
255
+ if (typeof window === "undefined") return;
99
256
  const event = {
100
257
  type: "category_view",
101
258
  category_id: categoryId,
@@ -105,7 +262,7 @@ var ActivityService = class {
105
262
  this.sendEvents([event]);
106
263
  }
107
264
  async getState() {
108
- return chunk6JEKKL3M_js.safe(this.client.get("/api/v1/activity/state"));
265
+ return chunkFWKSBF3F_js.safe(this.client.get("/api/v1/activity/state"));
109
266
  }
110
267
  async getRecommendations(options) {
111
268
  const params = new URLSearchParams();
@@ -113,10 +270,10 @@ var ActivityService = class {
113
270
  if (options?.limit) params.set("limit", String(options.limit));
114
271
  const query = params.toString();
115
272
  const path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
116
- return chunk6JEKKL3M_js.safe(this.client.get(path));
273
+ return chunkFWKSBF3F_js.safe(this.client.get(path));
117
274
  }
118
275
  async dismissMessage(code) {
119
- return chunk6JEKKL3M_js.safe(
276
+ return chunkFWKSBF3F_js.safe(
120
277
  this.client.post("/api/v1/activity/messages/dismiss", { code })
121
278
  );
122
279
  }
@@ -151,10 +308,33 @@ var ActivityService = class {
151
308
  window.removeEventListener("popstate", record);
152
309
  };
153
310
  }
154
- sendEvents(events) {
155
- this.startSession();
156
- this.client.post("/api/v1/activity/events", { events }).catch(() => {
311
+ sendEvents(events, session) {
312
+ if (typeof window === "undefined") return;
313
+ void this.postEvents(events, session ?? this.sessions.beginEvent()).catch(() => {
314
+ });
315
+ }
316
+ async postEvents(events, session) {
317
+ await this.bootstrapSession(session);
318
+ await this.client.post("/api/v1/activity/events", {
319
+ analytics_session_id: session.id,
320
+ occurred_at: session.occurredAt,
321
+ events
322
+ });
323
+ }
324
+ bootstrapSession(session, force = false) {
325
+ if (!force && !session.requiresBootstrap) return Promise.resolve();
326
+ if (!force && this.bootstrapRequest?.sessionId === session.id) {
327
+ return this.bootstrapRequest.promise;
328
+ }
329
+ const promise = this.client.post("/api/v1/activity/session", this.buildSessionPayload(session)).then(() => {
330
+ this.sessions.markBootstrapped(session.id);
331
+ }).finally(() => {
332
+ if (this.bootstrapRequest?.promise === promise) {
333
+ this.bootstrapRequest = null;
334
+ }
157
335
  });
336
+ this.bootstrapRequest = { sessionId: session.id, promise };
337
+ return promise;
158
338
  }
159
339
  };
160
340
  function currentPath() {
@@ -189,16 +369,16 @@ var SubscriptionService = class {
189
369
  this.client = client;
190
370
  }
191
371
  async list() {
192
- return chunk6JEKKL3M_js.safe(this.client.get("/api/v1/subscriptions"));
372
+ return chunkFWKSBF3F_js.safe(this.client.get("/api/v1/subscriptions"));
193
373
  }
194
374
  async get(id) {
195
375
  const encodedId = encodeURIComponent(id);
196
- return chunk6JEKKL3M_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
376
+ return chunkFWKSBF3F_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
197
377
  }
198
378
  async cancel(id, reason, opts) {
199
379
  const encodedId = encodeURIComponent(id);
200
- const idempotencyKey = opts?.idempotencyKey ?? chunk6JEKKL3M_js.generateIdempotencyKey();
201
- return chunk6JEKKL3M_js.safe(
380
+ const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
381
+ return chunkFWKSBF3F_js.safe(
202
382
  this.client.post(
203
383
  `/api/v1/subscriptions/${encodedId}/cancel`,
204
384
  { reason },
@@ -208,20 +388,20 @@ var SubscriptionService = class {
208
388
  }
209
389
  async pause(id) {
210
390
  const encodedId = encodeURIComponent(id);
211
- return chunk6JEKKL3M_js.safe(
391
+ return chunkFWKSBF3F_js.safe(
212
392
  this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
213
393
  );
214
394
  }
215
395
  async resume(id) {
216
396
  const encodedId = encodeURIComponent(id);
217
- return chunk6JEKKL3M_js.safe(
397
+ return chunkFWKSBF3F_js.safe(
218
398
  this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
219
399
  );
220
400
  }
221
401
  async skipNextRenewal(id, opts) {
222
402
  const encodedId = encodeURIComponent(id);
223
- const idempotencyKey = opts?.idempotencyKey ?? chunk6JEKKL3M_js.generateIdempotencyKey();
224
- return chunk6JEKKL3M_js.safe(
403
+ const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
404
+ return chunkFWKSBF3F_js.safe(
225
405
  this.client.post(
226
406
  `/api/v1/subscriptions/${encodedId}/skip`,
227
407
  void 0,
@@ -237,8 +417,8 @@ var UploadService = class {
237
417
  this.client = client;
238
418
  }
239
419
  async init(filename, contentType, sizeBytes, opts) {
240
- const idempotencyKey = opts?.idempotencyKey ?? chunk6JEKKL3M_js.generateIdempotencyKey();
241
- return chunk6JEKKL3M_js.safe(
420
+ const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
421
+ return chunkFWKSBF3F_js.safe(
242
422
  this.client.post(
243
423
  "/api/v1/uploads/init",
244
424
  {
@@ -251,7 +431,7 @@ var UploadService = class {
251
431
  );
252
432
  }
253
433
  async confirm(uploadId) {
254
- return chunk6JEKKL3M_js.safe(
434
+ return chunkFWKSBF3F_js.safe(
255
435
  this.client.post("/api/v1/uploads/confirm", {
256
436
  upload_id: uploadId
257
437
  })
@@ -297,7 +477,7 @@ var PlacesService = class {
297
477
  this.client = client;
298
478
  }
299
479
  async autocomplete(input, sessionToken) {
300
- return chunk6JEKKL3M_js.safe(
480
+ return chunkFWKSBF3F_js.safe(
301
481
  this.client.post("/api/v1/places/autocomplete", {
302
482
  input,
303
483
  sessionToken
@@ -305,7 +485,7 @@ var PlacesService = class {
305
485
  );
306
486
  }
307
487
  async details(placeId, sessionToken) {
308
- return chunk6JEKKL3M_js.safe(
488
+ return chunkFWKSBF3F_js.safe(
309
489
  this.client.post("/api/v1/places/details", {
310
490
  place_id: placeId,
311
491
  sessionToken
@@ -324,7 +504,7 @@ var DeliveryService = class {
324
504
  params.set("dropoff_lat", String(dropoffLat));
325
505
  params.set("dropoff_lng", String(dropoffLng));
326
506
  if (country) params.set("country", country);
327
- return chunk6JEKKL3M_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
507
+ return chunkFWKSBF3F_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
328
508
  }
329
509
  async getOptions(queryOrLatitude, longitude, legacyOptions) {
330
510
  const query = typeof queryOrLatitude === "number" ? {
@@ -337,7 +517,7 @@ var DeliveryService = class {
337
517
  if (query.dropoffLng != null) params.set("dropoff_lng", String(query.dropoffLng));
338
518
  if (query.country) params.set("country", query.country);
339
519
  if (query.orderValue != null) params.set("order_value", String(query.orderValue));
340
- return chunk6JEKKL3M_js.safe(
520
+ return chunkFWKSBF3F_js.safe(
341
521
  this.client.get(`/api/v1/delivery/options?${params.toString()}`)
342
522
  );
343
523
  }
@@ -414,7 +594,7 @@ var SupportService = class {
414
594
  async claimConversation() {
415
595
  const accessToken = this.client.getAccessToken();
416
596
  if (!accessToken) {
417
- return chunk6JEKKL3M_js.err(new chunkNIOUSKQQ_js.CimplifyError("not_authenticated", "No access token to claim with"));
597
+ return chunkFWKSBF3F_js.err(new chunkNIOUSKQQ_js.CimplifyError("not_authenticated", "No access token to claim with"));
418
598
  }
419
599
  if (this.claimInFlight) {
420
600
  if (this.claimInFlightToken === accessToken) return this.claimInFlight;
@@ -422,12 +602,12 @@ var SupportService = class {
422
602
  return this.claimConversation();
423
603
  }
424
604
  if (this.lastClaimedAccessToken === accessToken) {
425
- return chunk6JEKKL3M_js.err(new chunkNIOUSKQQ_js.CimplifyError("already_claimed", "Session already claimed for this token"));
605
+ return chunkFWKSBF3F_js.err(new chunkNIOUSKQQ_js.CimplifyError("already_claimed", "Session already claimed for this token"));
426
606
  }
427
607
  const epoch = this.client.getSessionEpoch();
428
608
  this.claimInFlightToken = accessToken;
429
609
  this.claimInFlight = (async () => {
430
- const result = await chunk6JEKKL3M_js.safe(
610
+ const result = await chunkFWKSBF3F_js.safe(
431
611
  this.client.post(
432
612
  "/api/v1/support/conversation/claim",
433
613
  { access_token: accessToken },
@@ -436,7 +616,7 @@ var SupportService = class {
436
616
  );
437
617
  if (result.ok) {
438
618
  if (this.client.getSessionEpoch() !== epoch) {
439
- return chunk6JEKKL3M_js.err(
619
+ return chunkFWKSBF3F_js.err(
440
620
  new chunkNIOUSKQQ_js.CimplifyError("session_cleared", "Session was cleared during the claim")
441
621
  );
442
622
  }
@@ -465,20 +645,20 @@ var SupportService = class {
465
645
  * the inbox with empty threads.
466
646
  */
467
647
  async peekConversation() {
468
- const result = await chunk6JEKKL3M_js.safe(
648
+ const result = await chunkFWKSBF3F_js.safe(
469
649
  this.client.get("/api/v1/support/conversation")
470
650
  );
471
651
  if (!result.ok) return result;
472
- if (!result.value.conversation) return chunk6JEKKL3M_js.ok(null);
473
- return chunk6JEKKL3M_js.ok({
652
+ if (!result.value.conversation) return chunkFWKSBF3F_js.ok(null);
653
+ return chunkFWKSBF3F_js.ok({
474
654
  conversation: result.value.conversation,
475
655
  messages: result.value.messages
476
656
  });
477
657
  }
478
658
  /** Open (or resume) the customer's widget conversation. */
479
659
  async openConversation(opts) {
480
- const idempotencyKey = opts?.idempotencyKey ?? chunk6JEKKL3M_js.generateIdempotencyKey();
481
- return chunk6JEKKL3M_js.safe(
660
+ const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
661
+ return chunkFWKSBF3F_js.safe(
482
662
  this.client.post("/api/v1/support/conversation", void 0, {
483
663
  idempotencyKey
484
664
  })
@@ -493,8 +673,8 @@ var SupportService = class {
493
673
  * server resolves it thread-scoped and echoes the quote as `reply_to`.
494
674
  */
495
675
  async sendMessage(content, opts) {
496
- const idempotencyKey = opts?.idempotencyKey ?? chunk6JEKKL3M_js.generateIdempotencyKey();
497
- return chunk6JEKKL3M_js.safe(
676
+ const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
677
+ return chunkFWKSBF3F_js.safe(
498
678
  this.client.post(
499
679
  "/api/v1/support/conversation/messages",
500
680
  {
@@ -518,11 +698,11 @@ var SupportService = class {
518
698
  if (options.limit) params.set("limit", String(options.limit));
519
699
  const query = params.toString();
520
700
  const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
521
- return chunk6JEKKL3M_js.safe(this.client.get(path));
701
+ return chunkFWKSBF3F_js.safe(this.client.get(path));
522
702
  }
523
703
  /** React to a message in the active conversation by its `ChatMessage.id`. */
524
704
  async reactToMessage(messageId, emoji) {
525
- return chunk6JEKKL3M_js.safe(
705
+ return chunkFWKSBF3F_js.safe(
526
706
  this.client.post(
527
707
  `/api/v1/support/conversation/messages/${messageId}/reactions`,
528
708
  { emoji }
@@ -531,8 +711,8 @@ var SupportService = class {
531
711
  }
532
712
  /** Ask for a person: flags the thread for the merchant's inbox. */
533
713
  async requestHuman(opts) {
534
- const idempotencyKey = opts?.idempotencyKey ?? chunk6JEKKL3M_js.generateIdempotencyKey();
535
- return chunk6JEKKL3M_js.safe(
714
+ const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
715
+ return chunkFWKSBF3F_js.safe(
536
716
  this.client.post(
537
717
  "/api/v1/support/conversation/handoff",
538
718
  void 0,
@@ -762,6 +942,7 @@ var CimplifyClient = class {
762
942
  clearSession() {
763
943
  const previous = this.accessToken;
764
944
  this.accessToken = null;
945
+ this._activity?.resetSession();
765
946
  this.sessionToken = null;
766
947
  this.sessionEpoch++;
767
948
  try {
@@ -1256,25 +1437,25 @@ var CimplifyClient = class {
1256
1437
  }
1257
1438
  get catalogue() {
1258
1439
  if (!this._catalogue) {
1259
- this._catalogue = new chunk6JEKKL3M_js.CatalogueQueries(this);
1440
+ this._catalogue = new chunkFWKSBF3F_js.CatalogueQueries(this);
1260
1441
  }
1261
1442
  return this._catalogue;
1262
1443
  }
1263
1444
  get cart() {
1264
1445
  if (!this._cart) {
1265
- this._cart = new chunk6JEKKL3M_js.CartOperations(this);
1446
+ this._cart = new chunkFWKSBF3F_js.CartOperations(this);
1266
1447
  }
1267
1448
  return this._cart;
1268
1449
  }
1269
1450
  get checkout() {
1270
1451
  if (!this._checkout) {
1271
- this._checkout = new chunk6JEKKL3M_js.CheckoutService(this);
1452
+ this._checkout = new chunkFWKSBF3F_js.CheckoutService(this);
1272
1453
  }
1273
1454
  return this._checkout;
1274
1455
  }
1275
1456
  get orders() {
1276
1457
  if (!this._orders) {
1277
- this._orders = new chunk6JEKKL3M_js.OrderQueries(this);
1458
+ this._orders = new chunkFWKSBF3F_js.OrderQueries(this);
1278
1459
  }
1279
1460
  return this._orders;
1280
1461
  }
@@ -1304,43 +1485,43 @@ var CimplifyClient = class {
1304
1485
  }
1305
1486
  get link() {
1306
1487
  if (!this._link) {
1307
- this._link = new chunk6JEKKL3M_js.LinkService(this);
1488
+ this._link = new chunkFWKSBF3F_js.LinkService(this);
1308
1489
  }
1309
1490
  return this._link;
1310
1491
  }
1311
1492
  get auth() {
1312
1493
  if (!this._auth) {
1313
- this._auth = new chunk6JEKKL3M_js.AuthService(this);
1494
+ this._auth = new chunkFWKSBF3F_js.AuthService(this);
1314
1495
  }
1315
1496
  return this._auth;
1316
1497
  }
1317
1498
  get business() {
1318
1499
  if (!this._business) {
1319
- this._business = new chunk6JEKKL3M_js.BusinessService(this);
1500
+ this._business = new chunkFWKSBF3F_js.BusinessService(this);
1320
1501
  }
1321
1502
  return this._business;
1322
1503
  }
1323
1504
  get inventory() {
1324
1505
  if (!this._inventory) {
1325
- this._inventory = new chunk6JEKKL3M_js.InventoryService(this);
1506
+ this._inventory = new chunkFWKSBF3F_js.InventoryService(this);
1326
1507
  }
1327
1508
  return this._inventory;
1328
1509
  }
1329
1510
  get scheduling() {
1330
1511
  if (!this._scheduling) {
1331
- this._scheduling = new chunk6JEKKL3M_js.SchedulingService(this);
1512
+ this._scheduling = new chunkFWKSBF3F_js.SchedulingService(this);
1332
1513
  }
1333
1514
  return this._scheduling;
1334
1515
  }
1335
1516
  get lite() {
1336
1517
  if (!this._lite) {
1337
- this._lite = new chunk6JEKKL3M_js.LiteService(this);
1518
+ this._lite = new chunkFWKSBF3F_js.LiteService(this);
1338
1519
  }
1339
1520
  return this._lite;
1340
1521
  }
1341
1522
  get fx() {
1342
1523
  if (!this._fx) {
1343
- this._fx = new chunk6JEKKL3M_js.FxService(this);
1524
+ this._fx = new chunkFWKSBF3F_js.FxService(this);
1344
1525
  }
1345
1526
  return this._fx;
1346
1527
  }
@@ -1375,7 +1556,7 @@ var CimplifyClient = class {
1375
1556
  if (businessId) {
1376
1557
  this.setBusinessId(businessId);
1377
1558
  }
1378
- return chunk6JEKKL3M_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
1559
+ return chunkFWKSBF3F_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
1379
1560
  }
1380
1561
  };
1381
1562
  function createCimplifyClient(config = {}) {
@@ -1859,6 +1859,7 @@ var LinkService = class {
1859
1859
  );
1860
1860
  if (result.ok && result.value.session_token) {
1861
1861
  this.client.setAccessToken(result.value.session_token);
1862
+ this.client.activity.refreshIdentity();
1862
1863
  this.client.autoClaimChatIdentity();
1863
1864
  }
1864
1865
  return result;
@@ -1871,6 +1872,7 @@ var LinkService = class {
1871
1872
  );
1872
1873
  if (result.ok && result.value.session_token) {
1873
1874
  this.client.setAccessToken(result.value.session_token);
1875
+ this.client.activity.refreshIdentity();
1874
1876
  this.client.autoClaimChatIdentity();
1875
1877
  }
1876
1878
  return result;
@@ -2055,6 +2057,7 @@ var AuthService = class {
2055
2057
  );
2056
2058
  if (result.ok && result.value.session_token) {
2057
2059
  this.client.setAccessToken(result.value.session_token);
2060
+ this.client.activity.refreshIdentity();
2058
2061
  this.client.autoClaimChatIdentity();
2059
2062
  }
2060
2063
  return result;
@@ -1861,6 +1861,7 @@ var LinkService = class {
1861
1861
  );
1862
1862
  if (result.ok && result.value.session_token) {
1863
1863
  this.client.setAccessToken(result.value.session_token);
1864
+ this.client.activity.refreshIdentity();
1864
1865
  this.client.autoClaimChatIdentity();
1865
1866
  }
1866
1867
  return result;
@@ -1873,6 +1874,7 @@ var LinkService = class {
1873
1874
  );
1874
1875
  if (result.ok && result.value.session_token) {
1875
1876
  this.client.setAccessToken(result.value.session_token);
1877
+ this.client.activity.refreshIdentity();
1876
1878
  this.client.autoClaimChatIdentity();
1877
1879
  }
1878
1880
  return result;
@@ -2057,6 +2059,7 @@ var AuthService = class {
2057
2059
  );
2058
2060
  if (result.ok && result.value.session_token) {
2059
2061
  this.client.setAccessToken(result.value.session_token);
2062
+ this.client.activity.refreshIdentity();
2060
2063
  this.client.autoClaimChatIdentity();
2061
2064
  }
2062
2065
  return result;
@@ -2468,7 +2468,7 @@ function buildV1(deps) {
2468
2468
  });
2469
2469
  app.post("/activity/events", async (c) => {
2470
2470
  const body = await c.req.json().catch(() => ({}));
2471
- return tryRoute(c, () => deps.activity.recordEvents(deps.defaultBusinessId, c.var.session.id, body.events ?? []));
2471
+ return tryRoute(c, () => deps.activity.recordEvents(deps.defaultBusinessId, body.analytics_session_id ?? c.var.session.id, body.events ?? []));
2472
2472
  });
2473
2473
  app.get("/activity/state", (c) => tryRoute(c, () => deps.activity.getState(deps.defaultBusinessId, c.var.session.id)));
2474
2474
  app.get("/activity/recommendations", (c) => tryRoute(c, () => deps.activity.getRecommendations(deps.defaultBusinessId)));
@@ -5431,7 +5431,7 @@ function createActivityService(opts) {
5431
5431
  id,
5432
5432
  business_id: businessId,
5433
5433
  session_id: sessionId,
5434
- event_type: e.event_type,
5434
+ event_type: e.type,
5435
5435
  payload: e.payload ?? {},
5436
5436
  created_at: clock.iso()
5437
5437
  };