@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.
Files changed (33) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/cjs/api.js +1 -1
  3. package/dist/cjs/clients/feed/feed.js +1 -1
  4. package/dist/cjs/clients/feed/feed.js.map +1 -1
  5. package/dist/cjs/clients/feed/utils.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/index.js +1 -1
  9. package/dist/esm/api.mjs +1 -1
  10. package/dist/esm/clients/feed/feed.mjs +2 -1
  11. package/dist/esm/clients/feed/feed.mjs.map +1 -1
  12. package/dist/esm/clients/feed/utils.mjs.map +1 -1
  13. package/dist/esm/clients/guide/client.mjs +212 -190
  14. package/dist/esm/clients/guide/client.mjs.map +1 -1
  15. package/dist/esm/index.mjs +11 -10
  16. package/dist/types/clients/feed/feed.d.ts.map +1 -1
  17. package/dist/types/clients/feed/interfaces.d.ts +35 -3
  18. package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
  19. package/dist/types/clients/feed/utils.d.ts +1 -0
  20. package/dist/types/clients/feed/utils.d.ts.map +1 -1
  21. package/dist/types/clients/guide/client.d.ts +4 -1
  22. package/dist/types/clients/guide/client.d.ts.map +1 -1
  23. package/dist/types/clients/guide/index.d.ts +2 -2
  24. package/dist/types/clients/guide/index.d.ts.map +1 -1
  25. package/dist/types/clients/guide/types.d.ts +12 -1
  26. package/dist/types/clients/guide/types.d.ts.map +1 -1
  27. package/package.json +2 -2
  28. package/src/clients/feed/feed.ts +2 -1
  29. package/src/clients/feed/interfaces.ts +35 -6
  30. package/src/clients/feed/utils.ts +11 -2
  31. package/src/clients/guide/client.ts +89 -52
  32. package/src/clients/guide/index.ts +7 -1
  33. package/src/clients/guide/types.ts +21 -1
@@ -1,16 +1,16 @@
1
- var _ = Object.defineProperty;
2
- var b = (u, e, t) => e in u ? _(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
3
- var d = (u, e, t) => b(u, typeof e != "symbol" ? e + "" : e, t);
4
- import { Store as I } from "@tanstack/store";
5
- import { URLPattern as C } from "urlpattern-polyfill";
6
- import { byKey as E, mockDefaultGroup as w, formatFilters as f, formatState as G, checkStateIfThrottled as S, formatGroupStage as y, DEFAULT_GROUP_KEY as R, SelectionResult as P, findDefaultGroup as A, newUrl as L, predicateUrlRules as D, predicateUrlPatterns as K } from "./helpers.mjs";
7
- const $ = 50, T = 30 * 1e3, O = 3, g = {
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
- }, k = "knock_guide_debug", l = () => {
10
+ }, f = "knock_guide_debug", l = () => {
11
11
  if (typeof window < "u")
12
12
  return window;
13
- }, U = (u) => `/v1/users/${u}/guides`, m = () => {
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 i = {
23
+ const n = {
24
24
  forcedGuideKey: t,
25
25
  previewSessionId: s
26
26
  };
27
- u.localStorage.setItem(k, JSON.stringify(i));
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 r = null, n = null;
35
+ let i = null, r = null;
36
36
  if (u.localStorage)
37
37
  try {
38
- const i = u.localStorage.getItem(k);
39
- if (i) {
40
- const o = F(i);
41
- r = o.forcedGuideKey, n = o.previewSessionId;
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: r,
47
- previewSessionId: n
46
+ forcedGuideKey: i,
47
+ previewSessionId: r
48
48
  };
49
- }, F = (u) => {
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
- }, v = (u, e = {}) => {
63
- const t = new P(), s = A(u.guideGroups);
62
+ }, _ = (u, e = {}) => {
63
+ const t = new $(), s = T(u.guideGroups);
64
64
  if (!s) return t;
65
- const r = [...s.display_sequence], n = u.location;
66
- if (u.debug.forcedGuideKey) {
67
- const i = r.indexOf(u.debug.forcedGuideKey);
68
- i > -1 && r.splice(i, 1), r.unshift(u.debug.forcedGuideKey);
69
- }
70
- for (const [i, o] of r.entries()) {
71
- let a = u.guides[o];
72
- u.debug.forcedGuideKey === o && u.previewGuides[o] && (a = u.previewGuides[o]), !(!a || !N(a, {
73
- location: n,
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
- })) && t.set(i, a);
72
+ }) || t.set(n, a);
77
73
  }
78
74
  return t.metadata = { guideGroup: s }, t;
79
- }, N = (u, { location: e, filters: t = {}, debug: s = {} }) => {
80
- if (t.type && t.type !== u.type || t.key && t.key !== u.key)
81
- return !1;
82
- if (s.forcedGuideKey === u.key)
83
- return !0;
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 B {
94
- constructor(e, t, s = {}, r = {}) {
95
- d(this, "store");
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
- d(this, "socket");
98
- d(this, "socketChannel");
99
- d(this, "socketChannelTopic");
100
- d(this, "socketEventTypes", [
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
- d(this, "subscribeRetryCount", 0);
98
+ c(this, "subscribeRetryCount", 0);
109
99
  // Original history methods to monkey patch, or restore in cleanups.
110
- d(this, "pushStateFn");
111
- d(this, "replaceStateFn");
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
- d(this, "stage");
116
- d(this, "counterIntervalId");
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
- d(this, "handleLocationChange", () => {
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
- const s = this.store.state.debug, r = m();
126
- this.setLocation(t, { debug: r }), this.checkDebugStateChanged(
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
- r
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 = r;
127
+ this.knock = e, this.channelId = t, this.targetParams = s, this.options = i;
135
128
  const {
136
- trackLocationFromWindow: n = !0,
137
- throttleCheckInterval: i = T
138
- } = r, o = l(), a = n ? (p = o == null ? void 0 : o.location) == null ? void 0 : p.href : void 0, h = m();
139
- this.store = new I({
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: a,
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: c } = this.knock.client();
151
- this.socket = c, this.socketChannelTopic = `guides:${t}`, n && this.listenForLocationChangesFromWindow(), i && this.startCounterInterval(i), this.knock.log("[Guide] Initialized a guide client");
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), r = this.store.state.queries[s];
170
- if (r)
171
- return r;
172
- this.store.setState((i) => ({
173
- ...i,
174
- queries: { ...i.queries, [s]: { status: "loading" } }
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 n;
173
+ let r;
177
174
  try {
178
175
  this.knock.log("[Guide] Fetching all eligible guides");
179
- const i = await this.knock.user.getGuides(this.channelId, t);
180
- n = { status: "ok" };
181
- const { entries: o, guide_groups: a, guide_group_display_logs: h } = i;
182
- this.knock.log("[Guide] Loading fetched guides"), this.store.setState((c) => ({
183
- ...c,
184
- guideGroups: (a == null ? void 0 : a.length) > 0 ? a : [w(o)],
185
- guideGroupDisplayLogs: h || {},
186
- guides: E(o.map((p) => this.localCopy(p))),
187
- queries: { ...c.queries, [s]: n }
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 (i) {
190
- n = { status: "error", error: i }, this.store.setState((o) => ({
192
+ } catch (n) {
193
+ r = { status: "error", error: n }, this.store.setState((o) => ({
191
194
  ...o,
192
- queries: { ...o.queries, [s]: n }
195
+ queries: { ...o.queries, [s]: r }
193
196
  }));
194
197
  }
195
- return n;
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 r of this.socketEventTypes)
207
- s.on(r, (n) => this.handleSocketEvent(n));
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", (r) => {
213
+ }).receive("error", (i) => {
211
214
  this.knock.log(
212
- `[Guide] Failed to join channel: ${JSON.stringify(r)}`
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 >= O) {
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 n;
256
- const r = (n = t == null ? void 0 : t.debug) != null && n.previewSessionId ? s.previewGuides : {};
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: r,
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(k);
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: ${f(t)}; state: ${G(e)})`
310
+ `[Guide] .selectGuides (filters: ${S(t)}; state: ${m(e)})`
289
311
  ), !this.selectGuide(e, t, s))
290
312
  return [];
291
- const n = [...v(e, t).values()];
292
- if (!s.includeThrottled && S(e)) {
293
- const i = n.filter(
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 = n.length - i.length;
317
+ ), o = r.length - n.length;
296
318
  return this.knock.log(
297
- `[Guide] Throttling ${o} guides from selection, and returning ${i.length} guides`
298
- ), i;
319
+ `[Guide] Throttling ${o} guides from selection, and returning ${n.length} guides`
320
+ ), n;
299
321
  }
300
- return this.knock.log(`[Guide] Returning ${n.length} guides from selection`), n;
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: ${f(t)}; state: ${G(e)})`
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 r = v(e, t);
310
- if (r.size === 0) {
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 [n, i] = [...r][0];
336
+ const [r, n] = [...i][0];
315
337
  if (this.knock.log(
316
- `[Guide] Selection found: \`${i.key}\` (total: ${r.size})`
317
- ), i.bypass_global_group_limit)
318
- return this.knock.log(`[Guide] Returning the unthrottled guide: ${i.key}`), i;
319
- if (!s.includeThrottled && S(e)) {
320
- this.knock.log(`[Guide] Throttling the selected guide: ${i.key}`);
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: ${i.key}`), this.stage.ordered[n] = i.key;
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: ${i.key}`), this.stage.ordered[n] = i.key;
330
- const o = this.stage.resolved === i.key ? i : void 0;
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: ${y(this.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 === i.key ? i : void 0;
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: ${y(this.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
- let e;
362
- return this.store.state.debug.forcedGuideKey && (e = this.stage.ordered.find(
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 r = {
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
- r
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 r = (/* @__PURE__ */ new Date()).toISOString(), n = this.setStepMessageAttrs(e.key, t.ref, {
436
- read_at: r,
437
- interacted_at: r
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 (!n) return;
440
- const i = {
441
- ...this.buildEngagementEventBaseParams(e, n),
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", i), n;
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 r = this.buildEngagementEventBaseParams(e, s);
475
+ const i = this.buildEngagementEventBaseParams(e, s);
456
476
  return this.knock.user.markGuideStepAs(
457
477
  "archived",
458
478
  {
459
- ...r,
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
- return t.store.state.debug.forcedGuideKey === this.key ? this.steps[0] : this.steps.find((r) => !r.message.archived_at);
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: r, ...n }) => {
476
- const i = {
477
- ...n,
478
- message: { ...r },
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 i.markAsSeen = i.markAsSeen.bind(i), i.markAsInteracted = i.markAsInteracted.bind(i), i.markAsArchived = i.markAsArchived.bind(i), i;
490
- }), s.activation_url_patterns = e.activation_url_patterns.map((r) => ({
491
- ...r,
492
- pattern: new C({
493
- pathname: r.pathname ?? void 0,
494
- search: r.search ?? void 0
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
- this.store.state.debug.forcedGuideKey && (t.force_all_guides = !0);
504
- let r = Object.fromEntries(
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
- ([n, i]) => i != null
527
+ ([r, n]) => n != null
507
528
  )
508
529
  );
509
- return r = r.data ? { ...r, data: JSON.stringify(r.data) } : r, r;
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
- (n) => `${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`
514
- ).join("&"), r = U(this.knock.userId);
515
- return s ? `${r}?${s}` : r;
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 r;
519
- return s.archived_at && this.clearGroupStage(), this.store.setState((n) => {
520
- let i = n.guides[e];
521
- if (!i) return n;
522
- const o = i.steps.map((c) => (c.ref !== t || (c.message = { ...c.message, ...s }, r = c), c));
523
- i = r ? { ...i, steps: o } : i;
524
- const a = { ...n.guides, [i.key]: i }, h = s.archived_at && !i.bypass_global_group_limit ? {
525
- ...n.guideGroupDisplayLogs,
526
- [R]: s.archived_at
527
- } : n.guideGroupDisplayLogs;
528
- return { ...n, guides: a, guideGroupDisplayLogs: h };
529
- }), r;
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 r = { ...s.guides, [t.key]: t };
546
- return { ...s, guides: r };
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, ...r } = t.guides;
552
- return { ...t, guides: r };
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], r = e.guide_group.display_sequence_unthrottled || [], n = e.guide_group.display_sequence_throttled || [];
560
- let i = t.guides;
561
- return i = r.reduce((o, a) => {
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 h = { ...o[a], bypass_global_group_limit: !0 };
564
- return { ...o, [a]: h };
565
- }, i), i = n.reduce((o, a) => {
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 h = { ...o[a], bypass_global_group_limit: !1 };
568
- return { ...o, [a]: h };
569
- }, i), { ...t, guides: i, guideGroups: s };
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 r = { ...s.previewGuides, [t.key]: t };
576
- return { ...s, previewGuides: r };
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, i) => {
591
- Reflect.apply(r, n, i), setTimeout(() => {
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, i) => {
597
- Reflect.apply(r, n, i), setTimeout(() => {
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
- B as KnockGuideClient,
615
- U as guidesApiRootPath
635
+ W as KnockGuideClient,
636
+ j as checkActivatable,
637
+ F as guidesApiRootPath
616
638
  };
617
639
  //# sourceMappingURL=client.mjs.map