@knocklabs/client 0.21.6 → 0.21.8

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 +14 -0
  2. package/dist/cjs/api.js +1 -1
  3. package/dist/cjs/clients/guide/client.js +1 -1
  4. package/dist/cjs/clients/guide/client.js.map +1 -1
  5. package/dist/cjs/clients/guide/helpers.js +1 -1
  6. package/dist/cjs/clients/guide/helpers.js.map +1 -1
  7. package/dist/cjs/clients/guide/types.js.map +1 -1
  8. package/dist/cjs/clients/users/index.js +1 -1
  9. package/dist/cjs/clients/users/index.js.map +1 -1
  10. package/dist/esm/api.mjs +1 -1
  11. package/dist/esm/clients/guide/client.mjs +170 -147
  12. package/dist/esm/clients/guide/client.mjs.map +1 -1
  13. package/dist/esm/clients/guide/helpers.mjs +57 -45
  14. package/dist/esm/clients/guide/helpers.mjs.map +1 -1
  15. package/dist/esm/clients/guide/types.mjs.map +1 -1
  16. package/dist/esm/clients/users/index.mjs +13 -5
  17. package/dist/esm/clients/users/index.mjs.map +1 -1
  18. package/dist/types/clients/guide/client.d.ts +3 -0
  19. package/dist/types/clients/guide/client.d.ts.map +1 -1
  20. package/dist/types/clients/guide/helpers.d.ts +6 -1
  21. package/dist/types/clients/guide/helpers.d.ts.map +1 -1
  22. package/dist/types/clients/guide/index.d.ts +1 -0
  23. package/dist/types/clients/guide/index.d.ts.map +1 -1
  24. package/dist/types/clients/guide/types.d.ts +9 -0
  25. package/dist/types/clients/guide/types.d.ts.map +1 -1
  26. package/dist/types/clients/users/index.d.ts +2 -1
  27. package/dist/types/clients/users/index.d.ts.map +1 -1
  28. package/package.json +3 -3
  29. package/src/clients/guide/client.ts +60 -5
  30. package/src/clients/guide/helpers.ts +38 -0
  31. package/src/clients/guide/index.ts +1 -0
  32. package/src/clients/guide/types.ts +11 -0
  33. package/src/clients/users/index.ts +15 -1
@@ -1,31 +1,31 @@
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);
1
+ var C = Object.defineProperty;
2
+ var w = (a, e, s) => e in a ? C(a, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : a[e] = s;
3
+ var h = (a, e, s) => w(a, typeof e != "symbol" ? e + "" : e, s);
4
4
  import { Store as R } from "@tanstack/store";
5
5
  import { URLPattern as A } from "urlpattern-polyfill";
6
- import { byKey as m, 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 = {
6
+ import { byKey as S, mockDefaultGroup as P, formatFilters as b, formatState as v, checkStateIfThrottled as _, formatGroupStage as m, DEFAULT_GROUP_KEY as D, getToolbarRunConfigFromUrl as K, newUrl as L, predicateUrlRules as T, predicateUrlPatterns as $, findDefaultGroup as O } from "./helpers.mjs";
7
+ import { SelectionResult as F } from "./types.mjs";
8
+ const U = 50, N = 30 * 1e3, q = 3, f = {
9
9
  GUIDE_KEY: "knock_guide_key",
10
10
  PREVIEW_SESSION_ID: "knock_preview_session_id"
11
- }, G = "knock_guide_debug", p = () => {
11
+ }, y = "knock_guide_debug", p = () => {
12
12
  if (typeof window < "u")
13
13
  return window;
14
- }, N = (u) => `/v1/users/${u}/guides`, I = () => {
15
- const u = p();
16
- if (!u || !u.location)
14
+ }, j = (a) => `/v1/users/${a}/guides`, I = () => {
15
+ const a = p();
16
+ if (!a || !a.location)
17
17
  return { forcedGuideKey: null, previewSessionId: null };
18
- const e = new URLSearchParams(u.location.search), s = e.get(f.GUIDE_KEY), t = e.get(
18
+ const e = new URLSearchParams(a.location.search), s = e.get(f.GUIDE_KEY), t = e.get(
19
19
  f.PREVIEW_SESSION_ID
20
20
  );
21
21
  if (s || t) {
22
- if (u.localStorage)
22
+ if (a.localStorage)
23
23
  try {
24
- const r = {
24
+ const n = {
25
25
  forcedGuideKey: s,
26
26
  previewSessionId: t
27
27
  };
28
- u.localStorage.setItem(G, JSON.stringify(r));
28
+ a.localStorage.setItem(y, JSON.stringify(n));
29
29
  } catch {
30
30
  }
31
31
  return {
@@ -33,23 +33,23 @@ const F = 50, U = 30 * 1e3, q = 3, f = {
33
33
  previewSessionId: t
34
34
  };
35
35
  }
36
- let i = null, n = null;
37
- if (u.localStorage)
36
+ let i = null, r = null;
37
+ if (a.localStorage)
38
38
  try {
39
- const r = u.localStorage.getItem(G);
40
- if (r) {
41
- const a = j(r);
42
- i = a.forcedGuideKey, n = a.previewSessionId;
39
+ const n = a.localStorage.getItem(y);
40
+ if (n) {
41
+ const u = B(n);
42
+ i = u.forcedGuideKey, r = u.previewSessionId;
43
43
  }
44
44
  } catch {
45
45
  }
46
46
  return {
47
47
  forcedGuideKey: i,
48
- previewSessionId: n
48
+ previewSessionId: r
49
49
  };
50
- }, j = (u) => {
50
+ }, B = (a) => {
51
51
  try {
52
- const e = JSON.parse(u);
52
+ const e = JSON.parse(a);
53
53
  return {
54
54
  forcedGuideKey: (e == null ? void 0 : e.forcedGuideKey) ?? null,
55
55
  previewSessionId: (e == null ? void 0 : e.previewSessionId) ?? null
@@ -60,28 +60,28 @@ const F = 50, U = 30 * 1e3, q = 3, f = {
60
60
  previewSessionId: null
61
61
  };
62
62
  }
63
- }, C = (u, e, s) => {
64
- const t = new O(), i = T(u.guideGroups);
63
+ }, E = (a, e, s) => {
64
+ const t = new F(), i = O(a.guideGroups);
65
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, {
70
- location: r,
71
- ineligibleGuides: u.ineligibleGuides,
72
- debug: u.debug
73
- }) || t.set(a, c);
66
+ const r = i.display_sequence, n = a.location;
67
+ for (const [u, o] of r.entries()) {
68
+ const c = a.previewGuides[o] || a.guides[o];
69
+ !c || !M(c, e, {
70
+ location: n,
71
+ ineligibleGuides: a.ineligibleGuides,
72
+ debug: a.debug
73
+ }) || t.set(u, c);
74
74
  }
75
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 || [];
76
+ }, M = (a, e, { location: s, ineligibleGuides: t = {}, debug: i = {} }) => e.type && e.type !== a.type || e.key && e.key !== a.key ? !1 : i.focusedGuideKeys && Object.keys(i.focusedGuideKeys).length > 0 ? !!i.focusedGuideKeys[a.key] : i.forcedGuideKey ? i.forcedGuideKey === a.key : t[a.key] || !a.active || a.steps.every((n) => !!n.message.archived_at) ? !1 : Q(a, s), Q = (a, e) => {
77
+ const s = e ? L(e) : void 0, t = a.activation_url_rules || [], i = a.activation_url_patterns || [];
78
78
  if (s && t.length > 0) {
79
- if (!L(s, t)) return !1;
79
+ if (!T(s, t)) return !1;
80
80
  } else if (s && i.length > 0 && !$(s, i))
81
81
  return !1;
82
82
  return !0;
83
83
  };
84
- class V {
84
+ class z {
85
85
  constructor(e, s, t = {}, i = {}) {
86
86
  h(this, "store");
87
87
  // Phoenix channels for real time guide updates over websocket
@@ -124,15 +124,15 @@ class V {
124
124
  "[Guide] Debug state changed, refetching guides and resubscribing to the websocket channel"
125
125
  ), this.fetch(), this.subscribe());
126
126
  });
127
- var g;
127
+ var l;
128
128
  this.knock = e, this.channelId = s, this.targetParams = t, this.options = i;
129
129
  const {
130
- trackLocationFromWindow: n = !0,
130
+ trackLocationFromWindow: r = !0,
131
131
  // TODO(KNO-11523): Remove once we ship guide toolbar v2, and offload as
132
132
  // much debugging specific logic and responsibilities to toolbar.
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;
133
+ trackDebugParams: n = !1,
134
+ throttleCheckInterval: u = N
135
+ } = i, o = p(), c = r ? (l = o == null ? void 0 : o.location) == null ? void 0 : l.href : void 0, d = n ? I() : void 0;
136
136
  this.store = new R({
137
137
  guideGroups: [],
138
138
  guideGroupDisplayLogs: {},
@@ -145,8 +145,8 @@ class V {
145
145
  counter: 0,
146
146
  debug: d
147
147
  });
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");
148
+ const { socket: g } = this.knock.client();
149
+ this.socket = g, this.socketChannelTopic = `guides:${s}`, r && this.listenForLocationChangesFromWindow(), u && this.startCounterInterval(u), this.knock.log("[Guide] Initialized a guide client");
150
150
  }
151
151
  incrementCounter() {
152
152
  this.knock.log("[Guide] Incrementing the counter"), this.store.setState((e) => ({ ...e, counter: e.counter + 1 }));
@@ -165,38 +165,38 @@ class V {
165
165
  async fetch(e) {
166
166
  this.knock.log("[Guide] .fetch"), this.knock.failIfNotAuthenticated();
167
167
  const s = this.buildQueryParams(e == null ? void 0 : e.filters), t = this.formatQueryKey(s), i = this.store.state.queries[t];
168
- if (i)
168
+ if (i && !(e != null && e.force))
169
169
  return i;
170
- this.store.setState((r) => ({
171
- ...r,
172
- queries: { ...r.queries, [t]: { status: "loading" } }
170
+ this.store.setState((n) => ({
171
+ ...n,
172
+ queries: { ...n.queries, [t]: { status: "loading" } }
173
173
  }));
174
- let n;
174
+ let r;
175
175
  try {
176
176
  this.knock.log("[Guide] Fetching all eligible guides");
177
- const r = await this.knock.user.getGuides(this.channelId, s);
178
- n = { status: "ok" };
177
+ const n = await this.knock.user.getGuides(this.channelId, s);
178
+ r = { status: "ok" };
179
179
  const {
180
- entries: a,
180
+ entries: u,
181
181
  guide_groups: o,
182
182
  guide_group_display_logs: c,
183
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)],
184
+ } = n;
185
+ this.stage && this.clearGroupStage(), this.knock.log("[Guide] Loading fetched guides"), this.store.setState((g) => ({
186
+ ...g,
187
+ guideGroups: (o == null ? void 0 : o.length) > 0 ? o : [P(u)],
188
188
  guideGroupDisplayLogs: c || {},
189
- guides: m(a.map((g) => this.localCopy(g))),
190
- ineligibleGuides: m(d || []),
191
- queries: { ...l.queries, [t]: n }
189
+ guides: S(u.map((l) => this.localCopy(l))),
190
+ ineligibleGuides: S(d || []),
191
+ queries: { ...g.queries, [t]: r }
192
192
  }));
193
- } catch (r) {
194
- n = { status: "error", error: r }, this.store.setState((a) => ({
195
- ...a,
196
- queries: { ...a.queries, [t]: n }
193
+ } catch (n) {
194
+ r = { status: "error", error: n }, this.store.setState((u) => ({
195
+ ...u,
196
+ queries: { ...u.queries, [t]: r }
197
197
  }));
198
198
  }
199
- return n;
199
+ return r;
200
200
  }
201
201
  subscribe() {
202
202
  if (!this.socket) return;
@@ -208,7 +208,7 @@ class V {
208
208
  preview_session_id: (e == null ? void 0 : e.previewSessionId) || void 0
209
209
  }, t = this.socket.channel(this.socketChannelTopic, s);
210
210
  for (const i of this.socketEventTypes)
211
- t.on(i, (n) => this.handleSocketEvent(n));
211
+ t.on(i, (r) => this.handleSocketEvent(r));
212
212
  ["closed", "errored"].includes(t.state) && (this.subscribeRetryCount = 0, t.join().receive("ok", () => {
213
213
  this.knock.log("[Guide] Successfully joined channel");
214
214
  }).receive("error", (i) => {
@@ -256,8 +256,8 @@ class V {
256
256
  }
257
257
  setLocation(e, s = {}) {
258
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 : {};
259
+ var r;
260
+ const i = (r = s == null ? void 0 : s.debug) != null && r.previewSessionId ? t.previewGuides : {};
261
261
  return {
262
262
  ...t,
263
263
  ...s,
@@ -271,7 +271,7 @@ class V {
271
271
  const e = p();
272
272
  if (e != null && e.localStorage)
273
273
  try {
274
- e.localStorage.removeItem(G);
274
+ e.localStorage.removeItem(y);
275
275
  } catch {
276
276
  }
277
277
  if (this.store.setState((s) => ({
@@ -290,7 +290,10 @@ class V {
290
290
  }
291
291
  setDebug(e) {
292
292
  var t;
293
- this.knock.log("[Guide] .setDebug()");
293
+ if (this.knock.log("[Guide] .setDebug()"), !this.knock.isAuthenticated()) {
294
+ this.knock.log("[Guide] Not authenticated, cannot start debugging");
295
+ return;
296
+ }
294
297
  const s = !((t = this.store.state.debug) != null && t.debugging);
295
298
  this.clearGroupStage(), this.store.setState((i) => ({
296
299
  ...i,
@@ -303,15 +306,19 @@ class V {
303
306
  }
304
307
  })), s && (this.knock.log(
305
308
  "[Guide] Start debugging, refetching guides and resubscribing to the websocket channel"
306
- ), this.fetch(), this.subscribe());
309
+ ), this.fetch({ force: !0 }), this.subscribe());
307
310
  }
308
311
  unsetDebug() {
309
312
  var s;
310
313
  this.knock.log("[Guide] .unsetDebug()");
311
314
  const e = (s = this.store.state.debug) == null ? void 0 : s.debugging;
312
- this.clearGroupStage(), this.store.setState((t) => ({ ...t, debug: void 0 })), e && (this.knock.log(
315
+ if (this.clearGroupStage(), this.store.setState((t) => ({ ...t, debug: void 0 })), !this.knock.isAuthenticated()) {
316
+ this.knock.log("[Guide] Not authenticated, will not refetch");
317
+ return;
318
+ }
319
+ e && (this.knock.log(
313
320
  "[Guide] Stop debugging, refetching guides and resubscribing to the websocket channel"
314
- ), this.fetch(), this.subscribe());
321
+ ), this.fetch({ force: !0 }), this.subscribe());
315
322
  }
316
323
  //
317
324
  // Store selector
@@ -319,61 +326,61 @@ class V {
319
326
  selectGuides(e, s = {}, t = {}) {
320
327
  var c;
321
328
  this.knock.log(
322
- `[Guide] .selectGuides (filters: ${v(s)}; state: ${b(e)})`
329
+ `[Guide] .selectGuides (filters: ${b(s)}; state: ${v(e)})`
323
330
  );
324
331
  const i = this.selectGuide(e, s, {
325
332
  ...t,
326
333
  // Don't record this result, not the actual query result we need.
327
334
  recordSelectQuery: !1
328
- }), { recordSelectQuery: n = !!((c = e.debug) != null && c.debugging) } = t, r = {
335
+ }), { recordSelectQuery: r = !!((c = e.debug) != null && c.debugging) } = t, n = {
329
336
  limit: "all",
330
- opts: { ...t, recordSelectQuery: n }
331
- }, a = C(e, s, r);
332
- if (this.maybeRecordSelectResult(a), !i && !t.includeThrottled)
337
+ opts: { ...t, recordSelectQuery: r }
338
+ }, u = E(e, s, n);
339
+ if (this.maybeRecordSelectResult(u), !i && !t.includeThrottled)
333
340
  return [];
334
- const o = [...a.values()];
341
+ const o = [...u.values()];
335
342
  if (!t.includeThrottled && _(e)) {
336
343
  const d = o.filter(
337
- (g) => g.bypass_global_group_limit
338
- ), l = o.length - d.length;
344
+ (l) => l.bypass_global_group_limit
345
+ ), g = o.length - d.length;
339
346
  return this.knock.log(
340
- `[Guide] Throttling ${l} guides from selection, and returning ${d.length} guides`
347
+ `[Guide] Throttling ${g} guides from selection, and returning ${d.length} guides`
341
348
  ), d;
342
349
  }
343
350
  return this.knock.log(`[Guide] Returning ${o.length} guides from selection`), o;
344
351
  }
345
352
  selectGuide(e, s = {}, t = {}) {
346
- var l, g, S;
353
+ var g, l, G;
347
354
  if (this.knock.log(
348
- `[Guide] .selectGuide (filters: ${v(s)}; state: ${b(e)})`
355
+ `[Guide] .selectGuide (filters: ${b(s)}; state: ${v(e)})`
349
356
  ), Object.keys(e.guides).length === 0 && Object.keys(e.previewGuides).length === 0) {
350
357
  this.knock.log("[Guide] Exiting selection (no guides)");
351
358
  return;
352
359
  }
353
360
  this.stage || (this.stage = this.openGroupStage());
354
- const { recordSelectQuery: i = !!((l = e.debug) != null && l.debugging) } = t, n = {
361
+ const { recordSelectQuery: i = !!((g = e.debug) != null && g.debugging) } = t, r = {
355
362
  limit: "one",
356
363
  opts: { ...t, recordSelectQuery: i }
357
- }, r = C(e, s, n);
358
- if (this.maybeRecordSelectResult(r), r.size === 0) {
364
+ }, n = E(e, s, r);
365
+ if (this.maybeRecordSelectResult(n), n.size === 0) {
359
366
  this.knock.log("[Guide] Selection found zero result");
360
367
  return;
361
368
  }
362
- const [a, o] = [...r][0];
369
+ const [u, o] = [...n][0];
363
370
  if (this.knock.log(
364
- `[Guide] Selection found: \`${o.key}\` (total: ${r.size})`
371
+ `[Guide] Selection found: \`${o.key}\` (total: ${n.size})`
365
372
  ), o.bypass_global_group_limit)
366
373
  return this.knock.log(`[Guide] Returning the unthrottled guide: ${o.key}`), o;
367
- const c = (S = (g = e.debug) == null ? void 0 : g.focusedGuideKeys) == null ? void 0 : S[o.key], d = !t.includeThrottled && _(e);
374
+ const c = (G = (l = e.debug) == null ? void 0 : l.focusedGuideKeys) == null ? void 0 : G[o.key], d = !t.includeThrottled && _(e);
368
375
  switch (this.stage.status) {
369
376
  case "open": {
370
- this.knock.log(`[Guide] Adding to the group stage: ${o.key}`), this.stage.ordered[a] = o.key;
377
+ this.knock.log(`[Guide] Adding to the group stage: ${o.key}`), this.stage.ordered[u] = o.key;
371
378
  return;
372
379
  }
373
380
  case "patch": {
374
- if (this.knock.log(`[Guide] Patching the group stage: ${o.key}`), this.stage.ordered[a] = o.key, c)
381
+ if (this.knock.log(`[Guide] Patching the group stage: ${o.key}`), this.stage.ordered[u] = o.key, c)
375
382
  return this.knock.log(
376
- `[Guide] Focused to return \`${o.key}\` (stage: ${y(this.stage)})`
383
+ `[Guide] Focused to return \`${o.key}\` (stage: ${m(this.stage)})`
377
384
  ), o;
378
385
  if (d) {
379
386
  this.knock.log(`[Guide] Throttling the selected guide: ${o.key}`);
@@ -381,13 +388,13 @@ class V {
381
388
  }
382
389
  const k = this.stage.resolved === o.key ? o : void 0;
383
390
  return this.knock.log(
384
- `[Guide] Returning \`${k == null ? void 0 : k.key}\` (stage: ${y(this.stage)})`
391
+ `[Guide] Returning \`${k == null ? void 0 : k.key}\` (stage: ${m(this.stage)})`
385
392
  ), k;
386
393
  }
387
394
  case "closed": {
388
395
  if (c)
389
396
  return this.knock.log(
390
- `[Guide] Focused to return \`${o.key}\` (stage: ${y(this.stage)})`
397
+ `[Guide] Focused to return \`${o.key}\` (stage: ${m(this.stage)})`
391
398
  ), o;
392
399
  if (d) {
393
400
  this.knock.log(`[Guide] Throttling the selected guide: ${o.key}`);
@@ -395,7 +402,7 @@ class V {
395
402
  }
396
403
  const k = this.stage.resolved === o.key ? o : void 0;
397
404
  return this.knock.log(
398
- `[Guide] Returning \`${k == null ? void 0 : k.key}\` (stage: ${y(this.stage)})`
405
+ `[Guide] Returning \`${k == null ? void 0 : k.key}\` (stage: ${m(this.stage)})`
399
406
  ), k;
400
407
  }
401
408
  }
@@ -406,18 +413,18 @@ class V {
406
413
  if (!e.metadata) return;
407
414
  const { opts: s, filters: t, limit: i } = e.metadata;
408
415
  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] || {},
416
+ const r = this.stage.results.key || {};
417
+ t.key && (r[t.key] = {
418
+ ...r[t.key] || {},
412
419
  [i]: e
413
420
  });
414
- const r = this.stage.results.type || {};
415
- t.type && (r[t.type] = {
416
- ...r[t.type] || {},
421
+ const n = this.stage.results.type || {};
422
+ t.type && (n[t.type] = {
423
+ ...n[t.type] || {},
417
424
  [i]: e
418
425
  }), this.stage = {
419
426
  ...this.stage,
420
- results: { key: n, type: r }
427
+ results: { key: r, type: n }
421
428
  };
422
429
  }
423
430
  getStage() {
@@ -426,7 +433,7 @@ class V {
426
433
  openGroupStage() {
427
434
  this.knock.log("[Guide] Opening a new group stage");
428
435
  const {
429
- orderResolutionDuration: e = F
436
+ orderResolutionDuration: e = U
430
437
  } = this.options, s = setTimeout(() => {
431
438
  this.closePendingGroupStage(), this.incrementCounter();
432
439
  }, e);
@@ -518,20 +525,20 @@ class V {
518
525
  this.knock.log(
519
526
  `[Guide] Marking as interacted (Guide key: ${e.key}; Step ref:${s.ref})`
520
527
  );
521
- const i = (/* @__PURE__ */ new Date()).toISOString(), n = this.setStepMessageAttrs(e.key, s.ref, {
528
+ const i = (/* @__PURE__ */ new Date()).toISOString(), r = this.setStepMessageAttrs(e.key, s.ref, {
522
529
  read_at: i,
523
530
  interacted_at: i
524
531
  });
525
- if (!n) return;
532
+ if (!r) return;
526
533
  if (this.shouldSkipEngagementApi())
527
534
  return this.knock.log(
528
535
  "[Guide] Skipping engagement API call for markAsInteracted (debug mode)"
529
- ), n;
530
- const r = {
531
- ...this.buildEngagementEventBaseParams(e, n),
536
+ ), r;
537
+ const n = {
538
+ ...this.buildEngagementEventBaseParams(e, r),
532
539
  metadata: t
533
540
  };
534
- return this.knock.user.markGuideStepAs("interacted", r), n;
541
+ return this.knock.user.markGuideStepAs("interacted", n), r;
535
542
  }
536
543
  async markAsArchived(e, s) {
537
544
  if (s.message.archived_at) return;
@@ -555,6 +562,13 @@ class V {
555
562
  }
556
563
  ), t;
557
564
  }
565
+ async resetEngagement(e) {
566
+ const s = this.store.state.guides[e.key];
567
+ !s || !s.hasEngagement() || (this.knock.log(`[Guide] Resetting engagement (Guide key: ${e.key})`), (await this.knock.user.resetGuideEngagement({
568
+ guide_key: e.key,
569
+ tenant: this.targetParams.tenant
570
+ })).status !== "ok") || await this.fetch({ force: !0 });
571
+ }
558
572
  shouldSkipEngagementApi() {
559
573
  var e;
560
574
  return !!((e = this.store.state.debug) != null && e.skipEngagementTracking);
@@ -567,25 +581,31 @@ class V {
567
581
  ...e,
568
582
  // Get the next unarchived step.
569
583
  getStep() {
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);
584
+ var i, r, n;
585
+ return ((i = s.store.state.debug) == null ? void 0 : i.forcedGuideKey) === this.key || (n = (r = s.store.state.debug) == null ? void 0 : r.focusedGuideKeys) != null && n[this.key] ? this.steps[0] : this.steps.find((u) => !u.message.archived_at);
586
+ },
587
+ // Check whether any of its steps have an engagement timestamp.
588
+ hasEngagement() {
589
+ return this.steps.some(
590
+ (i) => i.message.seen_at || i.message.read_at || i.message.interacted_at || i.message.archived_at || i.message.link_clicked_at
591
+ );
572
592
  }
573
593
  };
574
- return t.getStep = t.getStep.bind(t), t.steps = e.steps.map(({ message: i, ...n }) => {
575
- const r = {
576
- ...n,
594
+ return t.getStep = t.getStep.bind(t), t.hasEngagement = t.hasEngagement.bind(t), t.steps = e.steps.map(({ message: i, ...r }) => {
595
+ const n = {
596
+ ...r,
577
597
  message: { ...i },
578
598
  markAsSeen() {
579
599
  return s.markAsSeen(t, this);
580
600
  },
581
- markAsInteracted({ metadata: a } = {}) {
582
- return s.markAsInteracted(t, this, a);
601
+ markAsInteracted({ metadata: u } = {}) {
602
+ return s.markAsInteracted(t, this, u);
583
603
  },
584
604
  markAsArchived() {
585
605
  return s.markAsArchived(t, this);
586
606
  }
587
607
  };
588
- return r.markAsSeen = r.markAsSeen.bind(r), r.markAsInteracted = r.markAsInteracted.bind(r), r.markAsArchived = r.markAsArchived.bind(r), r;
608
+ return n.markAsSeen = n.markAsSeen.bind(n), n.markAsInteracted = n.markAsInteracted.bind(n), n.markAsArchived = n.markAsArchived.bind(n), n;
589
609
  }), t.activation_url_patterns = e.activation_url_patterns.map((i) => ({
590
610
  ...i,
591
611
  pattern: new A({
@@ -602,29 +622,29 @@ class V {
602
622
  (t != null && t.forcedGuideKey || t != null && t.debugging) && (s.force_all_guides = !0);
603
623
  let i = Object.fromEntries(
604
624
  Object.entries(s).filter(
605
- ([n, r]) => r != null
625
+ ([r, n]) => n != null
606
626
  )
607
627
  );
608
628
  return i = i.data ? { ...i, data: JSON.stringify(i.data) } : i, i;
609
629
  }
610
630
  formatQueryKey(e) {
611
631
  const t = Object.keys(e).sort().map(
612
- (n) => `${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`
613
- ).join("&"), i = N(this.knock.userId);
632
+ (r) => `${encodeURIComponent(r)}=${encodeURIComponent(e[r])}`
633
+ ).join("&"), i = j(this.knock.userId);
614
634
  return t ? `${i}?${t}` : i;
615
635
  }
616
636
  setStepMessageAttrs(e, s, t) {
617
637
  let i;
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,
638
+ return t.archived_at && this.clearGroupStage(), this.store.setState((r) => {
639
+ let n = r.guides[e];
640
+ if (!n) return r;
641
+ const u = n.steps.map((d) => (d.ref !== s || (d.message = { ...d.message, ...t }, i = d), d));
642
+ n = i ? { ...n, steps: u } : n;
643
+ const o = { ...r.guides, [n.key]: n }, c = t.archived_at && !n.bypass_global_group_limit ? {
644
+ ...r.guideGroupDisplayLogs,
625
645
  [D]: t.archived_at
626
- } : n.guideGroupDisplayLogs;
627
- return { ...n, guides: o, guideGroupDisplayLogs: c };
646
+ } : r.guideGroupDisplayLogs;
647
+ return { ...r, guides: o, guideGroupDisplayLogs: c };
628
648
  }), i;
629
649
  }
630
650
  buildEngagementEventBaseParams(e, s) {
@@ -655,17 +675,17 @@ class V {
655
675
  data: e
656
676
  }) {
657
677
  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 };
678
+ const t = [e.guide_group], i = e.guide_group.display_sequence_unthrottled || [], r = e.guide_group.display_sequence_throttled || [];
679
+ let n = s.guides;
680
+ return n = i.reduce((u, o) => {
681
+ if (!u[o]) return u;
682
+ const c = { ...u[o], bypass_global_group_limit: !0 };
683
+ return { ...u, [o]: c };
684
+ }, n), n = r.reduce((u, o) => {
685
+ if (!u[o]) return u;
686
+ const c = { ...u[o], bypass_global_group_limit: !1 };
687
+ return { ...u, [o]: c };
688
+ }, n), { ...s, guides: n, guideGroups: t };
669
689
  });
670
690
  }
671
691
  updatePreviewGuide({ data: e }) {
@@ -686,14 +706,14 @@ class V {
686
706
  e.addEventListener("popstate", this.handleLocationChange), e.addEventListener("hashchange", this.handleLocationChange);
687
707
  const s = e.history.pushState, t = e.history.replaceState;
688
708
  e.history.pushState = new Proxy(s, {
689
- apply: (i, n, r) => {
690
- Reflect.apply(i, n, r), setTimeout(() => {
709
+ apply: (i, r, n) => {
710
+ Reflect.apply(i, r, n), setTimeout(() => {
691
711
  this.handleLocationChange();
692
712
  }, 0);
693
713
  }
694
714
  }), e.history.replaceState = new Proxy(t, {
695
- apply: (i, n, r) => {
696
- Reflect.apply(i, n, r), setTimeout(() => {
715
+ apply: (i, r, n) => {
716
+ Reflect.apply(i, r, n), setTimeout(() => {
697
717
  this.handleLocationChange();
698
718
  }, 0);
699
719
  }
@@ -707,11 +727,14 @@ class V {
707
727
  const e = p();
708
728
  !(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));
709
729
  }
730
+ static getToolbarRunConfigFromUrl() {
731
+ return K();
732
+ }
710
733
  }
711
734
  export {
712
735
  f as DEBUG_QUERY_PARAMS,
713
- V as KnockGuideClient,
714
- M as checkActivatable,
715
- N as guidesApiRootPath
736
+ z as KnockGuideClient,
737
+ Q as checkActivatable,
738
+ j as guidesApiRootPath
716
739
  };
717
740
  //# sourceMappingURL=client.mjs.map