@knocklabs/client 0.19.4 → 0.20.1
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/helpers.js +1 -1
- package/dist/cjs/clients/guide/helpers.js.map +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/clients/guide/client.mjs +162 -155
- package/dist/esm/clients/guide/client.mjs.map +1 -1
- package/dist/esm/clients/guide/helpers.mjs +49 -43
- package/dist/esm/clients/guide/helpers.mjs.map +1 -1
- package/dist/types/clients/guide/client.d.ts +4 -3
- package/dist/types/clients/guide/client.d.ts.map +1 -1
- package/dist/types/clients/guide/helpers.d.ts +1 -1
- package/dist/types/clients/guide/helpers.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 -0
- package/dist/types/clients/guide/types.d.ts.map +1 -1
- package/dist/types/clients/preferences/interfaces.d.ts +4 -4
- package/dist/types/clients/preferences/interfaces.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/guide/client.ts +48 -37
- package/src/clients/guide/helpers.ts +21 -1
- package/src/clients/guide/index.ts +2 -0
- package/src/clients/guide/types.ts +6 -0
- package/src/clients/preferences/interfaces.ts +4 -4
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (
|
|
4
|
-
import { Store as
|
|
5
|
-
import { URLPattern as
|
|
6
|
-
import { byKey as
|
|
7
|
-
const
|
|
1
|
+
var _ = Object.defineProperty;
|
|
2
|
+
var b = (u, e, t) => e in u ? _(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
|
|
3
|
+
var d = (u, e, t) => b(u, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { Store as I } from "@tanstack/store";
|
|
5
|
+
import { URLPattern as C } from "urlpattern-polyfill";
|
|
6
|
+
import { byKey as E, mockDefaultGroup as w, formatFilters as k, formatState as f, checkStateIfThrottled as G, formatGroupStage as S, DEFAULT_GROUP_KEY as R, SelectionResult as P, findDefaultGroup as A, newUrl as D, predicateUrlRules as K, predicateUrlPatterns as L } from "./helpers.mjs";
|
|
7
|
+
const $ = 50, T = 30 * 1e3, O = 3, g = {
|
|
8
8
|
GUIDE_KEY: "knock_guide_key",
|
|
9
9
|
PREVIEW_SESSION_ID: "knock_preview_session_id"
|
|
10
10
|
}, p = "knock_guide_debug", l = () => {
|
|
11
11
|
if (typeof window < "u")
|
|
12
12
|
return window;
|
|
13
|
-
}, U = (
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
13
|
+
}, U = (u) => `/v1/users/${u}/guides`, y = () => {
|
|
14
|
+
const u = l();
|
|
15
|
+
if (!u)
|
|
16
16
|
return { forcedGuideKey: null, previewSessionId: null };
|
|
17
|
-
const e = new URLSearchParams(
|
|
17
|
+
const e = new URLSearchParams(u.location.search), t = e.get(g.GUIDE_KEY), s = e.get(
|
|
18
18
|
g.PREVIEW_SESSION_ID
|
|
19
19
|
);
|
|
20
20
|
if (t || s) {
|
|
21
|
-
if (
|
|
21
|
+
if (u.localStorage)
|
|
22
22
|
try {
|
|
23
|
-
const
|
|
23
|
+
const i = {
|
|
24
24
|
forcedGuideKey: t,
|
|
25
25
|
previewSessionId: s
|
|
26
26
|
};
|
|
27
|
-
|
|
27
|
+
u.localStorage.setItem(p, JSON.stringify(i));
|
|
28
28
|
} catch {
|
|
29
29
|
}
|
|
30
30
|
return {
|
|
@@ -32,23 +32,23 @@ const O = 50, $ = 30 * 1e3, T = 3, g = {
|
|
|
32
32
|
previewSessionId: s
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
let
|
|
36
|
-
if (
|
|
35
|
+
let r = null, n = null;
|
|
36
|
+
if (u.localStorage)
|
|
37
37
|
try {
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
const o = F(
|
|
41
|
-
|
|
38
|
+
const i = u.localStorage.getItem(p);
|
|
39
|
+
if (i) {
|
|
40
|
+
const o = F(i);
|
|
41
|
+
r = o.forcedGuideKey, n = o.previewSessionId;
|
|
42
42
|
}
|
|
43
43
|
} catch {
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
|
-
forcedGuideKey:
|
|
46
|
+
forcedGuideKey: r,
|
|
47
47
|
previewSessionId: n
|
|
48
48
|
};
|
|
49
|
-
}, F = (
|
|
49
|
+
}, F = (u) => {
|
|
50
50
|
try {
|
|
51
|
-
const e = JSON.parse(
|
|
51
|
+
const e = JSON.parse(u);
|
|
52
52
|
return {
|
|
53
53
|
forcedGuideKey: (e == null ? void 0 : e.forcedGuideKey) ?? null,
|
|
54
54
|
previewSessionId: (e == null ? void 0 : e.previewSessionId) ?? null
|
|
@@ -59,39 +59,39 @@ const O = 50, $ = 30 * 1e3, T = 3, g = {
|
|
|
59
59
|
previewSessionId: null
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
}, m = (
|
|
63
|
-
const t = new
|
|
62
|
+
}, m = (u, e = {}) => {
|
|
63
|
+
const t = new P(), s = A(u.guideGroups);
|
|
64
64
|
if (!s) return t;
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
for (const [
|
|
71
|
-
let
|
|
72
|
-
|
|
65
|
+
const r = [...s.display_sequence], n = u.location;
|
|
66
|
+
if (u.debug.forcedGuideKey) {
|
|
67
|
+
const i = r.indexOf(u.debug.forcedGuideKey);
|
|
68
|
+
i > -1 && r.splice(i, 1), r.unshift(u.debug.forcedGuideKey);
|
|
69
|
+
}
|
|
70
|
+
for (const [i, o] of r.entries()) {
|
|
71
|
+
let a = u.guides[o];
|
|
72
|
+
u.debug.forcedGuideKey === o && u.previewGuides[o] && (a = u.previewGuides[o]), !(!a || !N(a, {
|
|
73
73
|
location: n,
|
|
74
74
|
filters: e,
|
|
75
|
-
debug:
|
|
76
|
-
})) && t.set(
|
|
75
|
+
debug: u.debug
|
|
76
|
+
})) && t.set(i, a);
|
|
77
77
|
}
|
|
78
78
|
return t.metadata = { guideGroup: s }, t;
|
|
79
|
-
}, N = (
|
|
80
|
-
if (t.type && t.type !==
|
|
79
|
+
}, N = (u, { location: e, filters: t = {}, debug: s = {} }) => {
|
|
80
|
+
if (t.type && t.type !== u.type || t.key && t.key !== u.key)
|
|
81
81
|
return !1;
|
|
82
|
-
if (s.forcedGuideKey ===
|
|
82
|
+
if (s.forcedGuideKey === u.key)
|
|
83
83
|
return !0;
|
|
84
|
-
if (!
|
|
84
|
+
if (!u.active || u.steps.every((o) => !!o.message.archived_at))
|
|
85
85
|
return !1;
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
if (!K(
|
|
89
|
-
} else if (
|
|
86
|
+
const r = e ? D(e) : void 0, n = u.activation_url_rules || [], i = u.activation_url_patterns || [];
|
|
87
|
+
if (r && n.length > 0) {
|
|
88
|
+
if (!K(r, n)) return !1;
|
|
89
|
+
} else if (r && i.length > 0 && !L(r, i))
|
|
90
90
|
return !1;
|
|
91
91
|
return !0;
|
|
92
92
|
};
|
|
93
93
|
class B {
|
|
94
|
-
constructor(e, t, s = {},
|
|
94
|
+
constructor(e, t, s = {}, r = {}) {
|
|
95
95
|
d(this, "store");
|
|
96
96
|
// Phoenix channels for real time guide updates over websocket
|
|
97
97
|
d(this, "socket");
|
|
@@ -122,32 +122,32 @@ class B {
|
|
|
122
122
|
const t = e.location.href;
|
|
123
123
|
if (this.store.state.location === t) return;
|
|
124
124
|
this.knock.log(`[Guide] Detected a location change: ${t}`);
|
|
125
|
-
const s = this.store.state.debug,
|
|
126
|
-
this.setLocation(t, { debug:
|
|
125
|
+
const s = this.store.state.debug, r = y();
|
|
126
|
+
this.setLocation(t, { debug: r }), this.checkDebugStateChanged(
|
|
127
127
|
s,
|
|
128
|
-
|
|
128
|
+
r
|
|
129
129
|
) && (this.knock.log(
|
|
130
130
|
"[Guide] Debug state changed, refetching guides and resubscribing to the websocket channel"
|
|
131
131
|
), this.fetch(), this.subscribe());
|
|
132
132
|
});
|
|
133
|
-
this.knock = e, this.channelId = t, this.targetParams = s, this.options =
|
|
133
|
+
this.knock = e, this.channelId = t, this.targetParams = s, this.options = r;
|
|
134
134
|
const {
|
|
135
135
|
trackLocationFromWindow: n = !0,
|
|
136
|
-
throttleCheckInterval:
|
|
137
|
-
} =
|
|
138
|
-
this.store = new
|
|
136
|
+
throttleCheckInterval: i = T
|
|
137
|
+
} = r, o = l(), a = n ? o == null ? void 0 : o.location.href : void 0, h = y();
|
|
138
|
+
this.store = new I({
|
|
139
139
|
guideGroups: [],
|
|
140
140
|
guideGroupDisplayLogs: {},
|
|
141
141
|
guides: {},
|
|
142
142
|
previewGuides: {},
|
|
143
143
|
queries: {},
|
|
144
|
-
location:
|
|
144
|
+
location: a,
|
|
145
145
|
// Increment to update the state store and trigger re-selection.
|
|
146
146
|
counter: 0,
|
|
147
147
|
debug: h
|
|
148
148
|
});
|
|
149
149
|
const { socket: c } = this.knock.client();
|
|
150
|
-
this.socket = c, this.socketChannelTopic = `guides:${t}`, n && this.listenForLocationChangesFromWindow(),
|
|
150
|
+
this.socket = c, this.socketChannelTopic = `guides:${t}`, n && this.listenForLocationChangesFromWindow(), i && this.startCounterInterval(i), this.knock.log("[Guide] Initialized a guide client");
|
|
151
151
|
}
|
|
152
152
|
incrementCounter() {
|
|
153
153
|
this.knock.log("[Guide] Incrementing the counter"), this.store.setState((e) => ({ ...e, counter: e.counter + 1 }));
|
|
@@ -165,28 +165,28 @@ class B {
|
|
|
165
165
|
}
|
|
166
166
|
async fetch(e) {
|
|
167
167
|
this.knock.log("[Guide] .fetch"), this.knock.failIfNotAuthenticated();
|
|
168
|
-
const t = this.buildQueryParams(e == null ? void 0 : e.filters), s = this.formatQueryKey(t),
|
|
169
|
-
if (
|
|
170
|
-
return
|
|
171
|
-
this.store.setState((
|
|
172
|
-
...
|
|
173
|
-
queries: { ...
|
|
168
|
+
const t = this.buildQueryParams(e == null ? void 0 : e.filters), s = this.formatQueryKey(t), r = this.store.state.queries[s];
|
|
169
|
+
if (r)
|
|
170
|
+
return r;
|
|
171
|
+
this.store.setState((i) => ({
|
|
172
|
+
...i,
|
|
173
|
+
queries: { ...i.queries, [s]: { status: "loading" } }
|
|
174
174
|
}));
|
|
175
175
|
let n;
|
|
176
176
|
try {
|
|
177
177
|
this.knock.log("[Guide] Fetching all eligible guides");
|
|
178
|
-
const
|
|
178
|
+
const i = await this.knock.user.getGuides(this.channelId, t);
|
|
179
179
|
n = { status: "ok" };
|
|
180
|
-
const { entries: o, guide_groups:
|
|
180
|
+
const { entries: o, guide_groups: a, guide_group_display_logs: h } = i;
|
|
181
181
|
this.knock.log("[Guide] Loading fetched guides"), this.store.setState((c) => ({
|
|
182
182
|
...c,
|
|
183
|
-
guideGroups: (
|
|
183
|
+
guideGroups: (a == null ? void 0 : a.length) > 0 ? a : [w(o)],
|
|
184
184
|
guideGroupDisplayLogs: h || {},
|
|
185
|
-
guides:
|
|
185
|
+
guides: E(o.map((v) => this.localCopy(v))),
|
|
186
186
|
queries: { ...c.queries, [s]: n }
|
|
187
187
|
}));
|
|
188
|
-
} catch (
|
|
189
|
-
n = { status: "error", error:
|
|
188
|
+
} catch (i) {
|
|
189
|
+
n = { status: "error", error: i }, this.store.setState((o) => ({
|
|
190
190
|
...o,
|
|
191
191
|
queries: { ...o.queries, [s]: n }
|
|
192
192
|
}));
|
|
@@ -202,20 +202,20 @@ class B {
|
|
|
202
202
|
force_all_guides: e.forcedGuideKey ? !0 : void 0,
|
|
203
203
|
preview_session_id: e.previewSessionId || void 0
|
|
204
204
|
}, s = this.socket.channel(this.socketChannelTopic, t);
|
|
205
|
-
for (const
|
|
206
|
-
s.on(
|
|
205
|
+
for (const r of this.socketEventTypes)
|
|
206
|
+
s.on(r, (n) => this.handleSocketEvent(n));
|
|
207
207
|
["closed", "errored"].includes(s.state) && (this.subscribeRetryCount = 0, s.join().receive("ok", () => {
|
|
208
208
|
this.knock.log("[Guide] Successfully joined channel");
|
|
209
|
-
}).receive("error", (
|
|
209
|
+
}).receive("error", (r) => {
|
|
210
210
|
this.knock.log(
|
|
211
|
-
`[Guide] Failed to join channel: ${JSON.stringify(
|
|
211
|
+
`[Guide] Failed to join channel: ${JSON.stringify(r)}`
|
|
212
212
|
), this.handleChannelJoinError();
|
|
213
213
|
}).receive("timeout", () => {
|
|
214
214
|
this.knock.log("[Guide] Channel join timed out"), this.handleChannelJoinError();
|
|
215
215
|
})), this.socketChannel = s;
|
|
216
216
|
}
|
|
217
217
|
handleChannelJoinError() {
|
|
218
|
-
if (this.subscribeRetryCount >=
|
|
218
|
+
if (this.subscribeRetryCount >= O) {
|
|
219
219
|
this.knock.log(
|
|
220
220
|
`[Guide] Channel join max retry limit reached: ${this.subscribeRetryCount}`
|
|
221
221
|
), this.unsubscribe();
|
|
@@ -252,11 +252,11 @@ class B {
|
|
|
252
252
|
setLocation(e, t = {}) {
|
|
253
253
|
this.knock.log(`[Guide] .setLocation (loc=${e})`), this.clearGroupStage(), this.knock.log("[Guide] Updating the tracked location"), this.store.setState((s) => {
|
|
254
254
|
var n;
|
|
255
|
-
const
|
|
255
|
+
const r = (n = t == null ? void 0 : t.debug) != null && n.previewSessionId ? s.previewGuides : {};
|
|
256
256
|
return {
|
|
257
257
|
...s,
|
|
258
258
|
...t,
|
|
259
|
-
previewGuides:
|
|
259
|
+
previewGuides: r,
|
|
260
260
|
location: e
|
|
261
261
|
};
|
|
262
262
|
});
|
|
@@ -282,63 +282,67 @@ class B {
|
|
|
282
282
|
//
|
|
283
283
|
// Store selector
|
|
284
284
|
//
|
|
285
|
-
selectGuides(e, t = {}) {
|
|
285
|
+
selectGuides(e, t = {}, s = {}) {
|
|
286
286
|
if (this.knock.log(
|
|
287
287
|
`[Guide] .selectGuides (filters: ${k(t)}; state: ${f(e)})`
|
|
288
|
-
),
|
|
289
|
-
return
|
|
290
|
-
const
|
|
291
|
-
|
|
288
|
+
), !this.selectGuide(e, t, s))
|
|
289
|
+
return [];
|
|
290
|
+
const n = [...m(e, t).values()];
|
|
291
|
+
if (!s.includeThrottled && G(e)) {
|
|
292
|
+
const i = n.filter(
|
|
293
|
+
(a) => a.bypass_global_group_limit
|
|
294
|
+
), o = n.length - i.length;
|
|
295
|
+
return this.knock.log(
|
|
296
|
+
`[Guide] Throttling ${o} guides from selection, and returning ${i.length} guides`
|
|
297
|
+
), i;
|
|
298
|
+
}
|
|
299
|
+
return this.knock.log(`[Guide] Returning ${n.length} guides from selection`), n;
|
|
292
300
|
}
|
|
293
|
-
selectGuide(e, t = {}) {
|
|
301
|
+
selectGuide(e, t = {}, s = {}) {
|
|
294
302
|
if (this.knock.log(
|
|
295
303
|
`[Guide] .selectGuide (filters: ${k(t)}; state: ${f(e)})`
|
|
296
304
|
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0) {
|
|
297
305
|
this.knock.log("[Guide] Exiting selection (no guides)");
|
|
298
306
|
return;
|
|
299
307
|
}
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
308
|
+
const r = m(e, t);
|
|
309
|
+
if (r.size === 0) {
|
|
302
310
|
this.knock.log("[Guide] Selection found zero result");
|
|
303
311
|
return;
|
|
304
312
|
}
|
|
305
|
-
const [
|
|
313
|
+
const [n, i] = [...r][0];
|
|
306
314
|
if (this.knock.log(
|
|
307
|
-
`[Guide] Selection found: \`${
|
|
308
|
-
),
|
|
309
|
-
return this.knock.log(`[Guide] Returning the unthrottled guide: ${
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
o,
|
|
313
|
-
r.display_interval
|
|
314
|
-
)) {
|
|
315
|
-
this.knock.log(`[Guide] Throttling the selected guide: ${n.key}`);
|
|
315
|
+
`[Guide] Selection found: \`${i.key}\` (total: ${r.size})`
|
|
316
|
+
), i.bypass_global_group_limit)
|
|
317
|
+
return this.knock.log(`[Guide] Returning the unthrottled guide: ${i.key}`), i;
|
|
318
|
+
if (!s.includeThrottled && G(e)) {
|
|
319
|
+
this.knock.log(`[Guide] Throttling the selected guide: ${i.key}`);
|
|
316
320
|
return;
|
|
317
321
|
}
|
|
318
322
|
switch (this.stage || (this.stage = this.openGroupStage()), this.stage.status) {
|
|
319
323
|
case "open": {
|
|
320
|
-
this.knock.log(`[Guide] Adding to the group stage: ${
|
|
324
|
+
this.knock.log(`[Guide] Adding to the group stage: ${i.key}`), this.stage.ordered[n] = i.key;
|
|
321
325
|
return;
|
|
322
326
|
}
|
|
323
327
|
case "patch": {
|
|
324
|
-
this.knock.log(`[Guide] Patching the group stage: ${
|
|
325
|
-
const
|
|
328
|
+
this.knock.log(`[Guide] Patching the group stage: ${i.key}`), this.stage.ordered[n] = i.key;
|
|
329
|
+
const o = this.stage.resolved === i.key ? i : void 0;
|
|
326
330
|
return this.knock.log(
|
|
327
|
-
`[Guide] Returning \`${
|
|
328
|
-
),
|
|
331
|
+
`[Guide] Returning \`${o == null ? void 0 : o.key}\` (stage: ${S(this.stage)})`
|
|
332
|
+
), o;
|
|
329
333
|
}
|
|
330
334
|
case "closed": {
|
|
331
|
-
const
|
|
335
|
+
const o = this.stage.resolved === i.key ? i : void 0;
|
|
332
336
|
return this.knock.log(
|
|
333
|
-
`[Guide] Returning \`${
|
|
334
|
-
),
|
|
337
|
+
`[Guide] Returning \`${o == null ? void 0 : o.key}\` (stage: ${S(this.stage)})`
|
|
338
|
+
), o;
|
|
335
339
|
}
|
|
336
340
|
}
|
|
337
341
|
}
|
|
338
342
|
openGroupStage() {
|
|
339
343
|
this.knock.log("[Guide] Opening a new group stage");
|
|
340
344
|
const {
|
|
341
|
-
orderResolutionDuration: e =
|
|
345
|
+
orderResolutionDuration: e = $
|
|
342
346
|
} = this.options, t = setTimeout(() => {
|
|
343
347
|
this.closePendingGroupStage(), this.incrementCounter();
|
|
344
348
|
}, e);
|
|
@@ -390,10 +394,13 @@ class B {
|
|
|
390
394
|
var e;
|
|
391
395
|
(e = this.stage) != null && e.timeoutId && clearTimeout(this.stage.timeoutId);
|
|
392
396
|
}
|
|
393
|
-
// Test
|
|
394
|
-
//
|
|
395
|
-
_selectGuide(e, t = {}) {
|
|
396
|
-
return this.openGroupStage(), this.selectGuide(e, t), this.closePendingGroupStage(), this.selectGuide(e, t);
|
|
397
|
+
// Test helpers to open and close the group stage to return the select result
|
|
398
|
+
// immediately.
|
|
399
|
+
_selectGuide(e, t = {}, s = {}) {
|
|
400
|
+
return this.openGroupStage(), this.selectGuide(e, t, s), this.closePendingGroupStage(), this.selectGuide(e, t, s);
|
|
401
|
+
}
|
|
402
|
+
_selectGuides(e, t = {}, s = {}) {
|
|
403
|
+
return this.openGroupStage(), this.selectGuides(e, t, s), this.closePendingGroupStage(), this.selectGuides(e, t, s);
|
|
397
404
|
}
|
|
398
405
|
//
|
|
399
406
|
// Engagement event handlers
|
|
@@ -410,30 +417,30 @@ class B {
|
|
|
410
417
|
seen_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
411
418
|
});
|
|
412
419
|
if (!s) return;
|
|
413
|
-
const
|
|
420
|
+
const r = {
|
|
414
421
|
...this.buildEngagementEventBaseParams(e, s),
|
|
415
422
|
content: s.content,
|
|
416
423
|
data: this.targetParams.data
|
|
417
424
|
};
|
|
418
425
|
return this.knock.user.markGuideStepAs(
|
|
419
426
|
"seen",
|
|
420
|
-
|
|
427
|
+
r
|
|
421
428
|
), s;
|
|
422
429
|
}
|
|
423
430
|
async markAsInteracted(e, t, s) {
|
|
424
431
|
this.knock.log(
|
|
425
432
|
`[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${t.ref})`
|
|
426
433
|
);
|
|
427
|
-
const
|
|
428
|
-
read_at:
|
|
429
|
-
interacted_at:
|
|
434
|
+
const r = (/* @__PURE__ */ new Date()).toISOString(), n = this.setStepMessageAttrs(e.key, t.ref, {
|
|
435
|
+
read_at: r,
|
|
436
|
+
interacted_at: r
|
|
430
437
|
});
|
|
431
438
|
if (!n) return;
|
|
432
|
-
const
|
|
439
|
+
const i = {
|
|
433
440
|
...this.buildEngagementEventBaseParams(e, n),
|
|
434
441
|
metadata: s
|
|
435
442
|
};
|
|
436
|
-
return this.knock.user.markGuideStepAs("interacted",
|
|
443
|
+
return this.knock.user.markGuideStepAs("interacted", i), n;
|
|
437
444
|
}
|
|
438
445
|
async markAsArchived(e, t) {
|
|
439
446
|
if (t.message.archived_at) return;
|
|
@@ -444,11 +451,11 @@ class B {
|
|
|
444
451
|
archived_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
445
452
|
});
|
|
446
453
|
if (!s) return;
|
|
447
|
-
const
|
|
454
|
+
const r = this.buildEngagementEventBaseParams(e, s);
|
|
448
455
|
return this.knock.user.markGuideStepAs(
|
|
449
456
|
"archived",
|
|
450
457
|
{
|
|
451
|
-
...
|
|
458
|
+
...r,
|
|
452
459
|
unthrottled: e.bypass_global_group_limit
|
|
453
460
|
}
|
|
454
461
|
), s;
|
|
@@ -461,13 +468,13 @@ class B {
|
|
|
461
468
|
...e,
|
|
462
469
|
// Get the next unarchived step.
|
|
463
470
|
getStep() {
|
|
464
|
-
return t.store.state.debug.forcedGuideKey === this.key ? this.steps[0] : this.steps.find((
|
|
471
|
+
return t.store.state.debug.forcedGuideKey === this.key ? this.steps[0] : this.steps.find((r) => !r.message.archived_at);
|
|
465
472
|
}
|
|
466
473
|
};
|
|
467
|
-
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message:
|
|
468
|
-
const
|
|
474
|
+
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: r, ...n }) => {
|
|
475
|
+
const i = {
|
|
469
476
|
...n,
|
|
470
|
-
message: { ...
|
|
477
|
+
message: { ...r },
|
|
471
478
|
markAsSeen() {
|
|
472
479
|
if (!this.message.seen_at)
|
|
473
480
|
return t.markAsSeen(s, this);
|
|
@@ -480,10 +487,10 @@ class B {
|
|
|
480
487
|
return t.markAsArchived(s, this);
|
|
481
488
|
}
|
|
482
489
|
};
|
|
483
|
-
return
|
|
484
|
-
}), s.activation_url_patterns = e.activation_url_patterns.map((
|
|
485
|
-
...
|
|
486
|
-
pattern: new
|
|
490
|
+
return i.markAsSeen = i.markAsSeen.bind(i), i.markAsInteracted = i.markAsInteracted.bind(i), i.markAsArchived = i.markAsArchived.bind(i), i;
|
|
491
|
+
}), s.activation_url_patterns = e.activation_url_patterns.map((r) => ({
|
|
492
|
+
...r,
|
|
493
|
+
pattern: new C({ pathname: r.pathname })
|
|
487
494
|
})), s;
|
|
488
495
|
}
|
|
489
496
|
buildQueryParams(e = {}) {
|
|
@@ -492,32 +499,32 @@ class B {
|
|
|
492
499
|
...e
|
|
493
500
|
};
|
|
494
501
|
this.store.state.debug.forcedGuideKey && (t.force_all_guides = !0);
|
|
495
|
-
let
|
|
502
|
+
let r = Object.fromEntries(
|
|
496
503
|
Object.entries(t).filter(
|
|
497
|
-
([n,
|
|
504
|
+
([n, i]) => i != null
|
|
498
505
|
)
|
|
499
506
|
);
|
|
500
|
-
return
|
|
507
|
+
return r = r.data ? { ...r, data: JSON.stringify(r.data) } : r, r;
|
|
501
508
|
}
|
|
502
509
|
formatQueryKey(e) {
|
|
503
510
|
const s = Object.keys(e).sort().map(
|
|
504
511
|
(n) => `${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`
|
|
505
|
-
).join("&"),
|
|
506
|
-
return s ? `${
|
|
512
|
+
).join("&"), r = U(this.knock.userId);
|
|
513
|
+
return s ? `${r}?${s}` : r;
|
|
507
514
|
}
|
|
508
515
|
setStepMessageAttrs(e, t, s) {
|
|
509
|
-
let
|
|
516
|
+
let r;
|
|
510
517
|
return s.archived_at && this.clearGroupStage(), this.store.setState((n) => {
|
|
511
|
-
let
|
|
512
|
-
if (!
|
|
513
|
-
const o =
|
|
514
|
-
|
|
515
|
-
const
|
|
518
|
+
let i = n.guides[e];
|
|
519
|
+
if (!i) return n;
|
|
520
|
+
const o = i.steps.map((c) => (c.ref !== t || (c.message = { ...c.message, ...s }, r = c), c));
|
|
521
|
+
i = r ? { ...i, steps: o } : i;
|
|
522
|
+
const a = { ...n.guides, [i.key]: i }, h = s.archived_at && !i.bypass_global_group_limit ? {
|
|
516
523
|
...n.guideGroupDisplayLogs,
|
|
517
|
-
[
|
|
524
|
+
[R]: s.archived_at
|
|
518
525
|
} : n.guideGroupDisplayLogs;
|
|
519
|
-
return { ...n, guides:
|
|
520
|
-
}),
|
|
526
|
+
return { ...n, guides: a, guideGroupDisplayLogs: h };
|
|
527
|
+
}), r;
|
|
521
528
|
}
|
|
522
529
|
buildEngagementEventBaseParams(e, t) {
|
|
523
530
|
return {
|
|
@@ -533,38 +540,38 @@ class B {
|
|
|
533
540
|
this.patchClosedGroupStage();
|
|
534
541
|
const t = this.localCopy(e.guide);
|
|
535
542
|
this.store.setState((s) => {
|
|
536
|
-
const
|
|
537
|
-
return { ...s, guides:
|
|
543
|
+
const r = { ...s.guides, [t.key]: t };
|
|
544
|
+
return { ...s, guides: r };
|
|
538
545
|
});
|
|
539
546
|
}
|
|
540
547
|
removeGuide({ data: e }) {
|
|
541
548
|
this.patchClosedGroupStage(), this.store.setState((t) => {
|
|
542
|
-
const { [e.guide.key]: s, ...
|
|
543
|
-
return { ...t, guides:
|
|
549
|
+
const { [e.guide.key]: s, ...r } = t.guides;
|
|
550
|
+
return { ...t, guides: r };
|
|
544
551
|
});
|
|
545
552
|
}
|
|
546
553
|
addOrReplaceGuideGroup({
|
|
547
554
|
data: e
|
|
548
555
|
}) {
|
|
549
556
|
this.patchClosedGroupStage(), this.store.setState((t) => {
|
|
550
|
-
const s = [e.guide_group],
|
|
551
|
-
let
|
|
552
|
-
return
|
|
553
|
-
if (!o[
|
|
554
|
-
const h = { ...o[
|
|
555
|
-
return { ...o, [
|
|
556
|
-
},
|
|
557
|
-
if (!o[
|
|
558
|
-
const h = { ...o[
|
|
559
|
-
return { ...o, [
|
|
560
|
-
},
|
|
557
|
+
const s = [e.guide_group], r = e.guide_group.display_sequence_unthrottled || [], n = e.guide_group.display_sequence_throttled || [];
|
|
558
|
+
let i = t.guides;
|
|
559
|
+
return i = r.reduce((o, a) => {
|
|
560
|
+
if (!o[a]) return o;
|
|
561
|
+
const h = { ...o[a], bypass_global_group_limit: !0 };
|
|
562
|
+
return { ...o, [a]: h };
|
|
563
|
+
}, i), i = n.reduce((o, a) => {
|
|
564
|
+
if (!o[a]) return o;
|
|
565
|
+
const h = { ...o[a], bypass_global_group_limit: !1 };
|
|
566
|
+
return { ...o, [a]: h };
|
|
567
|
+
}, i), { ...t, guides: i, guideGroups: s };
|
|
561
568
|
});
|
|
562
569
|
}
|
|
563
570
|
updatePreviewGuide({ data: e }) {
|
|
564
571
|
const t = this.localCopy(e.guide);
|
|
565
572
|
this.store.setState((s) => {
|
|
566
|
-
const
|
|
567
|
-
return { ...s, previewGuides:
|
|
573
|
+
const r = { ...s.previewGuides, [t.key]: t };
|
|
574
|
+
return { ...s, previewGuides: r };
|
|
568
575
|
});
|
|
569
576
|
}
|
|
570
577
|
// Returns whether debug params have changed. For guide key, we only check
|
|
@@ -578,14 +585,14 @@ class B {
|
|
|
578
585
|
e.addEventListener("popstate", this.handleLocationChange), e.addEventListener("hashchange", this.handleLocationChange);
|
|
579
586
|
const t = e.history.pushState, s = e.history.replaceState;
|
|
580
587
|
e.history.pushState = new Proxy(t, {
|
|
581
|
-
apply: (
|
|
582
|
-
Reflect.apply(
|
|
588
|
+
apply: (r, n, i) => {
|
|
589
|
+
Reflect.apply(r, n, i), setTimeout(() => {
|
|
583
590
|
this.handleLocationChange();
|
|
584
591
|
}, 0);
|
|
585
592
|
}
|
|
586
593
|
}), e.history.replaceState = new Proxy(s, {
|
|
587
|
-
apply: (
|
|
588
|
-
Reflect.apply(
|
|
594
|
+
apply: (r, n, i) => {
|
|
595
|
+
Reflect.apply(r, n, i), setTimeout(() => {
|
|
589
596
|
this.handleLocationChange();
|
|
590
597
|
}, 0);
|
|
591
598
|
}
|