@knocklabs/client 0.21.1 → 0.21.2
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 +8 -0
- package/dist/cjs/api.js +1 -1
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/clients/feed/feed.js +1 -1
- package/dist/cjs/clients/feed/feed.js.map +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/clients/guide/types.js +2 -0
- package/dist/cjs/clients/guide/types.js.map +1 -0
- package/dist/cjs/helpers.js +1 -1
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/knock.js +2 -2
- package/dist/cjs/knock.js.map +1 -1
- package/dist/cjs/pageVisibility.js +2 -0
- package/dist/cjs/pageVisibility.js.map +1 -0
- package/dist/esm/api.mjs +27 -12
- package/dist/esm/api.mjs.map +1 -1
- package/dist/esm/clients/feed/feed.mjs +60 -87
- package/dist/esm/clients/feed/feed.mjs.map +1 -1
- package/dist/esm/clients/guide/client.mjs +191 -147
- package/dist/esm/clients/guide/client.mjs.map +1 -1
- package/dist/esm/clients/guide/helpers.mjs +34 -44
- package/dist/esm/clients/guide/helpers.mjs.map +1 -1
- package/dist/esm/clients/guide/types.mjs +13 -0
- package/dist/esm/clients/guide/types.mjs.map +1 -0
- package/dist/esm/helpers.mjs +19 -4
- package/dist/esm/helpers.mjs.map +1 -1
- package/dist/esm/index.mjs +14 -12
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/knock.mjs +31 -29
- package/dist/esm/knock.mjs.map +1 -1
- package/dist/esm/pageVisibility.mjs +31 -0
- package/dist/esm/pageVisibility.mjs.map +1 -0
- package/dist/types/api.d.ts +4 -0
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/clients/feed/feed.d.ts +1 -11
- package/dist/types/clients/feed/feed.d.ts.map +1 -1
- package/dist/types/clients/feed/interfaces.d.ts +0 -4
- package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
- package/dist/types/clients/feed/utils.d.ts +0 -2
- package/dist/types/clients/feed/utils.d.ts.map +1 -1
- package/dist/types/clients/guide/client.d.ts +3 -1
- package/dist/types/clients/guide/client.d.ts.map +1 -1
- package/dist/types/clients/guide/helpers.d.ts +1 -7
- package/dist/types/clients/guide/helpers.d.ts.map +1 -1
- package/dist/types/clients/guide/index.d.ts +2 -1
- package/dist/types/clients/guide/index.d.ts.map +1 -1
- package/dist/types/clients/guide/types.d.ts +21 -0
- package/dist/types/clients/guide/types.d.ts.map +1 -1
- package/dist/types/helpers.d.ts +19 -0
- package/dist/types/helpers.d.ts.map +1 -1
- package/dist/types/interfaces.d.ts +2 -0
- package/dist/types/interfaces.d.ts.map +1 -1
- package/dist/types/knock.d.ts +1 -0
- package/dist/types/knock.d.ts.map +1 -1
- package/dist/types/pageVisibility.d.ts +22 -0
- package/dist/types/pageVisibility.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/api.ts +30 -0
- package/src/clients/feed/feed.ts +0 -73
- package/src/clients/feed/interfaces.ts +0 -7
- package/src/clients/guide/client.ts +117 -32
- package/src/clients/guide/helpers.ts +0 -12
- package/src/clients/guide/index.ts +3 -0
- package/src/clients/guide/types.ts +34 -0
- package/src/helpers.ts +39 -0
- package/src/interfaces.ts +2 -0
- package/src/knock.ts +4 -3
- package/src/pageVisibility.ts +70 -0
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
var I = Object.defineProperty;
|
|
2
2
|
var C = (u, e, t) => e in u ? I(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
|
|
3
|
-
var
|
|
3
|
+
var l = (u, e, t) => C(u, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { Store as E } from "@tanstack/store";
|
|
5
5
|
import { URLPattern as w } from "urlpattern-polyfill";
|
|
6
|
-
import { byKey as
|
|
7
|
-
|
|
6
|
+
import { byKey as y, mockDefaultGroup as R, formatFilters as G, formatState as S, checkStateIfThrottled as m, formatGroupStage as v, DEFAULT_GROUP_KEY as P, newUrl as D, predicateUrlRules as A, predicateUrlPatterns as L, findDefaultGroup as T } from "./helpers.mjs";
|
|
7
|
+
import { SelectionResult as $ } from "./types.mjs";
|
|
8
|
+
const K = 50, O = 30 * 1e3, U = 3, p = {
|
|
8
9
|
GUIDE_KEY: "knock_guide_key",
|
|
9
10
|
PREVIEW_SESSION_ID: "knock_preview_session_id"
|
|
10
|
-
}, f = "knock_guide_debug",
|
|
11
|
+
}, f = "knock_guide_debug", k = () => {
|
|
11
12
|
if (typeof window < "u")
|
|
12
13
|
return window;
|
|
13
14
|
}, F = (u) => `/v1/users/${u}/guides`, b = () => {
|
|
14
|
-
const u =
|
|
15
|
+
const u = k();
|
|
15
16
|
if (!u || !u.location)
|
|
16
17
|
return { forcedGuideKey: null, previewSessionId: null };
|
|
17
|
-
const e = new URLSearchParams(u.location.search), t = e.get(
|
|
18
|
-
|
|
18
|
+
const e = new URLSearchParams(u.location.search), t = e.get(p.GUIDE_KEY), s = e.get(
|
|
19
|
+
p.PREVIEW_SESSION_ID
|
|
19
20
|
);
|
|
20
21
|
if (t || s) {
|
|
21
22
|
if (u.localStorage)
|
|
22
23
|
try {
|
|
23
|
-
const
|
|
24
|
+
const r = {
|
|
24
25
|
forcedGuideKey: t,
|
|
25
26
|
previewSessionId: s
|
|
26
27
|
};
|
|
27
|
-
u.localStorage.setItem(f, JSON.stringify(
|
|
28
|
+
u.localStorage.setItem(f, JSON.stringify(r));
|
|
28
29
|
} catch {
|
|
29
30
|
}
|
|
30
31
|
return {
|
|
@@ -32,21 +33,21 @@ const K = 50, O = 30 * 1e3, U = 3, g = {
|
|
|
32
33
|
previewSessionId: s
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
let i = null,
|
|
36
|
+
let i = null, n = null;
|
|
36
37
|
if (u.localStorage)
|
|
37
38
|
try {
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
41
|
-
i =
|
|
39
|
+
const r = u.localStorage.getItem(f);
|
|
40
|
+
if (r) {
|
|
41
|
+
const a = q(r);
|
|
42
|
+
i = a.forcedGuideKey, n = a.previewSessionId;
|
|
42
43
|
}
|
|
43
44
|
} catch {
|
|
44
45
|
}
|
|
45
46
|
return {
|
|
46
47
|
forcedGuideKey: i,
|
|
47
|
-
previewSessionId:
|
|
48
|
+
previewSessionId: n
|
|
48
49
|
};
|
|
49
|
-
},
|
|
50
|
+
}, q = (u) => {
|
|
50
51
|
try {
|
|
51
52
|
const e = JSON.parse(u);
|
|
52
53
|
return {
|
|
@@ -59,20 +60,20 @@ const K = 50, O = 30 * 1e3, U = 3, g = {
|
|
|
59
60
|
previewSessionId: null
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
|
-
}, _ = (u, e
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
65
|
-
const
|
|
66
|
-
for (const [
|
|
67
|
-
const
|
|
68
|
-
!
|
|
63
|
+
}, _ = (u, e, t) => {
|
|
64
|
+
const s = new $(), i = T(u.guideGroups);
|
|
65
|
+
if (!i) return s;
|
|
66
|
+
const n = i.display_sequence, r = u.location;
|
|
67
|
+
for (const [a, o] of n.entries()) {
|
|
68
|
+
const c = u.previewGuides[o] || u.guides[o];
|
|
69
|
+
!c || !N(c, e, {
|
|
69
70
|
location: r,
|
|
70
71
|
ineligibleGuides: u.ineligibleGuides,
|
|
71
72
|
debug: u.debug
|
|
72
|
-
}) ||
|
|
73
|
+
}) || s.set(a, c);
|
|
73
74
|
}
|
|
74
|
-
return
|
|
75
|
-
},
|
|
75
|
+
return s.metadata = { guideGroup: i, filters: e, ...t }, s;
|
|
76
|
+
}, N = (u, e, { location: t, ineligibleGuides: s = {}, debug: i = {} }) => e.type && e.type !== u.type || e.key && e.key !== u.key ? !1 : i.forcedGuideKey ? i.forcedGuideKey === u.key : s[u.key] || !u.active || u.steps.every((r) => !!r.message.archived_at) ? !1 : j(u, t), j = (u, e) => {
|
|
76
77
|
const t = e ? D(e) : void 0, s = u.activation_url_rules || [], i = u.activation_url_patterns || [];
|
|
77
78
|
if (t && s.length > 0) {
|
|
78
79
|
if (!A(t, s)) return !1;
|
|
@@ -82,12 +83,12 @@ const K = 50, O = 30 * 1e3, U = 3, g = {
|
|
|
82
83
|
};
|
|
83
84
|
class W {
|
|
84
85
|
constructor(e, t, s = {}, i = {}) {
|
|
85
|
-
|
|
86
|
+
l(this, "store");
|
|
86
87
|
// Phoenix channels for real time guide updates over websocket
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
l(this, "socket");
|
|
89
|
+
l(this, "socketChannel");
|
|
90
|
+
l(this, "socketChannelTopic");
|
|
91
|
+
l(this, "socketEventTypes", [
|
|
91
92
|
"guide.added",
|
|
92
93
|
"guide.updated",
|
|
93
94
|
"guide.removed",
|
|
@@ -95,19 +96,19 @@ class W {
|
|
|
95
96
|
"guide_group.updated",
|
|
96
97
|
"guide.live_preview_updated"
|
|
97
98
|
]);
|
|
98
|
-
|
|
99
|
+
l(this, "subscribeRetryCount", 0);
|
|
99
100
|
// Original history methods to monkey patch, or restore in cleanups.
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
l(this, "pushStateFn");
|
|
102
|
+
l(this, "replaceStateFn");
|
|
102
103
|
// Guides that are competing to render are "staged" first without rendering
|
|
103
104
|
// and ranked based on its relative order in the group over a duration of time
|
|
104
105
|
// to resolve and render the prevailing one.
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
l(this, "stage");
|
|
107
|
+
l(this, "counterIntervalId");
|
|
107
108
|
// Define as an arrow func property to always bind this to the class instance.
|
|
108
|
-
|
|
109
|
+
l(this, "handleLocationChange", () => {
|
|
109
110
|
this.knock.log("[Guide] .handleLocationChange");
|
|
110
|
-
const e =
|
|
111
|
+
const e = k();
|
|
111
112
|
if (!(e != null && e.location)) return;
|
|
112
113
|
const t = e.location.href;
|
|
113
114
|
if (this.store.state.location === t) return;
|
|
@@ -123,15 +124,15 @@ class W {
|
|
|
123
124
|
"[Guide] Debug state changed, refetching guides and resubscribing to the websocket channel"
|
|
124
125
|
), this.fetch(), this.subscribe());
|
|
125
126
|
});
|
|
126
|
-
var
|
|
127
|
+
var g;
|
|
127
128
|
this.knock = e, this.channelId = t, this.targetParams = s, this.options = i;
|
|
128
129
|
const {
|
|
129
|
-
trackLocationFromWindow:
|
|
130
|
+
trackLocationFromWindow: n = !0,
|
|
130
131
|
// TODO(KNO-11523): Remove once we ship guide toolbar v2, and offload as
|
|
131
132
|
// much debugging specific logic and responsibilities to toolbar.
|
|
132
|
-
trackDebugParams:
|
|
133
|
-
throttleCheckInterval:
|
|
134
|
-
} = i,
|
|
133
|
+
trackDebugParams: r = !1,
|
|
134
|
+
throttleCheckInterval: a = O
|
|
135
|
+
} = i, o = k(), c = n ? (g = o == null ? void 0 : o.location) == null ? void 0 : g.href : void 0, d = r ? b() : void 0;
|
|
135
136
|
this.store = new E({
|
|
136
137
|
guideGroups: [],
|
|
137
138
|
guideGroupDisplayLogs: {},
|
|
@@ -139,13 +140,13 @@ class W {
|
|
|
139
140
|
ineligibleGuides: {},
|
|
140
141
|
previewGuides: {},
|
|
141
142
|
queries: {},
|
|
142
|
-
location:
|
|
143
|
+
location: c,
|
|
143
144
|
// Increment to update the state store and trigger re-selection.
|
|
144
145
|
counter: 0,
|
|
145
|
-
debug:
|
|
146
|
+
debug: d
|
|
146
147
|
});
|
|
147
|
-
const { socket:
|
|
148
|
-
this.socket =
|
|
148
|
+
const { socket: h } = this.knock.client();
|
|
149
|
+
this.socket = h, this.socketChannelTopic = `guides:${t}`, n && this.listenForLocationChangesFromWindow(), a && this.startCounterInterval(a), this.knock.log("[Guide] Initialized a guide client");
|
|
149
150
|
}
|
|
150
151
|
incrementCounter() {
|
|
151
152
|
this.knock.log("[Guide] Incrementing the counter"), this.store.setState((e) => ({ ...e, counter: e.counter + 1 }));
|
|
@@ -166,36 +167,36 @@ class W {
|
|
|
166
167
|
const t = this.buildQueryParams(e == null ? void 0 : e.filters), s = this.formatQueryKey(t), i = this.store.state.queries[s];
|
|
167
168
|
if (i)
|
|
168
169
|
return i;
|
|
169
|
-
this.store.setState((
|
|
170
|
-
...
|
|
171
|
-
queries: { ...
|
|
170
|
+
this.store.setState((r) => ({
|
|
171
|
+
...r,
|
|
172
|
+
queries: { ...r.queries, [s]: { status: "loading" } }
|
|
172
173
|
}));
|
|
173
|
-
let
|
|
174
|
+
let n;
|
|
174
175
|
try {
|
|
175
176
|
this.knock.log("[Guide] Fetching all eligible guides");
|
|
176
|
-
const
|
|
177
|
-
|
|
177
|
+
const r = await this.knock.user.getGuides(this.channelId, t);
|
|
178
|
+
n = { status: "ok" };
|
|
178
179
|
const {
|
|
179
|
-
entries:
|
|
180
|
-
guide_groups:
|
|
181
|
-
guide_group_display_logs:
|
|
182
|
-
ineligible_guides:
|
|
183
|
-
} =
|
|
184
|
-
this.knock.log("[Guide] Loading fetched guides"), this.store.setState((
|
|
185
|
-
...
|
|
186
|
-
guideGroups: (
|
|
187
|
-
guideGroupDisplayLogs:
|
|
188
|
-
guides:
|
|
189
|
-
ineligibleGuides:
|
|
190
|
-
queries: { ...
|
|
180
|
+
entries: a,
|
|
181
|
+
guide_groups: o,
|
|
182
|
+
guide_group_display_logs: c,
|
|
183
|
+
ineligible_guides: d
|
|
184
|
+
} = r;
|
|
185
|
+
this.knock.log("[Guide] Loading fetched guides"), this.store.setState((h) => ({
|
|
186
|
+
...h,
|
|
187
|
+
guideGroups: (o == null ? void 0 : o.length) > 0 ? o : [R(a)],
|
|
188
|
+
guideGroupDisplayLogs: c || {},
|
|
189
|
+
guides: y(a.map((g) => this.localCopy(g))),
|
|
190
|
+
ineligibleGuides: y(d || []),
|
|
191
|
+
queries: { ...h.queries, [s]: n }
|
|
191
192
|
}));
|
|
192
|
-
} catch (
|
|
193
|
-
|
|
194
|
-
...
|
|
195
|
-
queries: { ...
|
|
193
|
+
} catch (r) {
|
|
194
|
+
n = { status: "error", error: r }, this.store.setState((a) => ({
|
|
195
|
+
...a,
|
|
196
|
+
queries: { ...a.queries, [s]: n }
|
|
196
197
|
}));
|
|
197
198
|
}
|
|
198
|
-
return
|
|
199
|
+
return n;
|
|
199
200
|
}
|
|
200
201
|
subscribe() {
|
|
201
202
|
if (!this.socket) return;
|
|
@@ -207,7 +208,7 @@ class W {
|
|
|
207
208
|
preview_session_id: (e == null ? void 0 : e.previewSessionId) || void 0
|
|
208
209
|
}, s = this.socket.channel(this.socketChannelTopic, t);
|
|
209
210
|
for (const i of this.socketEventTypes)
|
|
210
|
-
s.on(i, (
|
|
211
|
+
s.on(i, (n) => this.handleSocketEvent(n));
|
|
211
212
|
["closed", "errored"].includes(s.state) && (this.subscribeRetryCount = 0, s.join().receive("ok", () => {
|
|
212
213
|
this.knock.log("[Guide] Successfully joined channel");
|
|
213
214
|
}).receive("error", (i) => {
|
|
@@ -255,8 +256,8 @@ class W {
|
|
|
255
256
|
}
|
|
256
257
|
setLocation(e, t = {}) {
|
|
257
258
|
this.knock.log(`[Guide] .setLocation (loc=${e})`), this.clearGroupStage(), this.knock.log("[Guide] Updating the tracked location"), this.store.setState((s) => {
|
|
258
|
-
var
|
|
259
|
-
const i = (
|
|
259
|
+
var n;
|
|
260
|
+
const i = (n = t == null ? void 0 : t.debug) != null && n.previewSessionId ? s.previewGuides : {};
|
|
260
261
|
return {
|
|
261
262
|
...s,
|
|
262
263
|
...t,
|
|
@@ -267,7 +268,7 @@ class W {
|
|
|
267
268
|
}
|
|
268
269
|
exitDebugMode() {
|
|
269
270
|
this.knock.log("[Guide] Exiting debug mode");
|
|
270
|
-
const e =
|
|
271
|
+
const e = k();
|
|
271
272
|
if (e != null && e.localStorage)
|
|
272
273
|
try {
|
|
273
274
|
e.localStorage.removeItem(f);
|
|
@@ -280,7 +281,7 @@ class W {
|
|
|
280
281
|
// Clear preview guides when exiting debug mode
|
|
281
282
|
})), e != null && e.location) {
|
|
282
283
|
const t = new URL(e.location.href);
|
|
283
|
-
(t.searchParams.has(
|
|
284
|
+
(t.searchParams.has(p.GUIDE_KEY) || t.searchParams.has(p.PREVIEW_SESSION_ID)) && (t.searchParams.delete(p.GUIDE_KEY), t.searchParams.delete(p.PREVIEW_SESSION_ID), e.location.href = t.toString());
|
|
284
285
|
}
|
|
285
286
|
}
|
|
286
287
|
setDebug(e) {
|
|
@@ -306,62 +307,104 @@ class W {
|
|
|
306
307
|
// Store selector
|
|
307
308
|
//
|
|
308
309
|
selectGuides(e, t = {}, s = {}) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
310
|
+
var c;
|
|
311
|
+
this.knock.log(
|
|
312
|
+
`[Guide] .selectGuides (filters: ${G(t)}; state: ${S(e)})`
|
|
313
|
+
);
|
|
314
|
+
const i = this.selectGuide(e, t, {
|
|
315
|
+
...s,
|
|
316
|
+
// Don't record this result, not the actual query result we need.
|
|
317
|
+
recordSelectQuery: !1
|
|
318
|
+
}), { recordSelectQuery: n = !!((c = e.debug) != null && c.debugging) } = s, r = {
|
|
319
|
+
limit: "all",
|
|
320
|
+
opts: { ...s, recordSelectQuery: n }
|
|
321
|
+
}, a = _(e, t, r);
|
|
322
|
+
if (this.maybeRecordSelectResult(a), !i && !s.includeThrottled)
|
|
312
323
|
return [];
|
|
313
|
-
const
|
|
314
|
-
if (!s.includeThrottled &&
|
|
315
|
-
const
|
|
316
|
-
(
|
|
317
|
-
),
|
|
324
|
+
const o = [...a.values()];
|
|
325
|
+
if (!s.includeThrottled && m(e)) {
|
|
326
|
+
const d = o.filter(
|
|
327
|
+
(g) => g.bypass_global_group_limit
|
|
328
|
+
), h = o.length - d.length;
|
|
318
329
|
return this.knock.log(
|
|
319
|
-
`[Guide] Throttling ${
|
|
320
|
-
),
|
|
330
|
+
`[Guide] Throttling ${h} guides from selection, and returning ${d.length} guides`
|
|
331
|
+
), d;
|
|
321
332
|
}
|
|
322
|
-
return this.knock.log(`[Guide] Returning ${
|
|
333
|
+
return this.knock.log(`[Guide] Returning ${o.length} guides from selection`), o;
|
|
323
334
|
}
|
|
324
335
|
selectGuide(e, t = {}, s = {}) {
|
|
336
|
+
var d;
|
|
325
337
|
if (this.knock.log(
|
|
326
|
-
`[Guide] .selectGuide (filters: ${
|
|
338
|
+
`[Guide] .selectGuide (filters: ${G(t)}; state: ${S(e)})`
|
|
327
339
|
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0) {
|
|
328
340
|
this.knock.log("[Guide] Exiting selection (no guides)");
|
|
329
341
|
return;
|
|
330
342
|
}
|
|
331
|
-
|
|
332
|
-
|
|
343
|
+
this.stage || (this.stage = this.openGroupStage());
|
|
344
|
+
const { recordSelectQuery: i = !!((d = e.debug) != null && d.debugging) } = s, n = {
|
|
345
|
+
limit: "one",
|
|
346
|
+
opts: { ...s, recordSelectQuery: i }
|
|
347
|
+
}, r = _(e, t, n);
|
|
348
|
+
if (this.maybeRecordSelectResult(r), r.size === 0) {
|
|
333
349
|
this.knock.log("[Guide] Selection found zero result");
|
|
334
350
|
return;
|
|
335
351
|
}
|
|
336
|
-
const [
|
|
352
|
+
const [a, o] = [...r][0];
|
|
337
353
|
if (this.knock.log(
|
|
338
|
-
`[Guide] Selection found: \`${
|
|
339
|
-
),
|
|
340
|
-
return this.knock.log(`[Guide] Returning the unthrottled guide: ${
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
switch (this.stage || (this.stage = this.openGroupStage()), this.stage.status) {
|
|
354
|
+
`[Guide] Selection found: \`${o.key}\` (total: ${r.size})`
|
|
355
|
+
), o.bypass_global_group_limit)
|
|
356
|
+
return this.knock.log(`[Guide] Returning the unthrottled guide: ${o.key}`), o;
|
|
357
|
+
const c = !s.includeThrottled && m(e);
|
|
358
|
+
switch (this.stage.status) {
|
|
346
359
|
case "open": {
|
|
347
|
-
this.knock.log(`[Guide] Adding to the group stage: ${
|
|
360
|
+
this.knock.log(`[Guide] Adding to the group stage: ${o.key}`), this.stage.ordered[a] = o.key;
|
|
348
361
|
return;
|
|
349
362
|
}
|
|
350
363
|
case "patch": {
|
|
351
|
-
this.knock.log(`[Guide] Patching the group stage: ${
|
|
352
|
-
|
|
364
|
+
if (this.knock.log(`[Guide] Patching the group stage: ${o.key}`), this.stage.ordered[a] = o.key, c) {
|
|
365
|
+
this.knock.log(`[Guide] Throttling the selected guide: ${o.key}`);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const h = this.stage.resolved === o.key ? o : void 0;
|
|
353
369
|
return this.knock.log(
|
|
354
|
-
`[Guide] Returning \`${
|
|
355
|
-
),
|
|
370
|
+
`[Guide] Returning \`${h == null ? void 0 : h.key}\` (stage: ${v(this.stage)})`
|
|
371
|
+
), h;
|
|
356
372
|
}
|
|
357
373
|
case "closed": {
|
|
358
|
-
|
|
374
|
+
if (c) {
|
|
375
|
+
this.knock.log(`[Guide] Throttling the selected guide: ${o.key}`);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const h = this.stage.resolved === o.key ? o : void 0;
|
|
359
379
|
return this.knock.log(
|
|
360
|
-
`[Guide] Returning \`${
|
|
361
|
-
),
|
|
380
|
+
`[Guide] Returning \`${h == null ? void 0 : h.key}\` (stage: ${v(this.stage)})`
|
|
381
|
+
), h;
|
|
362
382
|
}
|
|
363
383
|
}
|
|
364
384
|
}
|
|
385
|
+
// Record select query results by accumulating them by 1) key or type first,
|
|
386
|
+
// and then 2) "one" or "all".
|
|
387
|
+
maybeRecordSelectResult(e) {
|
|
388
|
+
if (!e.metadata) return;
|
|
389
|
+
const { opts: t, filters: s, limit: i } = e.metadata;
|
|
390
|
+
if (!t.recordSelectQuery || !s.key && !s.type || !this.stage || this.stage.status === "closed") return;
|
|
391
|
+
const n = this.stage.results.key || {};
|
|
392
|
+
s.key && (n[s.key] = {
|
|
393
|
+
...n[s.key] || {},
|
|
394
|
+
[i]: e
|
|
395
|
+
});
|
|
396
|
+
const r = this.stage.results.type || {};
|
|
397
|
+
s.type && (r[s.type] = {
|
|
398
|
+
...r[s.type] || {},
|
|
399
|
+
[i]: e
|
|
400
|
+
}), this.stage = {
|
|
401
|
+
...this.stage,
|
|
402
|
+
results: { key: n, type: r }
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
getStage() {
|
|
406
|
+
return this.stage;
|
|
407
|
+
}
|
|
365
408
|
openGroupStage() {
|
|
366
409
|
this.knock.log("[Guide] Opening a new group stage");
|
|
367
410
|
const {
|
|
@@ -372,6 +415,7 @@ class W {
|
|
|
372
415
|
return this.stage = {
|
|
373
416
|
status: "open",
|
|
374
417
|
ordered: [],
|
|
418
|
+
results: {},
|
|
375
419
|
timeoutId: t
|
|
376
420
|
}, this.stage;
|
|
377
421
|
}
|
|
@@ -452,16 +496,16 @@ class W {
|
|
|
452
496
|
this.knock.log(
|
|
453
497
|
`[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${t.ref})`
|
|
454
498
|
);
|
|
455
|
-
const i = (/* @__PURE__ */ new Date()).toISOString(),
|
|
499
|
+
const i = (/* @__PURE__ */ new Date()).toISOString(), n = this.setStepMessageAttrs(e.key, t.ref, {
|
|
456
500
|
read_at: i,
|
|
457
501
|
interacted_at: i
|
|
458
502
|
});
|
|
459
|
-
if (!
|
|
460
|
-
const
|
|
461
|
-
...this.buildEngagementEventBaseParams(e,
|
|
503
|
+
if (!n) return;
|
|
504
|
+
const r = {
|
|
505
|
+
...this.buildEngagementEventBaseParams(e, n),
|
|
462
506
|
metadata: s
|
|
463
507
|
};
|
|
464
|
-
return this.knock.user.markGuideStepAs("interacted",
|
|
508
|
+
return this.knock.user.markGuideStepAs("interacted", r), n;
|
|
465
509
|
}
|
|
466
510
|
async markAsArchived(e, t) {
|
|
467
511
|
if (t.message.archived_at) return;
|
|
@@ -490,24 +534,24 @@ class W {
|
|
|
490
534
|
// Get the next unarchived step.
|
|
491
535
|
getStep() {
|
|
492
536
|
var i;
|
|
493
|
-
return ((i = t.store.state.debug) == null ? void 0 : i.forcedGuideKey) === this.key ? this.steps[0] : this.steps.find((
|
|
537
|
+
return ((i = t.store.state.debug) == null ? void 0 : i.forcedGuideKey) === this.key ? this.steps[0] : this.steps.find((n) => !n.message.archived_at);
|
|
494
538
|
}
|
|
495
539
|
};
|
|
496
|
-
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: i, ...
|
|
497
|
-
const
|
|
498
|
-
...
|
|
540
|
+
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: i, ...n }) => {
|
|
541
|
+
const r = {
|
|
542
|
+
...n,
|
|
499
543
|
message: { ...i },
|
|
500
544
|
markAsSeen() {
|
|
501
545
|
return t.markAsSeen(s, this);
|
|
502
546
|
},
|
|
503
|
-
markAsInteracted({ metadata:
|
|
504
|
-
return t.markAsInteracted(s, this,
|
|
547
|
+
markAsInteracted({ metadata: a } = {}) {
|
|
548
|
+
return t.markAsInteracted(s, this, a);
|
|
505
549
|
},
|
|
506
550
|
markAsArchived() {
|
|
507
551
|
return t.markAsArchived(s, this);
|
|
508
552
|
}
|
|
509
553
|
};
|
|
510
|
-
return
|
|
554
|
+
return r.markAsSeen = r.markAsSeen.bind(r), r.markAsInteracted = r.markAsInteracted.bind(r), r.markAsArchived = r.markAsArchived.bind(r), r;
|
|
511
555
|
}), s.activation_url_patterns = e.activation_url_patterns.map((i) => ({
|
|
512
556
|
...i,
|
|
513
557
|
pattern: new w({
|
|
@@ -524,29 +568,29 @@ class W {
|
|
|
524
568
|
(s != null && s.forcedGuideKey || s != null && s.debugging) && (t.force_all_guides = !0);
|
|
525
569
|
let i = Object.fromEntries(
|
|
526
570
|
Object.entries(t).filter(
|
|
527
|
-
([
|
|
571
|
+
([n, r]) => r != null
|
|
528
572
|
)
|
|
529
573
|
);
|
|
530
574
|
return i = i.data ? { ...i, data: JSON.stringify(i.data) } : i, i;
|
|
531
575
|
}
|
|
532
576
|
formatQueryKey(e) {
|
|
533
577
|
const s = Object.keys(e).sort().map(
|
|
534
|
-
(
|
|
578
|
+
(n) => `${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`
|
|
535
579
|
).join("&"), i = F(this.knock.userId);
|
|
536
580
|
return s ? `${i}?${s}` : i;
|
|
537
581
|
}
|
|
538
582
|
setStepMessageAttrs(e, t, s) {
|
|
539
583
|
let i;
|
|
540
|
-
return s.archived_at && this.clearGroupStage(), this.store.setState((
|
|
541
|
-
let
|
|
542
|
-
if (!
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
...
|
|
584
|
+
return s.archived_at && this.clearGroupStage(), this.store.setState((n) => {
|
|
585
|
+
let r = n.guides[e];
|
|
586
|
+
if (!r) return n;
|
|
587
|
+
const a = r.steps.map((d) => (d.ref !== t || (d.message = { ...d.message, ...s }, i = d), d));
|
|
588
|
+
r = i ? { ...r, steps: a } : r;
|
|
589
|
+
const o = { ...n.guides, [r.key]: r }, c = s.archived_at && !r.bypass_global_group_limit ? {
|
|
590
|
+
...n.guideGroupDisplayLogs,
|
|
547
591
|
[P]: s.archived_at
|
|
548
|
-
} :
|
|
549
|
-
return { ...
|
|
592
|
+
} : n.guideGroupDisplayLogs;
|
|
593
|
+
return { ...n, guides: o, guideGroupDisplayLogs: c };
|
|
550
594
|
}), i;
|
|
551
595
|
}
|
|
552
596
|
buildEngagementEventBaseParams(e, t) {
|
|
@@ -577,17 +621,17 @@ class W {
|
|
|
577
621
|
data: e
|
|
578
622
|
}) {
|
|
579
623
|
this.patchClosedGroupStage(), this.store.setState((t) => {
|
|
580
|
-
const s = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [],
|
|
581
|
-
let
|
|
582
|
-
return
|
|
583
|
-
if (!o
|
|
584
|
-
const
|
|
585
|
-
return { ...
|
|
586
|
-
},
|
|
587
|
-
if (!o
|
|
588
|
-
const
|
|
589
|
-
return { ...
|
|
590
|
-
},
|
|
624
|
+
const s = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [], n = e.guide_group.display_sequence_throttled || [];
|
|
625
|
+
let r = t.guides;
|
|
626
|
+
return r = i.reduce((a, o) => {
|
|
627
|
+
if (!a[o]) return a;
|
|
628
|
+
const c = { ...a[o], bypass_global_group_limit: !0 };
|
|
629
|
+
return { ...a, [o]: c };
|
|
630
|
+
}, r), r = n.reduce((a, o) => {
|
|
631
|
+
if (!a[o]) return a;
|
|
632
|
+
const c = { ...a[o], bypass_global_group_limit: !1 };
|
|
633
|
+
return { ...a, [o]: c };
|
|
634
|
+
}, r), { ...t, guides: r, guideGroups: s };
|
|
591
635
|
});
|
|
592
636
|
}
|
|
593
637
|
updatePreviewGuide({ data: e }) {
|
|
@@ -603,19 +647,19 @@ class W {
|
|
|
603
647
|
return !!e.forcedGuideKey != !!t.forcedGuideKey || e.previewSessionId !== t.previewSessionId;
|
|
604
648
|
}
|
|
605
649
|
listenForLocationChangesFromWindow() {
|
|
606
|
-
const e =
|
|
650
|
+
const e = k();
|
|
607
651
|
if (e != null && e.history && (e != null && e.addEventListener)) {
|
|
608
652
|
e.addEventListener("popstate", this.handleLocationChange), e.addEventListener("hashchange", this.handleLocationChange);
|
|
609
653
|
const t = e.history.pushState, s = e.history.replaceState;
|
|
610
654
|
e.history.pushState = new Proxy(t, {
|
|
611
|
-
apply: (i,
|
|
612
|
-
Reflect.apply(i,
|
|
655
|
+
apply: (i, n, r) => {
|
|
656
|
+
Reflect.apply(i, n, r), setTimeout(() => {
|
|
613
657
|
this.handleLocationChange();
|
|
614
658
|
}, 0);
|
|
615
659
|
}
|
|
616
660
|
}), e.history.replaceState = new Proxy(s, {
|
|
617
|
-
apply: (i,
|
|
618
|
-
Reflect.apply(i,
|
|
661
|
+
apply: (i, n, r) => {
|
|
662
|
+
Reflect.apply(i, n, r), setTimeout(() => {
|
|
619
663
|
this.handleLocationChange();
|
|
620
664
|
}, 0);
|
|
621
665
|
}
|
|
@@ -626,12 +670,12 @@ class W {
|
|
|
626
670
|
);
|
|
627
671
|
}
|
|
628
672
|
removeLocationChangeEventListeners() {
|
|
629
|
-
const e =
|
|
673
|
+
const e = k();
|
|
630
674
|
!(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));
|
|
631
675
|
}
|
|
632
676
|
}
|
|
633
677
|
export {
|
|
634
|
-
|
|
678
|
+
p as DEBUG_QUERY_PARAMS,
|
|
635
679
|
W as KnockGuideClient,
|
|
636
680
|
j as checkActivatable,
|
|
637
681
|
F as guidesApiRootPath
|