@cimplify/sdk 0.100.1 → 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.
- 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-BHQCSHIG.js → chunk-CNY2XFN4.js} +266 -84
- package/dist/{chunk-PTKAN4SI.mjs → chunk-FFRQNNUQ.mjs} +8 -0
- package/dist/{chunk-QGFKIAEM.js → chunk-FWKSBF3F.js} +8 -0
- package/dist/{chunk-NKZIXLKW.mjs → chunk-HFTRLRLM.mjs} +3 -3
- package/dist/{chunk-NR4Z2SFY.js → chunk-KNCW5DI7.js} +4 -4
- package/dist/{chunk-KEC2CX4R.mjs → chunk-NOGCGI4J.mjs} +2 -2
- package/dist/{chunk-NH3HYUC3.js → chunk-XCS56XSS.js} +3 -3
- package/dist/{chunk-T2B656RS.mjs → chunk-XG4DZT4I.mjs} +221 -39
- package/dist/{client-T5c-Nxq-.d.mts → client-BGeSemVv.d.mts} +2 -2
- package/dist/{client-DxgC_lXU.d.ts → client-BWdeCgmo.d.ts} +34 -14
- package/dist/{client-B0Lku_lc.d.mts → client-Bx4NRdl8.d.mts} +34 -14
- package/dist/{client-DRgEa78P.d.ts → client-Cvp8W1r9.d.ts} +2 -2
- package/dist/{index-CzKN1hjf.d.ts → index-B_RYmvlF.d.ts} +3 -3
- package/dist/{index-DzuLT5wi.d.mts → index-D-LUYk1Y.d.mts} +3 -3
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +69 -69
- package/dist/index.mjs +3 -3
- package/dist/mock/cli.mjs +3 -3
- package/dist/mock/library.js +3 -3
- package/dist/mock/library.mjs +3 -3
- package/dist/mock/msw.js +3 -3
- package/dist/mock/msw.mjs +3 -3
- package/dist/{payment-D8NEwCna.d.mts → payment-BSzy7sly.d.mts} +1 -1
- package/dist/{payment-lZBP7h5M.d.ts → payment-jK8ztICx.d.ts} +1 -1
- package/dist/{price-ncQb-TC8.d.ts → price-CJLfcYKd.d.ts} +1 -1
- package/dist/{price-DepWAmcL.d.mts → price-D96h6c6L.d.mts} +1 -1
- package/dist/{product-B384_Qm2.d.mts → product-CeV8euw4.d.mts} +11 -10
- package/dist/{product-B384_Qm2.d.ts → product-CeV8euw4.d.ts} +11 -10
- package/dist/react.d.mts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +51 -29
- package/dist/react.mjs +28 -6
- package/dist/{server-oCGNIO_K.d.mts → server-BRJ61o2J.d.mts} +4 -4
- package/dist/{server-B7O4ttpv.d.ts → server-CXrVYtNo.d.ts} +4 -4
- 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/testing/msw.d.mts +2 -2
- package/dist/testing/msw.d.ts +2 -2
- package/dist/testing/msw.js +2 -2
- package/dist/testing/msw.mjs +1 -1
- package/dist/testing/suite.d.mts +6 -6
- package/dist/testing/suite.d.ts +6 -6
- package/dist/testing/suite.js +23 -23
- package/dist/testing/suite.mjs +4 -4
- package/dist/testing.d.mts +5 -5
- package/dist/testing.d.ts +5 -5
- package/dist/testing.js +79 -79
- package/dist/testing.mjs +5 -5
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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
|
|
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
|
|
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
|
-
|
|
34
|
-
|
|
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(() => {
|
|
45
176
|
});
|
|
46
177
|
}
|
|
47
|
-
|
|
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(() => {
|
|
184
|
+
});
|
|
185
|
+
}
|
|
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
|
-
|
|
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
|
|
222
|
+
/** Route-level page view. Product/category interactions are tracked separately. */
|
|
78
223
|
trackPageView(options = {}) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
|
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
|
|
273
|
+
return chunkFWKSBF3F_js.safe(this.client.get(path));
|
|
117
274
|
}
|
|
118
275
|
async dismissMessage(code) {
|
|
119
|
-
return
|
|
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
|
-
|
|
156
|
-
this.
|
|
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
|
|
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
|
|
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 ??
|
|
201
|
-
return
|
|
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
|
|
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
|
|
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 ??
|
|
224
|
-
return
|
|
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 ??
|
|
241
|
-
return
|
|
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
|
|
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
|
|
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
|
|
488
|
+
return chunkFWKSBF3F_js.safe(
|
|
309
489
|
this.client.post("/api/v1/places/details", {
|
|
310
490
|
place_id: placeId,
|
|
311
491
|
sessionToken
|
|
@@ -324,19 +504,20 @@ 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
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
507
|
+
return chunkFWKSBF3F_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
|
|
508
|
+
}
|
|
509
|
+
async getOptions(queryOrLatitude, longitude, legacyOptions) {
|
|
510
|
+
const query = typeof queryOrLatitude === "number" ? {
|
|
511
|
+
...legacyOptions,
|
|
512
|
+
dropoffLat: queryOrLatitude,
|
|
513
|
+
dropoffLng: longitude
|
|
514
|
+
} : queryOrLatitude ?? {};
|
|
334
515
|
const params = new URLSearchParams();
|
|
335
|
-
params.set("dropoff_lat", String(dropoffLat));
|
|
336
|
-
params.set("dropoff_lng", String(dropoffLng));
|
|
337
|
-
if (
|
|
338
|
-
if (
|
|
339
|
-
return
|
|
516
|
+
if (query.dropoffLat != null) params.set("dropoff_lat", String(query.dropoffLat));
|
|
517
|
+
if (query.dropoffLng != null) params.set("dropoff_lng", String(query.dropoffLng));
|
|
518
|
+
if (query.country) params.set("country", query.country);
|
|
519
|
+
if (query.orderValue != null) params.set("order_value", String(query.orderValue));
|
|
520
|
+
return chunkFWKSBF3F_js.safe(
|
|
340
521
|
this.client.get(`/api/v1/delivery/options?${params.toString()}`)
|
|
341
522
|
);
|
|
342
523
|
}
|
|
@@ -413,7 +594,7 @@ var SupportService = class {
|
|
|
413
594
|
async claimConversation() {
|
|
414
595
|
const accessToken = this.client.getAccessToken();
|
|
415
596
|
if (!accessToken) {
|
|
416
|
-
return
|
|
597
|
+
return chunkFWKSBF3F_js.err(new chunkNIOUSKQQ_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
417
598
|
}
|
|
418
599
|
if (this.claimInFlight) {
|
|
419
600
|
if (this.claimInFlightToken === accessToken) return this.claimInFlight;
|
|
@@ -421,12 +602,12 @@ var SupportService = class {
|
|
|
421
602
|
return this.claimConversation();
|
|
422
603
|
}
|
|
423
604
|
if (this.lastClaimedAccessToken === accessToken) {
|
|
424
|
-
return
|
|
605
|
+
return chunkFWKSBF3F_js.err(new chunkNIOUSKQQ_js.CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
425
606
|
}
|
|
426
607
|
const epoch = this.client.getSessionEpoch();
|
|
427
608
|
this.claimInFlightToken = accessToken;
|
|
428
609
|
this.claimInFlight = (async () => {
|
|
429
|
-
const result = await
|
|
610
|
+
const result = await chunkFWKSBF3F_js.safe(
|
|
430
611
|
this.client.post(
|
|
431
612
|
"/api/v1/support/conversation/claim",
|
|
432
613
|
{ access_token: accessToken },
|
|
@@ -435,7 +616,7 @@ var SupportService = class {
|
|
|
435
616
|
);
|
|
436
617
|
if (result.ok) {
|
|
437
618
|
if (this.client.getSessionEpoch() !== epoch) {
|
|
438
|
-
return
|
|
619
|
+
return chunkFWKSBF3F_js.err(
|
|
439
620
|
new chunkNIOUSKQQ_js.CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
440
621
|
);
|
|
441
622
|
}
|
|
@@ -464,20 +645,20 @@ var SupportService = class {
|
|
|
464
645
|
* the inbox with empty threads.
|
|
465
646
|
*/
|
|
466
647
|
async peekConversation() {
|
|
467
|
-
const result = await
|
|
648
|
+
const result = await chunkFWKSBF3F_js.safe(
|
|
468
649
|
this.client.get("/api/v1/support/conversation")
|
|
469
650
|
);
|
|
470
651
|
if (!result.ok) return result;
|
|
471
|
-
if (!result.value.conversation) return
|
|
472
|
-
return
|
|
652
|
+
if (!result.value.conversation) return chunkFWKSBF3F_js.ok(null);
|
|
653
|
+
return chunkFWKSBF3F_js.ok({
|
|
473
654
|
conversation: result.value.conversation,
|
|
474
655
|
messages: result.value.messages
|
|
475
656
|
});
|
|
476
657
|
}
|
|
477
658
|
/** Open (or resume) the customer's widget conversation. */
|
|
478
659
|
async openConversation(opts) {
|
|
479
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
480
|
-
return
|
|
660
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
|
|
661
|
+
return chunkFWKSBF3F_js.safe(
|
|
481
662
|
this.client.post("/api/v1/support/conversation", void 0, {
|
|
482
663
|
idempotencyKey
|
|
483
664
|
})
|
|
@@ -492,8 +673,8 @@ var SupportService = class {
|
|
|
492
673
|
* server resolves it thread-scoped and echoes the quote as `reply_to`.
|
|
493
674
|
*/
|
|
494
675
|
async sendMessage(content, opts) {
|
|
495
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
496
|
-
return
|
|
676
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
|
|
677
|
+
return chunkFWKSBF3F_js.safe(
|
|
497
678
|
this.client.post(
|
|
498
679
|
"/api/v1/support/conversation/messages",
|
|
499
680
|
{
|
|
@@ -517,11 +698,11 @@ var SupportService = class {
|
|
|
517
698
|
if (options.limit) params.set("limit", String(options.limit));
|
|
518
699
|
const query = params.toString();
|
|
519
700
|
const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
|
|
520
|
-
return
|
|
701
|
+
return chunkFWKSBF3F_js.safe(this.client.get(path));
|
|
521
702
|
}
|
|
522
703
|
/** React to a message in the active conversation by its `ChatMessage.id`. */
|
|
523
704
|
async reactToMessage(messageId, emoji) {
|
|
524
|
-
return
|
|
705
|
+
return chunkFWKSBF3F_js.safe(
|
|
525
706
|
this.client.post(
|
|
526
707
|
`/api/v1/support/conversation/messages/${messageId}/reactions`,
|
|
527
708
|
{ emoji }
|
|
@@ -530,8 +711,8 @@ var SupportService = class {
|
|
|
530
711
|
}
|
|
531
712
|
/** Ask for a person: flags the thread for the merchant's inbox. */
|
|
532
713
|
async requestHuman(opts) {
|
|
533
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
534
|
-
return
|
|
714
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunkFWKSBF3F_js.generateIdempotencyKey();
|
|
715
|
+
return chunkFWKSBF3F_js.safe(
|
|
535
716
|
this.client.post(
|
|
536
717
|
"/api/v1/support/conversation/handoff",
|
|
537
718
|
void 0,
|
|
@@ -761,6 +942,7 @@ var CimplifyClient = class {
|
|
|
761
942
|
clearSession() {
|
|
762
943
|
const previous = this.accessToken;
|
|
763
944
|
this.accessToken = null;
|
|
945
|
+
this._activity?.resetSession();
|
|
764
946
|
this.sessionToken = null;
|
|
765
947
|
this.sessionEpoch++;
|
|
766
948
|
try {
|
|
@@ -1255,25 +1437,25 @@ var CimplifyClient = class {
|
|
|
1255
1437
|
}
|
|
1256
1438
|
get catalogue() {
|
|
1257
1439
|
if (!this._catalogue) {
|
|
1258
|
-
this._catalogue = new
|
|
1440
|
+
this._catalogue = new chunkFWKSBF3F_js.CatalogueQueries(this);
|
|
1259
1441
|
}
|
|
1260
1442
|
return this._catalogue;
|
|
1261
1443
|
}
|
|
1262
1444
|
get cart() {
|
|
1263
1445
|
if (!this._cart) {
|
|
1264
|
-
this._cart = new
|
|
1446
|
+
this._cart = new chunkFWKSBF3F_js.CartOperations(this);
|
|
1265
1447
|
}
|
|
1266
1448
|
return this._cart;
|
|
1267
1449
|
}
|
|
1268
1450
|
get checkout() {
|
|
1269
1451
|
if (!this._checkout) {
|
|
1270
|
-
this._checkout = new
|
|
1452
|
+
this._checkout = new chunkFWKSBF3F_js.CheckoutService(this);
|
|
1271
1453
|
}
|
|
1272
1454
|
return this._checkout;
|
|
1273
1455
|
}
|
|
1274
1456
|
get orders() {
|
|
1275
1457
|
if (!this._orders) {
|
|
1276
|
-
this._orders = new
|
|
1458
|
+
this._orders = new chunkFWKSBF3F_js.OrderQueries(this);
|
|
1277
1459
|
}
|
|
1278
1460
|
return this._orders;
|
|
1279
1461
|
}
|
|
@@ -1303,43 +1485,43 @@ var CimplifyClient = class {
|
|
|
1303
1485
|
}
|
|
1304
1486
|
get link() {
|
|
1305
1487
|
if (!this._link) {
|
|
1306
|
-
this._link = new
|
|
1488
|
+
this._link = new chunkFWKSBF3F_js.LinkService(this);
|
|
1307
1489
|
}
|
|
1308
1490
|
return this._link;
|
|
1309
1491
|
}
|
|
1310
1492
|
get auth() {
|
|
1311
1493
|
if (!this._auth) {
|
|
1312
|
-
this._auth = new
|
|
1494
|
+
this._auth = new chunkFWKSBF3F_js.AuthService(this);
|
|
1313
1495
|
}
|
|
1314
1496
|
return this._auth;
|
|
1315
1497
|
}
|
|
1316
1498
|
get business() {
|
|
1317
1499
|
if (!this._business) {
|
|
1318
|
-
this._business = new
|
|
1500
|
+
this._business = new chunkFWKSBF3F_js.BusinessService(this);
|
|
1319
1501
|
}
|
|
1320
1502
|
return this._business;
|
|
1321
1503
|
}
|
|
1322
1504
|
get inventory() {
|
|
1323
1505
|
if (!this._inventory) {
|
|
1324
|
-
this._inventory = new
|
|
1506
|
+
this._inventory = new chunkFWKSBF3F_js.InventoryService(this);
|
|
1325
1507
|
}
|
|
1326
1508
|
return this._inventory;
|
|
1327
1509
|
}
|
|
1328
1510
|
get scheduling() {
|
|
1329
1511
|
if (!this._scheduling) {
|
|
1330
|
-
this._scheduling = new
|
|
1512
|
+
this._scheduling = new chunkFWKSBF3F_js.SchedulingService(this);
|
|
1331
1513
|
}
|
|
1332
1514
|
return this._scheduling;
|
|
1333
1515
|
}
|
|
1334
1516
|
get lite() {
|
|
1335
1517
|
if (!this._lite) {
|
|
1336
|
-
this._lite = new
|
|
1518
|
+
this._lite = new chunkFWKSBF3F_js.LiteService(this);
|
|
1337
1519
|
}
|
|
1338
1520
|
return this._lite;
|
|
1339
1521
|
}
|
|
1340
1522
|
get fx() {
|
|
1341
1523
|
if (!this._fx) {
|
|
1342
|
-
this._fx = new
|
|
1524
|
+
this._fx = new chunkFWKSBF3F_js.FxService(this);
|
|
1343
1525
|
}
|
|
1344
1526
|
return this._fx;
|
|
1345
1527
|
}
|
|
@@ -1374,7 +1556,7 @@ var CimplifyClient = class {
|
|
|
1374
1556
|
if (businessId) {
|
|
1375
1557
|
this.setBusinessId(businessId);
|
|
1376
1558
|
}
|
|
1377
|
-
return
|
|
1559
|
+
return chunkFWKSBF3F_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
|
|
1378
1560
|
}
|
|
1379
1561
|
};
|
|
1380
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;
|
|
@@ -2777,6 +2780,7 @@ var KNOWN_IFRAME_TYPES = /* @__PURE__ */ new Set([
|
|
|
2777
2780
|
MESSAGE_TYPES.READY,
|
|
2778
2781
|
MESSAGE_TYPES.HEIGHT_CHANGE,
|
|
2779
2782
|
MESSAGE_TYPES.AUTH_REQUESTED,
|
|
2783
|
+
MESSAGE_TYPES.SESSION_ESTABLISHED,
|
|
2780
2784
|
MESSAGE_TYPES.ERROR,
|
|
2781
2785
|
MESSAGE_TYPES.ADDRESS_CHANGED,
|
|
2782
2786
|
MESSAGE_TYPES.ADDRESS_SELECTED,
|
|
@@ -2809,6 +2813,10 @@ function parseIframeMessage(data) {
|
|
|
2809
2813
|
return null;
|
|
2810
2814
|
}
|
|
2811
2815
|
break;
|
|
2816
|
+
case MESSAGE_TYPES.SESSION_ESTABLISHED:
|
|
2817
|
+
if (typeof record.accessToken !== "string" || !record.accessToken.trim()) return null;
|
|
2818
|
+
if (record.refreshToken !== void 0 && typeof record.refreshToken !== "string") return null;
|
|
2819
|
+
break;
|
|
2812
2820
|
case MESSAGE_TYPES.ADDRESS_CHANGED:
|
|
2813
2821
|
case MESSAGE_TYPES.ADDRESS_SELECTED:
|
|
2814
2822
|
if (!record.address || typeof record.address !== "object") return null;
|