@fiction/sdk 1.0.43 → 1.0.45

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 (21) hide show
  1. package/dist/{FModal.vue_vue_type_script_setup_true_lang-DPZCriHI.js → FModal.vue_vue_type_script_setup_true_lang-CjBOzrZ5.js} +2 -2
  2. package/dist/{FModal.vue_vue_type_script_setup_true_lang-DPZCriHI.js.map → FModal.vue_vue_type_script_setup_true_lang-CjBOzrZ5.js.map} +1 -1
  3. package/dist/{SelfProvider.vue_vue_type_script_setup_true_lang-CS_BJmdz.js → SelfProvider.vue_vue_type_script_setup_true_lang-wp53YXNd.js} +2 -2
  4. package/dist/{SelfProvider.vue_vue_type_script_setup_true_lang-CS_BJmdz.js.map → SelfProvider.vue_vue_type_script_setup_true_lang-wp53YXNd.js.map} +1 -1
  5. package/dist/{SelfWidgetInline-Cdu0dXY5.js → SelfWidgetInline-CgXet5hG.js} +2 -2
  6. package/dist/{SelfWidgetInline-Cdu0dXY5.js.map → SelfWidgetInline-CgXet5hG.js.map} +1 -1
  7. package/dist/{SelfWidgetModal-CyUeJQi-.js → SelfWidgetModal-Cr_DCA7h.js} +3 -3
  8. package/dist/{SelfWidgetModal-CyUeJQi-.js.map → SelfWidgetModal-Cr_DCA7h.js.map} +1 -1
  9. package/dist/{SelfWidgetPopup-DeOemzWc.js → SelfWidgetPopup-vD1JFq-Q.js} +2 -2
  10. package/dist/{SelfWidgetPopup-DeOemzWc.js.map → SelfWidgetPopup-vD1JFq-Q.js.map} +1 -1
  11. package/dist/{SelfWrap.vue_vue_type_script_setup_true_lang-hERTpS6V.js → SelfWrap.vue_vue_type_script_setup_true_lang-5yJk1rsa.js} +8 -2
  12. package/dist/{SelfWrap.vue_vue_type_script_setup_true_lang-hERTpS6V.js.map → SelfWrap.vue_vue_type_script_setup_true_lang-5yJk1rsa.js.map} +1 -1
  13. package/dist/sdk.css +1 -1
  14. package/dist/sdk.js +1 -1
  15. package/dist/{sdkClient-7CpWV9KZ.js → sdkClient-Dg6A3ZgO.js} +92 -76
  16. package/dist/{sdkClient-7CpWV9KZ.js.map → sdkClient-Dg6A3ZgO.js.map} +1 -1
  17. package/dist/sdkClient.d.ts +9 -0
  18. package/dist/self.js +4 -4
  19. package/dist/widget.js +5 -5
  20. package/dist/widget.js.map +1 -1
  21. package/package.json +2 -2
package/dist/sdk.js CHANGED
@@ -1,4 +1,4 @@
1
- import { F as r } from "./sdkClient-7CpWV9KZ.js";
1
+ import { F as r } from "./sdkClient-Dg6A3ZgO.js";
2
2
  import { MediaSchema as i } from "@fiction/types";
3
3
  export {
4
4
  r as FictionSDK,
@@ -5,7 +5,7 @@ var n = (u, r, e) => Q(u, typeof r != "symbol" ? r + "" : r, e);
5
5
  import { objectId as M } from "@fiction/utils";
6
6
  import { watch as P, ref as k, computed as G } from "vue";
7
7
  import { hc as H } from "hono/client";
8
- const w = globalThis.process, v = typeof window < "u", x = typeof w < "u" && !v, p = v ? typeof window < "u" && window.location && !window.location.hostname.includes("localhost") : x && typeof w < "u" && w.env?.NODE_ENV === "production", Y = !p, S = {
8
+ const w = globalThis.process, v = typeof window < "u", x = typeof w < "u" && !v, m = v ? typeof window < "u" && window.location && !window.location.hostname.includes("localhost") : x && typeof w < "u" && w.env?.NODE_ENV === "production", Y = !m, S = {
9
9
  error: { priority: 50, color: "#FF0000", nodeColor: "\x1B[31m" },
10
10
  warn: { priority: 40, color: "#FFA500", nodeColor: "\x1B[33m" },
11
11
  info: { priority: 30, color: "#00ABFF", nodeColor: "\x1B[36m" },
@@ -30,13 +30,13 @@ const w = globalThis.process, v = typeof window < "u", x = typeof w < "u" && !v,
30
30
  if (r)
31
31
  return r;
32
32
  }
33
- return p ? "info" : "debug";
33
+ return m ? "info" : "debug";
34
34
  }
35
35
  initBrowserLogging() {
36
36
  if (!v)
37
37
  return;
38
38
  const e = localStorage.getItem("FICTION_LOG") === "true", t = window.location?.hostname || "";
39
- this.enabledInBrowser = Y || e || t === "localhost" || t.includes("127.0.0.1"), p && !e && !y.hasShownHelp && (console.log(
39
+ this.enabledInBrowser = Y || e || t === "localhost" || t.includes("127.0.0.1"), m && !e && !y.hasShownHelp && (console.log(
40
40
  "%cFiction WWW Logger (disabled in production)",
41
41
  "color: #888; font-size: 12px"
42
42
  ), console.log(
@@ -68,8 +68,8 @@ const w = globalThis.process, v = typeof window < "u", x = typeof w < "u" && !v,
68
68
  return r.map((t) => this.redactSensitive(t));
69
69
  const e = {};
70
70
  for (const [t, o] of Object.entries(r)) {
71
- const s = t.toLowerCase();
72
- X.some((i) => s.includes(i)) ? e[t] = "[REDACTED]" : typeof o == "object" && o !== null ? e[t] = this.redactSensitive(o) : e[t] = o;
71
+ const i = t.toLowerCase();
72
+ X.some((s) => i.includes(s)) ? e[t] = "[REDACTED]" : typeof o == "object" && o !== null ? e[t] = this.redactSensitive(o) : e[t] = o;
73
73
  }
74
74
  return e;
75
75
  }
@@ -82,7 +82,7 @@ const w = globalThis.process, v = typeof window < "u", x = typeof w < "u" && !v,
82
82
  return {
83
83
  name: r.name,
84
84
  message: r.message,
85
- stack: p ? r.stack?.split(`
85
+ stack: m ? r.stack?.split(`
86
86
  `).slice(0, 3).join(`
87
87
  `) : r.stack,
88
88
  ...r
@@ -93,12 +93,12 @@ const w = globalThis.process, v = typeof window < "u", x = typeof w < "u" && !v,
93
93
  if (typeof r != "object")
94
94
  return r;
95
95
  if (Array.isArray(r))
96
- return r.length > 20 && p ? `Array(${r.length}) [${r.slice(0, 3).map((o) => this.formatData(o, e, t + 1)).join(", ")}, ...]` : r.map((o) => this.formatData(o, e, t + 1));
96
+ return r.length > 20 && m ? `Array(${r.length}) [${r.slice(0, 3).map((o) => this.formatData(o, e, t + 1)).join(", ")}, ...]` : r.map((o) => this.formatData(o, e, t + 1));
97
97
  try {
98
- const o = {}, s = Object.entries(r), i = p ? 50 : 200;
99
- for (const [c, d] of s.slice(0, i))
98
+ const o = {}, i = Object.entries(r), s = m ? 50 : 200;
99
+ for (const [c, d] of i.slice(0, s))
100
100
  o[c] = this.formatData(d, e, t + 1);
101
- return s.length > i && (o["..."] = `${s.length - i} more properties`), this.redactSensitive(o);
101
+ return i.length > s && (o["..."] = `${i.length - s} more properties`), this.redactSensitive(o);
102
102
  } catch {
103
103
  return "[Unserializable]";
104
104
  }
@@ -106,29 +106,29 @@ const w = globalThis.process, v = typeof window < "u", x = typeof w < "u" && !v,
106
106
  logToBrowser(r) {
107
107
  if (!v || !this.shouldLog(r.level))
108
108
  return;
109
- const { level: e, description: t, context: o, data: s, error: i } = r, c = S[e], a = `[${o || this.context || "www"}] ${e.toUpperCase()}:`, h = `color: ${c.color}; font-weight: bold;`;
110
- s !== void 0 ? console[e](`%c${a}`, h, t, this.formatData(s)) : console[e](`%c${a}`, h, t), i && (i instanceof Error ? console.error(i) : console.error("Error details:", i));
109
+ const { level: e, description: t, context: o, data: i, error: s } = r, c = S[e], a = `[${o || this.context || "www"}] ${e.toUpperCase()}:`, h = `color: ${c.color}; font-weight: bold;`;
110
+ i !== void 0 ? console[e](`%c${a}`, h, t, this.formatData(i)) : console[e](`%c${a}`, h, t), s && (s instanceof Error ? console.error(s) : console.error("Error details:", s));
111
111
  }
112
112
  async logToNode(r) {
113
113
  if (!x || !this.shouldLog(r.level))
114
114
  return;
115
- const { level: e, description: t, context: o, data: s, error: i } = r, c = o || this.context || "www";
116
- if (p) {
115
+ const { level: e, description: t, context: o, data: i, error: s } = r, c = o || this.context || "www";
116
+ if (m) {
117
117
  const d = {
118
118
  timestamp: this.formatISOTimestamp(),
119
119
  level: e.toUpperCase()
120
120
  };
121
- s && (d.data = this.formatData(s)), i && (d.error = this.formatData(i)), console[e](`${d.timestamp} ${d.level} [${c}] ${t}`, s || i ? JSON.stringify({ data: s, error: i }) : "");
121
+ i && (d.data = this.formatData(i)), s && (d.error = this.formatData(s)), console[e](`${d.timestamp} ${d.level} [${c}] ${t}`, i || s ? JSON.stringify({ data: i, error: s }) : "");
122
122
  } else
123
123
  try {
124
124
  const a = (await import("./index-C-0XxdQQ.js").catch(() => null))?.default, h = S[e], N = this.formatTimestamp();
125
125
  if (a) {
126
- const K = a.dim, B = a.hex(h.color), V = K(`${N} `), J = B(`${e.toUpperCase()} `), W = B(`(${c}): `), _ = `${V}${J}${W}${t}`;
127
- console[e](_), s !== void 0 && console.log(JSON.stringify(this.formatData(s), null, 2)), i && (i instanceof Error && a ? (console.error(a.red("Error:"), i.message), i.stack && console.error(a.gray(i.stack))) : console.error("Error:", i));
126
+ const z = a.dim, B = a.hex(h.color), V = z(`${N} `), J = B(`${e.toUpperCase()} `), W = B(`(${c}): `), _ = `${V}${J}${W}${t}`;
127
+ console[e](_), i !== void 0 && console.log(JSON.stringify(this.formatData(i), null, 2)), s && (s instanceof Error && a ? (console.error(a.red("Error:"), s.message), s.stack && console.error(a.gray(s.stack))) : console.error("Error:", s));
128
128
  } else
129
- console[e](`${N} ${e.toUpperCase()} (${c}): ${t}`), s !== void 0 && console.log(JSON.stringify(this.formatData(s), null, 2)), i && console.error("Error:", i);
129
+ console[e](`${N} ${e.toUpperCase()} (${c}): ${t}`), i !== void 0 && console.log(JSON.stringify(this.formatData(i), null, 2)), s && console.error("Error:", s);
130
130
  } catch {
131
- console[e](`${this.formatTimestamp()} ${e.toUpperCase()} (${c}): ${t}`), s !== void 0 && console.log(JSON.stringify(this.formatData(s), null, 2)), i && console.error("Error:", i);
131
+ console[e](`${this.formatTimestamp()} ${e.toUpperCase()} (${c}): ${t}`), i !== void 0 && console.log(JSON.stringify(this.formatData(i), null, 2)), s && console.error("Error:", s);
132
132
  }
133
133
  }
134
134
  log(r) {
@@ -170,10 +170,10 @@ const w = globalThis.process, v = typeof window < "u", x = typeof w < "u" && !v,
170
170
  };
171
171
  l(y, "Logger"), n(y, "hasShownHelp", !1);
172
172
  let U = y;
173
- function q(u) {
173
+ function R(u) {
174
174
  return new U({}, u).createContextLogger(u);
175
175
  }
176
- l(q, "createLogger");
176
+ l(R, "createLogger");
177
177
  const g = new U();
178
178
  g.error.bind(g);
179
179
  g.warn.bind(g);
@@ -185,7 +185,7 @@ const A = class A {
185
185
  n(this, "name");
186
186
  n(this, "settings");
187
187
  n(this, "logger");
188
- this.name = r, this.settings = e, this.logger = q(r);
188
+ this.name = r, this.settings = e, this.logger = R(r);
189
189
  }
190
190
  };
191
191
  l(A, "SettingsObject");
@@ -208,9 +208,9 @@ const F = class F {
208
208
  return null;
209
209
  const e = document.cookie.split(";");
210
210
  for (const t of e) {
211
- const [o, s] = t.trim().split("=");
211
+ const [o, i] = t.trim().split("=");
212
212
  if (o === r)
213
- return decodeURIComponent(s || "");
213
+ return decodeURIComponent(i || "");
214
214
  }
215
215
  return null;
216
216
  }
@@ -222,14 +222,14 @@ const F = class F {
222
222
  return;
223
223
  const {
224
224
  secure: o = !0,
225
- sameSite: s = "lax",
226
- maxAge: i = 3600 * 24 * 7,
225
+ sameSite: i = "lax",
226
+ maxAge: s = 3600 * 24 * 7,
227
227
  // 7 days default
228
228
  domain: c,
229
229
  path: d = "/"
230
230
  } = t;
231
231
  let a = `${r}=${encodeURIComponent(e)}`;
232
- a += `; Path=${d}`, a += `; Max-Age=${i}`, a += `; SameSite=${s}`, o && (a += "; Secure"), c && (a += `; Domain=${c}`), document.cookie = a;
232
+ a += `; Path=${d}`, a += `; Max-Age=${s}`, a += `; SameSite=${i}`, o && (a += "; Secure"), c && (a += `; Domain=${c}`), document.cookie = a;
233
233
  }
234
234
  /**
235
235
  * Remove cookie by setting expired date
@@ -281,14 +281,14 @@ const I = new L();
281
281
  function Z(u, r) {
282
282
  const e = u.apiBase || (u.isDev ? "http://localhost:5555" : "https://app.fiction.com");
283
283
  return H(e, {
284
- fetch: /* @__PURE__ */ l(async (o, s) => {
285
- const i = I.getAuthToken(), c = await fetch(o, {
286
- ...s,
284
+ fetch: /* @__PURE__ */ l(async (o, i) => {
285
+ const s = I.getAuthToken(), c = await fetch(o, {
286
+ ...i,
287
287
  headers: {
288
- ...s?.headers,
288
+ ...i?.headers,
289
289
  "Content-Type": "application/json",
290
290
  // Only include Authorization header if token exists
291
- ...i && { Authorization: `Bearer ${i}` }
291
+ ...s && { Authorization: `Bearer ${s}` }
292
292
  },
293
293
  // Use 'omit' for Bearer tokens (not cookies) to allow CORS wildcard origin
294
294
  credentials: "omit"
@@ -307,9 +307,9 @@ function Z(u, r) {
307
307
  });
308
308
  }
309
309
  l(Z, "createApiClient");
310
- let ee = Symbol("clean"), f = [], m = 0;
310
+ let ee = Symbol("clean"), f = [], p = 0;
311
311
  const b = 4;
312
- let z = /* @__PURE__ */ l((u) => {
312
+ let q = /* @__PURE__ */ l((u) => {
313
313
  let r = [], e = {
314
314
  get() {
315
315
  return e.lc || e.listen(() => {
@@ -318,22 +318,22 @@ let z = /* @__PURE__ */ l((u) => {
318
318
  lc: 0,
319
319
  listen(t) {
320
320
  return e.lc = r.push(t), () => {
321
- for (let s = m + b; s < f.length; )
322
- f[s] === t ? f.splice(s, b) : s += b;
321
+ for (let i = p + b; i < f.length; )
322
+ f[i] === t ? f.splice(i, b) : i += b;
323
323
  let o = r.indexOf(t);
324
324
  ~o && (r.splice(o, 1), --e.lc || e.off());
325
325
  };
326
326
  },
327
327
  notify(t, o) {
328
- let s = !f.length;
329
- for (let i of r)
330
- f.push(i, e.value, t, o);
331
- if (s) {
332
- for (m = 0; m < f.length; m += b)
333
- f[m](
334
- f[m + 1],
335
- f[m + 2],
336
- f[m + 3]
328
+ let i = !f.length;
329
+ for (let s of r)
330
+ f.push(s, e.value, t, o);
331
+ if (i) {
332
+ for (p = 0; p < f.length; p += b)
333
+ f[p](
334
+ f[p + 1],
335
+ f[p + 2],
336
+ f[p + 3]
337
337
  );
338
338
  f.length = 0;
339
339
  }
@@ -356,23 +356,23 @@ let z = /* @__PURE__ */ l((u) => {
356
356
  r = [], e.lc = 0, e.off();
357
357
  }), e;
358
358
  }, "atom");
359
- const C = z(void 0), $ = z(null), j = class j {
359
+ const C = q(void 0), $ = q(null), j = class j {
360
360
  constructor() {
361
- n(this, "logger", q("SDKStorage"));
361
+ n(this, "logger", R("SDKStorage"));
362
362
  }
363
363
  /**
364
364
  * Sync Vue reactive refs with global nanostores for cross-page persistence
365
365
  */
366
366
  syncWithGlobalStores(r, e) {
367
367
  const t = C.get(), o = $.get();
368
- t && (r.value = t), o && (e.value = o), P(r, (s) => {
369
- C.set(s);
370
- }, { immediate: !0 }), P(e, (s) => {
371
- $.set(s);
372
- }, { immediate: !0 }), C.subscribe((s) => {
373
- s !== r.value && (r.value = s);
374
- }), $.subscribe((s) => {
375
- s !== e.value && (e.value = s);
368
+ t && (r.value = t), o && (e.value = o), P(r, (i) => {
369
+ C.set(i);
370
+ }, { immediate: !0 }), P(e, (i) => {
371
+ $.set(i);
372
+ }, { immediate: !0 }), C.subscribe((i) => {
373
+ i !== r.value && (r.value = i);
374
+ }), $.subscribe((i) => {
375
+ i !== e.value && (e.value = i);
376
376
  });
377
377
  }
378
378
  /**
@@ -525,15 +525,15 @@ const D = class D extends E {
525
525
  async verifyCode(e, t) {
526
526
  this.loading.value = !0, this.error.value = null;
527
527
  try {
528
- const s = await (await this.api.auth["verify-code"].$post({
528
+ const i = await (await this.api.auth["verify-code"].$post({
529
529
  json: { email: e, code: t }
530
530
  })).json();
531
- if (!s.ok)
532
- throw this.error.value = s.error, new Error(s.error);
531
+ if (!i.ok)
532
+ throw this.error.value = i.error, new Error(i.error);
533
533
  } catch (o) {
534
534
  this.logger.error("Verify code error", { data: o });
535
- const s = o instanceof Error ? o.message : "Failed to verify code";
536
- throw this.error.value = s, o;
535
+ const i = o instanceof Error ? o.message : "Failed to verify code";
536
+ throw this.error.value = i, o;
537
537
  } finally {
538
538
  this.loading.value = !1;
539
539
  }
@@ -541,15 +541,15 @@ const D = class D extends E {
541
541
  async login(e, t) {
542
542
  this.loading.value = !0, this.error.value = null;
543
543
  try {
544
- const s = await (await this.api.auth.login.$post({
544
+ const i = await (await this.api.auth.login.$post({
545
545
  json: { email: e, password: t }
546
546
  })).json();
547
- if (!s.ok)
548
- throw this.error.value = s.error, new Error(s.error);
547
+ if (!i.ok)
548
+ throw this.error.value = i.error, new Error(i.error);
549
549
  } catch (o) {
550
550
  this.logger.error("Login error", { data: o });
551
- const s = o instanceof Error ? o.message : "Login failed";
552
- throw this.error.value = s, o;
551
+ const i = o instanceof Error ? o.message : "Login failed";
552
+ throw this.error.value = i, o;
553
553
  } finally {
554
554
  this.loading.value = !1;
555
555
  }
@@ -634,7 +634,7 @@ const D = class D extends E {
634
634
  const t = this.currentSelf.value;
635
635
  if (!t?.orgId)
636
636
  return this.logger.error("Cannot track usage: no current self with orgId", { args: e }), !1;
637
- const s = await (await this.api.usage.record.$post({
637
+ const i = await (await this.api.usage.record.$post({
638
638
  json: {
639
639
  orgId: t.orgId,
640
640
  selfId: e.selfId,
@@ -646,7 +646,7 @@ const D = class D extends E {
646
646
  userId: e.participantId || this.activeUser.value?.userId || "anonymous"
647
647
  }
648
648
  })).json();
649
- return s.ok ? !0 : (this.logger.error("Failed to track usage", { error: s.error, args: e }), !1);
649
+ return i.ok ? !0 : (this.logger.error("Failed to track usage", { error: i.error, args: e }), !1);
650
650
  } catch (t) {
651
651
  return this.logger.error("Track usage error", { error: t, args: e }), !1;
652
652
  }
@@ -676,7 +676,7 @@ const D = class D extends E {
676
676
  this.logger.error("Cannot start conversation: no current self with orgId", { args: e });
677
677
  return;
678
678
  }
679
- const s = await (await this.api.conversation.start.$post({
679
+ const i = await (await this.api.conversation.start.$post({
680
680
  json: {
681
681
  orgId: t.orgId,
682
682
  selfId: e.selfId,
@@ -684,12 +684,12 @@ const D = class D extends E {
684
684
  anonId: e.anonId
685
685
  }
686
686
  })).json();
687
- if (!s.ok || !s.data) {
688
- const i = s.ok ? "No conversation data returned" : "error" in s ? s.error : "Unknown error";
689
- this.logger.error("Failed to start conversation", { error: i, args: e });
687
+ if (!i.ok || !i.data) {
688
+ const s = i.ok ? "No conversation data returned" : "error" in i ? i.error : "Unknown error";
689
+ this.logger.error("Failed to start conversation", { error: s, args: e });
690
690
  return;
691
691
  }
692
- return this.logger.info("Conversation started", { conversationId: s.data.conversationId }), s.data;
692
+ return this.logger.info("Conversation started", { conversationId: i.data.conversationId }), i.data;
693
693
  } catch (t) {
694
694
  this.logger.error("Start conversation error", { error: t, args: e });
695
695
  return;
@@ -723,12 +723,28 @@ const D = class D extends E {
723
723
  return this.logger.error("Save message error", { error: t, args: e }), !1;
724
724
  }
725
725
  }
726
+ /**
727
+ * Track conversion events (view_profile, profile_interaction)
728
+ * Sends event to parent window if embedded, otherwise logs locally
729
+ */
730
+ track(e) {
731
+ try {
732
+ typeof window < "u" && window.parent !== window && window.parent.postMessage({
733
+ type: "fiction_track",
734
+ event: e.event,
735
+ selfId: e.selfId,
736
+ properties: e.properties || {}
737
+ }, "*"), this.logger.info("SDK event tracked", { event: e.event, selfId: e.selfId });
738
+ } catch (t) {
739
+ this.logger.error("Track event error", { error: t, args: e });
740
+ }
741
+ }
726
742
  };
727
743
  l(D, "FictionSDK");
728
- let R = D;
744
+ let K = D;
729
745
  export {
730
- R as F,
746
+ K as F,
731
747
  E as S,
732
- q as c
748
+ R as c
733
749
  };
734
- //# sourceMappingURL=sdkClient-7CpWV9KZ.js.map
750
+ //# sourceMappingURL=sdkClient-Dg6A3ZgO.js.map