@knocklabs/client 0.21.10 → 0.21.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/api.js +1 -1
- package/dist/cjs/clients/guide/client.js +1 -1
- package/dist/cjs/clients/guide/client.js.map +1 -1
- package/dist/cjs/clients/guide/types.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/clients/guide/client.mjs +92 -197
- package/dist/esm/clients/guide/client.mjs.map +1 -1
- package/dist/esm/clients/guide/types.mjs.map +1 -1
- package/dist/esm/index.mjs +12 -13
- package/dist/types/clients/guide/client.d.ts +1 -8
- package/dist/types/clients/guide/client.d.ts.map +1 -1
- package/dist/types/clients/guide/index.d.ts +1 -1
- package/dist/types/clients/guide/index.d.ts.map +1 -1
- package/dist/types/clients/guide/types.d.ts +4 -9
- package/dist/types/clients/guide/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/guide/client.ts +5 -175
- package/src/clients/guide/index.ts +1 -5
- package/src/clients/guide/types.ts +4 -12
|
@@ -1,87 +1,35 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (
|
|
4
|
-
import { Store as
|
|
1
|
+
var _ = Object.defineProperty;
|
|
2
|
+
var C = (u, e, s) => e in u ? _(u, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : u[e] = s;
|
|
3
|
+
var h = (u, e, s) => C(u, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
import { Store as I } from "@tanstack/store";
|
|
5
5
|
import { URLPattern as A } from "urlpattern-polyfill";
|
|
6
|
-
import { byKey as
|
|
7
|
-
import { SelectionResult as
|
|
8
|
-
const
|
|
9
|
-
GUIDE_KEY: "knock_guide_key",
|
|
10
|
-
PREVIEW_SESSION_ID: "knock_preview_session_id"
|
|
11
|
-
}, y = "knock_guide_debug", p = () => {
|
|
6
|
+
import { byKey as y, mockDefaultGroup as E, formatFilters as G, formatState as S, checkStateIfThrottled as b, formatGroupStage as p, DEFAULT_GROUP_KEY as R, getToolbarRunConfigFromUrl as T, newUrl as $, predicateUrlRules as L, predicateUrlPatterns as w, findDefaultGroup as F } from "./helpers.mjs";
|
|
7
|
+
import { SelectionResult as P } from "./types.mjs";
|
|
8
|
+
const D = 50, K = 30 * 1e3, O = 3, f = () => {
|
|
12
9
|
if (typeof window < "u")
|
|
13
10
|
return window;
|
|
14
|
-
},
|
|
15
|
-
const
|
|
16
|
-
if (!a || !a.location)
|
|
17
|
-
return { forcedGuideKey: null, previewSessionId: null };
|
|
18
|
-
const e = new URLSearchParams(a.location.search), s = e.get(f.GUIDE_KEY), t = e.get(
|
|
19
|
-
f.PREVIEW_SESSION_ID
|
|
20
|
-
);
|
|
21
|
-
if (s || t) {
|
|
22
|
-
if (a.localStorage)
|
|
23
|
-
try {
|
|
24
|
-
const n = {
|
|
25
|
-
forcedGuideKey: s,
|
|
26
|
-
previewSessionId: t
|
|
27
|
-
};
|
|
28
|
-
a.localStorage.setItem(y, JSON.stringify(n));
|
|
29
|
-
} catch {
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
forcedGuideKey: s,
|
|
33
|
-
previewSessionId: t
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
let i = null, r = null;
|
|
37
|
-
if (a.localStorage)
|
|
38
|
-
try {
|
|
39
|
-
const n = a.localStorage.getItem(y);
|
|
40
|
-
if (n) {
|
|
41
|
-
const u = B(n);
|
|
42
|
-
i = u.forcedGuideKey, r = u.previewSessionId;
|
|
43
|
-
}
|
|
44
|
-
} catch {
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
forcedGuideKey: i,
|
|
48
|
-
previewSessionId: r
|
|
49
|
-
};
|
|
50
|
-
}, B = (a) => {
|
|
51
|
-
try {
|
|
52
|
-
const e = JSON.parse(a);
|
|
53
|
-
return {
|
|
54
|
-
forcedGuideKey: (e == null ? void 0 : e.forcedGuideKey) ?? null,
|
|
55
|
-
previewSessionId: (e == null ? void 0 : e.previewSessionId) ?? null
|
|
56
|
-
};
|
|
57
|
-
} catch {
|
|
58
|
-
return {
|
|
59
|
-
forcedGuideKey: null,
|
|
60
|
-
previewSessionId: null
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}, E = (a, e, s) => {
|
|
64
|
-
const t = new F(), i = O(a.guideGroups);
|
|
11
|
+
}, U = (u) => `/v1/users/${u}/guides`, v = (u, e, s) => {
|
|
12
|
+
const t = new P(), i = F(u.guideGroups);
|
|
65
13
|
if (!i) return t;
|
|
66
|
-
const r = i.display_sequence, n =
|
|
67
|
-
for (const [
|
|
68
|
-
const c =
|
|
69
|
-
!c || !
|
|
14
|
+
const r = i.display_sequence, n = u.location;
|
|
15
|
+
for (const [a, o] of r.entries()) {
|
|
16
|
+
const c = u.previewGuides[o] || u.guides[o];
|
|
17
|
+
!c || !q(c, e, {
|
|
70
18
|
location: n,
|
|
71
|
-
ineligibleGuides:
|
|
72
|
-
debug:
|
|
73
|
-
}) || t.set(
|
|
19
|
+
ineligibleGuides: u.ineligibleGuides,
|
|
20
|
+
debug: u.debug
|
|
21
|
+
}) || t.set(a, c);
|
|
74
22
|
}
|
|
75
23
|
return t.metadata = { guideGroup: i, filters: e, ...s }, t;
|
|
76
|
-
},
|
|
77
|
-
const s = e ?
|
|
24
|
+
}, q = (u, e, { location: s, ineligibleGuides: t = {}, debug: i = {} }) => e.type && e.type !== u.type || e.key && e.key !== u.key ? !1 : i.focusedGuideKeys && Object.keys(i.focusedGuideKeys).length > 0 ? !!i.focusedGuideKeys[u.key] : i.forcedGuideKey ? i.forcedGuideKey === u.key : t[u.key] || !u.active || u.steps.every((n) => !!n.message.archived_at) ? !1 : j(u, s), j = (u, e) => {
|
|
25
|
+
const s = e ? $(e) : void 0, t = u.activation_url_rules || [], i = u.activation_url_patterns || [];
|
|
78
26
|
if (s && t.length > 0) {
|
|
79
|
-
if (!
|
|
80
|
-
} else if (s && i.length > 0 &&
|
|
27
|
+
if (!L(s, t)) return !1;
|
|
28
|
+
} else if (s && i.length > 0 && !w(s, i))
|
|
81
29
|
return !1;
|
|
82
30
|
return !0;
|
|
83
31
|
};
|
|
84
|
-
class
|
|
32
|
+
class J {
|
|
85
33
|
constructor(e, s, t = {}, i = {}) {
|
|
86
34
|
h(this, "store");
|
|
87
35
|
// Phoenix channels for real time guide updates over websocket
|
|
@@ -93,8 +41,7 @@ class z {
|
|
|
93
41
|
"guide.updated",
|
|
94
42
|
"guide.removed",
|
|
95
43
|
"guide_group.added",
|
|
96
|
-
"guide_group.updated"
|
|
97
|
-
"guide.live_preview_updated"
|
|
44
|
+
"guide_group.updated"
|
|
98
45
|
]);
|
|
99
46
|
h(this, "subscribeRetryCount", 0);
|
|
100
47
|
// Original history methods to monkey patch, or restore in cleanups.
|
|
@@ -108,45 +55,30 @@ class z {
|
|
|
108
55
|
// Define as an arrow func property to always bind this to the class instance.
|
|
109
56
|
h(this, "handleLocationChange", () => {
|
|
110
57
|
this.knock.log("[Guide] .handleLocationChange");
|
|
111
|
-
const e =
|
|
58
|
+
const e = f();
|
|
112
59
|
if (!(e != null && e.location)) return;
|
|
113
60
|
const s = e.location.href;
|
|
114
|
-
|
|
115
|
-
if (this.knock.log(`[Guide] Detected a location change: ${s}`), !this.options.trackDebugParams) {
|
|
116
|
-
this.setLocation(s);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const t = this.store.state.debug || {}, i = I();
|
|
120
|
-
this.setLocation(s, { debug: i }), this.checkDebugStateChanged(
|
|
121
|
-
t,
|
|
122
|
-
i
|
|
123
|
-
) && (this.knock.log(
|
|
124
|
-
"[Guide] Debug state changed, refetching guides and resubscribing to the websocket channel"
|
|
125
|
-
), this.fetch(), this.subscribe());
|
|
61
|
+
this.store.state.location !== s && (this.knock.log(`[Guide] Detected a location change: ${s}`), this.setLocation(s));
|
|
126
62
|
});
|
|
127
|
-
var
|
|
63
|
+
var d;
|
|
128
64
|
this.knock = e, this.channelId = s, this.targetParams = t, this.options = i;
|
|
129
65
|
const {
|
|
130
66
|
trackLocationFromWindow: r = !0,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
throttleCheckInterval: u = N
|
|
135
|
-
} = i, o = p(), c = r ? (l = o == null ? void 0 : o.location) == null ? void 0 : l.href : void 0, d = n ? I() : void 0;
|
|
136
|
-
this.store = new R({
|
|
67
|
+
throttleCheckInterval: n = K
|
|
68
|
+
} = i, a = f(), o = r ? (d = a == null ? void 0 : a.location) == null ? void 0 : d.href : void 0;
|
|
69
|
+
this.store = new I({
|
|
137
70
|
guideGroups: [],
|
|
138
71
|
guideGroupDisplayLogs: {},
|
|
139
72
|
guides: {},
|
|
140
73
|
ineligibleGuides: {},
|
|
141
74
|
previewGuides: {},
|
|
142
75
|
queries: {},
|
|
143
|
-
location:
|
|
76
|
+
location: o,
|
|
144
77
|
// Increment to update the state store and trigger re-selection.
|
|
145
|
-
counter: 0
|
|
146
|
-
debug: d
|
|
78
|
+
counter: 0
|
|
147
79
|
});
|
|
148
|
-
const { socket:
|
|
149
|
-
this.socket =
|
|
80
|
+
const { socket: c } = this.knock.client();
|
|
81
|
+
this.socket = c, this.socketChannelTopic = `guides:${s}`, r && this.listenForLocationChangesFromWindow(), n && this.startCounterInterval(n), this.knock.log("[Guide] Initialized a guide client");
|
|
150
82
|
}
|
|
151
83
|
incrementCounter() {
|
|
152
84
|
this.knock.log("[Guide] Incrementing the counter"), this.store.setState((e) => ({ ...e, counter: e.counter + 1 }));
|
|
@@ -177,23 +109,23 @@ class z {
|
|
|
177
109
|
const n = await this.knock.user.getGuides(this.channelId, s);
|
|
178
110
|
r = { status: "ok" };
|
|
179
111
|
const {
|
|
180
|
-
entries:
|
|
112
|
+
entries: a,
|
|
181
113
|
guide_groups: o,
|
|
182
114
|
guide_group_display_logs: c,
|
|
183
115
|
ineligible_guides: d
|
|
184
116
|
} = n;
|
|
185
|
-
this.stage && this.clearGroupStage(), this.knock.log("[Guide] Loading fetched guides"), this.store.setState((
|
|
186
|
-
...
|
|
187
|
-
guideGroups: (o == null ? void 0 : o.length) > 0 ? o : [
|
|
117
|
+
this.stage && this.clearGroupStage(), this.knock.log("[Guide] Loading fetched guides"), this.store.setState((l) => ({
|
|
118
|
+
...l,
|
|
119
|
+
guideGroups: (o == null ? void 0 : o.length) > 0 ? o : [E(a)],
|
|
188
120
|
guideGroupDisplayLogs: c || {},
|
|
189
|
-
guides:
|
|
190
|
-
ineligibleGuides:
|
|
191
|
-
queries: { ...
|
|
121
|
+
guides: y(a.map((k) => this.localCopy(k))),
|
|
122
|
+
ineligibleGuides: y(d || []),
|
|
123
|
+
queries: { ...l.queries, [t]: r }
|
|
192
124
|
}));
|
|
193
125
|
} catch (n) {
|
|
194
|
-
r = { status: "error", error: n }, this.store.setState((
|
|
195
|
-
...
|
|
196
|
-
queries: { ...
|
|
126
|
+
r = { status: "error", error: n }, this.store.setState((a) => ({
|
|
127
|
+
...a,
|
|
128
|
+
queries: { ...a.queries, [t]: r }
|
|
197
129
|
}));
|
|
198
130
|
}
|
|
199
131
|
return r;
|
|
@@ -220,7 +152,7 @@ class z {
|
|
|
220
152
|
})), this.socketChannel = t;
|
|
221
153
|
}
|
|
222
154
|
handleChannelJoinError() {
|
|
223
|
-
if (this.subscribeRetryCount >=
|
|
155
|
+
if (this.subscribeRetryCount >= O) {
|
|
224
156
|
this.knock.log(
|
|
225
157
|
`[Guide] Channel join max retry limit reached: ${this.subscribeRetryCount}`
|
|
226
158
|
), this.unsubscribe();
|
|
@@ -248,8 +180,6 @@ class z {
|
|
|
248
180
|
case "guide_group.added":
|
|
249
181
|
case "guide_group.updated":
|
|
250
182
|
return this.addOrReplaceGuideGroup(e);
|
|
251
|
-
case "guide.live_preview_updated":
|
|
252
|
-
return this.updatePreviewGuide(e);
|
|
253
183
|
default:
|
|
254
184
|
return;
|
|
255
185
|
}
|
|
@@ -266,28 +196,6 @@ class z {
|
|
|
266
196
|
};
|
|
267
197
|
});
|
|
268
198
|
}
|
|
269
|
-
exitDebugMode() {
|
|
270
|
-
this.knock.log("[Guide] Exiting debug mode");
|
|
271
|
-
const e = p();
|
|
272
|
-
if (e != null && e.localStorage)
|
|
273
|
-
try {
|
|
274
|
-
e.localStorage.removeItem(y);
|
|
275
|
-
} catch {
|
|
276
|
-
}
|
|
277
|
-
if (this.store.setState((s) => ({
|
|
278
|
-
...s,
|
|
279
|
-
debug: {
|
|
280
|
-
forcedGuideKey: null,
|
|
281
|
-
previewSessionId: null,
|
|
282
|
-
focusedGuideKeys: {}
|
|
283
|
-
},
|
|
284
|
-
previewGuides: {}
|
|
285
|
-
// Clear preview guides when exiting debug mode
|
|
286
|
-
})), e != null && e.location) {
|
|
287
|
-
const s = new URL(e.location.href);
|
|
288
|
-
(s.searchParams.has(f.GUIDE_KEY) || s.searchParams.has(f.PREVIEW_SESSION_ID)) && (s.searchParams.delete(f.GUIDE_KEY), s.searchParams.delete(f.PREVIEW_SESSION_ID), e.location.href = s.toString());
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
199
|
setDebug(e) {
|
|
292
200
|
var t;
|
|
293
201
|
if (this.knock.log("[Guide] .setDebug()"), !this.knock.isAuthenticated()) {
|
|
@@ -326,7 +234,7 @@ class z {
|
|
|
326
234
|
selectGuides(e, s = {}, t = {}) {
|
|
327
235
|
var c;
|
|
328
236
|
this.knock.log(
|
|
329
|
-
`[Guide] .selectGuides (filters: ${
|
|
237
|
+
`[Guide] .selectGuides (filters: ${G(s)}; state: ${S(e)})`
|
|
330
238
|
);
|
|
331
239
|
const i = this.selectGuide(e, s, {
|
|
332
240
|
...t,
|
|
@@ -335,75 +243,75 @@ class z {
|
|
|
335
243
|
}), { recordSelectQuery: r = !!((c = e.debug) != null && c.debugging) } = t, n = {
|
|
336
244
|
limit: "all",
|
|
337
245
|
opts: { ...t, recordSelectQuery: r }
|
|
338
|
-
},
|
|
339
|
-
if (this.maybeRecordSelectResult(
|
|
246
|
+
}, a = v(e, s, n);
|
|
247
|
+
if (this.maybeRecordSelectResult(a), !i && !t.includeThrottled)
|
|
340
248
|
return [];
|
|
341
|
-
const o = [...
|
|
342
|
-
if (!t.includeThrottled &&
|
|
249
|
+
const o = [...a.values()];
|
|
250
|
+
if (!t.includeThrottled && b(e)) {
|
|
343
251
|
const d = o.filter(
|
|
344
|
-
(
|
|
345
|
-
),
|
|
252
|
+
(k) => k.bypass_global_group_limit
|
|
253
|
+
), l = o.length - d.length;
|
|
346
254
|
return this.knock.log(
|
|
347
|
-
`[Guide] Throttling ${
|
|
255
|
+
`[Guide] Throttling ${l} guides from selection, and returning ${d.length} guides`
|
|
348
256
|
), d;
|
|
349
257
|
}
|
|
350
258
|
return this.knock.log(`[Guide] Returning ${o.length} guides from selection`), o;
|
|
351
259
|
}
|
|
352
260
|
selectGuide(e, s = {}, t = {}) {
|
|
353
|
-
var
|
|
261
|
+
var l, k, m;
|
|
354
262
|
if (this.knock.log(
|
|
355
|
-
`[Guide] .selectGuide (filters: ${
|
|
263
|
+
`[Guide] .selectGuide (filters: ${G(s)}; state: ${S(e)})`
|
|
356
264
|
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0) {
|
|
357
265
|
this.knock.log("[Guide] Exiting selection (no guides)");
|
|
358
266
|
return;
|
|
359
267
|
}
|
|
360
268
|
this.stage || (this.stage = this.openGroupStage());
|
|
361
|
-
const { recordSelectQuery: i = !!((
|
|
269
|
+
const { recordSelectQuery: i = !!((l = e.debug) != null && l.debugging) } = t, r = {
|
|
362
270
|
limit: "one",
|
|
363
271
|
opts: { ...t, recordSelectQuery: i }
|
|
364
|
-
}, n =
|
|
272
|
+
}, n = v(e, s, r);
|
|
365
273
|
if (this.maybeRecordSelectResult(n), n.size === 0) {
|
|
366
274
|
this.knock.log("[Guide] Selection found zero result");
|
|
367
275
|
return;
|
|
368
276
|
}
|
|
369
|
-
const [
|
|
277
|
+
const [a, o] = [...n][0];
|
|
370
278
|
if (this.knock.log(
|
|
371
279
|
`[Guide] Selection found: \`${o.key}\` (total: ${n.size})`
|
|
372
280
|
), o.bypass_global_group_limit)
|
|
373
281
|
return this.knock.log(`[Guide] Returning the unthrottled guide: ${o.key}`), o;
|
|
374
|
-
const c = (
|
|
282
|
+
const c = (m = (k = e.debug) == null ? void 0 : k.focusedGuideKeys) == null ? void 0 : m[o.key], d = !t.includeThrottled && b(e);
|
|
375
283
|
switch (this.stage.status) {
|
|
376
284
|
case "open": {
|
|
377
|
-
this.knock.log(`[Guide] Adding to the group stage: ${o.key}`), this.stage.ordered[
|
|
285
|
+
this.knock.log(`[Guide] Adding to the group stage: ${o.key}`), this.stage.ordered[a] = o.key;
|
|
378
286
|
return;
|
|
379
287
|
}
|
|
380
288
|
case "patch": {
|
|
381
|
-
if (this.knock.log(`[Guide] Patching the group stage: ${o.key}`), this.stage.ordered[
|
|
289
|
+
if (this.knock.log(`[Guide] Patching the group stage: ${o.key}`), this.stage.ordered[a] = o.key, c)
|
|
382
290
|
return this.knock.log(
|
|
383
|
-
`[Guide] Focused to return \`${o.key}\` (stage: ${
|
|
291
|
+
`[Guide] Focused to return \`${o.key}\` (stage: ${p(this.stage)})`
|
|
384
292
|
), o;
|
|
385
293
|
if (d) {
|
|
386
294
|
this.knock.log(`[Guide] Throttling the selected guide: ${o.key}`);
|
|
387
295
|
return;
|
|
388
296
|
}
|
|
389
|
-
const
|
|
297
|
+
const g = this.stage.resolved === o.key ? o : void 0;
|
|
390
298
|
return this.knock.log(
|
|
391
|
-
`[Guide] Returning \`${
|
|
392
|
-
),
|
|
299
|
+
`[Guide] Returning \`${g == null ? void 0 : g.key}\` (stage: ${p(this.stage)})`
|
|
300
|
+
), g;
|
|
393
301
|
}
|
|
394
302
|
case "closed": {
|
|
395
303
|
if (c)
|
|
396
304
|
return this.knock.log(
|
|
397
|
-
`[Guide] Focused to return \`${o.key}\` (stage: ${
|
|
305
|
+
`[Guide] Focused to return \`${o.key}\` (stage: ${p(this.stage)})`
|
|
398
306
|
), o;
|
|
399
307
|
if (d) {
|
|
400
308
|
this.knock.log(`[Guide] Throttling the selected guide: ${o.key}`);
|
|
401
309
|
return;
|
|
402
310
|
}
|
|
403
|
-
const
|
|
311
|
+
const g = this.stage.resolved === o.key ? o : void 0;
|
|
404
312
|
return this.knock.log(
|
|
405
|
-
`[Guide] Returning \`${
|
|
406
|
-
),
|
|
313
|
+
`[Guide] Returning \`${g == null ? void 0 : g.key}\` (stage: ${p(this.stage)})`
|
|
314
|
+
), g;
|
|
407
315
|
}
|
|
408
316
|
}
|
|
409
317
|
}
|
|
@@ -413,18 +321,18 @@ class z {
|
|
|
413
321
|
if (!e.metadata) return;
|
|
414
322
|
const { opts: s, filters: t, limit: i } = e.metadata;
|
|
415
323
|
if (!s.recordSelectQuery || !t.key && !t.type || !this.stage || this.stage.status === "closed") return;
|
|
416
|
-
const r = this.stage.results.
|
|
324
|
+
const r = this.stage.results.byKey || {};
|
|
417
325
|
t.key && (r[t.key] = {
|
|
418
326
|
...r[t.key] || {},
|
|
419
327
|
[i]: e
|
|
420
328
|
});
|
|
421
|
-
const n = this.stage.results.
|
|
329
|
+
const n = this.stage.results.byType || {};
|
|
422
330
|
t.type && (n[t.type] = {
|
|
423
331
|
...n[t.type] || {},
|
|
424
332
|
[i]: e
|
|
425
333
|
}), this.stage = {
|
|
426
334
|
...this.stage,
|
|
427
|
-
results: {
|
|
335
|
+
results: { byKey: r, byType: n }
|
|
428
336
|
};
|
|
429
337
|
}
|
|
430
338
|
getStage() {
|
|
@@ -433,7 +341,7 @@ class z {
|
|
|
433
341
|
openGroupStage() {
|
|
434
342
|
this.knock.log("[Guide] Opening a new group stage");
|
|
435
343
|
const {
|
|
436
|
-
orderResolutionDuration: e =
|
|
344
|
+
orderResolutionDuration: e = D
|
|
437
345
|
} = this.options, s = setTimeout(() => {
|
|
438
346
|
this.closePendingGroupStage(), this.incrementCounter();
|
|
439
347
|
}, e);
|
|
@@ -582,7 +490,7 @@ class z {
|
|
|
582
490
|
// Get the next unarchived step.
|
|
583
491
|
getStep() {
|
|
584
492
|
var i, r, n;
|
|
585
|
-
return ((i = s.store.state.debug) == null ? void 0 : i.forcedGuideKey) === this.key || (n = (r = s.store.state.debug) == null ? void 0 : r.focusedGuideKeys) != null && n[this.key] ? this.steps[0] : this.steps.find((
|
|
493
|
+
return ((i = s.store.state.debug) == null ? void 0 : i.forcedGuideKey) === this.key || (n = (r = s.store.state.debug) == null ? void 0 : r.focusedGuideKeys) != null && n[this.key] ? this.steps[0] : this.steps.find((a) => !a.message.archived_at);
|
|
586
494
|
},
|
|
587
495
|
// Check whether any of its steps have an engagement timestamp.
|
|
588
496
|
hasEngagement() {
|
|
@@ -598,8 +506,8 @@ class z {
|
|
|
598
506
|
markAsSeen() {
|
|
599
507
|
return s.markAsSeen(t, this);
|
|
600
508
|
},
|
|
601
|
-
markAsInteracted({ metadata:
|
|
602
|
-
return s.markAsInteracted(t, this,
|
|
509
|
+
markAsInteracted({ metadata: a } = {}) {
|
|
510
|
+
return s.markAsInteracted(t, this, a);
|
|
603
511
|
},
|
|
604
512
|
markAsArchived() {
|
|
605
513
|
return s.markAsArchived(t, this);
|
|
@@ -630,7 +538,7 @@ class z {
|
|
|
630
538
|
formatQueryKey(e) {
|
|
631
539
|
const t = Object.keys(e).sort().map(
|
|
632
540
|
(r) => `${encodeURIComponent(r)}=${encodeURIComponent(e[r])}`
|
|
633
|
-
).join("&"), i =
|
|
541
|
+
).join("&"), i = U(this.knock.userId);
|
|
634
542
|
return t ? `${i}?${t}` : i;
|
|
635
543
|
}
|
|
636
544
|
setStepMessageAttrs(e, s, t) {
|
|
@@ -638,11 +546,11 @@ class z {
|
|
|
638
546
|
return t.archived_at && this.clearGroupStage(), this.store.setState((r) => {
|
|
639
547
|
let n = r.guides[e];
|
|
640
548
|
if (!n) return r;
|
|
641
|
-
const
|
|
642
|
-
n = i ? { ...n, steps:
|
|
549
|
+
const a = n.steps.map((d) => (d.ref !== s || (d.message = { ...d.message, ...t }, i = d), d));
|
|
550
|
+
n = i ? { ...n, steps: a } : n;
|
|
643
551
|
const o = { ...r.guides, [n.key]: n }, c = t.archived_at && !n.bypass_global_group_limit ? {
|
|
644
552
|
...r.guideGroupDisplayLogs,
|
|
645
|
-
[
|
|
553
|
+
[R]: t.archived_at
|
|
646
554
|
} : r.guideGroupDisplayLogs;
|
|
647
555
|
return { ...r, guides: o, guideGroupDisplayLogs: c };
|
|
648
556
|
}), i;
|
|
@@ -677,31 +585,19 @@ class z {
|
|
|
677
585
|
this.patchClosedGroupStage(), this.store.setState((s) => {
|
|
678
586
|
const t = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [], r = e.guide_group.display_sequence_throttled || [];
|
|
679
587
|
let n = s.guides;
|
|
680
|
-
return n = i.reduce((
|
|
681
|
-
if (!
|
|
682
|
-
const c = { ...
|
|
683
|
-
return { ...
|
|
684
|
-
}, n), n = r.reduce((
|
|
685
|
-
if (!
|
|
686
|
-
const c = { ...
|
|
687
|
-
return { ...
|
|
588
|
+
return n = i.reduce((a, o) => {
|
|
589
|
+
if (!a[o]) return a;
|
|
590
|
+
const c = { ...a[o], bypass_global_group_limit: !0 };
|
|
591
|
+
return { ...a, [o]: c };
|
|
592
|
+
}, n), n = r.reduce((a, o) => {
|
|
593
|
+
if (!a[o]) return a;
|
|
594
|
+
const c = { ...a[o], bypass_global_group_limit: !1 };
|
|
595
|
+
return { ...a, [o]: c };
|
|
688
596
|
}, n), { ...s, guides: n, guideGroups: t };
|
|
689
597
|
});
|
|
690
598
|
}
|
|
691
|
-
updatePreviewGuide({ data: e }) {
|
|
692
|
-
const s = this.localCopy(e.guide);
|
|
693
|
-
this.store.setState((t) => {
|
|
694
|
-
const i = { ...t.previewGuides, [s.key]: s };
|
|
695
|
-
return { ...t, previewGuides: i };
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
// Returns whether debug params have changed. For guide key, we only check
|
|
699
|
-
// presence since the exact value has no impact on fetch/subscribe
|
|
700
|
-
checkDebugStateChanged(e, s) {
|
|
701
|
-
return !!e.forcedGuideKey != !!s.forcedGuideKey || e.previewSessionId !== s.previewSessionId;
|
|
702
|
-
}
|
|
703
599
|
listenForLocationChangesFromWindow() {
|
|
704
|
-
const e =
|
|
600
|
+
const e = f();
|
|
705
601
|
if (e != null && e.history && (e != null && e.addEventListener)) {
|
|
706
602
|
e.addEventListener("popstate", this.handleLocationChange), e.addEventListener("hashchange", this.handleLocationChange);
|
|
707
603
|
const s = e.history.pushState, t = e.history.replaceState;
|
|
@@ -724,17 +620,16 @@ class z {
|
|
|
724
620
|
);
|
|
725
621
|
}
|
|
726
622
|
removeLocationChangeEventListeners() {
|
|
727
|
-
const e =
|
|
623
|
+
const e = f();
|
|
728
624
|
!(e != null && e.history) || !(e != null && e.removeEventListener) || (e.removeEventListener("popstate", this.handleLocationChange), e.removeEventListener("hashchange", this.handleLocationChange), this.pushStateFn && (e.history.pushState = this.pushStateFn, this.pushStateFn = void 0), this.replaceStateFn && (e.history.replaceState = this.replaceStateFn, this.replaceStateFn = void 0));
|
|
729
625
|
}
|
|
730
626
|
static getToolbarRunConfigFromUrl() {
|
|
731
|
-
return
|
|
627
|
+
return T();
|
|
732
628
|
}
|
|
733
629
|
}
|
|
734
630
|
export {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
j as guidesApiRootPath
|
|
631
|
+
J as KnockGuideClient,
|
|
632
|
+
j as checkActivatable,
|
|
633
|
+
U as guidesApiRootPath
|
|
739
634
|
};
|
|
740
635
|
//# sourceMappingURL=client.mjs.map
|