@knocklabs/client 0.18.4 → 0.18.6
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 +13 -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/users/index.js +1 -1
- package/dist/cjs/clients/users/index.js.map +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/clients/guide/client.mjs +178 -118
- package/dist/esm/clients/guide/client.mjs.map +1 -1
- package/dist/esm/clients/users/index.mjs +1 -1
- package/dist/esm/clients/users/index.mjs.map +1 -1
- package/dist/types/clients/guide/client.d.ts +1 -0
- package/dist/types/clients/guide/client.d.ts.map +1 -1
- package/dist/types/clients/guide/types.d.ts +0 -2
- package/dist/types/clients/guide/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/guide/client.ts +102 -9
- package/src/clients/guide/types.ts +0 -2
- package/src/clients/users/index.ts +1 -1
|
@@ -1,53 +1,96 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var I = (u, e, t) => e in u ? b(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
|
|
3
|
+
var d = (u, e, t) => I(u, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { Store as C } from "@tanstack/store";
|
|
5
|
-
import { URLPattern as
|
|
6
|
-
import { byKey as w, mockDefaultGroup as
|
|
7
|
-
const
|
|
5
|
+
import { URLPattern as E } from "urlpattern-polyfill";
|
|
6
|
+
import { byKey as w, mockDefaultGroup as R, formatFilters as k, formatState as f, findDefaultGroup as v, DEFAULT_GROUP_KEY as S, checkIfThrottled as P, formatGroupStage as G, SelectionResult as A, newUrl as D, predicateUrlRules as K, predicateUrlPatterns as L } from "./helpers.mjs";
|
|
7
|
+
const O = 50, $ = 30 * 1e3, T = 3, g = {
|
|
8
8
|
GUIDE_KEY: "knock_guide_key",
|
|
9
9
|
PREVIEW_SESSION_ID: "knock_preview_session_id"
|
|
10
|
-
}, l = () => {
|
|
10
|
+
}, p = "knock_guide_debug", l = () => {
|
|
11
11
|
if (typeof window < "u")
|
|
12
12
|
return window;
|
|
13
|
-
},
|
|
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(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const e = new URLSearchParams(u.location.search), t = e.get(g.GUIDE_KEY), s = e.get(
|
|
18
|
+
g.PREVIEW_SESSION_ID
|
|
19
|
+
);
|
|
20
|
+
if (t || s) {
|
|
21
|
+
if (u.localStorage)
|
|
22
|
+
try {
|
|
23
|
+
const r = {
|
|
24
|
+
forcedGuideKey: t,
|
|
25
|
+
previewSessionId: s
|
|
26
|
+
};
|
|
27
|
+
u.localStorage.setItem(p, JSON.stringify(r));
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
forcedGuideKey: t,
|
|
32
|
+
previewSessionId: s
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
let i = null, n = null;
|
|
36
|
+
if (u.localStorage)
|
|
37
|
+
try {
|
|
38
|
+
const r = u.localStorage.getItem(p);
|
|
39
|
+
if (r) {
|
|
40
|
+
const o = F(r);
|
|
41
|
+
i = o.forcedGuideKey, n = o.previewSessionId;
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
forcedGuideKey: i,
|
|
47
|
+
previewSessionId: n
|
|
48
|
+
};
|
|
49
|
+
}, F = (u) => {
|
|
50
|
+
try {
|
|
51
|
+
const e = JSON.parse(u);
|
|
52
|
+
return {
|
|
53
|
+
forcedGuideKey: (e == null ? void 0 : e.forcedGuideKey) ?? null,
|
|
54
|
+
previewSessionId: (e == null ? void 0 : e.previewSessionId) ?? null
|
|
55
|
+
};
|
|
56
|
+
} catch {
|
|
57
|
+
return {
|
|
58
|
+
forcedGuideKey: null,
|
|
59
|
+
previewSessionId: null
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}, m = (u, e = {}) => {
|
|
63
|
+
const t = new A(), s = v(u.guideGroups);
|
|
21
64
|
if (!s) return t;
|
|
22
|
-
const i = [...s.display_sequence],
|
|
23
|
-
if (
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
for (const [
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
location:
|
|
65
|
+
const i = [...s.display_sequence], n = u.location;
|
|
66
|
+
if (u.debug.forcedGuideKey) {
|
|
67
|
+
const r = i.indexOf(u.debug.forcedGuideKey);
|
|
68
|
+
r > -1 && i.splice(r, 1), i.unshift(u.debug.forcedGuideKey);
|
|
69
|
+
}
|
|
70
|
+
for (const [r, o] of i.entries()) {
|
|
71
|
+
let a = u.guides[o];
|
|
72
|
+
u.debug.forcedGuideKey === o && u.previewGuides[o] && (a = u.previewGuides[o]), !(!a || !N(a, {
|
|
73
|
+
location: n,
|
|
31
74
|
filters: e,
|
|
32
|
-
debug:
|
|
33
|
-
})) && t.set(
|
|
75
|
+
debug: u.debug
|
|
76
|
+
})) && t.set(r, a);
|
|
34
77
|
}
|
|
35
78
|
return t.metadata = { guideGroup: s }, t;
|
|
36
|
-
},
|
|
37
|
-
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)
|
|
38
81
|
return !1;
|
|
39
|
-
if (s.forcedGuideKey ===
|
|
82
|
+
if (s.forcedGuideKey === u.key)
|
|
40
83
|
return !0;
|
|
41
|
-
if (!
|
|
84
|
+
if (!u.active || u.steps.every((o) => !!o.message.archived_at))
|
|
42
85
|
return !1;
|
|
43
|
-
const i = e ?
|
|
44
|
-
if (i &&
|
|
45
|
-
if (!
|
|
46
|
-
} else if (i &&
|
|
86
|
+
const i = e ? D(e) : void 0, n = u.activation_url_rules || [], r = u.activation_url_patterns || [];
|
|
87
|
+
if (i && n.length > 0) {
|
|
88
|
+
if (!K(i, n)) return !1;
|
|
89
|
+
} else if (i && r.length > 0 && !L(i, r))
|
|
47
90
|
return !1;
|
|
48
91
|
return !0;
|
|
49
92
|
};
|
|
50
|
-
class
|
|
93
|
+
class B {
|
|
51
94
|
constructor(e, t, s = {}, i = {}) {
|
|
52
95
|
d(this, "store");
|
|
53
96
|
// Phoenix channels for real time guide updates over websocket
|
|
@@ -88,22 +131,22 @@ class x {
|
|
|
88
131
|
});
|
|
89
132
|
this.knock = e, this.channelId = t, this.targetParams = s, this.options = i;
|
|
90
133
|
const {
|
|
91
|
-
trackLocationFromWindow:
|
|
92
|
-
throttleCheckInterval:
|
|
93
|
-
} = i, o = l(),
|
|
134
|
+
trackLocationFromWindow: n = !0,
|
|
135
|
+
throttleCheckInterval: r = $
|
|
136
|
+
} = i, o = l(), a = n ? o == null ? void 0 : o.location.href : void 0, h = y();
|
|
94
137
|
this.store = new C({
|
|
95
138
|
guideGroups: [],
|
|
96
139
|
guideGroupDisplayLogs: {},
|
|
97
140
|
guides: {},
|
|
98
141
|
previewGuides: {},
|
|
99
142
|
queries: {},
|
|
100
|
-
location:
|
|
143
|
+
location: a,
|
|
101
144
|
// Increment to update the state store and trigger re-selection.
|
|
102
145
|
counter: 0,
|
|
103
146
|
debug: h
|
|
104
147
|
});
|
|
105
148
|
const { socket: c } = this.knock.client();
|
|
106
|
-
this.socket = c, this.socketChannelTopic = `guides:${t}`,
|
|
149
|
+
this.socket = c, this.socketChannelTopic = `guides:${t}`, n && this.listenForLocationChangesFromWindow(), r && this.startCounterInterval(r), this.knock.log("[Guide] Initialized a guide client");
|
|
107
150
|
}
|
|
108
151
|
incrementCounter() {
|
|
109
152
|
this.knock.log("[Guide] Incrementing the counter"), this.store.setState((e) => ({ ...e, counter: e.counter + 1 }));
|
|
@@ -124,30 +167,30 @@ class x {
|
|
|
124
167
|
const t = this.buildQueryParams(e == null ? void 0 : e.filters), s = this.formatQueryKey(t), i = this.store.state.queries[s];
|
|
125
168
|
if (i)
|
|
126
169
|
return i;
|
|
127
|
-
this.store.setState((
|
|
128
|
-
...
|
|
129
|
-
queries: { ...
|
|
170
|
+
this.store.setState((r) => ({
|
|
171
|
+
...r,
|
|
172
|
+
queries: { ...r.queries, [s]: { status: "loading" } }
|
|
130
173
|
}));
|
|
131
|
-
let
|
|
174
|
+
let n;
|
|
132
175
|
try {
|
|
133
176
|
this.knock.log("[Guide] Fetching all eligible guides");
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
const { entries: o, guide_groups:
|
|
177
|
+
const r = await this.knock.user.getGuides(this.channelId, t);
|
|
178
|
+
n = { status: "ok" };
|
|
179
|
+
const { entries: o, guide_groups: a, guide_group_display_logs: h } = r;
|
|
137
180
|
this.knock.log("[Guide] Loading fetched guides"), this.store.setState((c) => ({
|
|
138
181
|
...c,
|
|
139
|
-
guideGroups: (
|
|
182
|
+
guideGroups: (a == null ? void 0 : a.length) > 0 ? a : [R(o)],
|
|
140
183
|
guideGroupDisplayLogs: h || {},
|
|
141
|
-
guides: w(o.map((
|
|
142
|
-
queries: { ...c.queries, [s]:
|
|
184
|
+
guides: w(o.map((_) => this.localCopy(_))),
|
|
185
|
+
queries: { ...c.queries, [s]: n }
|
|
143
186
|
}));
|
|
144
|
-
} catch (
|
|
145
|
-
|
|
187
|
+
} catch (r) {
|
|
188
|
+
n = { status: "error", error: r }, this.store.setState((o) => ({
|
|
146
189
|
...o,
|
|
147
|
-
queries: { ...o.queries, [s]:
|
|
190
|
+
queries: { ...o.queries, [s]: n }
|
|
148
191
|
}));
|
|
149
192
|
}
|
|
150
|
-
return
|
|
193
|
+
return n;
|
|
151
194
|
}
|
|
152
195
|
subscribe() {
|
|
153
196
|
if (!this.socket) return;
|
|
@@ -159,7 +202,7 @@ class x {
|
|
|
159
202
|
preview_session_id: e.previewSessionId || void 0
|
|
160
203
|
}, s = this.socket.channel(this.socketChannelTopic, t);
|
|
161
204
|
for (const i of this.socketEventTypes)
|
|
162
|
-
s.on(i, (
|
|
205
|
+
s.on(i, (n) => this.handleSocketEvent(n));
|
|
163
206
|
["closed", "errored"].includes(s.state) && (this.subscribeRetryCount = 0, s.join().receive("ok", () => {
|
|
164
207
|
this.knock.log("[Guide] Successfully joined channel");
|
|
165
208
|
}).receive("error", (i) => {
|
|
@@ -171,7 +214,7 @@ class x {
|
|
|
171
214
|
})), this.socketChannel = s;
|
|
172
215
|
}
|
|
173
216
|
handleChannelJoinError() {
|
|
174
|
-
if (this.subscribeRetryCount >=
|
|
217
|
+
if (this.subscribeRetryCount >= T) {
|
|
175
218
|
this.knock.log(
|
|
176
219
|
`[Guide] Channel join max retry limit reached: ${this.subscribeRetryCount}`
|
|
177
220
|
), this.unsubscribe();
|
|
@@ -207,8 +250,8 @@ class x {
|
|
|
207
250
|
}
|
|
208
251
|
setLocation(e, t = {}) {
|
|
209
252
|
this.knock.log(`[Guide] .setLocation (loc=${e})`), this.clearGroupStage(), this.knock.log("[Guide] Updating the tracked location"), this.store.setState((s) => {
|
|
210
|
-
var
|
|
211
|
-
const i = (
|
|
253
|
+
var n;
|
|
254
|
+
const i = (n = t == null ? void 0 : t.debug) != null && n.previewSessionId ? s.previewGuides : {};
|
|
212
255
|
return {
|
|
213
256
|
...s,
|
|
214
257
|
...t,
|
|
@@ -217,12 +260,30 @@ class x {
|
|
|
217
260
|
};
|
|
218
261
|
});
|
|
219
262
|
}
|
|
263
|
+
exitDebugMode() {
|
|
264
|
+
this.knock.log("[Guide] Exiting debug mode");
|
|
265
|
+
const e = l();
|
|
266
|
+
if (e != null && e.localStorage)
|
|
267
|
+
try {
|
|
268
|
+
e.localStorage.removeItem(p);
|
|
269
|
+
} catch {
|
|
270
|
+
}
|
|
271
|
+
if (this.store.setState((t) => ({
|
|
272
|
+
...t,
|
|
273
|
+
debug: { forcedGuideKey: null, previewSessionId: null },
|
|
274
|
+
previewGuides: {}
|
|
275
|
+
// Clear preview guides when exiting debug mode
|
|
276
|
+
})), e) {
|
|
277
|
+
const t = new URL(e.location.href);
|
|
278
|
+
(t.searchParams.has(g.GUIDE_KEY) || t.searchParams.has(g.PREVIEW_SESSION_ID)) && (t.searchParams.delete(g.GUIDE_KEY), t.searchParams.delete(g.PREVIEW_SESSION_ID), e.location.href = t.toString());
|
|
279
|
+
}
|
|
280
|
+
}
|
|
220
281
|
//
|
|
221
282
|
// Store selector
|
|
222
283
|
//
|
|
223
284
|
selectGuides(e, t = {}) {
|
|
224
285
|
if (this.knock.log(
|
|
225
|
-
`[Guide] .selectGuides (filters: ${
|
|
286
|
+
`[Guide] .selectGuides (filters: ${k(t)}; state: ${f(e)})`
|
|
226
287
|
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0)
|
|
227
288
|
return this.knock.log("[Guide] Exiting selection (no guides)"), [];
|
|
228
289
|
const s = m(e, t);
|
|
@@ -230,7 +291,7 @@ class x {
|
|
|
230
291
|
}
|
|
231
292
|
selectGuide(e, t = {}) {
|
|
232
293
|
if (this.knock.log(
|
|
233
|
-
`[Guide] .selectGuide (filters: ${
|
|
294
|
+
`[Guide] .selectGuide (filters: ${k(t)}; state: ${f(e)})`
|
|
234
295
|
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0) {
|
|
235
296
|
this.knock.log("[Guide] Exiting selection (no guides)");
|
|
236
297
|
return;
|
|
@@ -240,43 +301,43 @@ class x {
|
|
|
240
301
|
this.knock.log("[Guide] Selection found zero result");
|
|
241
302
|
return;
|
|
242
303
|
}
|
|
243
|
-
const [i,
|
|
304
|
+
const [i, n] = [...s][0];
|
|
244
305
|
if (this.knock.log(
|
|
245
|
-
`[Guide] Selection found: \`${
|
|
246
|
-
),
|
|
247
|
-
return this.knock.log(`[Guide] Returning the unthrottled guide: ${
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
306
|
+
`[Guide] Selection found: \`${n.key}\` (total: ${s.size})`
|
|
307
|
+
), n.bypass_global_group_limit)
|
|
308
|
+
return this.knock.log(`[Guide] Returning the unthrottled guide: ${n.key}`), n;
|
|
309
|
+
const r = v(e.guideGroups), o = e.guideGroupDisplayLogs[S];
|
|
310
|
+
if (r && r.display_interval && o && P(
|
|
250
311
|
o,
|
|
251
|
-
|
|
312
|
+
r.display_interval
|
|
252
313
|
)) {
|
|
253
|
-
this.knock.log(`[Guide] Throttling the selected guide: ${
|
|
314
|
+
this.knock.log(`[Guide] Throttling the selected guide: ${n.key}`);
|
|
254
315
|
return;
|
|
255
316
|
}
|
|
256
317
|
switch (this.stage || (this.stage = this.openGroupStage()), this.stage.status) {
|
|
257
318
|
case "open": {
|
|
258
|
-
this.knock.log(`[Guide]
|
|
319
|
+
this.knock.log(`[Guide] Adding to the group stage: ${n.key}`), this.stage.ordered[i] = n.key;
|
|
259
320
|
return;
|
|
260
321
|
}
|
|
261
322
|
case "patch": {
|
|
262
|
-
this.knock.log(`[Guide] Patching the group stage: ${
|
|
263
|
-
const
|
|
323
|
+
this.knock.log(`[Guide] Patching the group stage: ${n.key}`), this.stage.ordered[i] = n.key;
|
|
324
|
+
const a = this.stage.resolved === n.key ? n : void 0;
|
|
264
325
|
return this.knock.log(
|
|
265
|
-
`[Guide] Returning \`${
|
|
266
|
-
),
|
|
326
|
+
`[Guide] Returning \`${a == null ? void 0 : a.key}\` (stage: ${G(this.stage)})`
|
|
327
|
+
), a;
|
|
267
328
|
}
|
|
268
329
|
case "closed": {
|
|
269
|
-
const
|
|
330
|
+
const a = this.stage.resolved === n.key ? n : void 0;
|
|
270
331
|
return this.knock.log(
|
|
271
|
-
`[Guide] Returning \`${
|
|
272
|
-
),
|
|
332
|
+
`[Guide] Returning \`${a == null ? void 0 : a.key}\` (stage: ${G(this.stage)})`
|
|
333
|
+
), a;
|
|
273
334
|
}
|
|
274
335
|
}
|
|
275
336
|
}
|
|
276
337
|
openGroupStage() {
|
|
277
338
|
this.knock.log("[Guide] Opening a new group stage");
|
|
278
339
|
const {
|
|
279
|
-
orderResolutionDuration: e =
|
|
340
|
+
orderResolutionDuration: e = O
|
|
280
341
|
} = this.options, t = setTimeout(() => {
|
|
281
342
|
this.closePendingGroupStage(), this.incrementCounter();
|
|
282
343
|
}, e);
|
|
@@ -363,16 +424,16 @@ class x {
|
|
|
363
424
|
this.knock.log(
|
|
364
425
|
`[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${t.ref})`
|
|
365
426
|
);
|
|
366
|
-
const i = (/* @__PURE__ */ new Date()).toISOString(),
|
|
427
|
+
const i = (/* @__PURE__ */ new Date()).toISOString(), n = this.setStepMessageAttrs(e.key, t.ref, {
|
|
367
428
|
read_at: i,
|
|
368
429
|
interacted_at: i
|
|
369
430
|
});
|
|
370
|
-
if (!
|
|
371
|
-
const
|
|
372
|
-
...this.buildEngagementEventBaseParams(e,
|
|
431
|
+
if (!n) return;
|
|
432
|
+
const r = {
|
|
433
|
+
...this.buildEngagementEventBaseParams(e, n),
|
|
373
434
|
metadata: s
|
|
374
435
|
};
|
|
375
|
-
return this.knock.user.markGuideStepAs("interacted",
|
|
436
|
+
return this.knock.user.markGuideStepAs("interacted", r), n;
|
|
376
437
|
}
|
|
377
438
|
async markAsArchived(e, t) {
|
|
378
439
|
if (t.message.archived_at) return;
|
|
@@ -403,9 +464,9 @@ class x {
|
|
|
403
464
|
return t.store.state.debug.forcedGuideKey === this.key ? this.steps[0] : this.steps.find((i) => !i.message.archived_at);
|
|
404
465
|
}
|
|
405
466
|
};
|
|
406
|
-
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: i, ...
|
|
407
|
-
const
|
|
408
|
-
...
|
|
467
|
+
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: i, ...n }) => {
|
|
468
|
+
const r = {
|
|
469
|
+
...n,
|
|
409
470
|
message: { ...i },
|
|
410
471
|
markAsSeen() {
|
|
411
472
|
if (!this.message.seen_at)
|
|
@@ -419,10 +480,10 @@ class x {
|
|
|
419
480
|
return t.markAsArchived(s, this);
|
|
420
481
|
}
|
|
421
482
|
};
|
|
422
|
-
return
|
|
483
|
+
return r.markAsSeen = r.markAsSeen.bind(r), r.markAsInteracted = r.markAsInteracted.bind(r), r.markAsArchived = r.markAsArchived.bind(r), r;
|
|
423
484
|
}), s.activation_url_patterns = e.activation_url_patterns.map((i) => ({
|
|
424
485
|
...i,
|
|
425
|
-
pattern: new
|
|
486
|
+
pattern: new E({ pathname: i.pathname })
|
|
426
487
|
})), s;
|
|
427
488
|
}
|
|
428
489
|
buildQueryParams(e = {}) {
|
|
@@ -433,34 +494,33 @@ class x {
|
|
|
433
494
|
this.store.state.debug.forcedGuideKey && (t.force_all_guides = !0);
|
|
434
495
|
let i = Object.fromEntries(
|
|
435
496
|
Object.entries(t).filter(
|
|
436
|
-
([
|
|
497
|
+
([n, r]) => r != null
|
|
437
498
|
)
|
|
438
499
|
);
|
|
439
500
|
return i = i.data ? { ...i, data: JSON.stringify(i.data) } : i, i;
|
|
440
501
|
}
|
|
441
502
|
formatQueryKey(e) {
|
|
442
503
|
const s = Object.keys(e).sort().map(
|
|
443
|
-
(
|
|
444
|
-
).join("&"), i =
|
|
504
|
+
(n) => `${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`
|
|
505
|
+
).join("&"), i = U(this.knock.userId);
|
|
445
506
|
return s ? `${i}?${s}` : i;
|
|
446
507
|
}
|
|
447
508
|
setStepMessageAttrs(e, t, s) {
|
|
448
509
|
let i;
|
|
449
|
-
return s.archived_at && this.clearGroupStage(), this.store.setState((
|
|
450
|
-
|
|
451
|
-
if (!
|
|
452
|
-
const o =
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
...
|
|
456
|
-
[
|
|
457
|
-
} :
|
|
458
|
-
return { ...
|
|
510
|
+
return s.archived_at && this.clearGroupStage(), this.store.setState((n) => {
|
|
511
|
+
let r = n.guides[e];
|
|
512
|
+
if (!r) return n;
|
|
513
|
+
const o = r.steps.map((c) => (c.ref !== t || (c.message = { ...c.message, ...s }, i = c), c));
|
|
514
|
+
r = i ? { ...r, steps: o } : r;
|
|
515
|
+
const a = { ...n.guides, [r.key]: r }, h = s.archived_at && !r.bypass_global_group_limit ? {
|
|
516
|
+
...n.guideGroupDisplayLogs,
|
|
517
|
+
[S]: s.archived_at
|
|
518
|
+
} : n.guideGroupDisplayLogs;
|
|
519
|
+
return { ...n, guides: a, guideGroupDisplayLogs: h };
|
|
459
520
|
}), i;
|
|
460
521
|
}
|
|
461
522
|
buildEngagementEventBaseParams(e, t) {
|
|
462
523
|
return {
|
|
463
|
-
message_id: t.message.id,
|
|
464
524
|
channel_id: e.channel_id,
|
|
465
525
|
guide_key: e.key,
|
|
466
526
|
guide_id: e.id,
|
|
@@ -485,17 +545,17 @@ class x {
|
|
|
485
545
|
data: e
|
|
486
546
|
}) {
|
|
487
547
|
this.patchClosedGroupStage(), this.store.setState((t) => {
|
|
488
|
-
const s = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [],
|
|
489
|
-
let
|
|
490
|
-
return
|
|
491
|
-
if (!o[
|
|
492
|
-
const h = { ...o[
|
|
493
|
-
return { ...o, [
|
|
494
|
-
},
|
|
495
|
-
if (!o[
|
|
496
|
-
const h = { ...o[
|
|
497
|
-
return { ...o, [
|
|
498
|
-
},
|
|
548
|
+
const s = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [], n = e.guide_group.display_sequence_throttled || [];
|
|
549
|
+
let r = t.guides;
|
|
550
|
+
return r = i.reduce((o, a) => {
|
|
551
|
+
if (!o[a]) return o;
|
|
552
|
+
const h = { ...o[a], bypass_global_group_limit: !0 };
|
|
553
|
+
return { ...o, [a]: h };
|
|
554
|
+
}, r), r = n.reduce((o, a) => {
|
|
555
|
+
if (!o[a]) return o;
|
|
556
|
+
const h = { ...o[a], bypass_global_group_limit: !1 };
|
|
557
|
+
return { ...o, [a]: h };
|
|
558
|
+
}, r), { ...t, guides: r, guideGroups: s };
|
|
499
559
|
});
|
|
500
560
|
}
|
|
501
561
|
updatePreviewGuide({ data: e }) {
|
|
@@ -516,14 +576,14 @@ class x {
|
|
|
516
576
|
e.addEventListener("popstate", this.handleLocationChange), e.addEventListener("hashchange", this.handleLocationChange);
|
|
517
577
|
const t = e.history.pushState, s = e.history.replaceState;
|
|
518
578
|
e.history.pushState = new Proxy(t, {
|
|
519
|
-
apply: (i,
|
|
520
|
-
Reflect.apply(i,
|
|
579
|
+
apply: (i, n, r) => {
|
|
580
|
+
Reflect.apply(i, n, r), setTimeout(() => {
|
|
521
581
|
this.handleLocationChange();
|
|
522
582
|
}, 0);
|
|
523
583
|
}
|
|
524
584
|
}), e.history.replaceState = new Proxy(s, {
|
|
525
|
-
apply: (i,
|
|
526
|
-
Reflect.apply(i,
|
|
585
|
+
apply: (i, n, r) => {
|
|
586
|
+
Reflect.apply(i, n, r), setTimeout(() => {
|
|
527
587
|
this.handleLocationChange();
|
|
528
588
|
}, 0);
|
|
529
589
|
}
|
|
@@ -539,8 +599,8 @@ class x {
|
|
|
539
599
|
}
|
|
540
600
|
}
|
|
541
601
|
export {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
602
|
+
g as DEBUG_QUERY_PARAMS,
|
|
603
|
+
B as KnockGuideClient,
|
|
604
|
+
U as guidesApiRootPath
|
|
545
605
|
};
|
|
546
606
|
//# sourceMappingURL=client.mjs.map
|