@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.
Files changed (72) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/api.js +1 -1
  3. package/dist/cjs/api.js.map +1 -1
  4. package/dist/cjs/clients/feed/feed.js +1 -1
  5. package/dist/cjs/clients/feed/feed.js.map +1 -1
  6. package/dist/cjs/clients/guide/client.js +1 -1
  7. package/dist/cjs/clients/guide/client.js.map +1 -1
  8. package/dist/cjs/clients/guide/helpers.js +1 -1
  9. package/dist/cjs/clients/guide/helpers.js.map +1 -1
  10. package/dist/cjs/clients/guide/types.js +2 -0
  11. package/dist/cjs/clients/guide/types.js.map +1 -0
  12. package/dist/cjs/helpers.js +1 -1
  13. package/dist/cjs/helpers.js.map +1 -1
  14. package/dist/cjs/index.js +1 -1
  15. package/dist/cjs/knock.js +2 -2
  16. package/dist/cjs/knock.js.map +1 -1
  17. package/dist/cjs/pageVisibility.js +2 -0
  18. package/dist/cjs/pageVisibility.js.map +1 -0
  19. package/dist/esm/api.mjs +27 -12
  20. package/dist/esm/api.mjs.map +1 -1
  21. package/dist/esm/clients/feed/feed.mjs +60 -87
  22. package/dist/esm/clients/feed/feed.mjs.map +1 -1
  23. package/dist/esm/clients/guide/client.mjs +346 -268
  24. package/dist/esm/clients/guide/client.mjs.map +1 -1
  25. package/dist/esm/clients/guide/helpers.mjs +50 -57
  26. package/dist/esm/clients/guide/helpers.mjs.map +1 -1
  27. package/dist/esm/clients/guide/types.mjs +13 -0
  28. package/dist/esm/clients/guide/types.mjs.map +1 -0
  29. package/dist/esm/helpers.mjs +19 -4
  30. package/dist/esm/helpers.mjs.map +1 -1
  31. package/dist/esm/index.mjs +14 -12
  32. package/dist/esm/index.mjs.map +1 -1
  33. package/dist/esm/knock.mjs +31 -29
  34. package/dist/esm/knock.mjs.map +1 -1
  35. package/dist/esm/pageVisibility.mjs +31 -0
  36. package/dist/esm/pageVisibility.mjs.map +1 -0
  37. package/dist/types/api.d.ts +4 -0
  38. package/dist/types/api.d.ts.map +1 -1
  39. package/dist/types/clients/feed/feed.d.ts +1 -11
  40. package/dist/types/clients/feed/feed.d.ts.map +1 -1
  41. package/dist/types/clients/feed/interfaces.d.ts +0 -4
  42. package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
  43. package/dist/types/clients/feed/utils.d.ts +0 -2
  44. package/dist/types/clients/feed/utils.d.ts.map +1 -1
  45. package/dist/types/clients/guide/client.d.ts +4 -1
  46. package/dist/types/clients/guide/client.d.ts.map +1 -1
  47. package/dist/types/clients/guide/helpers.d.ts +1 -7
  48. package/dist/types/clients/guide/helpers.d.ts.map +1 -1
  49. package/dist/types/clients/guide/index.d.ts +2 -1
  50. package/dist/types/clients/guide/index.d.ts.map +1 -1
  51. package/dist/types/clients/guide/types.d.ts +24 -0
  52. package/dist/types/clients/guide/types.d.ts.map +1 -1
  53. package/dist/types/helpers.d.ts +19 -0
  54. package/dist/types/helpers.d.ts.map +1 -1
  55. package/dist/types/interfaces.d.ts +2 -0
  56. package/dist/types/interfaces.d.ts.map +1 -1
  57. package/dist/types/knock.d.ts +1 -0
  58. package/dist/types/knock.d.ts.map +1 -1
  59. package/dist/types/pageVisibility.d.ts +22 -0
  60. package/dist/types/pageVisibility.d.ts.map +1 -0
  61. package/package.json +1 -1
  62. package/src/api.ts +30 -0
  63. package/src/clients/feed/feed.ts +0 -73
  64. package/src/clients/feed/interfaces.ts +0 -7
  65. package/src/clients/guide/client.ts +182 -35
  66. package/src/clients/guide/helpers.ts +4 -12
  67. package/src/clients/guide/index.ts +3 -0
  68. package/src/clients/guide/types.ts +37 -0
  69. package/src/helpers.ts +39 -0
  70. package/src/interfaces.ts +2 -0
  71. package/src/knock.ts +4 -3
  72. package/src/pageVisibility.ts +70 -0
@@ -1,52 +1,53 @@
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 = {
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
- }, f = "knock_guide_debug", l = () => {
11
+ }, G = "knock_guide_debug", p = () => {
11
12
  if (typeof window < "u")
12
13
  return window;
13
- }, F = (u) => `/v1/users/${u}/guides`, b = () => {
14
- const u = l();
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), t = e.get(g.GUIDE_KEY), s = e.get(
18
- g.PREVIEW_SESSION_ID
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 (t || s) {
21
+ if (s || t) {
21
22
  if (u.localStorage)
22
23
  try {
23
- const n = {
24
- forcedGuideKey: t,
25
- previewSessionId: s
24
+ const r = {
25
+ forcedGuideKey: s,
26
+ previewSessionId: t
26
27
  };
27
- u.localStorage.setItem(f, JSON.stringify(n));
28
+ u.localStorage.setItem(G, JSON.stringify(r));
28
29
  } catch {
29
30
  }
30
31
  return {
31
- forcedGuideKey: t,
32
- previewSessionId: s
32
+ forcedGuideKey: s,
33
+ previewSessionId: t
33
34
  };
34
35
  }
35
- let i = null, r = null;
36
+ let i = null, n = null;
36
37
  if (u.localStorage)
37
38
  try {
38
- const n = u.localStorage.getItem(f);
39
- if (n) {
40
- const o = N(n);
41
- i = o.forcedGuideKey, r = o.previewSessionId;
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: r
48
+ previewSessionId: n
48
49
  };
49
- }, N = (u) => {
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
- }, _ = (u, e = {}) => {
63
- const t = new $(), s = T(u.guideGroups);
64
- if (!s) return t;
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, {
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(n, a);
73
- }
74
- return t.metadata = { guideGroup: s }, t;
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))
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 W {
84
- constructor(e, t, s = {}, i = {}) {
85
- c(this, "store");
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
- c(this, "socket");
88
- c(this, "socketChannel");
89
- c(this, "socketChannelTopic");
90
- c(this, "socketEventTypes", [
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
- c(this, "subscribeRetryCount", 0);
99
+ h(this, "subscribeRetryCount", 0);
99
100
  // Original history methods to monkey patch, or restore in cleanups.
100
- c(this, "pushStateFn");
101
- c(this, "replaceStateFn");
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
- c(this, "stage");
106
- c(this, "counterIntervalId");
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
- c(this, "handleLocationChange", () => {
109
+ h(this, "handleLocationChange", () => {
109
110
  this.knock.log("[Guide] .handleLocationChange");
110
- const e = l();
111
+ const e = p();
111
112
  if (!(e != null && e.location)) return;
112
- const t = e.location.href;
113
- if (this.store.state.location === t) return;
114
- if (this.knock.log(`[Guide] Detected a location change: ${t}`), !this.options.trackDebugParams) {
115
- this.setLocation(t);
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 s = this.store.state.debug || {}, i = b();
119
- this.setLocation(t, { debug: i }), this.checkDebugStateChanged(
120
- s,
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 p;
127
- this.knock = e, this.channelId = t, this.targetParams = s, this.options = i;
127
+ var g;
128
+ this.knock = e, this.channelId = s, this.targetParams = t, this.options = i;
128
129
  const {
129
- trackLocationFromWindow: r = !0,
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: 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({
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: d,
143
+ location: c,
143
144
  // Increment to update the state store and trigger re-selection.
144
145
  counter: 0,
145
- debug: h
146
+ debug: d
146
147
  });
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");
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 t = this.buildQueryParams(e == null ? void 0 : e.filters), s = this.formatQueryKey(t), i = this.store.state.queries[s];
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((n) => ({
170
- ...n,
171
- queries: { ...n.queries, [s]: { status: "loading" } }
170
+ this.store.setState((r) => ({
171
+ ...r,
172
+ queries: { ...r.queries, [t]: { status: "loading" } }
172
173
  }));
173
- let r;
174
+ let n;
174
175
  try {
175
176
  this.knock.log("[Guide] Fetching all eligible guides");
176
- const n = await this.knock.user.getGuides(this.channelId, t);
177
- r = { status: "ok" };
177
+ const r = await this.knock.user.getGuides(this.channelId, s);
178
+ n = { status: "ok" };
178
179
  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 }
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 (n) {
193
- r = { status: "error", error: n }, this.store.setState((o) => ({
194
- ...o,
195
- queries: { ...o.queries, [s]: r }
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 r;
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, t = {
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
- }, s = this.socket.channel(this.socketChannelTopic, t);
209
+ }, t = this.socket.channel(this.socketChannelTopic, s);
209
210
  for (const i of this.socketEventTypes)
210
- s.on(i, (r) => this.handleSocketEvent(r));
211
- ["closed", "errored"].includes(s.state) && (this.subscribeRetryCount = 0, s.join().receive("ok", () => {
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 = s;
220
+ })), this.socketChannel = t;
220
221
  }
221
222
  handleChannelJoinError() {
222
- if (this.subscribeRetryCount >= U) {
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: t, data: s } = e;
240
- switch (t) {
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 s.eligible ? this.addOrReplaceGuide(e) : this.removeGuide(e);
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, t = {}) {
257
- this.knock.log(`[Guide] .setLocation (loc=${e})`), this.clearGroupStage(), this.knock.log("[Guide] Updating the tracked location"), this.store.setState((s) => {
258
- var r;
259
- const i = (r = t == null ? void 0 : t.debug) != null && r.previewSessionId ? s.previewGuides : {};
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 = l();
271
+ const e = p();
271
272
  if (e != null && e.localStorage)
272
273
  try {
273
- e.localStorage.removeItem(f);
274
+ e.localStorage.removeItem(G);
274
275
  } catch {
275
276
  }
276
- if (this.store.setState((t) => ({
277
- ...t,
278
- debug: { forcedGuideKey: null, previewSessionId: null },
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 t = new URL(e.location.href);
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());
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 s;
292
+ var t;
288
293
  this.knock.log("[Guide] .setDebug()");
289
- const t = !((s = this.store.state.debug) != null && s.debugging);
294
+ const s = !((t = this.store.state.debug) != null && t.debugging);
290
295
  this.store.setState((i) => ({
291
296
  ...i,
292
- debug: { ...e, debugging: !0 }
293
- })), t && (this.knock.log(
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 t;
309
+ var s;
299
310
  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(
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, t = {}, s = {}) {
309
- if (this.knock.log(
310
- `[Guide] .selectGuides (filters: ${S(t)}; state: ${m(e)})`
311
- ), !this.selectGuide(e, t, s))
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 r = [..._(e, t).values()];
314
- if (!s.includeThrottled && y(e)) {
315
- const n = r.filter(
316
- (a) => a.bypass_global_group_limit
317
- ), o = r.length - n.length;
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 ${o} guides from selection, and returning ${n.length} guides`
320
- ), n;
340
+ `[Guide] Throttling ${l} guides from selection, and returning ${d.length} guides`
341
+ ), d;
321
342
  }
322
- return this.knock.log(`[Guide] Returning ${r.length} guides from selection`), r;
343
+ return this.knock.log(`[Guide] Returning ${o.length} guides from selection`), o;
323
344
  }
324
- selectGuide(e, t = {}, s = {}) {
345
+ selectGuide(e, s = {}, t = {}) {
346
+ var l, g, m;
325
347
  if (this.knock.log(
326
- `[Guide] .selectGuide (filters: ${S(t)}; state: ${m(e)})`
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
- const i = _(e, t);
332
- if (i.size === 0) {
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 [r, n] = [...i][0];
362
+ const [a, o] = [...r][0];
337
363
  if (this.knock.log(
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}`);
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: ${n.key}`), this.stage.ordered[r] = n.key;
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: ${n.key}`), this.stage.ordered[r] = n.key;
352
- const o = this.stage.resolved === n.key ? n : void 0;
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 \`${o == null ? void 0 : o.key}\` (stage: ${v(this.stage)})`
355
- ), o;
384
+ `[Guide] Returning \`${k == null ? void 0 : k.key}\` (stage: ${y(this.stage)})`
385
+ ), k;
356
386
  }
357
387
  case "closed": {
358
- const o = this.stage.resolved === n.key ? n : void 0;
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 \`${o == null ? void 0 : o.key}\` (stage: ${v(this.stage)})`
361
- ), o;
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 = K
369
- } = this.options, t = setTimeout(() => {
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
- timeoutId: t
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((t) => t !== void 0);
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 s;
400
- if (this.knock.log("[Guide] .patchClosedGroupStage"), ((s = this.stage) == null ? void 0 : s.status) !== "closed") return;
401
- const { orderResolutionDuration: e = 0 } = this.options, t = setTimeout(() => {
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: t
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, t = {}, s = {}) {
421
- return this.openGroupStage(), this.selectGuide(e, t, s), this.closePendingGroupStage(), this.selectGuide(e, t, s);
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, t = {}, s = {}) {
424
- return this.openGroupStage(), this.selectGuides(e, t, s), this.closePendingGroupStage(), this.selectGuides(e, t, s);
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, t) {
433
- if (t.message.seen_at) return;
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:${t.ref})`
497
+ `[Guide] Marking as seen (Guide key: ${e.key}, Step ref:${s.ref})`
436
498
  );
437
- const s = this.setStepMessageAttrs(e.key, t.ref, {
499
+ const t = this.setStepMessageAttrs(e.key, s.ref, {
438
500
  seen_at: (/* @__PURE__ */ new Date()).toISOString()
439
501
  });
440
- if (!s) return;
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, s),
443
- content: s.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
- ), s;
515
+ ), t;
450
516
  }
451
- async markAsInteracted(e, t, s) {
517
+ async markAsInteracted(e, s, t) {
452
518
  this.knock.log(
453
- `[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${t.ref})`
519
+ `[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${s.ref})`
454
520
  );
455
- const i = (/* @__PURE__ */ new Date()).toISOString(), r = this.setStepMessageAttrs(e.key, t.ref, {
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 (!r) return;
460
- const n = {
461
- ...this.buildEngagementEventBaseParams(e, r),
462
- metadata: s
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", n), r;
534
+ return this.knock.user.markGuideStepAs("interacted", r), n;
465
535
  }
466
- async markAsArchived(e, t) {
467
- if (t.message.archived_at) return;
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:${t.ref})`
539
+ `[Guide] Marking as archived (Guide key: ${e.key}, Step ref:${s.ref})`
470
540
  );
471
- const s = this.setStepMessageAttrs(e.key, t.ref, {
541
+ const t = this.setStepMessageAttrs(e.key, s.ref, {
472
542
  archived_at: (/* @__PURE__ */ new Date()).toISOString()
473
543
  });
474
- if (!s) return;
475
- const i = this.buildEngagementEventBaseParams(e, s);
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
- ), s;
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 t = this, s = {
566
+ const s = this, t = {
489
567
  ...e,
490
568
  // Get the next unarchived step.
491
569
  getStep() {
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);
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 s.getStep = s.getStep.bind(s), s.steps = e.steps.map(({ message: i, ...r }) => {
497
- const n = {
498
- ...r,
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 t.markAsSeen(s, this);
579
+ return s.markAsSeen(t, this);
502
580
  },
503
- markAsInteracted({ metadata: o } = {}) {
504
- return t.markAsInteracted(s, this, o);
581
+ markAsInteracted({ metadata: a } = {}) {
582
+ return s.markAsInteracted(t, this, a);
505
583
  },
506
584
  markAsArchived() {
507
- return t.markAsArchived(s, this);
585
+ return s.markAsArchived(t, this);
508
586
  }
509
587
  };
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) => ({
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 w({
591
+ pattern: new A({
514
592
  pathname: i.pathname ?? void 0,
515
593
  search: i.search ?? void 0
516
594
  })
517
- })), s;
595
+ })), t;
518
596
  }
519
597
  buildQueryParams(e = {}) {
520
- const t = {
598
+ const s = {
521
599
  ...this.targetParams,
522
600
  ...e
523
- }, s = this.store.state.debug;
524
- (s != null && s.forcedGuideKey || s != null && s.debugging) && (t.force_all_guides = !0);
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(t).filter(
527
- ([r, n]) => n != null
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 s = Object.keys(e).sort().map(
534
- (r) => `${encodeURIComponent(r)}=${encodeURIComponent(e[r])}`
535
- ).join("&"), i = F(this.knock.userId);
536
- return s ? `${i}?${s}` : i;
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, t, s) {
616
+ setStepMessageAttrs(e, s, t) {
539
617
  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 };
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, t) {
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: t.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 t = this.localCopy(e.guide);
565
- this.store.setState((s) => {
566
- const i = { ...s.guides, [t.key]: t };
567
- return { ...s, guides: i };
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((t) => {
572
- const { [e.guide.key]: s, ...i } = t.guides;
573
- return { ...t, guides: i };
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((t) => {
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) => {
583
- if (!o[a]) return o;
584
- const d = { ...o[a], bypass_global_group_limit: !0 };
585
- return { ...o, [a]: d };
586
- }, n), n = r.reduce((o, a) => {
587
- if (!o[a]) return o;
588
- const d = { ...o[a], bypass_global_group_limit: !1 };
589
- return { ...o, [a]: d };
590
- }, n), { ...t, guides: n, guideGroups: s };
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 t = this.localCopy(e.guide);
595
- this.store.setState((s) => {
596
- const i = { ...s.previewGuides, [t.key]: t };
597
- return { ...s, previewGuides: i };
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, t) {
603
- return !!e.forcedGuideKey != !!t.forcedGuideKey || e.previewSessionId !== t.previewSessionId;
680
+ checkDebugStateChanged(e, s) {
681
+ return !!e.forcedGuideKey != !!s.forcedGuideKey || e.previewSessionId !== s.previewSessionId;
604
682
  }
605
683
  listenForLocationChangesFromWindow() {
606
- const e = l();
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 t = e.history.pushState, s = e.history.replaceState;
610
- e.history.pushState = new Proxy(t, {
611
- apply: (i, r, n) => {
612
- Reflect.apply(i, r, n), setTimeout(() => {
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(s, {
617
- apply: (i, r, n) => {
618
- Reflect.apply(i, r, n), setTimeout(() => {
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 = t, this.replaceStateFn = s;
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 = l();
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
- g as DEBUG_QUERY_PARAMS,
635
- W as KnockGuideClient,
636
- j as checkActivatable,
637
- F as guidesApiRootPath
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