@knocklabs/client 0.20.4 → 0.21.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 +48 -0
- package/dist/cjs/api.js +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/feed/utils.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/index.js +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/clients/feed/feed.mjs +2 -1
- package/dist/esm/clients/feed/feed.mjs.map +1 -1
- package/dist/esm/clients/feed/utils.mjs.map +1 -1
- package/dist/esm/clients/guide/client.mjs +212 -190
- package/dist/esm/clients/guide/client.mjs.map +1 -1
- package/dist/esm/index.mjs +11 -10
- package/dist/types/clients/feed/feed.d.ts.map +1 -1
- package/dist/types/clients/feed/interfaces.d.ts +35 -3
- package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
- package/dist/types/clients/feed/utils.d.ts +1 -0
- package/dist/types/clients/feed/utils.d.ts.map +1 -1
- package/dist/types/clients/guide/client.d.ts +4 -1
- package/dist/types/clients/guide/client.d.ts.map +1 -1
- package/dist/types/clients/guide/index.d.ts +2 -2
- package/dist/types/clients/guide/index.d.ts.map +1 -1
- package/dist/types/clients/guide/types.d.ts +12 -1
- package/dist/types/clients/guide/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/clients/feed/feed.ts +2 -1
- package/src/clients/feed/interfaces.ts +35 -6
- package/src/clients/feed/utils.ts +11 -2
- package/src/clients/guide/client.ts +89 -52
- package/src/clients/guide/index.ts +7 -1
- package/src/clients/guide/types.ts +21 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Store as
|
|
5
|
-
import { URLPattern as
|
|
6
|
-
import { byKey as
|
|
7
|
-
const
|
|
1
|
+
var I = Object.defineProperty;
|
|
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 c = (u, e, t) => C(u, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { Store as E } from "@tanstack/store";
|
|
5
|
+
import { URLPattern as w } from "urlpattern-polyfill";
|
|
6
|
+
import { byKey as G, mockDefaultGroup as R, formatFilters as S, formatState as m, checkStateIfThrottled as y, formatGroupStage as v, DEFAULT_GROUP_KEY as P, newUrl as D, predicateUrlRules as A, predicateUrlPatterns as L, SelectionResult as $, findDefaultGroup as T } from "./helpers.mjs";
|
|
7
|
+
const K = 50, O = 30 * 1e3, U = 3, g = {
|
|
8
8
|
GUIDE_KEY: "knock_guide_key",
|
|
9
9
|
PREVIEW_SESSION_ID: "knock_preview_session_id"
|
|
10
|
-
},
|
|
10
|
+
}, f = "knock_guide_debug", l = () => {
|
|
11
11
|
if (typeof window < "u")
|
|
12
12
|
return window;
|
|
13
|
-
},
|
|
13
|
+
}, F = (u) => `/v1/users/${u}/guides`, b = () => {
|
|
14
14
|
const u = l();
|
|
15
15
|
if (!u || !u.location)
|
|
16
16
|
return { forcedGuideKey: null, previewSessionId: null };
|
|
@@ -20,11 +20,11 @@ const $ = 50, T = 30 * 1e3, O = 3, g = {
|
|
|
20
20
|
if (t || s) {
|
|
21
21
|
if (u.localStorage)
|
|
22
22
|
try {
|
|
23
|
-
const
|
|
23
|
+
const n = {
|
|
24
24
|
forcedGuideKey: t,
|
|
25
25
|
previewSessionId: s
|
|
26
26
|
};
|
|
27
|
-
u.localStorage.setItem(
|
|
27
|
+
u.localStorage.setItem(f, JSON.stringify(n));
|
|
28
28
|
} catch {
|
|
29
29
|
}
|
|
30
30
|
return {
|
|
@@ -32,21 +32,21 @@ const $ = 50, T = 30 * 1e3, O = 3, g = {
|
|
|
32
32
|
previewSessionId: s
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
let
|
|
35
|
+
let i = null, r = null;
|
|
36
36
|
if (u.localStorage)
|
|
37
37
|
try {
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
const o =
|
|
41
|
-
|
|
38
|
+
const n = u.localStorage.getItem(f);
|
|
39
|
+
if (n) {
|
|
40
|
+
const o = N(n);
|
|
41
|
+
i = o.forcedGuideKey, r = o.previewSessionId;
|
|
42
42
|
}
|
|
43
43
|
} catch {
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
|
-
forcedGuideKey:
|
|
47
|
-
previewSessionId:
|
|
46
|
+
forcedGuideKey: i,
|
|
47
|
+
previewSessionId: r
|
|
48
48
|
};
|
|
49
|
-
},
|
|
49
|
+
}, N = (u) => {
|
|
50
50
|
try {
|
|
51
51
|
const e = JSON.parse(u);
|
|
52
52
|
return {
|
|
@@ -59,45 +59,35 @@ const $ = 50, T = 30 * 1e3, O = 3, g = {
|
|
|
59
59
|
previewSessionId: null
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
},
|
|
63
|
-
const t = new
|
|
62
|
+
}, _ = (u, e = {}) => {
|
|
63
|
+
const t = new $(), s = T(u.guideGroups);
|
|
64
64
|
if (!s) return t;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
let a = u.guides[o];
|
|
72
|
-
u.debug.forcedGuideKey === o && u.previewGuides[o] && (a = u.previewGuides[o]), !(!a || !N(a, {
|
|
73
|
-
location: n,
|
|
74
|
-
filters: e,
|
|
65
|
+
const i = s.display_sequence, r = u.location;
|
|
66
|
+
for (const [n, o] of i.entries()) {
|
|
67
|
+
const a = u.previewGuides[o] || u.guides[o];
|
|
68
|
+
!a || !q(a, e, {
|
|
69
|
+
location: r,
|
|
70
|
+
ineligibleGuides: u.ineligibleGuides,
|
|
75
71
|
debug: u.debug
|
|
76
|
-
})
|
|
72
|
+
}) || t.set(n, a);
|
|
77
73
|
}
|
|
78
74
|
return t.metadata = { guideGroup: s }, t;
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!u.active || u.steps.every((o) => !!o.message.archived_at))
|
|
85
|
-
return !1;
|
|
86
|
-
const r = e ? L(e) : void 0, n = u.activation_url_rules || [], i = u.activation_url_patterns || [];
|
|
87
|
-
if (r && n.length > 0) {
|
|
88
|
-
if (!D(r, n)) return !1;
|
|
89
|
-
} else if (r && i.length > 0 && !K(r, i))
|
|
75
|
+
}, q = (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((n) => !!n.message.archived_at) ? !1 : j(u, t), j = (u, e) => {
|
|
76
|
+
const t = e ? D(e) : void 0, s = u.activation_url_rules || [], i = u.activation_url_patterns || [];
|
|
77
|
+
if (t && s.length > 0) {
|
|
78
|
+
if (!A(t, s)) return !1;
|
|
79
|
+
} else if (t && i.length > 0 && !L(t, i))
|
|
90
80
|
return !1;
|
|
91
81
|
return !0;
|
|
92
82
|
};
|
|
93
|
-
class
|
|
94
|
-
constructor(e, t, s = {},
|
|
95
|
-
|
|
83
|
+
class W {
|
|
84
|
+
constructor(e, t, s = {}, i = {}) {
|
|
85
|
+
c(this, "store");
|
|
96
86
|
// Phoenix channels for real time guide updates over websocket
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
c(this, "socket");
|
|
88
|
+
c(this, "socketChannel");
|
|
89
|
+
c(this, "socketChannelTopic");
|
|
90
|
+
c(this, "socketEventTypes", [
|
|
101
91
|
"guide.added",
|
|
102
92
|
"guide.updated",
|
|
103
93
|
"guide.removed",
|
|
@@ -105,50 +95,57 @@ class B {
|
|
|
105
95
|
"guide_group.updated",
|
|
106
96
|
"guide.live_preview_updated"
|
|
107
97
|
]);
|
|
108
|
-
|
|
98
|
+
c(this, "subscribeRetryCount", 0);
|
|
109
99
|
// Original history methods to monkey patch, or restore in cleanups.
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
c(this, "pushStateFn");
|
|
101
|
+
c(this, "replaceStateFn");
|
|
112
102
|
// Guides that are competing to render are "staged" first without rendering
|
|
113
103
|
// and ranked based on its relative order in the group over a duration of time
|
|
114
104
|
// to resolve and render the prevailing one.
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
c(this, "stage");
|
|
106
|
+
c(this, "counterIntervalId");
|
|
117
107
|
// Define as an arrow func property to always bind this to the class instance.
|
|
118
|
-
|
|
108
|
+
c(this, "handleLocationChange", () => {
|
|
119
109
|
this.knock.log("[Guide] .handleLocationChange");
|
|
120
110
|
const e = l();
|
|
121
111
|
if (!(e != null && e.location)) return;
|
|
122
112
|
const t = e.location.href;
|
|
123
113
|
if (this.store.state.location === t) return;
|
|
124
|
-
this.knock.log(`[Guide] Detected a location change: ${t}`)
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
if (this.knock.log(`[Guide] Detected a location change: ${t}`), !this.options.trackDebugParams) {
|
|
115
|
+
this.setLocation(t);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const s = this.store.state.debug || {}, i = b();
|
|
119
|
+
this.setLocation(t, { debug: i }), this.checkDebugStateChanged(
|
|
127
120
|
s,
|
|
128
|
-
|
|
121
|
+
i
|
|
129
122
|
) && (this.knock.log(
|
|
130
123
|
"[Guide] Debug state changed, refetching guides and resubscribing to the websocket channel"
|
|
131
124
|
), this.fetch(), this.subscribe());
|
|
132
125
|
});
|
|
133
126
|
var p;
|
|
134
|
-
this.knock = e, this.channelId = t, this.targetParams = s, this.options =
|
|
127
|
+
this.knock = e, this.channelId = t, this.targetParams = s, this.options = i;
|
|
135
128
|
const {
|
|
136
|
-
trackLocationFromWindow:
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
trackLocationFromWindow: r = !0,
|
|
130
|
+
// TODO(KNO-11523): Remove once we ship guide toolbar v2, and offload as
|
|
131
|
+
// much debugging specific logic and responsibilities to toolbar.
|
|
132
|
+
trackDebugParams: n = !1,
|
|
133
|
+
throttleCheckInterval: o = O
|
|
134
|
+
} = i, a = l(), d = r ? (p = a == null ? void 0 : a.location) == null ? void 0 : p.href : void 0, h = n ? b() : void 0;
|
|
135
|
+
this.store = new E({
|
|
140
136
|
guideGroups: [],
|
|
141
137
|
guideGroupDisplayLogs: {},
|
|
142
138
|
guides: {},
|
|
139
|
+
ineligibleGuides: {},
|
|
143
140
|
previewGuides: {},
|
|
144
141
|
queries: {},
|
|
145
|
-
location:
|
|
142
|
+
location: d,
|
|
146
143
|
// Increment to update the state store and trigger re-selection.
|
|
147
144
|
counter: 0,
|
|
148
145
|
debug: h
|
|
149
146
|
});
|
|
150
|
-
const { socket:
|
|
151
|
-
this.socket =
|
|
147
|
+
const { socket: k } = this.knock.client();
|
|
148
|
+
this.socket = k, this.socketChannelTopic = `guides:${t}`, r && this.listenForLocationChangesFromWindow(), o && this.startCounterInterval(o), this.knock.log("[Guide] Initialized a guide client");
|
|
152
149
|
}
|
|
153
150
|
incrementCounter() {
|
|
154
151
|
this.knock.log("[Guide] Incrementing the counter"), this.store.setState((e) => ({ ...e, counter: e.counter + 1 }));
|
|
@@ -166,33 +163,39 @@ class B {
|
|
|
166
163
|
}
|
|
167
164
|
async fetch(e) {
|
|
168
165
|
this.knock.log("[Guide] .fetch"), this.knock.failIfNotAuthenticated();
|
|
169
|
-
const t = this.buildQueryParams(e == null ? void 0 : e.filters), s = this.formatQueryKey(t),
|
|
170
|
-
if (
|
|
171
|
-
return
|
|
172
|
-
this.store.setState((
|
|
173
|
-
...
|
|
174
|
-
queries: { ...
|
|
166
|
+
const t = this.buildQueryParams(e == null ? void 0 : e.filters), s = this.formatQueryKey(t), i = this.store.state.queries[s];
|
|
167
|
+
if (i)
|
|
168
|
+
return i;
|
|
169
|
+
this.store.setState((n) => ({
|
|
170
|
+
...n,
|
|
171
|
+
queries: { ...n.queries, [s]: { status: "loading" } }
|
|
175
172
|
}));
|
|
176
|
-
let
|
|
173
|
+
let r;
|
|
177
174
|
try {
|
|
178
175
|
this.knock.log("[Guide] Fetching all eligible guides");
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
const {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
176
|
+
const n = await this.knock.user.getGuides(this.channelId, t);
|
|
177
|
+
r = { status: "ok" };
|
|
178
|
+
const {
|
|
179
|
+
entries: o,
|
|
180
|
+
guide_groups: a,
|
|
181
|
+
guide_group_display_logs: d,
|
|
182
|
+
ineligible_guides: h
|
|
183
|
+
} = n;
|
|
184
|
+
this.knock.log("[Guide] Loading fetched guides"), this.store.setState((k) => ({
|
|
185
|
+
...k,
|
|
186
|
+
guideGroups: (a == null ? void 0 : a.length) > 0 ? a : [R(o)],
|
|
187
|
+
guideGroupDisplayLogs: d || {},
|
|
188
|
+
guides: G(o.map((p) => this.localCopy(p))),
|
|
189
|
+
ineligibleGuides: G(h || []),
|
|
190
|
+
queries: { ...k.queries, [s]: r }
|
|
188
191
|
}));
|
|
189
|
-
} catch (
|
|
190
|
-
|
|
192
|
+
} catch (n) {
|
|
193
|
+
r = { status: "error", error: n }, this.store.setState((o) => ({
|
|
191
194
|
...o,
|
|
192
|
-
queries: { ...o.queries, [s]:
|
|
195
|
+
queries: { ...o.queries, [s]: r }
|
|
193
196
|
}));
|
|
194
197
|
}
|
|
195
|
-
return
|
|
198
|
+
return r;
|
|
196
199
|
}
|
|
197
200
|
subscribe() {
|
|
198
201
|
if (!this.socket) return;
|
|
@@ -200,23 +203,23 @@ class B {
|
|
|
200
203
|
const e = this.store.state.debug, t = {
|
|
201
204
|
...this.targetParams,
|
|
202
205
|
user_id: this.knock.userId,
|
|
203
|
-
force_all_guides: e.forcedGuideKey ? !0 : void 0,
|
|
204
|
-
preview_session_id: e.previewSessionId || void 0
|
|
206
|
+
force_all_guides: e != null && e.forcedGuideKey || e != null && e.debugging ? !0 : void 0,
|
|
207
|
+
preview_session_id: (e == null ? void 0 : e.previewSessionId) || void 0
|
|
205
208
|
}, s = this.socket.channel(this.socketChannelTopic, t);
|
|
206
|
-
for (const
|
|
207
|
-
s.on(
|
|
209
|
+
for (const i of this.socketEventTypes)
|
|
210
|
+
s.on(i, (r) => this.handleSocketEvent(r));
|
|
208
211
|
["closed", "errored"].includes(s.state) && (this.subscribeRetryCount = 0, s.join().receive("ok", () => {
|
|
209
212
|
this.knock.log("[Guide] Successfully joined channel");
|
|
210
|
-
}).receive("error", (
|
|
213
|
+
}).receive("error", (i) => {
|
|
211
214
|
this.knock.log(
|
|
212
|
-
`[Guide] Failed to join channel: ${JSON.stringify(
|
|
215
|
+
`[Guide] Failed to join channel: ${JSON.stringify(i)}`
|
|
213
216
|
), this.handleChannelJoinError();
|
|
214
217
|
}).receive("timeout", () => {
|
|
215
218
|
this.knock.log("[Guide] Channel join timed out"), this.handleChannelJoinError();
|
|
216
219
|
})), this.socketChannel = s;
|
|
217
220
|
}
|
|
218
221
|
handleChannelJoinError() {
|
|
219
|
-
if (this.subscribeRetryCount >=
|
|
222
|
+
if (this.subscribeRetryCount >= U) {
|
|
220
223
|
this.knock.log(
|
|
221
224
|
`[Guide] Channel join max retry limit reached: ${this.subscribeRetryCount}`
|
|
222
225
|
), this.unsubscribe();
|
|
@@ -252,12 +255,12 @@ class B {
|
|
|
252
255
|
}
|
|
253
256
|
setLocation(e, t = {}) {
|
|
254
257
|
this.knock.log(`[Guide] .setLocation (loc=${e})`), this.clearGroupStage(), this.knock.log("[Guide] Updating the tracked location"), this.store.setState((s) => {
|
|
255
|
-
var
|
|
256
|
-
const
|
|
258
|
+
var r;
|
|
259
|
+
const i = (r = t == null ? void 0 : t.debug) != null && r.previewSessionId ? s.previewGuides : {};
|
|
257
260
|
return {
|
|
258
261
|
...s,
|
|
259
262
|
...t,
|
|
260
|
-
previewGuides:
|
|
263
|
+
previewGuides: i,
|
|
261
264
|
location: e
|
|
262
265
|
};
|
|
263
266
|
});
|
|
@@ -267,7 +270,7 @@ class B {
|
|
|
267
270
|
const e = l();
|
|
268
271
|
if (e != null && e.localStorage)
|
|
269
272
|
try {
|
|
270
|
-
e.localStorage.removeItem(
|
|
273
|
+
e.localStorage.removeItem(f);
|
|
271
274
|
} catch {
|
|
272
275
|
}
|
|
273
276
|
if (this.store.setState((t) => ({
|
|
@@ -280,62 +283,81 @@ class B {
|
|
|
280
283
|
(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());
|
|
281
284
|
}
|
|
282
285
|
}
|
|
286
|
+
setDebug(e) {
|
|
287
|
+
var s;
|
|
288
|
+
this.knock.log("[Guide] .setDebug()");
|
|
289
|
+
const t = !((s = this.store.state.debug) != null && s.debugging);
|
|
290
|
+
this.store.setState((i) => ({
|
|
291
|
+
...i,
|
|
292
|
+
debug: { ...e, debugging: !0 }
|
|
293
|
+
})), t && (this.knock.log(
|
|
294
|
+
"[Guide] Start debugging, refetching guides and resubscribing to the websocket channel"
|
|
295
|
+
), this.fetch(), this.subscribe());
|
|
296
|
+
}
|
|
297
|
+
unsetDebug() {
|
|
298
|
+
var t;
|
|
299
|
+
this.knock.log("[Guide] .unsetDebug()");
|
|
300
|
+
const e = (t = this.store.state.debug) == null ? void 0 : t.debugging;
|
|
301
|
+
this.store.setState((s) => ({ ...s, debug: void 0 })), e && (this.knock.log(
|
|
302
|
+
"[Guide] Stop debugging, refetching guides and resubscribing to the websocket channel"
|
|
303
|
+
), this.fetch(), this.subscribe());
|
|
304
|
+
}
|
|
283
305
|
//
|
|
284
306
|
// Store selector
|
|
285
307
|
//
|
|
286
308
|
selectGuides(e, t = {}, s = {}) {
|
|
287
309
|
if (this.knock.log(
|
|
288
|
-
`[Guide] .selectGuides (filters: ${
|
|
310
|
+
`[Guide] .selectGuides (filters: ${S(t)}; state: ${m(e)})`
|
|
289
311
|
), !this.selectGuide(e, t, s))
|
|
290
312
|
return [];
|
|
291
|
-
const
|
|
292
|
-
if (!s.includeThrottled &&
|
|
293
|
-
const
|
|
313
|
+
const r = [..._(e, t).values()];
|
|
314
|
+
if (!s.includeThrottled && y(e)) {
|
|
315
|
+
const n = r.filter(
|
|
294
316
|
(a) => a.bypass_global_group_limit
|
|
295
|
-
), o =
|
|
317
|
+
), o = r.length - n.length;
|
|
296
318
|
return this.knock.log(
|
|
297
|
-
`[Guide] Throttling ${o} guides from selection, and returning ${
|
|
298
|
-
),
|
|
319
|
+
`[Guide] Throttling ${o} guides from selection, and returning ${n.length} guides`
|
|
320
|
+
), n;
|
|
299
321
|
}
|
|
300
|
-
return this.knock.log(`[Guide] Returning ${
|
|
322
|
+
return this.knock.log(`[Guide] Returning ${r.length} guides from selection`), r;
|
|
301
323
|
}
|
|
302
324
|
selectGuide(e, t = {}, s = {}) {
|
|
303
325
|
if (this.knock.log(
|
|
304
|
-
`[Guide] .selectGuide (filters: ${
|
|
326
|
+
`[Guide] .selectGuide (filters: ${S(t)}; state: ${m(e)})`
|
|
305
327
|
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0) {
|
|
306
328
|
this.knock.log("[Guide] Exiting selection (no guides)");
|
|
307
329
|
return;
|
|
308
330
|
}
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
331
|
+
const i = _(e, t);
|
|
332
|
+
if (i.size === 0) {
|
|
311
333
|
this.knock.log("[Guide] Selection found zero result");
|
|
312
334
|
return;
|
|
313
335
|
}
|
|
314
|
-
const [
|
|
336
|
+
const [r, n] = [...i][0];
|
|
315
337
|
if (this.knock.log(
|
|
316
|
-
`[Guide] Selection found: \`${
|
|
317
|
-
),
|
|
318
|
-
return this.knock.log(`[Guide] Returning the unthrottled guide: ${
|
|
319
|
-
if (!s.includeThrottled &&
|
|
320
|
-
this.knock.log(`[Guide] Throttling the selected guide: ${
|
|
338
|
+
`[Guide] Selection found: \`${n.key}\` (total: ${i.size})`
|
|
339
|
+
), n.bypass_global_group_limit)
|
|
340
|
+
return this.knock.log(`[Guide] Returning the unthrottled guide: ${n.key}`), n;
|
|
341
|
+
if (!s.includeThrottled && y(e)) {
|
|
342
|
+
this.knock.log(`[Guide] Throttling the selected guide: ${n.key}`);
|
|
321
343
|
return;
|
|
322
344
|
}
|
|
323
345
|
switch (this.stage || (this.stage = this.openGroupStage()), this.stage.status) {
|
|
324
346
|
case "open": {
|
|
325
|
-
this.knock.log(`[Guide] Adding to the group stage: ${
|
|
347
|
+
this.knock.log(`[Guide] Adding to the group stage: ${n.key}`), this.stage.ordered[r] = n.key;
|
|
326
348
|
return;
|
|
327
349
|
}
|
|
328
350
|
case "patch": {
|
|
329
|
-
this.knock.log(`[Guide] Patching the group stage: ${
|
|
330
|
-
const o = this.stage.resolved ===
|
|
351
|
+
this.knock.log(`[Guide] Patching the group stage: ${n.key}`), this.stage.ordered[r] = n.key;
|
|
352
|
+
const o = this.stage.resolved === n.key ? n : void 0;
|
|
331
353
|
return this.knock.log(
|
|
332
|
-
`[Guide] Returning \`${o == null ? void 0 : o.key}\` (stage: ${
|
|
354
|
+
`[Guide] Returning \`${o == null ? void 0 : o.key}\` (stage: ${v(this.stage)})`
|
|
333
355
|
), o;
|
|
334
356
|
}
|
|
335
357
|
case "closed": {
|
|
336
|
-
const o = this.stage.resolved ===
|
|
358
|
+
const o = this.stage.resolved === n.key ? n : void 0;
|
|
337
359
|
return this.knock.log(
|
|
338
|
-
`[Guide] Returning \`${o == null ? void 0 : o.key}\` (stage: ${
|
|
360
|
+
`[Guide] Returning \`${o == null ? void 0 : o.key}\` (stage: ${v(this.stage)})`
|
|
339
361
|
), o;
|
|
340
362
|
}
|
|
341
363
|
}
|
|
@@ -343,7 +365,7 @@ class B {
|
|
|
343
365
|
openGroupStage() {
|
|
344
366
|
this.knock.log("[Guide] Opening a new group stage");
|
|
345
367
|
const {
|
|
346
|
-
orderResolutionDuration: e =
|
|
368
|
+
orderResolutionDuration: e = K
|
|
347
369
|
} = this.options, t = setTimeout(() => {
|
|
348
370
|
this.closePendingGroupStage(), this.incrementCounter();
|
|
349
371
|
}, e);
|
|
@@ -358,10 +380,8 @@ class B {
|
|
|
358
380
|
closePendingGroupStage() {
|
|
359
381
|
if (this.knock.log("[Guide] .closePendingGroupStage"), !this.stage || this.stage.status === "closed") return;
|
|
360
382
|
this.ensureClearTimeout();
|
|
361
|
-
|
|
362
|
-
return this.
|
|
363
|
-
(t) => t === this.store.state.debug.forcedGuideKey
|
|
364
|
-
)), e || (e = this.stage.ordered.find((t) => t !== void 0)), this.knock.log(
|
|
383
|
+
const e = this.stage.ordered.find((t) => t !== void 0);
|
|
384
|
+
return this.knock.log(
|
|
365
385
|
`[Guide] Closing the current group stage: resolved=${e}`
|
|
366
386
|
), this.stage = {
|
|
367
387
|
...this.stage,
|
|
@@ -418,30 +438,30 @@ class B {
|
|
|
418
438
|
seen_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
419
439
|
});
|
|
420
440
|
if (!s) return;
|
|
421
|
-
const
|
|
441
|
+
const i = {
|
|
422
442
|
...this.buildEngagementEventBaseParams(e, s),
|
|
423
443
|
content: s.content,
|
|
424
444
|
data: this.targetParams.data
|
|
425
445
|
};
|
|
426
446
|
return this.knock.user.markGuideStepAs(
|
|
427
447
|
"seen",
|
|
428
|
-
|
|
448
|
+
i
|
|
429
449
|
), s;
|
|
430
450
|
}
|
|
431
451
|
async markAsInteracted(e, t, s) {
|
|
432
452
|
this.knock.log(
|
|
433
453
|
`[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${t.ref})`
|
|
434
454
|
);
|
|
435
|
-
const
|
|
436
|
-
read_at:
|
|
437
|
-
interacted_at:
|
|
455
|
+
const i = (/* @__PURE__ */ new Date()).toISOString(), r = this.setStepMessageAttrs(e.key, t.ref, {
|
|
456
|
+
read_at: i,
|
|
457
|
+
interacted_at: i
|
|
438
458
|
});
|
|
439
|
-
if (!
|
|
440
|
-
const
|
|
441
|
-
...this.buildEngagementEventBaseParams(e,
|
|
459
|
+
if (!r) return;
|
|
460
|
+
const n = {
|
|
461
|
+
...this.buildEngagementEventBaseParams(e, r),
|
|
442
462
|
metadata: s
|
|
443
463
|
};
|
|
444
|
-
return this.knock.user.markGuideStepAs("interacted",
|
|
464
|
+
return this.knock.user.markGuideStepAs("interacted", n), r;
|
|
445
465
|
}
|
|
446
466
|
async markAsArchived(e, t) {
|
|
447
467
|
if (t.message.archived_at) return;
|
|
@@ -452,11 +472,11 @@ class B {
|
|
|
452
472
|
archived_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
453
473
|
});
|
|
454
474
|
if (!s) return;
|
|
455
|
-
const
|
|
475
|
+
const i = this.buildEngagementEventBaseParams(e, s);
|
|
456
476
|
return this.knock.user.markGuideStepAs(
|
|
457
477
|
"archived",
|
|
458
478
|
{
|
|
459
|
-
...
|
|
479
|
+
...i,
|
|
460
480
|
unthrottled: e.bypass_global_group_limit
|
|
461
481
|
}
|
|
462
482
|
), s;
|
|
@@ -469,13 +489,14 @@ class B {
|
|
|
469
489
|
...e,
|
|
470
490
|
// Get the next unarchived step.
|
|
471
491
|
getStep() {
|
|
472
|
-
|
|
492
|
+
var i;
|
|
493
|
+
return ((i = t.store.state.debug) == null ? void 0 : i.forcedGuideKey) === this.key ? this.steps[0] : this.steps.find((r) => !r.message.archived_at);
|
|
473
494
|
}
|
|
474
495
|
};
|
|
475
|
-
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message:
|
|
476
|
-
const
|
|
477
|
-
...
|
|
478
|
-
message: { ...
|
|
496
|
+
return s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: i, ...r }) => {
|
|
497
|
+
const n = {
|
|
498
|
+
...r,
|
|
499
|
+
message: { ...i },
|
|
479
500
|
markAsSeen() {
|
|
480
501
|
return t.markAsSeen(s, this);
|
|
481
502
|
},
|
|
@@ -486,12 +507,12 @@ class B {
|
|
|
486
507
|
return t.markAsArchived(s, this);
|
|
487
508
|
}
|
|
488
509
|
};
|
|
489
|
-
return
|
|
490
|
-
}), s.activation_url_patterns = e.activation_url_patterns.map((
|
|
491
|
-
...
|
|
492
|
-
pattern: new
|
|
493
|
-
pathname:
|
|
494
|
-
search:
|
|
510
|
+
return n.markAsSeen = n.markAsSeen.bind(n), n.markAsInteracted = n.markAsInteracted.bind(n), n.markAsArchived = n.markAsArchived.bind(n), n;
|
|
511
|
+
}), s.activation_url_patterns = e.activation_url_patterns.map((i) => ({
|
|
512
|
+
...i,
|
|
513
|
+
pattern: new w({
|
|
514
|
+
pathname: i.pathname ?? void 0,
|
|
515
|
+
search: i.search ?? void 0
|
|
495
516
|
})
|
|
496
517
|
})), s;
|
|
497
518
|
}
|
|
@@ -499,34 +520,34 @@ class B {
|
|
|
499
520
|
const t = {
|
|
500
521
|
...this.targetParams,
|
|
501
522
|
...e
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
let
|
|
523
|
+
}, s = this.store.state.debug;
|
|
524
|
+
(s != null && s.forcedGuideKey || s != null && s.debugging) && (t.force_all_guides = !0);
|
|
525
|
+
let i = Object.fromEntries(
|
|
505
526
|
Object.entries(t).filter(
|
|
506
|
-
([
|
|
527
|
+
([r, n]) => n != null
|
|
507
528
|
)
|
|
508
529
|
);
|
|
509
|
-
return
|
|
530
|
+
return i = i.data ? { ...i, data: JSON.stringify(i.data) } : i, i;
|
|
510
531
|
}
|
|
511
532
|
formatQueryKey(e) {
|
|
512
533
|
const s = Object.keys(e).sort().map(
|
|
513
|
-
(
|
|
514
|
-
).join("&"),
|
|
515
|
-
return s ? `${
|
|
534
|
+
(r) => `${encodeURIComponent(r)}=${encodeURIComponent(e[r])}`
|
|
535
|
+
).join("&"), i = F(this.knock.userId);
|
|
536
|
+
return s ? `${i}?${s}` : i;
|
|
516
537
|
}
|
|
517
538
|
setStepMessageAttrs(e, t, s) {
|
|
518
|
-
let
|
|
519
|
-
return s.archived_at && this.clearGroupStage(), this.store.setState((
|
|
520
|
-
let
|
|
521
|
-
if (!
|
|
522
|
-
const o =
|
|
523
|
-
|
|
524
|
-
const a = { ...
|
|
525
|
-
...
|
|
526
|
-
[
|
|
527
|
-
} :
|
|
528
|
-
return { ...
|
|
529
|
-
}),
|
|
539
|
+
let i;
|
|
540
|
+
return s.archived_at && this.clearGroupStage(), this.store.setState((r) => {
|
|
541
|
+
let n = r.guides[e];
|
|
542
|
+
if (!n) return r;
|
|
543
|
+
const o = n.steps.map((h) => (h.ref !== t || (h.message = { ...h.message, ...s }, i = h), h));
|
|
544
|
+
n = i ? { ...n, steps: o } : n;
|
|
545
|
+
const a = { ...r.guides, [n.key]: n }, d = s.archived_at && !n.bypass_global_group_limit ? {
|
|
546
|
+
...r.guideGroupDisplayLogs,
|
|
547
|
+
[P]: s.archived_at
|
|
548
|
+
} : r.guideGroupDisplayLogs;
|
|
549
|
+
return { ...r, guides: a, guideGroupDisplayLogs: d };
|
|
550
|
+
}), i;
|
|
530
551
|
}
|
|
531
552
|
buildEngagementEventBaseParams(e, t) {
|
|
532
553
|
return {
|
|
@@ -542,38 +563,38 @@ class B {
|
|
|
542
563
|
this.patchClosedGroupStage();
|
|
543
564
|
const t = this.localCopy(e.guide);
|
|
544
565
|
this.store.setState((s) => {
|
|
545
|
-
const
|
|
546
|
-
return { ...s, guides:
|
|
566
|
+
const i = { ...s.guides, [t.key]: t };
|
|
567
|
+
return { ...s, guides: i };
|
|
547
568
|
});
|
|
548
569
|
}
|
|
549
570
|
removeGuide({ data: e }) {
|
|
550
571
|
this.patchClosedGroupStage(), this.store.setState((t) => {
|
|
551
|
-
const { [e.guide.key]: s, ...
|
|
552
|
-
return { ...t, guides:
|
|
572
|
+
const { [e.guide.key]: s, ...i } = t.guides;
|
|
573
|
+
return { ...t, guides: i };
|
|
553
574
|
});
|
|
554
575
|
}
|
|
555
576
|
addOrReplaceGuideGroup({
|
|
556
577
|
data: e
|
|
557
578
|
}) {
|
|
558
579
|
this.patchClosedGroupStage(), this.store.setState((t) => {
|
|
559
|
-
const s = [e.guide_group],
|
|
560
|
-
let
|
|
561
|
-
return
|
|
580
|
+
const s = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [], r = e.guide_group.display_sequence_throttled || [];
|
|
581
|
+
let n = t.guides;
|
|
582
|
+
return n = i.reduce((o, a) => {
|
|
562
583
|
if (!o[a]) return o;
|
|
563
|
-
const
|
|
564
|
-
return { ...o, [a]:
|
|
565
|
-
},
|
|
584
|
+
const d = { ...o[a], bypass_global_group_limit: !0 };
|
|
585
|
+
return { ...o, [a]: d };
|
|
586
|
+
}, n), n = r.reduce((o, a) => {
|
|
566
587
|
if (!o[a]) return o;
|
|
567
|
-
const
|
|
568
|
-
return { ...o, [a]:
|
|
569
|
-
},
|
|
588
|
+
const d = { ...o[a], bypass_global_group_limit: !1 };
|
|
589
|
+
return { ...o, [a]: d };
|
|
590
|
+
}, n), { ...t, guides: n, guideGroups: s };
|
|
570
591
|
});
|
|
571
592
|
}
|
|
572
593
|
updatePreviewGuide({ data: e }) {
|
|
573
594
|
const t = this.localCopy(e.guide);
|
|
574
595
|
this.store.setState((s) => {
|
|
575
|
-
const
|
|
576
|
-
return { ...s, previewGuides:
|
|
596
|
+
const i = { ...s.previewGuides, [t.key]: t };
|
|
597
|
+
return { ...s, previewGuides: i };
|
|
577
598
|
});
|
|
578
599
|
}
|
|
579
600
|
// Returns whether debug params have changed. For guide key, we only check
|
|
@@ -587,14 +608,14 @@ class B {
|
|
|
587
608
|
e.addEventListener("popstate", this.handleLocationChange), e.addEventListener("hashchange", this.handleLocationChange);
|
|
588
609
|
const t = e.history.pushState, s = e.history.replaceState;
|
|
589
610
|
e.history.pushState = new Proxy(t, {
|
|
590
|
-
apply: (r, n
|
|
591
|
-
Reflect.apply(r, n
|
|
611
|
+
apply: (i, r, n) => {
|
|
612
|
+
Reflect.apply(i, r, n), setTimeout(() => {
|
|
592
613
|
this.handleLocationChange();
|
|
593
614
|
}, 0);
|
|
594
615
|
}
|
|
595
616
|
}), e.history.replaceState = new Proxy(s, {
|
|
596
|
-
apply: (r, n
|
|
597
|
-
Reflect.apply(r, n
|
|
617
|
+
apply: (i, r, n) => {
|
|
618
|
+
Reflect.apply(i, r, n), setTimeout(() => {
|
|
598
619
|
this.handleLocationChange();
|
|
599
620
|
}, 0);
|
|
600
621
|
}
|
|
@@ -611,7 +632,8 @@ class B {
|
|
|
611
632
|
}
|
|
612
633
|
export {
|
|
613
634
|
g as DEBUG_QUERY_PARAMS,
|
|
614
|
-
|
|
615
|
-
|
|
635
|
+
W as KnockGuideClient,
|
|
636
|
+
j as checkActivatable,
|
|
637
|
+
F as guidesApiRootPath
|
|
616
638
|
};
|
|
617
639
|
//# sourceMappingURL=client.mjs.map
|