@journeeze/sdk 0.0.0-stage → 0.1.0-rc.2

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 (60) hide show
  1. package/AGENTS.md +67 -0
  2. package/CHANGELOG.md +30 -0
  3. package/LICENSE.md +27 -0
  4. package/README.md +164 -2
  5. package/dist/THIRD_PARTY_LICENSES.txt +246 -0
  6. package/dist/consent-CoKD33Rm.js +170 -0
  7. package/dist/context-UnG6_X61.js +17 -0
  8. package/dist/contract.js +10 -0
  9. package/dist/feedback-C4CYtS2A.js +196 -0
  10. package/dist/help-C1x-y2f9.js +878 -0
  11. package/dist/hook-BdG4UL4k.js +91 -0
  12. package/dist/index-B_nob8S0.js +2091 -0
  13. package/dist/index-CfCbJJXa.js +20 -0
  14. package/dist/index.js +10 -0
  15. package/dist/loader-Ba4X-WNl.js +95 -0
  16. package/dist/react.js +70 -0
  17. package/dist/resolve-BfWByuTp.js +97 -0
  18. package/dist/script.js +13 -0
  19. package/dist/signals-E3VEdmWH.js +477 -0
  20. package/dist/telemetry-Cik-cYzw.js +140 -0
  21. package/dist/transport-B5YJFQEF.js +60 -0
  22. package/dist/types/config.d.ts +17 -0
  23. package/dist/types/context.d.ts +6 -0
  24. package/dist/types/contract.d.ts +13 -0
  25. package/dist/types/help/core/client.d.ts +26 -0
  26. package/dist/types/help/core/controller.d.ts +175 -0
  27. package/dist/types/help/core/events.d.ts +8 -0
  28. package/dist/types/help/core/help.d.ts +24 -0
  29. package/dist/types/help/core/highlight.d.ts +38 -0
  30. package/dist/types/help/core/panel.d.ts +11 -0
  31. package/dist/types/help/core/search.d.ts +7 -0
  32. package/dist/types/help/ui/callout.d.ts +2 -0
  33. package/dist/types/help/ui/panel.d.ts +3 -0
  34. package/dist/types/help/ui/request.d.ts +2 -0
  35. package/dist/types/help/ui/styles.d.ts +1 -0
  36. package/dist/types/index.d.ts +7 -0
  37. package/dist/types/invite.d.ts +4 -0
  38. package/dist/types/loader.d.ts +57 -0
  39. package/dist/types/mask.d.ts +10 -0
  40. package/dist/types/react.d.ts +9 -0
  41. package/dist/types/resolve/resolve.d.ts +12 -0
  42. package/dist/types/script.d.ts +6 -0
  43. package/dist/types/signals/cel.d.ts +8 -0
  44. package/dist/types/signals/hook.d.ts +10 -0
  45. package/dist/types/signals/signals.conformance.d.ts +2 -0
  46. package/dist/types/signals/signals.d.ts +145 -0
  47. package/dist/types/telemetry/telemetry.d.ts +63 -0
  48. package/dist/types/transport.d.ts +30 -0
  49. package/dist/types/types.d.ts +391 -0
  50. package/dist/types/widget/anchor.d.ts +11 -0
  51. package/dist/types/widget/capture.d.ts +28 -0
  52. package/dist/types/widget/consent.d.ts +25 -0
  53. package/dist/types/widget/feedback.d.ts +36 -0
  54. package/dist/types/widget/icons.d.ts +14 -0
  55. package/dist/types/widget/outbox.d.ts +69 -0
  56. package/dist/types/widget/styles.d.ts +1 -0
  57. package/dist/types/widget.d.ts +27 -0
  58. package/dist/types/wire.d.ts +66 -0
  59. package/dist/widget-DQZm8sAC.js +1599 -0
  60. package/package.json +68 -4
@@ -0,0 +1,170 @@
1
+ var g = Object.defineProperty;
2
+ var T = (e, t, n) => t in e ? g(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var u = (e, t, n) => T(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { CONTEXT_FIELDS as w, CONTEXT_VALUE_MAX_LEN as S, CONTEXT_ID_PATTERN as N, API_PATH_PATTERN as _ } from "./contract.js";
5
+ import { p as E } from "./context-UnG6_X61.js";
6
+ import { w as c } from "./loader-Ba4X-WNl.js";
7
+ class m extends Error {
8
+ constructor(n, o, r = 0, i) {
9
+ super(o);
10
+ u(this, "code");
11
+ u(this, "status");
12
+ u(this, "retryAfterMs");
13
+ this.code = n, this.status = r, this.retryAfterMs = i;
14
+ }
15
+ }
16
+ const C = "https://app.journeeze.dev", b = 15e3;
17
+ function k(e, t = b) {
18
+ return typeof AbortSignal < "u" && typeof AbortSignal.timeout == "function" ? { ...e, signal: AbortSignal.timeout(t) } : e;
19
+ }
20
+ function O(e, t = location.href) {
21
+ try {
22
+ return new URL(e, t).origin !== new URL(t).origin;
23
+ } catch {
24
+ return !0;
25
+ }
26
+ }
27
+ const $ = "text/plain;charset=UTF-8";
28
+ function A(e, t) {
29
+ return `${e.replace(/\/+$/, "")}/journeeze.collector.v1.CollectorService/${t}`;
30
+ }
31
+ function I(e, t) {
32
+ const n = O(e) ? { "content-type": $ } : { "content-type": "application/json", "connect-protocol-version": "1" };
33
+ return t ? { ...n, "if-none-match": t } : n;
34
+ }
35
+ function y(e, t, n, o, r) {
36
+ const i = k({
37
+ method: "POST",
38
+ headers: I(e, r.etag),
39
+ body: JSON.stringify(n),
40
+ credentials: "omit",
41
+ cache: "no-store",
42
+ referrerPolicy: "no-referrer",
43
+ ...r.keepalive ? { keepalive: !0 } : {}
44
+ });
45
+ return o(A(e, t), i);
46
+ }
47
+ const j = 6e4;
48
+ function M(e, t = Date.now()) {
49
+ if (!e) return;
50
+ const n = Number(e.trim()), o = Number.isFinite(n) && /^\d+$/.test(e.trim()) ? n * 1e3 : Date.parse(e) - t;
51
+ return Number.isFinite(o) ? Math.min(Math.max(o, 0), j) : void 0;
52
+ }
53
+ async function v(e) {
54
+ const t = await e.json().catch(() => {
55
+ });
56
+ if (!e.ok) {
57
+ const n = typeof t?.code == "string" ? t.code : P(e.status);
58
+ throw new m(n, String(t?.message ?? e.statusText), e.status, M(e.headers.get("retry-after")));
59
+ }
60
+ if (t === void 0 || typeof t != "object" || t === null)
61
+ throw new m("unavailable", "the collector did not answer with Connect JSON", e.status);
62
+ return t;
63
+ }
64
+ async function F(e, t, n, o = fetch, r = {}) {
65
+ return v(await y(e, t, n, o, r.keepalive ? { keepalive: !0 } : {}));
66
+ }
67
+ async function H(e, t, n, o, r = fetch) {
68
+ const i = await y(e, t, n, r, o ? { etag: o } : {});
69
+ if (i.status === 304) return { notModified: !0 };
70
+ const s = await v(i), a = i.headers.get("etag");
71
+ return a ? { notModified: !1, value: s, etag: a } : { notModified: !1, value: s };
72
+ }
73
+ function X(e, t) {
74
+ return t ? `${e.replace(/\/+$/, "")}${t.startsWith("/") ? "" : "/"}${t}` : void 0;
75
+ }
76
+ function P(e) {
77
+ return e === 401 ? "unauthenticated" : e === 403 ? "permission_denied" : e === 409 ? "already_exists" : e === 412 ? "failed_precondition" : e === 429 ? "resource_exhausted" : e === 404 || e === 408 || e >= 500 ? "unavailable" : e >= 400 ? "invalid_argument" : "unknown";
78
+ }
79
+ function J(e, t = location.href) {
80
+ const { endpoint: n, apiHost: o, apiPath: r } = e;
81
+ if (n !== void 0)
82
+ return c("endpoint is deprecated; use apiHost"), new URL(n, t).href.replace(/\/+$/, "");
83
+ let i = C;
84
+ if (o !== void 0) {
85
+ const s = o.replace(/\/$/, "");
86
+ let a = !1;
87
+ try {
88
+ const f = new URL(s);
89
+ a = f.origin === s && (f.protocol === "https:" || /^(localhost|127\.0\.0\.1)$/.test(f.hostname));
90
+ } catch {
91
+ }
92
+ a ? i = s : c("invalid apiHost ignored");
93
+ }
94
+ return r === void 0 ? i : _.test(r) ? i + r : (c("invalid apiPath ignored"), i);
95
+ }
96
+ function z(e) {
97
+ const t = {};
98
+ for (const n of w) {
99
+ if (!(n in e)) continue;
100
+ const o = e[n] || void 0;
101
+ if (o !== void 0 && (typeof o != "string" || o.length > S || /[\0-\x1f\x7f]/.test(o))) {
102
+ c(`context.${n} dropped (1..=128 printable characters)`), t[n] = void 0;
103
+ continue;
104
+ }
105
+ o !== void 0 && !N.test(o) && c(`context.${n} should be an id`), t[n] = o;
106
+ }
107
+ return t;
108
+ }
109
+ const R = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|[0-9a-f]{16}|@|^[\w-]{24,}$/i;
110
+ function Y(e) {
111
+ return E(e).split("/").map((t) => {
112
+ let n = t;
113
+ try {
114
+ n = decodeURIComponent(t);
115
+ } catch {
116
+ }
117
+ return R.test(n) ? ":id" : t;
118
+ }).join("/");
119
+ }
120
+ const d = 1, q = "Feedback mode captures the element you point at, a screenshot of this page with form fields hidden, your comment, and your persona and journey step. It never records keystrokes, form contents or query strings. Your feedback is visible to the project's review team.", V = "Feedback mode captures the element you point at, your comment, and your persona and journey step. No screenshot is sent. It never records keystrokes, form contents or query strings. Your feedback is visible to the project's review team.", l = (e) => `jz:consent:v${d}:${e}`, p = /* @__PURE__ */ new Set(), B = (e) => e.userId ? `${e.siteKey}:u:${e.userId}` : e.siteKey;
121
+ function G(e, t = h()) {
122
+ p.delete(e);
123
+ try {
124
+ t?.removeItem(l(e));
125
+ } catch {
126
+ }
127
+ }
128
+ function h() {
129
+ try {
130
+ return window.localStorage;
131
+ } catch {
132
+ return;
133
+ }
134
+ }
135
+ function K(e, t = h()) {
136
+ if (p.has(e)) return !0;
137
+ try {
138
+ const n = t?.getItem(l(e));
139
+ return n ? JSON.parse(n).v === d : !1;
140
+ } catch {
141
+ return !1;
142
+ }
143
+ }
144
+ function W(e, t = h()) {
145
+ p.add(e);
146
+ try {
147
+ t?.setItem(l(e), JSON.stringify({ v: d, at: (/* @__PURE__ */ new Date()).toISOString() }));
148
+ } catch {
149
+ }
150
+ }
151
+ export {
152
+ m as C,
153
+ q as D,
154
+ j as R,
155
+ $ as T,
156
+ G as a,
157
+ J as b,
158
+ F as c,
159
+ z as d,
160
+ Y as e,
161
+ B as f,
162
+ V as g,
163
+ K as h,
164
+ W as i,
165
+ H as j,
166
+ X as k,
167
+ A as r,
168
+ h as s,
169
+ k as w
170
+ };
@@ -0,0 +1,17 @@
1
+ const o = /^[a-z0-9._:-]{1,96}$/;
2
+ function e(t) {
3
+ const a = t?.closest("[data-tflow-id]")?.getAttribute("data-tflow-id") ?? void 0;
4
+ return a !== void 0 && o.test(a) ? a : void 0;
5
+ }
6
+ function n(t) {
7
+ try {
8
+ return new URL(t).pathname;
9
+ } catch {
10
+ return "/";
11
+ }
12
+ }
13
+ export {
14
+ o as T,
15
+ n as p,
16
+ e as t
17
+ };
@@ -0,0 +1,10 @@
1
+ import { S as t, U as A } from "./loader-Ba4X-WNl.js";
2
+ const T = /^(?:\/[A-Za-z0-9._~-]+)+$/, _ = 128, E = /^[a-z0-9._:-]{1,96}$/, e = ["persona", "journeyId", "journeyStep", "device", "businessType", "state"];
3
+ export {
4
+ T as API_PATH_PATTERN,
5
+ e as CONTEXT_FIELDS,
6
+ E as CONTEXT_ID_PATTERN,
7
+ _ as CONTEXT_VALUE_MAX_LEN,
8
+ t as SITE_KEY_PATTERN,
9
+ A as USER_ID_PATTERN
10
+ };
@@ -0,0 +1,196 @@
1
+ var E = Object.defineProperty;
2
+ var I = (s, e, t) => e in s ? E(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var d = (s, e, t) => I(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { C as w, s as v, c as f, a as _, b as q } from "./consent-CoKD33Rm.js";
5
+ const x = /* @__PURE__ */ new Set(["invalid_argument", "failed_precondition", "permission_denied", "unauthenticated", "not_found", "already_exists", "unimplemented"]), g = 50, A = 1e3, O = 6e4, y = 1440 * 60 * 1e3;
6
+ function T(s) {
7
+ return Math.min(O, A * 2 ** Math.max(0, s));
8
+ }
9
+ function L(s) {
10
+ return s instanceof w && x.has(s.code);
11
+ }
12
+ class M {
13
+ constructor(e) {
14
+ d(this, "deps");
15
+ d(this, "items", []);
16
+ d(this, "inFlight");
17
+ d(this, "attempt", 0);
18
+ d(this, "flushing");
19
+ d(this, "timer");
20
+ d(this, "disposed", !1);
21
+ d(this, "schedule");
22
+ d(this, "cancel");
23
+ d(this, "now");
24
+ this.deps = e, this.schedule = e.schedule ?? ((t, i) => setTimeout(t, i)), this.cancel = e.cancel ?? ((t) => clearTimeout(t)), this.now = e.now ?? Date.now, this.claim();
25
+ }
26
+ get size() {
27
+ return this.items.length;
28
+ }
29
+ enqueue(e) {
30
+ return new Promise((t) => {
31
+ const i = { request: e, settle: t };
32
+ this.add(i), this.flush().then(() => {
33
+ this.items.includes(i) && u(i, "queued");
34
+ });
35
+ });
36
+ }
37
+ stash(e) {
38
+ this.add({ request: e });
39
+ }
40
+ flush() {
41
+ return this.disposed ? Promise.resolve() : (this.timer !== void 0 && (this.cancel(this.timer), this.timer = void 0), this.flushing ? this.flushing.then(() => this.timer === void 0 ? this.flush() : void 0) : (this.flushing = this.drain().finally(() => {
42
+ this.flushing = void 0;
43
+ }), this.flushing));
44
+ }
45
+ persist() {
46
+ const e = this.items.filter((t) => t !== this.inFlight);
47
+ if (!(e.length === 0 || !this.deps.storage))
48
+ try {
49
+ const t = this.read(), i = this.now(), n = this.deps.user?.(), c = [...t, ...e.map((r) => ({ owner: this.deps.owner, request: r.request, at: r.at ?? i, ...n ? { user: n } : {} }))].slice(-g);
50
+ this.deps.storage?.setItem(this.deps.storageKey, JSON.stringify(c));
51
+ for (const r of e) u(r, "queued");
52
+ this.items = this.items.filter((r) => r === this.inFlight);
53
+ } catch {
54
+ }
55
+ }
56
+ claim() {
57
+ try {
58
+ const e = this.read(), t = e.filter((n) => n.owner === this.deps.owner);
59
+ if (t.length === 0) return;
60
+ const i = e.filter((n) => n.owner !== this.deps.owner);
61
+ i.length === 0 ? this.deps.storage?.removeItem(this.deps.storageKey) : this.deps.storage?.setItem(this.deps.storageKey, JSON.stringify(i));
62
+ for (const n of t) this.fresh(n) && this.add({ request: n.request, at: n.at });
63
+ } catch {
64
+ }
65
+ }
66
+ dispose() {
67
+ this.persist(), this.disposed = !0, this.timer !== void 0 && this.cancel(this.timer), this.timer = void 0;
68
+ }
69
+ add(e) {
70
+ var t;
71
+ for ((t = e.request).submissionId ?? (t.submissionId = F()), this.items.push(e); this.items.length > g; ) {
72
+ const i = this.items[0] === this.inFlight ? 1 : 0, [n] = this.items.splice(i, 1);
73
+ n && u(n, "dropped");
74
+ }
75
+ }
76
+ async drain() {
77
+ for (; !this.disposed; ) {
78
+ const e = this.items[0];
79
+ if (!e) {
80
+ this.attempt = 0;
81
+ return;
82
+ }
83
+ this.inFlight = e;
84
+ try {
85
+ await this.deps.send(e.request), this.remove(e), this.attempt = 0, u(e, "sent");
86
+ } catch (t) {
87
+ if (L(t)) {
88
+ this.remove(e), u(e, "dropped"), this.deps.onDropped?.(t);
89
+ continue;
90
+ }
91
+ if (this.disposed) {
92
+ this.inFlight = void 0, this.persist();
93
+ return;
94
+ }
95
+ const i = T(this.attempt++);
96
+ this.timer = this.schedule(() => {
97
+ this.timer = void 0, this.flush();
98
+ }, i);
99
+ return;
100
+ } finally {
101
+ this.inFlight = void 0;
102
+ }
103
+ }
104
+ }
105
+ fresh(e) {
106
+ return e.at === void 0 ? !0 : typeof e.at == "number" && Number.isFinite(e.at) && this.now() - e.at <= y;
107
+ }
108
+ remove(e) {
109
+ const t = this.items.indexOf(e);
110
+ t >= 0 && this.items.splice(t, 1);
111
+ }
112
+ read() {
113
+ const e = this.deps.storage?.getItem(this.deps.storageKey), t = e ? JSON.parse(e) : [];
114
+ return Array.isArray(t) ? t.filter(
115
+ (i) => typeof i == "object" && i !== null && typeof i.owner == "string" && typeof i.request == "object" && i.request !== null
116
+ ) : [];
117
+ }
118
+ }
119
+ function D(s) {
120
+ if (!s) return "";
121
+ let e = 2166136261;
122
+ for (let t = 0; t < s.length; t++)
123
+ e ^= s.charCodeAt(t), e = Math.imul(e, 16777619) >>> 0;
124
+ return e.toString(16).padStart(8, "0");
125
+ }
126
+ function F() {
127
+ return crypto.randomUUID();
128
+ }
129
+ function u(s, e) {
130
+ const t = s.settle;
131
+ s.settle = void 0, t?.(e);
132
+ }
133
+ function P(s, e, t, i = Date.now()) {
134
+ try {
135
+ const n = s?.getItem(e), c = n ? JSON.parse(n) : [], r = Array.isArray(c) ? c : [], a = r.filter((o) => o?.owner === t), h = r.filter((o) => o?.owner !== t);
136
+ return h.length === 0 ? s?.removeItem(e) : s?.setItem(e, JSON.stringify(h)), a.filter((o) => o.request && (o.at === void 0 || i - o.at <= y)).sort((o, l) => (o.at ?? 0) - (l.at ?? 0)).map((o) => o.request);
137
+ } catch {
138
+ return [];
139
+ }
140
+ }
141
+ const b = (s) => D(s.reviewerToken || (s.userId ? `u:${s.userId}` : void 0)), N = 32 * 1024;
142
+ async function k(s) {
143
+ const e = P(v(), `jz:outbox:v2:${s.siteKey}`, b(s));
144
+ if (_(s.siteKey), e.length === 0) return;
145
+ const t = q(s);
146
+ let i = N;
147
+ const n = (a, h) => f(t, "SubmitFeedback", a, fetch, { keepalive: h }), r = (await Promise.allSettled(
148
+ e.map((a) => {
149
+ const h = S(s, a), o = new Blob([JSON.stringify(h)]).size, l = o <= i;
150
+ l && (i -= o);
151
+ const m = n(h, l);
152
+ return l ? m.catch((p) => p instanceof w ? Promise.reject(p) : n(h, !1)) : m;
153
+ })
154
+ )).filter((a) => a.status === "rejected").length;
155
+ r && console.warn(`[journeeze] ${r} feedback item(s) could not be sent at logout and were discarded`);
156
+ }
157
+ function S(s, e) {
158
+ const t = s.reviewerToken ? { ...e, reviewerToken: s.reviewerToken } : { ...e };
159
+ if (s.pagePath === "none") {
160
+ const { pagePath: i, ...n } = t.context;
161
+ t.context = n;
162
+ }
163
+ return t;
164
+ }
165
+ function K(s, e, t = {}) {
166
+ const i = (h) => f(e, "SubmitFeedback", S(s, h), fetch, { keepalive: !0 }).then(() => {
167
+ }), n = new M({
168
+ send: i,
169
+ storage: t.memoryOnly ? void 0 : v(),
170
+ storageKey: `jz:outbox:v2:${s.siteKey}`,
171
+ owner: b(s),
172
+ user: () => s.userId,
173
+ ...t.onDropped ? { onDropped: t.onDropped } : {}
174
+ }), c = () => {
175
+ n.flush();
176
+ }, r = () => {
177
+ t.beforePersist?.(), n.persist();
178
+ }, a = (h) => {
179
+ h.persisted && (n.claim(), n.flush());
180
+ };
181
+ return window.addEventListener("online", c), window.addEventListener("pagehide", r), window.addEventListener("pageshow", a), {
182
+ outbox: n,
183
+ dispose() {
184
+ window.removeEventListener("online", c), window.removeEventListener("pagehide", r), window.removeEventListener("pageshow", a), n.dispose();
185
+ }
186
+ };
187
+ }
188
+ function z(s, e) {
189
+ return f(s, "GetWidgetConfig", { siteKey: e });
190
+ }
191
+ export {
192
+ K as feedbackChannel,
193
+ k as logout,
194
+ b as ownerOf,
195
+ z as widgetConfig
196
+ };