@knocklabs/client 0.17.2 → 0.18.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/cjs/knock.js +1 -1
- package/dist/cjs/knock.js.map +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/clients/guide/client.mjs +150 -130
- package/dist/esm/clients/guide/client.mjs.map +1 -1
- package/dist/esm/clients/guide/helpers.mjs +35 -33
- package/dist/esm/clients/guide/helpers.mjs.map +1 -1
- package/dist/esm/knock.mjs +54 -49
- package/dist/esm/knock.mjs.map +1 -1
- package/dist/types/clients/guide/client.d.ts.map +1 -1
- package/dist/types/clients/guide/helpers.d.ts +3 -1
- package/dist/types/clients/guide/helpers.d.ts.map +1 -1
- package/dist/types/interfaces.d.ts +1 -0
- package/dist/types/interfaces.d.ts.map +1 -1
- package/dist/types/knock.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/guide/client.ts +57 -22
- package/src/clients/guide/helpers.ts +10 -0
- package/src/interfaces.ts +1 -0
- package/src/knock.ts +11 -1
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (a, e, t) =>
|
|
4
|
-
import { Store as
|
|
5
|
-
import { URLPattern as
|
|
6
|
-
import { byKey as
|
|
7
|
-
const
|
|
1
|
+
var _ = Object.defineProperty;
|
|
2
|
+
var b = (a, e, t) => e in a ? _(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var d = (a, e, t) => b(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { Store as C } from "@tanstack/store";
|
|
5
|
+
import { URLPattern as I } from "urlpattern-polyfill";
|
|
6
|
+
import { byKey as w, mockDefaultGroup as E, formatFilters as g, formatState as p, findDefaultGroup as S, DEFAULT_GROUP_KEY as k, checkIfThrottled as R, formatGroupStage as f, SelectionResult as A, newUrl as L, predicateUrlRules as P, predicateUrlPatterns as $ } from "./helpers.mjs";
|
|
7
|
+
const D = 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
|
}, l = () => {
|
|
11
11
|
if (typeof window < "u")
|
|
12
12
|
return window;
|
|
13
|
-
},
|
|
13
|
+
}, K = (a) => `/v1/users/${a}/guides`, y = () => {
|
|
14
14
|
const a = l();
|
|
15
15
|
if (!a)
|
|
16
16
|
return { forcedGuideKey: null, previewSessionId: null };
|
|
17
|
-
const e = new URLSearchParams(a.location.search), t = e.get(
|
|
17
|
+
const e = new URLSearchParams(a.location.search), t = e.get(G.GUIDE_KEY), s = e.get(G.PREVIEW_SESSION_ID);
|
|
18
18
|
return { forcedGuideKey: t, previewSessionId: s };
|
|
19
|
-
},
|
|
20
|
-
const t = new
|
|
19
|
+
}, m = (a, e = {}) => {
|
|
20
|
+
const t = new A(), s = S(a.guideGroups);
|
|
21
21
|
if (!s) return t;
|
|
22
|
-
const i = [...s.display_sequence],
|
|
22
|
+
const i = [...s.display_sequence], r = a.location;
|
|
23
23
|
if (a.debug.forcedGuideKey) {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const n = i.indexOf(a.debug.forcedGuideKey);
|
|
25
|
+
n > -1 && i.splice(n, 1), i.unshift(a.debug.forcedGuideKey);
|
|
26
26
|
}
|
|
27
|
-
for (const [
|
|
27
|
+
for (const [n, o] of i.entries()) {
|
|
28
28
|
let u = a.guides[o];
|
|
29
|
-
a.debug.forcedGuideKey === o && a.previewGuides[o] && (u = a.previewGuides[o]), !(!u || !
|
|
30
|
-
location:
|
|
29
|
+
a.debug.forcedGuideKey === o && a.previewGuides[o] && (u = a.previewGuides[o]), !(!u || !F(u, {
|
|
30
|
+
location: r,
|
|
31
31
|
filters: e,
|
|
32
32
|
debug: a.debug
|
|
33
|
-
})) && t.set(
|
|
33
|
+
})) && t.set(n, u);
|
|
34
34
|
}
|
|
35
35
|
return t.metadata = { guideGroup: s }, t;
|
|
36
|
-
},
|
|
36
|
+
}, F = (a, { location: e, filters: t = {}, debug: s = {} }) => {
|
|
37
37
|
if (t.type && t.type !== a.type || t.key && t.key !== a.key)
|
|
38
38
|
return !1;
|
|
39
39
|
if (s.forcedGuideKey === a.key)
|
|
40
40
|
return !0;
|
|
41
41
|
if (!a.active || a.steps.every((o) => !!o.message.archived_at))
|
|
42
42
|
return !1;
|
|
43
|
-
const i = e ?
|
|
44
|
-
if (i &&
|
|
45
|
-
if (!
|
|
46
|
-
} else if (i &&
|
|
43
|
+
const i = e ? L(e) : void 0, r = a.activation_url_rules || [], n = a.activation_url_patterns || [];
|
|
44
|
+
if (i && r.length > 0) {
|
|
45
|
+
if (!P(i, r)) return !1;
|
|
46
|
+
} else if (i && n.length > 0 && !$(i, n))
|
|
47
47
|
return !1;
|
|
48
48
|
return !0;
|
|
49
49
|
};
|
|
50
|
-
class
|
|
50
|
+
class x {
|
|
51
51
|
constructor(e, t, s = {}, i = {}) {
|
|
52
52
|
d(this, "store");
|
|
53
53
|
// Phoenix channels for real time guide updates over websocket
|
|
@@ -77,8 +77,8 @@ class j {
|
|
|
77
77
|
if (!(e != null && e.location)) return;
|
|
78
78
|
const t = e.location.href;
|
|
79
79
|
if (this.store.state.location === t) return;
|
|
80
|
-
this.knock.log(`[Guide]
|
|
81
|
-
const s = this.store.state.debug, i =
|
|
80
|
+
this.knock.log(`[Guide] Detected a location change: ${t}`);
|
|
81
|
+
const s = this.store.state.debug, i = y();
|
|
82
82
|
this.setLocation(t, { debug: i }), this.checkDebugStateChanged(
|
|
83
83
|
s,
|
|
84
84
|
i
|
|
@@ -87,28 +87,28 @@ class j {
|
|
|
87
87
|
), this.fetch(), this.subscribe());
|
|
88
88
|
});
|
|
89
89
|
this.knock = e, this.channelId = t, this.targetParams = s, this.options = i;
|
|
90
|
-
const {
|
|
91
|
-
|
|
90
|
+
const {
|
|
91
|
+
trackLocationFromWindow: r = !0,
|
|
92
|
+
throttleCheckInterval: n = T
|
|
93
|
+
} = i, o = l(), u = r ? o == null ? void 0 : o.location.href : void 0, h = y();
|
|
94
|
+
this.store = new C({
|
|
92
95
|
guideGroups: [],
|
|
93
96
|
guideGroupDisplayLogs: {},
|
|
94
97
|
guides: {},
|
|
95
98
|
previewGuides: {},
|
|
96
99
|
queries: {},
|
|
97
|
-
location:
|
|
100
|
+
location: u,
|
|
98
101
|
// Increment to update the state store and trigger re-selection.
|
|
99
102
|
counter: 0,
|
|
100
|
-
debug:
|
|
103
|
+
debug: h
|
|
101
104
|
});
|
|
102
105
|
const { socket: c } = this.knock.client();
|
|
103
|
-
this.socket = c, this.socketChannelTopic = `guides:${t}`,
|
|
106
|
+
this.socket = c, this.socketChannelTopic = `guides:${t}`, r && this.listenForLocationChangesFromWindow(), n && this.startCounterInterval(n), this.knock.log("[Guide] Initialized a guide client");
|
|
104
107
|
}
|
|
105
108
|
incrementCounter() {
|
|
106
109
|
this.knock.log("[Guide] Incrementing the counter"), this.store.setState((e) => ({ ...e, counter: e.counter + 1 }));
|
|
107
110
|
}
|
|
108
|
-
startCounterInterval() {
|
|
109
|
-
const {
|
|
110
|
-
throttleCheckInterval: e = D
|
|
111
|
-
} = this.options;
|
|
111
|
+
startCounterInterval(e) {
|
|
112
112
|
this.counterIntervalId = setInterval(() => {
|
|
113
113
|
this.knock.log("[Guide] Counter interval tick"), !(this.stage && this.stage.status !== "closed") && this.incrementCounter();
|
|
114
114
|
}, e);
|
|
@@ -120,33 +120,34 @@ class j {
|
|
|
120
120
|
this.unsubscribe(), this.removeEventListeners(), this.clearGroupStage(), this.clearCounterInterval();
|
|
121
121
|
}
|
|
122
122
|
async fetch(e) {
|
|
123
|
-
this.knock.
|
|
123
|
+
this.knock.log("[Guide] .fetch"), this.knock.failIfNotAuthenticated();
|
|
124
124
|
const t = this.buildQueryParams(e == null ? void 0 : e.filters), s = this.formatQueryKey(t), i = this.store.state.queries[s];
|
|
125
125
|
if (i)
|
|
126
126
|
return i;
|
|
127
|
-
this.store.setState((
|
|
128
|
-
...
|
|
129
|
-
queries: { ...
|
|
127
|
+
this.store.setState((n) => ({
|
|
128
|
+
...n,
|
|
129
|
+
queries: { ...n.queries, [s]: { status: "loading" } }
|
|
130
130
|
}));
|
|
131
|
-
let
|
|
131
|
+
let r;
|
|
132
132
|
try {
|
|
133
|
-
|
|
134
|
-
n =
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
this.knock.log("[Guide] Fetching all eligible guides");
|
|
134
|
+
const n = await this.knock.user.getGuides(this.channelId, t);
|
|
135
|
+
r = { status: "ok" };
|
|
136
|
+
const { entries: o, guide_groups: u, guide_group_display_logs: h } = n;
|
|
137
|
+
this.knock.log("[Guide] Loading fetched guides"), this.store.setState((c) => ({
|
|
138
|
+
...c,
|
|
139
|
+
guideGroups: (u == null ? void 0 : u.length) > 0 ? u : [E(o)],
|
|
140
|
+
guideGroupDisplayLogs: h || {},
|
|
141
|
+
guides: w(o.map((v) => this.localCopy(v))),
|
|
142
|
+
queries: { ...c.queries, [s]: r }
|
|
142
143
|
}));
|
|
143
|
-
} catch (
|
|
144
|
-
|
|
144
|
+
} catch (n) {
|
|
145
|
+
r = { status: "error", error: n }, this.store.setState((o) => ({
|
|
145
146
|
...o,
|
|
146
|
-
queries: { ...o.queries, [s]:
|
|
147
|
+
queries: { ...o.queries, [s]: r }
|
|
147
148
|
}));
|
|
148
149
|
}
|
|
149
|
-
return
|
|
150
|
+
return r;
|
|
150
151
|
}
|
|
151
152
|
subscribe() {
|
|
152
153
|
if (!this.socket) return;
|
|
@@ -158,7 +159,7 @@ class j {
|
|
|
158
159
|
preview_session_id: e.previewSessionId || void 0
|
|
159
160
|
}, s = this.socket.channel(this.socketChannelTopic, t);
|
|
160
161
|
for (const i of this.socketEventTypes)
|
|
161
|
-
s.on(i, (
|
|
162
|
+
s.on(i, (r) => this.handleSocketEvent(r));
|
|
162
163
|
["closed", "errored"].includes(s.state) && (this.subscribeRetryCount = 0, s.join().receive("ok", () => {
|
|
163
164
|
this.knock.log("[Guide] Successfully joined channel");
|
|
164
165
|
}).receive("error", (i) => {
|
|
@@ -170,7 +171,7 @@ class j {
|
|
|
170
171
|
})), this.socketChannel = s;
|
|
171
172
|
}
|
|
172
173
|
handleChannelJoinError() {
|
|
173
|
-
if (this.subscribeRetryCount >=
|
|
174
|
+
if (this.subscribeRetryCount >= O) {
|
|
174
175
|
this.knock.log(
|
|
175
176
|
`[Guide] Channel join max retry limit reached: ${this.subscribeRetryCount}`
|
|
176
177
|
), this.unsubscribe();
|
|
@@ -205,9 +206,9 @@ class j {
|
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
208
|
setLocation(e, t = {}) {
|
|
208
|
-
this.clearGroupStage(), this.store.setState((s) => {
|
|
209
|
-
var
|
|
210
|
-
const i = (
|
|
209
|
+
this.knock.log(`[Guide] .setLocation (loc=${e})`), this.clearGroupStage(), this.knock.log("[Guide] Updating the tracked location"), this.store.setState((s) => {
|
|
210
|
+
var r;
|
|
211
|
+
const i = (r = t == null ? void 0 : t.debug) != null && r.previewSessionId ? s.previewGuides : {};
|
|
211
212
|
return {
|
|
212
213
|
...s,
|
|
213
214
|
...t,
|
|
@@ -220,44 +221,62 @@ class j {
|
|
|
220
221
|
// Store selector
|
|
221
222
|
//
|
|
222
223
|
selectGuides(e, t = {}) {
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
if (this.knock.log(
|
|
225
|
+
`[Guide] .selectGuides (filters: ${g(t)}; state: ${p(e)})`
|
|
226
|
+
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0)
|
|
227
|
+
return this.knock.log("[Guide] Exiting selection (no guides)"), [];
|
|
228
|
+
const s = m(e, t);
|
|
227
229
|
return s.size === 0 ? (this.knock.log("[Guide] Selection returned zero result"), []) : [...s.values()];
|
|
228
230
|
}
|
|
229
231
|
selectGuide(e, t = {}) {
|
|
230
|
-
if (
|
|
232
|
+
if (this.knock.log(
|
|
233
|
+
`[Guide] .selectGuide (filters: ${g(t)}; state: ${p(e)})`
|
|
234
|
+
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0) {
|
|
235
|
+
this.knock.log("[Guide] Exiting selection (no guides)");
|
|
231
236
|
return;
|
|
232
|
-
|
|
233
|
-
const s =
|
|
237
|
+
}
|
|
238
|
+
const s = m(e, t);
|
|
234
239
|
if (s.size === 0) {
|
|
235
|
-
this.knock.log("[Guide] Selection
|
|
240
|
+
this.knock.log("[Guide] Selection found zero result");
|
|
236
241
|
return;
|
|
237
242
|
}
|
|
238
|
-
const [i,
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
+
const [i, r] = [...s][0];
|
|
244
|
+
if (this.knock.log(
|
|
245
|
+
`[Guide] Selection found: \`${r.key}\` (total: ${s.size})`
|
|
246
|
+
), r.bypass_global_group_limit)
|
|
247
|
+
return this.knock.log(`[Guide] Returning the unthrottled guide: ${r.key}`), r;
|
|
248
|
+
const n = S(e.guideGroups), o = e.guideGroupDisplayLogs[k];
|
|
249
|
+
if (n && n.display_interval && o && R(
|
|
243
250
|
o,
|
|
244
|
-
|
|
245
|
-
))
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
251
|
+
n.display_interval
|
|
252
|
+
)) {
|
|
253
|
+
this.knock.log(`[Guide] Throttling the selected guide: ${r.key}`);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
switch (this.stage || (this.stage = this.openGroupStage()), this.stage.status) {
|
|
257
|
+
case "open": {
|
|
258
|
+
this.knock.log(`[Guide] Addng to the group stage: ${r.key}`), this.stage.ordered[i] = r.key;
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
case "patch": {
|
|
262
|
+
this.knock.log(`[Guide] Patching the group stage: ${r.key}`), this.stage.ordered[i] = r.key;
|
|
263
|
+
const u = this.stage.resolved === r.key ? r : void 0;
|
|
264
|
+
return this.knock.log(
|
|
265
|
+
`[Guide] Returning \`${u == null ? void 0 : u.key}\` (stage: ${f(this.stage)})`
|
|
266
|
+
), u;
|
|
255
267
|
}
|
|
268
|
+
case "closed": {
|
|
269
|
+
const u = this.stage.resolved === r.key ? r : void 0;
|
|
270
|
+
return this.knock.log(
|
|
271
|
+
`[Guide] Returning \`${u == null ? void 0 : u.key}\` (stage: ${f(this.stage)})`
|
|
272
|
+
), u;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
256
275
|
}
|
|
257
276
|
openGroupStage() {
|
|
258
277
|
this.knock.log("[Guide] Opening a new group stage");
|
|
259
278
|
const {
|
|
260
|
-
orderResolutionDuration: e =
|
|
279
|
+
orderResolutionDuration: e = D
|
|
261
280
|
} = this.options, t = setTimeout(() => {
|
|
262
281
|
this.closePendingGroupStage(), this.incrementCounter();
|
|
263
282
|
}, e);
|
|
@@ -270,12 +289,14 @@ class j {
|
|
|
270
289
|
// Close the current non-closed stage to resolve the prevailing guide up next
|
|
271
290
|
// for display amongst the ones that have been staged.
|
|
272
291
|
closePendingGroupStage() {
|
|
273
|
-
if (!this.stage || this.stage.status === "closed") return;
|
|
274
|
-
this.
|
|
292
|
+
if (this.knock.log("[Guide] .closePendingGroupStage"), !this.stage || this.stage.status === "closed") return;
|
|
293
|
+
this.ensureClearTimeout();
|
|
275
294
|
let e;
|
|
276
295
|
return this.store.state.debug.forcedGuideKey && (e = this.stage.ordered.find(
|
|
277
296
|
(t) => t === this.store.state.debug.forcedGuideKey
|
|
278
|
-
)), e || (e = this.stage.ordered.find((t) => t !== void 0)), this.
|
|
297
|
+
)), e || (e = this.stage.ordered.find((t) => t !== void 0)), this.knock.log(
|
|
298
|
+
`[Guide] Closing the current group stage: resolved=${e}`
|
|
299
|
+
), this.stage = {
|
|
279
300
|
...this.stage,
|
|
280
301
|
status: "closed",
|
|
281
302
|
resolved: e,
|
|
@@ -289,12 +310,11 @@ class j {
|
|
|
289
310
|
// Note, must be called ahead of updating the state store.
|
|
290
311
|
patchClosedGroupStage() {
|
|
291
312
|
var s;
|
|
292
|
-
if (((s = this.stage) == null ? void 0 : s.status) !== "closed") return;
|
|
293
|
-
this.knock.log("[Guide] Patching the current group stage");
|
|
313
|
+
if (this.knock.log("[Guide] .patchClosedGroupStage"), ((s = this.stage) == null ? void 0 : s.status) !== "closed") return;
|
|
294
314
|
const { orderResolutionDuration: e = 0 } = this.options, t = setTimeout(() => {
|
|
295
315
|
this.closePendingGroupStage(), this.incrementCounter();
|
|
296
316
|
}, e);
|
|
297
|
-
return this.ensureClearTimeout(), this.stage = {
|
|
317
|
+
return this.ensureClearTimeout(), this.knock.log("[Guide] Patching the current group stage"), this.stage = {
|
|
298
318
|
...this.stage,
|
|
299
319
|
status: "patch",
|
|
300
320
|
ordered: [],
|
|
@@ -302,7 +322,7 @@ class j {
|
|
|
302
322
|
}, this.stage;
|
|
303
323
|
}
|
|
304
324
|
clearGroupStage() {
|
|
305
|
-
this.stage && (this.knock.log("[Guide] Clearing the current group stage"), this.ensureClearTimeout(), this.stage = void 0);
|
|
325
|
+
this.knock.log("[Guide] .clearGroupStage"), this.stage && (this.knock.log("[Guide] Clearing the current group stage"), this.ensureClearTimeout(), this.stage = void 0);
|
|
306
326
|
}
|
|
307
327
|
ensureClearTimeout() {
|
|
308
328
|
var e;
|
|
@@ -341,18 +361,18 @@ class j {
|
|
|
341
361
|
}
|
|
342
362
|
async markAsInteracted(e, t, s) {
|
|
343
363
|
this.knock.log(
|
|
344
|
-
`[Guide] Marking as interacted (Guide key: ${e.key}
|
|
364
|
+
`[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${t.ref})`
|
|
345
365
|
);
|
|
346
|
-
const i = (/* @__PURE__ */ new Date()).toISOString(),
|
|
366
|
+
const i = (/* @__PURE__ */ new Date()).toISOString(), r = this.setStepMessageAttrs(e.key, t.ref, {
|
|
347
367
|
read_at: i,
|
|
348
368
|
interacted_at: i
|
|
349
369
|
});
|
|
350
|
-
if (!
|
|
351
|
-
const
|
|
352
|
-
...this.buildEngagementEventBaseParams(e,
|
|
370
|
+
if (!r) return;
|
|
371
|
+
const n = {
|
|
372
|
+
...this.buildEngagementEventBaseParams(e, r),
|
|
353
373
|
metadata: s
|
|
354
374
|
};
|
|
355
|
-
return this.knock.user.markGuideStepAs("interacted",
|
|
375
|
+
return this.knock.user.markGuideStepAs("interacted", n), r;
|
|
356
376
|
}
|
|
357
377
|
async markAsArchived(e, t) {
|
|
358
378
|
if (t.message.archived_at) return;
|
|
@@ -383,9 +403,9 @@ class j {
|
|
|
383
403
|
return t.store.state.debug.forcedGuideKey === this.key ? this.steps[0] : this.steps.find((i) => !i.message.archived_at);
|
|
384
404
|
}
|
|
385
405
|
};
|
|
386
|
-
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: i, ...
|
|
387
|
-
const
|
|
388
|
-
...
|
|
406
|
+
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: i, ...r }) => {
|
|
407
|
+
const n = {
|
|
408
|
+
...r,
|
|
389
409
|
message: { ...i },
|
|
390
410
|
markAsSeen() {
|
|
391
411
|
if (!this.message.seen_at)
|
|
@@ -399,10 +419,10 @@ class j {
|
|
|
399
419
|
return t.markAsArchived(s, this);
|
|
400
420
|
}
|
|
401
421
|
};
|
|
402
|
-
return
|
|
422
|
+
return n.markAsSeen = n.markAsSeen.bind(n), n.markAsInteracted = n.markAsInteracted.bind(n), n.markAsArchived = n.markAsArchived.bind(n), n;
|
|
403
423
|
}), s.activation_url_patterns = e.activation_url_patterns.map((i) => ({
|
|
404
424
|
...i,
|
|
405
|
-
pattern: new
|
|
425
|
+
pattern: new I({ pathname: i.pathname })
|
|
406
426
|
})), s;
|
|
407
427
|
}
|
|
408
428
|
buildQueryParams(e = {}) {
|
|
@@ -413,29 +433,29 @@ class j {
|
|
|
413
433
|
this.store.state.debug.forcedGuideKey && (t.force_all_guides = !0);
|
|
414
434
|
let i = Object.fromEntries(
|
|
415
435
|
Object.entries(t).filter(
|
|
416
|
-
([
|
|
436
|
+
([r, n]) => n != null
|
|
417
437
|
)
|
|
418
438
|
);
|
|
419
439
|
return i = i.data ? { ...i, data: JSON.stringify(i.data) } : i, i;
|
|
420
440
|
}
|
|
421
441
|
formatQueryKey(e) {
|
|
422
442
|
const s = Object.keys(e).sort().map(
|
|
423
|
-
(
|
|
424
|
-
).join("&"), i =
|
|
443
|
+
(r) => `${encodeURIComponent(r)}=${encodeURIComponent(e[r])}`
|
|
444
|
+
).join("&"), i = K(this.knock.userId);
|
|
425
445
|
return s ? `${i}?${s}` : i;
|
|
426
446
|
}
|
|
427
447
|
setStepMessageAttrs(e, t, s) {
|
|
428
448
|
let i;
|
|
429
|
-
return s.archived_at && this.clearGroupStage(), this.store.setState((
|
|
430
|
-
const
|
|
431
|
-
if (!
|
|
432
|
-
const o =
|
|
433
|
-
|
|
434
|
-
const u = { ...
|
|
435
|
-
...
|
|
436
|
-
[
|
|
437
|
-
} :
|
|
438
|
-
return { ...
|
|
449
|
+
return s.archived_at && this.clearGroupStage(), this.store.setState((r) => {
|
|
450
|
+
const n = r.guides[e];
|
|
451
|
+
if (!n) return r;
|
|
452
|
+
const o = n.steps.map((c) => (c.ref !== t || (c.message = { ...c.message, ...s }, i = c), c));
|
|
453
|
+
n.steps = o;
|
|
454
|
+
const u = { ...r.guides, [n.key]: n }, h = s.archived_at && !n.bypass_global_group_limit ? {
|
|
455
|
+
...r.guideGroupDisplayLogs,
|
|
456
|
+
[k]: s.archived_at
|
|
457
|
+
} : r.guideGroupDisplayLogs;
|
|
458
|
+
return { ...r, guides: u, guideGroupDisplayLogs: h };
|
|
439
459
|
}), i;
|
|
440
460
|
}
|
|
441
461
|
buildEngagementEventBaseParams(e, t) {
|
|
@@ -465,17 +485,17 @@ class j {
|
|
|
465
485
|
data: e
|
|
466
486
|
}) {
|
|
467
487
|
this.patchClosedGroupStage(), this.store.setState((t) => {
|
|
468
|
-
const s = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [],
|
|
469
|
-
let
|
|
470
|
-
return
|
|
488
|
+
const s = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [], r = e.guide_group.display_sequence_throttled || [];
|
|
489
|
+
let n = t.guides;
|
|
490
|
+
return n = i.reduce((o, u) => {
|
|
471
491
|
if (!o[u]) return o;
|
|
472
|
-
const
|
|
473
|
-
return { ...o, [u]:
|
|
474
|
-
},
|
|
492
|
+
const h = { ...o[u], bypass_global_group_limit: !0 };
|
|
493
|
+
return { ...o, [u]: h };
|
|
494
|
+
}, n), n = r.reduce((o, u) => {
|
|
475
495
|
if (!o[u]) return o;
|
|
476
|
-
const
|
|
477
|
-
return { ...o, [u]:
|
|
478
|
-
},
|
|
496
|
+
const h = { ...o[u], bypass_global_group_limit: !1 };
|
|
497
|
+
return { ...o, [u]: h };
|
|
498
|
+
}, n), { ...t, guides: n, guideGroups: s };
|
|
479
499
|
});
|
|
480
500
|
}
|
|
481
501
|
updatePreviewGuide({ data: e }) {
|
|
@@ -496,14 +516,14 @@ class j {
|
|
|
496
516
|
e.addEventListener("popstate", this.handleLocationChange), e.addEventListener("hashchange", this.handleLocationChange);
|
|
497
517
|
const t = e.history.pushState, s = e.history.replaceState;
|
|
498
518
|
e.history.pushState = new Proxy(t, {
|
|
499
|
-
apply: (i,
|
|
500
|
-
Reflect.apply(i,
|
|
519
|
+
apply: (i, r, n) => {
|
|
520
|
+
Reflect.apply(i, r, n), setTimeout(() => {
|
|
501
521
|
this.handleLocationChange();
|
|
502
522
|
}, 0);
|
|
503
523
|
}
|
|
504
524
|
}), e.history.replaceState = new Proxy(s, {
|
|
505
|
-
apply: (i,
|
|
506
|
-
Reflect.apply(i,
|
|
525
|
+
apply: (i, r, n) => {
|
|
526
|
+
Reflect.apply(i, r, n), setTimeout(() => {
|
|
507
527
|
this.handleLocationChange();
|
|
508
528
|
}, 0);
|
|
509
529
|
}
|
|
@@ -519,8 +539,8 @@ class j {
|
|
|
519
539
|
}
|
|
520
540
|
}
|
|
521
541
|
export {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
542
|
+
G as DEBUG_QUERY_PARAMS,
|
|
543
|
+
x as KnockGuideClient,
|
|
544
|
+
K as guidesApiRootPath
|
|
525
545
|
};
|
|
526
546
|
//# sourceMappingURL=client.mjs.map
|