@knocklabs/client 0.21.1 → 0.21.3
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 +20 -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 +346 -268
- package/dist/esm/clients/guide/client.mjs.map +1 -1
- package/dist/esm/clients/guide/helpers.mjs +50 -57
- 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 +4 -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 +24 -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 +182 -35
- package/src/clients/guide/helpers.ts +4 -12
- package/src/clients/guide/index.ts +3 -0
- package/src/clients/guide/types.ts +37 -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,52 +1,53 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Store as
|
|
5
|
-
import { URLPattern as
|
|
6
|
-
import { byKey as
|
|
7
|
-
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var w = (u, e, s) => e in u ? E(u, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : u[e] = s;
|
|
3
|
+
var h = (u, e, s) => w(u, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
import { Store as R } from "@tanstack/store";
|
|
5
|
+
import { URLPattern as A } from "urlpattern-polyfill";
|
|
6
|
+
import { byKey as S, mockDefaultGroup as P, formatFilters as v, formatState as b, checkStateIfThrottled as _, formatGroupStage as y, DEFAULT_GROUP_KEY as D, newUrl as K, predicateUrlRules as L, predicateUrlPatterns as $, findDefaultGroup as T } from "./helpers.mjs";
|
|
7
|
+
import { SelectionResult as O } from "./types.mjs";
|
|
8
|
+
const F = 50, U = 30 * 1e3, q = 3, f = {
|
|
8
9
|
GUIDE_KEY: "knock_guide_key",
|
|
9
10
|
PREVIEW_SESSION_ID: "knock_preview_session_id"
|
|
10
|
-
},
|
|
11
|
+
}, G = "knock_guide_debug", p = () => {
|
|
11
12
|
if (typeof window < "u")
|
|
12
13
|
return window;
|
|
13
|
-
},
|
|
14
|
-
const u =
|
|
14
|
+
}, N = (u) => `/v1/users/${u}/guides`, I = () => {
|
|
15
|
+
const u = p();
|
|
15
16
|
if (!u || !u.location)
|
|
16
17
|
return { forcedGuideKey: null, previewSessionId: null };
|
|
17
|
-
const e = new URLSearchParams(u.location.search),
|
|
18
|
-
|
|
18
|
+
const e = new URLSearchParams(u.location.search), s = e.get(f.GUIDE_KEY), t = e.get(
|
|
19
|
+
f.PREVIEW_SESSION_ID
|
|
19
20
|
);
|
|
20
|
-
if (
|
|
21
|
+
if (s || t) {
|
|
21
22
|
if (u.localStorage)
|
|
22
23
|
try {
|
|
23
|
-
const
|
|
24
|
-
forcedGuideKey:
|
|
25
|
-
previewSessionId:
|
|
24
|
+
const r = {
|
|
25
|
+
forcedGuideKey: s,
|
|
26
|
+
previewSessionId: t
|
|
26
27
|
};
|
|
27
|
-
u.localStorage.setItem(
|
|
28
|
+
u.localStorage.setItem(G, JSON.stringify(r));
|
|
28
29
|
} catch {
|
|
29
30
|
}
|
|
30
31
|
return {
|
|
31
|
-
forcedGuideKey:
|
|
32
|
-
previewSessionId:
|
|
32
|
+
forcedGuideKey: s,
|
|
33
|
+
previewSessionId: t
|
|
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(G);
|
|
40
|
+
if (r) {
|
|
41
|
+
const a = j(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
|
+
}, j = (u) => {
|
|
50
51
|
try {
|
|
51
52
|
const e = JSON.parse(u);
|
|
52
53
|
return {
|
|
@@ -59,35 +60,35 @@ const K = 50, O = 30 * 1e3, U = 3, g = {
|
|
|
59
60
|
previewSessionId: null
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
|
-
},
|
|
63
|
-
const t = new
|
|
64
|
-
if (!
|
|
65
|
-
const
|
|
66
|
-
for (const [
|
|
67
|
-
const
|
|
68
|
-
!
|
|
63
|
+
}, C = (u, e, s) => {
|
|
64
|
+
const t = new O(), i = T(u.guideGroups);
|
|
65
|
+
if (!i) return t;
|
|
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 || !B(c, e, {
|
|
69
70
|
location: r,
|
|
70
71
|
ineligibleGuides: u.ineligibleGuides,
|
|
71
72
|
debug: u.debug
|
|
72
|
-
}) || t.set(
|
|
73
|
-
}
|
|
74
|
-
return t.metadata = { guideGroup: s }, t;
|
|
75
|
-
},
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
if (!
|
|
79
|
-
} else if (
|
|
73
|
+
}) || t.set(a, c);
|
|
74
|
+
}
|
|
75
|
+
return t.metadata = { guideGroup: i, filters: e, ...s }, t;
|
|
76
|
+
}, B = (u, e, { location: s, ineligibleGuides: t = {}, debug: i = {} }) => e.type && e.type !== u.type || e.key && e.key !== u.key ? !1 : i.focusedGuideKeys && Object.keys(i.focusedGuideKeys).length > 0 ? !!i.focusedGuideKeys[u.key] : i.forcedGuideKey ? i.forcedGuideKey === u.key : t[u.key] || !u.active || u.steps.every((r) => !!r.message.archived_at) ? !1 : M(u, s), M = (u, e) => {
|
|
77
|
+
const s = e ? K(e) : void 0, t = u.activation_url_rules || [], i = u.activation_url_patterns || [];
|
|
78
|
+
if (s && t.length > 0) {
|
|
79
|
+
if (!L(s, t)) return !1;
|
|
80
|
+
} else if (s && i.length > 0 && !$(s, i))
|
|
80
81
|
return !1;
|
|
81
82
|
return !0;
|
|
82
83
|
};
|
|
83
|
-
class
|
|
84
|
-
constructor(e,
|
|
85
|
-
|
|
84
|
+
class V {
|
|
85
|
+
constructor(e, s, t = {}, i = {}) {
|
|
86
|
+
h(this, "store");
|
|
86
87
|
// Phoenix channels for real time guide updates over websocket
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
h(this, "socket");
|
|
89
|
+
h(this, "socketChannel");
|
|
90
|
+
h(this, "socketChannelTopic");
|
|
91
|
+
h(this, "socketEventTypes", [
|
|
91
92
|
"guide.added",
|
|
92
93
|
"guide.updated",
|
|
93
94
|
"guide.removed",
|
|
@@ -95,57 +96,57 @@ class W {
|
|
|
95
96
|
"guide_group.updated",
|
|
96
97
|
"guide.live_preview_updated"
|
|
97
98
|
]);
|
|
98
|
-
|
|
99
|
+
h(this, "subscribeRetryCount", 0);
|
|
99
100
|
// Original history methods to monkey patch, or restore in cleanups.
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
h(this, "pushStateFn");
|
|
102
|
+
h(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
|
+
h(this, "stage");
|
|
107
|
+
h(this, "counterIntervalId");
|
|
107
108
|
// Define as an arrow func property to always bind this to the class instance.
|
|
108
|
-
|
|
109
|
+
h(this, "handleLocationChange", () => {
|
|
109
110
|
this.knock.log("[Guide] .handleLocationChange");
|
|
110
|
-
const e =
|
|
111
|
+
const e = p();
|
|
111
112
|
if (!(e != null && e.location)) return;
|
|
112
|
-
const
|
|
113
|
-
if (this.store.state.location ===
|
|
114
|
-
if (this.knock.log(`[Guide] Detected a location change: ${
|
|
115
|
-
this.setLocation(
|
|
113
|
+
const s = e.location.href;
|
|
114
|
+
if (this.store.state.location === s) return;
|
|
115
|
+
if (this.knock.log(`[Guide] Detected a location change: ${s}`), !this.options.trackDebugParams) {
|
|
116
|
+
this.setLocation(s);
|
|
116
117
|
return;
|
|
117
118
|
}
|
|
118
|
-
const
|
|
119
|
-
this.setLocation(
|
|
120
|
-
|
|
119
|
+
const t = this.store.state.debug || {}, i = I();
|
|
120
|
+
this.setLocation(s, { debug: i }), this.checkDebugStateChanged(
|
|
121
|
+
t,
|
|
121
122
|
i
|
|
122
123
|
) && (this.knock.log(
|
|
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
|
-
this.knock = e, this.channelId =
|
|
127
|
+
var g;
|
|
128
|
+
this.knock = e, this.channelId = s, this.targetParams = t, 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,
|
|
135
|
-
this.store = new
|
|
133
|
+
trackDebugParams: r = !1,
|
|
134
|
+
throttleCheckInterval: a = U
|
|
135
|
+
} = i, o = p(), c = n ? (g = o == null ? void 0 : o.location) == null ? void 0 : g.href : void 0, d = r ? I() : void 0;
|
|
136
|
+
this.store = new R({
|
|
136
137
|
guideGroups: [],
|
|
137
138
|
guideGroupDisplayLogs: {},
|
|
138
139
|
guides: {},
|
|
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: l } = this.knock.client();
|
|
149
|
+
this.socket = l, this.socketChannelTopic = `guides:${s}`, 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 }));
|
|
@@ -163,52 +164,52 @@ class W {
|
|
|
163
164
|
}
|
|
164
165
|
async fetch(e) {
|
|
165
166
|
this.knock.log("[Guide] .fetch"), this.knock.failIfNotAuthenticated();
|
|
166
|
-
const
|
|
167
|
+
const s = this.buildQueryParams(e == null ? void 0 : e.filters), t = this.formatQueryKey(s), i = this.store.state.queries[t];
|
|
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, [t]: { 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, s);
|
|
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((l) => ({
|
|
186
|
+
...l,
|
|
187
|
+
guideGroups: (o == null ? void 0 : o.length) > 0 ? o : [P(a)],
|
|
188
|
+
guideGroupDisplayLogs: c || {},
|
|
189
|
+
guides: S(a.map((g) => this.localCopy(g))),
|
|
190
|
+
ineligibleGuides: S(d || []),
|
|
191
|
+
queries: { ...l.queries, [t]: 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, [t]: n }
|
|
196
197
|
}));
|
|
197
198
|
}
|
|
198
|
-
return
|
|
199
|
+
return n;
|
|
199
200
|
}
|
|
200
201
|
subscribe() {
|
|
201
202
|
if (!this.socket) return;
|
|
202
203
|
this.knock.failIfNotAuthenticated(), this.knock.log("[Guide] Subscribing to real time updates"), this.socket.isConnected() || this.socket.connect(), this.socketChannel && this.unsubscribe();
|
|
203
|
-
const e = this.store.state.debug,
|
|
204
|
+
const e = this.store.state.debug, s = {
|
|
204
205
|
...this.targetParams,
|
|
205
206
|
user_id: this.knock.userId,
|
|
206
207
|
force_all_guides: e != null && e.forcedGuideKey || e != null && e.debugging ? !0 : void 0,
|
|
207
208
|
preview_session_id: (e == null ? void 0 : e.previewSessionId) || void 0
|
|
208
|
-
},
|
|
209
|
+
}, t = this.socket.channel(this.socketChannelTopic, s);
|
|
209
210
|
for (const i of this.socketEventTypes)
|
|
210
|
-
|
|
211
|
-
["closed", "errored"].includes(
|
|
211
|
+
t.on(i, (n) => this.handleSocketEvent(n));
|
|
212
|
+
["closed", "errored"].includes(t.state) && (this.subscribeRetryCount = 0, t.join().receive("ok", () => {
|
|
212
213
|
this.knock.log("[Guide] Successfully joined channel");
|
|
213
214
|
}).receive("error", (i) => {
|
|
214
215
|
this.knock.log(
|
|
@@ -216,10 +217,10 @@ class W {
|
|
|
216
217
|
), this.handleChannelJoinError();
|
|
217
218
|
}).receive("timeout", () => {
|
|
218
219
|
this.knock.log("[Guide] Channel join timed out"), this.handleChannelJoinError();
|
|
219
|
-
})), this.socketChannel =
|
|
220
|
+
})), this.socketChannel = t;
|
|
220
221
|
}
|
|
221
222
|
handleChannelJoinError() {
|
|
222
|
-
if (this.subscribeRetryCount >=
|
|
223
|
+
if (this.subscribeRetryCount >= q) {
|
|
223
224
|
this.knock.log(
|
|
224
225
|
`[Guide] Channel join max retry limit reached: ${this.subscribeRetryCount}`
|
|
225
226
|
), this.unsubscribe();
|
|
@@ -236,12 +237,12 @@ class W {
|
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
handleSocketEvent(e) {
|
|
239
|
-
const { event:
|
|
240
|
-
switch (
|
|
240
|
+
const { event: s, data: t } = e;
|
|
241
|
+
switch (s) {
|
|
241
242
|
case "guide.added":
|
|
242
243
|
return this.addOrReplaceGuide(e);
|
|
243
244
|
case "guide.updated":
|
|
244
|
-
return
|
|
245
|
+
return t.eligible ? this.addOrReplaceGuide(e) : this.removeGuide(e);
|
|
245
246
|
case "guide.removed":
|
|
246
247
|
return this.removeGuide(e);
|
|
247
248
|
case "guide_group.added":
|
|
@@ -253,13 +254,13 @@ class W {
|
|
|
253
254
|
return;
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
|
-
setLocation(e,
|
|
257
|
-
this.knock.log(`[Guide] .setLocation (loc=${e})`), this.clearGroupStage(), this.knock.log("[Guide] Updating the tracked location"), this.store.setState((
|
|
258
|
-
var
|
|
259
|
-
const i = (
|
|
257
|
+
setLocation(e, s = {}) {
|
|
258
|
+
this.knock.log(`[Guide] .setLocation (loc=${e})`), this.clearGroupStage(), this.knock.log("[Guide] Updating the tracked location"), this.store.setState((t) => {
|
|
259
|
+
var n;
|
|
260
|
+
const i = (n = s == null ? void 0 : s.debug) != null && n.previewSessionId ? t.previewGuides : {};
|
|
260
261
|
return {
|
|
261
|
-
...s,
|
|
262
262
|
...t,
|
|
263
|
+
...s,
|
|
263
264
|
previewGuides: i,
|
|
264
265
|
location: e
|
|
265
266
|
};
|
|
@@ -267,112 +268,173 @@ class W {
|
|
|
267
268
|
}
|
|
268
269
|
exitDebugMode() {
|
|
269
270
|
this.knock.log("[Guide] Exiting debug mode");
|
|
270
|
-
const e =
|
|
271
|
+
const e = p();
|
|
271
272
|
if (e != null && e.localStorage)
|
|
272
273
|
try {
|
|
273
|
-
e.localStorage.removeItem(
|
|
274
|
+
e.localStorage.removeItem(G);
|
|
274
275
|
} catch {
|
|
275
276
|
}
|
|
276
|
-
if (this.store.setState((
|
|
277
|
-
...
|
|
278
|
-
debug: {
|
|
277
|
+
if (this.store.setState((s) => ({
|
|
278
|
+
...s,
|
|
279
|
+
debug: {
|
|
280
|
+
forcedGuideKey: null,
|
|
281
|
+
previewSessionId: null,
|
|
282
|
+
focusedGuideKeys: {}
|
|
283
|
+
},
|
|
279
284
|
previewGuides: {}
|
|
280
285
|
// Clear preview guides when exiting debug mode
|
|
281
286
|
})), e != null && e.location) {
|
|
282
|
-
const
|
|
283
|
-
(
|
|
287
|
+
const s = new URL(e.location.href);
|
|
288
|
+
(s.searchParams.has(f.GUIDE_KEY) || s.searchParams.has(f.PREVIEW_SESSION_ID)) && (s.searchParams.delete(f.GUIDE_KEY), s.searchParams.delete(f.PREVIEW_SESSION_ID), e.location.href = s.toString());
|
|
284
289
|
}
|
|
285
290
|
}
|
|
286
291
|
setDebug(e) {
|
|
287
|
-
var
|
|
292
|
+
var t;
|
|
288
293
|
this.knock.log("[Guide] .setDebug()");
|
|
289
|
-
const
|
|
294
|
+
const s = !((t = this.store.state.debug) != null && t.debugging);
|
|
290
295
|
this.store.setState((i) => ({
|
|
291
296
|
...i,
|
|
292
|
-
debug: {
|
|
293
|
-
|
|
297
|
+
debug: {
|
|
298
|
+
skipEngagementTracking: !0,
|
|
299
|
+
ignoreDisplayInterval: !0,
|
|
300
|
+
focusedGuideKeys: {},
|
|
301
|
+
...e,
|
|
302
|
+
debugging: !0
|
|
303
|
+
}
|
|
304
|
+
})), s && (this.knock.log(
|
|
294
305
|
"[Guide] Start debugging, refetching guides and resubscribing to the websocket channel"
|
|
295
306
|
), this.fetch(), this.subscribe());
|
|
296
307
|
}
|
|
297
308
|
unsetDebug() {
|
|
298
|
-
var
|
|
309
|
+
var s;
|
|
299
310
|
this.knock.log("[Guide] .unsetDebug()");
|
|
300
|
-
const e = (
|
|
301
|
-
this.store.setState((
|
|
311
|
+
const e = (s = this.store.state.debug) == null ? void 0 : s.debugging;
|
|
312
|
+
this.store.setState((t) => ({ ...t, debug: void 0 })), e && (this.knock.log(
|
|
302
313
|
"[Guide] Stop debugging, refetching guides and resubscribing to the websocket channel"
|
|
303
314
|
), this.fetch(), this.subscribe());
|
|
304
315
|
}
|
|
305
316
|
//
|
|
306
317
|
// Store selector
|
|
307
318
|
//
|
|
308
|
-
selectGuides(e,
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
319
|
+
selectGuides(e, s = {}, t = {}) {
|
|
320
|
+
var c;
|
|
321
|
+
this.knock.log(
|
|
322
|
+
`[Guide] .selectGuides (filters: ${v(s)}; state: ${b(e)})`
|
|
323
|
+
);
|
|
324
|
+
const i = this.selectGuide(e, s, {
|
|
325
|
+
...t,
|
|
326
|
+
// Don't record this result, not the actual query result we need.
|
|
327
|
+
recordSelectQuery: !1
|
|
328
|
+
}), { recordSelectQuery: n = !!((c = e.debug) != null && c.debugging) } = t, r = {
|
|
329
|
+
limit: "all",
|
|
330
|
+
opts: { ...t, recordSelectQuery: n }
|
|
331
|
+
}, a = C(e, s, r);
|
|
332
|
+
if (this.maybeRecordSelectResult(a), !i && !t.includeThrottled)
|
|
312
333
|
return [];
|
|
313
|
-
const
|
|
314
|
-
if (!
|
|
315
|
-
const
|
|
316
|
-
(
|
|
317
|
-
),
|
|
334
|
+
const o = [...a.values()];
|
|
335
|
+
if (!t.includeThrottled && _(e)) {
|
|
336
|
+
const d = o.filter(
|
|
337
|
+
(g) => g.bypass_global_group_limit
|
|
338
|
+
), l = o.length - d.length;
|
|
318
339
|
return this.knock.log(
|
|
319
|
-
`[Guide] Throttling ${
|
|
320
|
-
),
|
|
340
|
+
`[Guide] Throttling ${l} guides from selection, and returning ${d.length} guides`
|
|
341
|
+
), d;
|
|
321
342
|
}
|
|
322
|
-
return this.knock.log(`[Guide] Returning ${
|
|
343
|
+
return this.knock.log(`[Guide] Returning ${o.length} guides from selection`), o;
|
|
323
344
|
}
|
|
324
|
-
selectGuide(e,
|
|
345
|
+
selectGuide(e, s = {}, t = {}) {
|
|
346
|
+
var l, g, m;
|
|
325
347
|
if (this.knock.log(
|
|
326
|
-
`[Guide] .selectGuide (filters: ${
|
|
348
|
+
`[Guide] .selectGuide (filters: ${v(s)}; state: ${b(e)})`
|
|
327
349
|
), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0) {
|
|
328
350
|
this.knock.log("[Guide] Exiting selection (no guides)");
|
|
329
351
|
return;
|
|
330
352
|
}
|
|
331
|
-
|
|
332
|
-
|
|
353
|
+
this.stage || (this.stage = this.openGroupStage());
|
|
354
|
+
const { recordSelectQuery: i = !!((l = e.debug) != null && l.debugging) } = t, n = {
|
|
355
|
+
limit: "one",
|
|
356
|
+
opts: { ...t, recordSelectQuery: i }
|
|
357
|
+
}, r = C(e, s, n);
|
|
358
|
+
if (this.maybeRecordSelectResult(r), r.size === 0) {
|
|
333
359
|
this.knock.log("[Guide] Selection found zero result");
|
|
334
360
|
return;
|
|
335
361
|
}
|
|
336
|
-
const [
|
|
362
|
+
const [a, o] = [...r][0];
|
|
337
363
|
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) {
|
|
364
|
+
`[Guide] Selection found: \`${o.key}\` (total: ${r.size})`
|
|
365
|
+
), o.bypass_global_group_limit)
|
|
366
|
+
return this.knock.log(`[Guide] Returning the unthrottled guide: ${o.key}`), o;
|
|
367
|
+
const c = (m = (g = e.debug) == null ? void 0 : g.focusedGuideKeys) == null ? void 0 : m[o.key], d = !t.includeThrottled && _(e);
|
|
368
|
+
switch (this.stage.status) {
|
|
346
369
|
case "open": {
|
|
347
|
-
this.knock.log(`[Guide] Adding to the group stage: ${
|
|
370
|
+
this.knock.log(`[Guide] Adding to the group stage: ${o.key}`), this.stage.ordered[a] = o.key;
|
|
348
371
|
return;
|
|
349
372
|
}
|
|
350
373
|
case "patch": {
|
|
351
|
-
this.knock.log(`[Guide] Patching the group stage: ${
|
|
352
|
-
|
|
374
|
+
if (this.knock.log(`[Guide] Patching the group stage: ${o.key}`), this.stage.ordered[a] = o.key, c)
|
|
375
|
+
return this.knock.log(
|
|
376
|
+
`[Guide] Focused to return \`${o.key}\` (stage: ${y(this.stage)})`
|
|
377
|
+
), o;
|
|
378
|
+
if (d) {
|
|
379
|
+
this.knock.log(`[Guide] Throttling the selected guide: ${o.key}`);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const k = this.stage.resolved === o.key ? o : void 0;
|
|
353
383
|
return this.knock.log(
|
|
354
|
-
`[Guide] Returning \`${
|
|
355
|
-
),
|
|
384
|
+
`[Guide] Returning \`${k == null ? void 0 : k.key}\` (stage: ${y(this.stage)})`
|
|
385
|
+
), k;
|
|
356
386
|
}
|
|
357
387
|
case "closed": {
|
|
358
|
-
|
|
388
|
+
if (c)
|
|
389
|
+
return this.knock.log(
|
|
390
|
+
`[Guide] Focused to return \`${o.key}\` (stage: ${y(this.stage)})`
|
|
391
|
+
), o;
|
|
392
|
+
if (d) {
|
|
393
|
+
this.knock.log(`[Guide] Throttling the selected guide: ${o.key}`);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
const k = this.stage.resolved === o.key ? o : void 0;
|
|
359
397
|
return this.knock.log(
|
|
360
|
-
`[Guide] Returning \`${
|
|
361
|
-
),
|
|
398
|
+
`[Guide] Returning \`${k == null ? void 0 : k.key}\` (stage: ${y(this.stage)})`
|
|
399
|
+
), k;
|
|
362
400
|
}
|
|
363
401
|
}
|
|
364
402
|
}
|
|
403
|
+
// Record select query results by accumulating them by 1) key or type first,
|
|
404
|
+
// and then 2) "one" or "all".
|
|
405
|
+
maybeRecordSelectResult(e) {
|
|
406
|
+
if (!e.metadata) return;
|
|
407
|
+
const { opts: s, filters: t, limit: i } = e.metadata;
|
|
408
|
+
if (!s.recordSelectQuery || !t.key && !t.type || !this.stage || this.stage.status === "closed") return;
|
|
409
|
+
const n = this.stage.results.key || {};
|
|
410
|
+
t.key && (n[t.key] = {
|
|
411
|
+
...n[t.key] || {},
|
|
412
|
+
[i]: e
|
|
413
|
+
});
|
|
414
|
+
const r = this.stage.results.type || {};
|
|
415
|
+
t.type && (r[t.type] = {
|
|
416
|
+
...r[t.type] || {},
|
|
417
|
+
[i]: e
|
|
418
|
+
}), this.stage = {
|
|
419
|
+
...this.stage,
|
|
420
|
+
results: { key: n, type: r }
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
getStage() {
|
|
424
|
+
return this.stage;
|
|
425
|
+
}
|
|
365
426
|
openGroupStage() {
|
|
366
427
|
this.knock.log("[Guide] Opening a new group stage");
|
|
367
428
|
const {
|
|
368
|
-
orderResolutionDuration: e =
|
|
369
|
-
} = this.options,
|
|
429
|
+
orderResolutionDuration: e = F
|
|
430
|
+
} = this.options, s = setTimeout(() => {
|
|
370
431
|
this.closePendingGroupStage(), this.incrementCounter();
|
|
371
432
|
}, e);
|
|
372
433
|
return this.stage = {
|
|
373
434
|
status: "open",
|
|
374
435
|
ordered: [],
|
|
375
|
-
|
|
436
|
+
results: {},
|
|
437
|
+
timeoutId: s
|
|
376
438
|
}, this.stage;
|
|
377
439
|
}
|
|
378
440
|
// Close the current non-closed stage to resolve the prevailing guide up next
|
|
@@ -380,7 +442,7 @@ class W {
|
|
|
380
442
|
closePendingGroupStage() {
|
|
381
443
|
if (this.knock.log("[Guide] .closePendingGroupStage"), !this.stage || this.stage.status === "closed") return;
|
|
382
444
|
this.ensureClearTimeout();
|
|
383
|
-
const e = this.stage.ordered.find((
|
|
445
|
+
const e = this.stage.ordered.find((s) => s !== void 0);
|
|
384
446
|
return this.knock.log(
|
|
385
447
|
`[Guide] Closing the current group stage: resolved=${e}`
|
|
386
448
|
), this.stage = {
|
|
@@ -396,16 +458,16 @@ class W {
|
|
|
396
458
|
// rendered until we are ready to resolve the updated stage and re-render.
|
|
397
459
|
// Note, must be called ahead of updating the state store.
|
|
398
460
|
patchClosedGroupStage() {
|
|
399
|
-
var
|
|
400
|
-
if (this.knock.log("[Guide] .patchClosedGroupStage"), ((
|
|
401
|
-
const { orderResolutionDuration: e = 0 } = this.options,
|
|
461
|
+
var t;
|
|
462
|
+
if (this.knock.log("[Guide] .patchClosedGroupStage"), ((t = this.stage) == null ? void 0 : t.status) !== "closed") return;
|
|
463
|
+
const { orderResolutionDuration: e = 0 } = this.options, s = setTimeout(() => {
|
|
402
464
|
this.closePendingGroupStage(), this.incrementCounter();
|
|
403
465
|
}, e);
|
|
404
466
|
return this.ensureClearTimeout(), this.knock.log("[Guide] Patching the current group stage"), this.stage = {
|
|
405
467
|
...this.stage,
|
|
406
468
|
status: "patch",
|
|
407
469
|
ordered: [],
|
|
408
|
-
timeoutId:
|
|
470
|
+
timeoutId: s
|
|
409
471
|
}, this.stage;
|
|
410
472
|
}
|
|
411
473
|
clearGroupStage() {
|
|
@@ -417,11 +479,11 @@ class W {
|
|
|
417
479
|
}
|
|
418
480
|
// Test helpers to open and close the group stage to return the select result
|
|
419
481
|
// immediately.
|
|
420
|
-
_selectGuide(e,
|
|
421
|
-
return this.openGroupStage(), this.selectGuide(e,
|
|
482
|
+
_selectGuide(e, s = {}, t = {}) {
|
|
483
|
+
return this.openGroupStage(), this.selectGuide(e, s, t), this.closePendingGroupStage(), this.selectGuide(e, s, t);
|
|
422
484
|
}
|
|
423
|
-
_selectGuides(e,
|
|
424
|
-
return this.openGroupStage(), this.selectGuides(e,
|
|
485
|
+
_selectGuides(e, s = {}, t = {}) {
|
|
486
|
+
return this.openGroupStage(), this.selectGuides(e, s, t), this.closePendingGroupStage(), this.selectGuides(e, s, t);
|
|
425
487
|
}
|
|
426
488
|
//
|
|
427
489
|
// Engagement event handlers
|
|
@@ -429,211 +491,227 @@ class W {
|
|
|
429
491
|
// Make an optimistic update on the client side first, then send an engagement
|
|
430
492
|
// event to the backend.
|
|
431
493
|
//
|
|
432
|
-
async markAsSeen(e,
|
|
433
|
-
if (
|
|
494
|
+
async markAsSeen(e, s) {
|
|
495
|
+
if (s.message.seen_at) return;
|
|
434
496
|
this.knock.log(
|
|
435
|
-
`[Guide] Marking as seen (Guide key: ${e.key}, Step ref:${
|
|
497
|
+
`[Guide] Marking as seen (Guide key: ${e.key}, Step ref:${s.ref})`
|
|
436
498
|
);
|
|
437
|
-
const
|
|
499
|
+
const t = this.setStepMessageAttrs(e.key, s.ref, {
|
|
438
500
|
seen_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
439
501
|
});
|
|
440
|
-
if (!
|
|
502
|
+
if (!t) return;
|
|
503
|
+
if (this.shouldSkipEngagementApi())
|
|
504
|
+
return this.knock.log(
|
|
505
|
+
"[Guide] Skipping engagement API call for markAsSeen (debug mode)"
|
|
506
|
+
), t;
|
|
441
507
|
const i = {
|
|
442
|
-
...this.buildEngagementEventBaseParams(e,
|
|
443
|
-
content:
|
|
508
|
+
...this.buildEngagementEventBaseParams(e, t),
|
|
509
|
+
content: t.content,
|
|
444
510
|
data: this.targetParams.data
|
|
445
511
|
};
|
|
446
512
|
return this.knock.user.markGuideStepAs(
|
|
447
513
|
"seen",
|
|
448
514
|
i
|
|
449
|
-
),
|
|
515
|
+
), t;
|
|
450
516
|
}
|
|
451
|
-
async markAsInteracted(e,
|
|
517
|
+
async markAsInteracted(e, s, t) {
|
|
452
518
|
this.knock.log(
|
|
453
|
-
`[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${
|
|
519
|
+
`[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${s.ref})`
|
|
454
520
|
);
|
|
455
|
-
const i = (/* @__PURE__ */ new Date()).toISOString(),
|
|
521
|
+
const i = (/* @__PURE__ */ new Date()).toISOString(), n = this.setStepMessageAttrs(e.key, s.ref, {
|
|
456
522
|
read_at: i,
|
|
457
523
|
interacted_at: i
|
|
458
524
|
});
|
|
459
|
-
if (!
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
525
|
+
if (!n) return;
|
|
526
|
+
if (this.shouldSkipEngagementApi())
|
|
527
|
+
return this.knock.log(
|
|
528
|
+
"[Guide] Skipping engagement API call for markAsInteracted (debug mode)"
|
|
529
|
+
), n;
|
|
530
|
+
const r = {
|
|
531
|
+
...this.buildEngagementEventBaseParams(e, n),
|
|
532
|
+
metadata: t
|
|
463
533
|
};
|
|
464
|
-
return this.knock.user.markGuideStepAs("interacted",
|
|
534
|
+
return this.knock.user.markGuideStepAs("interacted", r), n;
|
|
465
535
|
}
|
|
466
|
-
async markAsArchived(e,
|
|
467
|
-
if (
|
|
536
|
+
async markAsArchived(e, s) {
|
|
537
|
+
if (s.message.archived_at) return;
|
|
468
538
|
this.knock.log(
|
|
469
|
-
`[Guide] Marking as archived (Guide key: ${e.key}, Step ref:${
|
|
539
|
+
`[Guide] Marking as archived (Guide key: ${e.key}, Step ref:${s.ref})`
|
|
470
540
|
);
|
|
471
|
-
const
|
|
541
|
+
const t = this.setStepMessageAttrs(e.key, s.ref, {
|
|
472
542
|
archived_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
473
543
|
});
|
|
474
|
-
if (!
|
|
475
|
-
|
|
544
|
+
if (!t) return;
|
|
545
|
+
if (this.shouldSkipEngagementApi())
|
|
546
|
+
return this.knock.log(
|
|
547
|
+
"[Guide] Skipping engagement API call for markAsArchived (debug mode)"
|
|
548
|
+
), t;
|
|
549
|
+
const i = this.buildEngagementEventBaseParams(e, t);
|
|
476
550
|
return this.knock.user.markGuideStepAs(
|
|
477
551
|
"archived",
|
|
478
552
|
{
|
|
479
553
|
...i,
|
|
480
554
|
unthrottled: e.bypass_global_group_limit
|
|
481
555
|
}
|
|
482
|
-
),
|
|
556
|
+
), t;
|
|
557
|
+
}
|
|
558
|
+
shouldSkipEngagementApi() {
|
|
559
|
+
var e;
|
|
560
|
+
return !!((e = this.store.state.debug) != null && e.skipEngagementTracking);
|
|
483
561
|
}
|
|
484
562
|
//
|
|
485
563
|
// Helpers
|
|
486
564
|
//
|
|
487
565
|
localCopy(e) {
|
|
488
|
-
const
|
|
566
|
+
const s = this, t = {
|
|
489
567
|
...e,
|
|
490
568
|
// Get the next unarchived step.
|
|
491
569
|
getStep() {
|
|
492
|
-
var i;
|
|
493
|
-
return ((i =
|
|
570
|
+
var i, n, r;
|
|
571
|
+
return ((i = s.store.state.debug) == null ? void 0 : i.forcedGuideKey) === this.key || (r = (n = s.store.state.debug) == null ? void 0 : n.focusedGuideKeys) != null && r[this.key] ? this.steps[0] : this.steps.find((a) => !a.message.archived_at);
|
|
494
572
|
}
|
|
495
573
|
};
|
|
496
|
-
return
|
|
497
|
-
const
|
|
498
|
-
...
|
|
574
|
+
return t.getStep = t.getStep.bind(t), t.steps = e.steps.map(({ message: i, ...n }) => {
|
|
575
|
+
const r = {
|
|
576
|
+
...n,
|
|
499
577
|
message: { ...i },
|
|
500
578
|
markAsSeen() {
|
|
501
|
-
return
|
|
579
|
+
return s.markAsSeen(t, this);
|
|
502
580
|
},
|
|
503
|
-
markAsInteracted({ metadata:
|
|
504
|
-
return
|
|
581
|
+
markAsInteracted({ metadata: a } = {}) {
|
|
582
|
+
return s.markAsInteracted(t, this, a);
|
|
505
583
|
},
|
|
506
584
|
markAsArchived() {
|
|
507
|
-
return
|
|
585
|
+
return s.markAsArchived(t, this);
|
|
508
586
|
}
|
|
509
587
|
};
|
|
510
|
-
return
|
|
511
|
-
}),
|
|
588
|
+
return r.markAsSeen = r.markAsSeen.bind(r), r.markAsInteracted = r.markAsInteracted.bind(r), r.markAsArchived = r.markAsArchived.bind(r), r;
|
|
589
|
+
}), t.activation_url_patterns = e.activation_url_patterns.map((i) => ({
|
|
512
590
|
...i,
|
|
513
|
-
pattern: new
|
|
591
|
+
pattern: new A({
|
|
514
592
|
pathname: i.pathname ?? void 0,
|
|
515
593
|
search: i.search ?? void 0
|
|
516
594
|
})
|
|
517
|
-
})),
|
|
595
|
+
})), t;
|
|
518
596
|
}
|
|
519
597
|
buildQueryParams(e = {}) {
|
|
520
|
-
const
|
|
598
|
+
const s = {
|
|
521
599
|
...this.targetParams,
|
|
522
600
|
...e
|
|
523
|
-
},
|
|
524
|
-
(
|
|
601
|
+
}, t = this.store.state.debug;
|
|
602
|
+
(t != null && t.forcedGuideKey || t != null && t.debugging) && (s.force_all_guides = !0);
|
|
525
603
|
let i = Object.fromEntries(
|
|
526
|
-
Object.entries(
|
|
527
|
-
([
|
|
604
|
+
Object.entries(s).filter(
|
|
605
|
+
([n, r]) => r != null
|
|
528
606
|
)
|
|
529
607
|
);
|
|
530
608
|
return i = i.data ? { ...i, data: JSON.stringify(i.data) } : i, i;
|
|
531
609
|
}
|
|
532
610
|
formatQueryKey(e) {
|
|
533
|
-
const
|
|
534
|
-
(
|
|
535
|
-
).join("&"), i =
|
|
536
|
-
return
|
|
611
|
+
const t = Object.keys(e).sort().map(
|
|
612
|
+
(n) => `${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`
|
|
613
|
+
).join("&"), i = N(this.knock.userId);
|
|
614
|
+
return t ? `${i}?${t}` : i;
|
|
537
615
|
}
|
|
538
|
-
setStepMessageAttrs(e,
|
|
616
|
+
setStepMessageAttrs(e, s, t) {
|
|
539
617
|
let i;
|
|
540
|
-
return
|
|
541
|
-
let
|
|
542
|
-
if (!
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
...
|
|
547
|
-
[
|
|
548
|
-
} :
|
|
549
|
-
return { ...
|
|
618
|
+
return t.archived_at && this.clearGroupStage(), this.store.setState((n) => {
|
|
619
|
+
let r = n.guides[e];
|
|
620
|
+
if (!r) return n;
|
|
621
|
+
const a = r.steps.map((d) => (d.ref !== s || (d.message = { ...d.message, ...t }, i = d), d));
|
|
622
|
+
r = i ? { ...r, steps: a } : r;
|
|
623
|
+
const o = { ...n.guides, [r.key]: r }, c = t.archived_at && !r.bypass_global_group_limit ? {
|
|
624
|
+
...n.guideGroupDisplayLogs,
|
|
625
|
+
[D]: t.archived_at
|
|
626
|
+
} : n.guideGroupDisplayLogs;
|
|
627
|
+
return { ...n, guides: o, guideGroupDisplayLogs: c };
|
|
550
628
|
}), i;
|
|
551
629
|
}
|
|
552
|
-
buildEngagementEventBaseParams(e,
|
|
630
|
+
buildEngagementEventBaseParams(e, s) {
|
|
553
631
|
return {
|
|
554
632
|
channel_id: e.channel_id,
|
|
555
633
|
guide_key: e.key,
|
|
556
634
|
guide_id: e.id,
|
|
557
|
-
guide_step_ref:
|
|
635
|
+
guide_step_ref: s.ref,
|
|
558
636
|
// Can be used for scoping guide messages.
|
|
559
637
|
tenant: this.targetParams.tenant
|
|
560
638
|
};
|
|
561
639
|
}
|
|
562
640
|
addOrReplaceGuide({ data: e }) {
|
|
563
641
|
this.patchClosedGroupStage();
|
|
564
|
-
const
|
|
565
|
-
this.store.setState((
|
|
566
|
-
const i = { ...
|
|
567
|
-
return { ...
|
|
642
|
+
const s = this.localCopy(e.guide);
|
|
643
|
+
this.store.setState((t) => {
|
|
644
|
+
const i = { ...t.guides, [s.key]: s };
|
|
645
|
+
return { ...t, guides: i };
|
|
568
646
|
});
|
|
569
647
|
}
|
|
570
648
|
removeGuide({ data: e }) {
|
|
571
|
-
this.patchClosedGroupStage(), this.store.setState((
|
|
572
|
-
const { [e.guide.key]:
|
|
573
|
-
return { ...
|
|
649
|
+
this.patchClosedGroupStage(), this.store.setState((s) => {
|
|
650
|
+
const { [e.guide.key]: t, ...i } = s.guides;
|
|
651
|
+
return { ...s, guides: i };
|
|
574
652
|
});
|
|
575
653
|
}
|
|
576
654
|
addOrReplaceGuideGroup({
|
|
577
655
|
data: e
|
|
578
656
|
}) {
|
|
579
|
-
this.patchClosedGroupStage(), this.store.setState((
|
|
580
|
-
const
|
|
581
|
-
let
|
|
582
|
-
return
|
|
583
|
-
if (!o
|
|
584
|
-
const
|
|
585
|
-
return { ...
|
|
586
|
-
},
|
|
587
|
-
if (!o
|
|
588
|
-
const
|
|
589
|
-
return { ...
|
|
590
|
-
},
|
|
657
|
+
this.patchClosedGroupStage(), this.store.setState((s) => {
|
|
658
|
+
const t = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [], n = e.guide_group.display_sequence_throttled || [];
|
|
659
|
+
let r = s.guides;
|
|
660
|
+
return r = i.reduce((a, o) => {
|
|
661
|
+
if (!a[o]) return a;
|
|
662
|
+
const c = { ...a[o], bypass_global_group_limit: !0 };
|
|
663
|
+
return { ...a, [o]: c };
|
|
664
|
+
}, r), r = n.reduce((a, o) => {
|
|
665
|
+
if (!a[o]) return a;
|
|
666
|
+
const c = { ...a[o], bypass_global_group_limit: !1 };
|
|
667
|
+
return { ...a, [o]: c };
|
|
668
|
+
}, r), { ...s, guides: r, guideGroups: t };
|
|
591
669
|
});
|
|
592
670
|
}
|
|
593
671
|
updatePreviewGuide({ data: e }) {
|
|
594
|
-
const
|
|
595
|
-
this.store.setState((
|
|
596
|
-
const i = { ...
|
|
597
|
-
return { ...
|
|
672
|
+
const s = this.localCopy(e.guide);
|
|
673
|
+
this.store.setState((t) => {
|
|
674
|
+
const i = { ...t.previewGuides, [s.key]: s };
|
|
675
|
+
return { ...t, previewGuides: i };
|
|
598
676
|
});
|
|
599
677
|
}
|
|
600
678
|
// Returns whether debug params have changed. For guide key, we only check
|
|
601
679
|
// presence since the exact value has no impact on fetch/subscribe
|
|
602
|
-
checkDebugStateChanged(e,
|
|
603
|
-
return !!e.forcedGuideKey != !!
|
|
680
|
+
checkDebugStateChanged(e, s) {
|
|
681
|
+
return !!e.forcedGuideKey != !!s.forcedGuideKey || e.previewSessionId !== s.previewSessionId;
|
|
604
682
|
}
|
|
605
683
|
listenForLocationChangesFromWindow() {
|
|
606
|
-
const e =
|
|
684
|
+
const e = p();
|
|
607
685
|
if (e != null && e.history && (e != null && e.addEventListener)) {
|
|
608
686
|
e.addEventListener("popstate", this.handleLocationChange), e.addEventListener("hashchange", this.handleLocationChange);
|
|
609
|
-
const
|
|
610
|
-
e.history.pushState = new Proxy(
|
|
611
|
-
apply: (i,
|
|
612
|
-
Reflect.apply(i,
|
|
687
|
+
const s = e.history.pushState, t = e.history.replaceState;
|
|
688
|
+
e.history.pushState = new Proxy(s, {
|
|
689
|
+
apply: (i, n, r) => {
|
|
690
|
+
Reflect.apply(i, n, r), setTimeout(() => {
|
|
613
691
|
this.handleLocationChange();
|
|
614
692
|
}, 0);
|
|
615
693
|
}
|
|
616
|
-
}), e.history.replaceState = new Proxy(
|
|
617
|
-
apply: (i,
|
|
618
|
-
Reflect.apply(i,
|
|
694
|
+
}), e.history.replaceState = new Proxy(t, {
|
|
695
|
+
apply: (i, n, r) => {
|
|
696
|
+
Reflect.apply(i, n, r), setTimeout(() => {
|
|
619
697
|
this.handleLocationChange();
|
|
620
698
|
}, 0);
|
|
621
699
|
}
|
|
622
|
-
}), this.pushStateFn =
|
|
700
|
+
}), this.pushStateFn = s, this.replaceStateFn = t;
|
|
623
701
|
} else
|
|
624
702
|
this.knock.log(
|
|
625
703
|
"[Guide] Unable to access the `window.history` object to detect location changes"
|
|
626
704
|
);
|
|
627
705
|
}
|
|
628
706
|
removeLocationChangeEventListeners() {
|
|
629
|
-
const e =
|
|
707
|
+
const e = p();
|
|
630
708
|
!(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
709
|
}
|
|
632
710
|
}
|
|
633
711
|
export {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
712
|
+
f as DEBUG_QUERY_PARAMS,
|
|
713
|
+
V as KnockGuideClient,
|
|
714
|
+
M as checkActivatable,
|
|
715
|
+
N as guidesApiRootPath
|
|
638
716
|
};
|
|
639
717
|
//# sourceMappingURL=client.mjs.map
|