@fiction/sdk 1.0.36 → 1.0.37
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.
- package/dist/{FModal.vue_vue_type_script_setup_true_lang-C276htVr.js → FModal.vue_vue_type_script_setup_true_lang-Dyl6-T1J.js} +2 -2
- package/dist/{FModal.vue_vue_type_script_setup_true_lang-C276htVr.js.map → FModal.vue_vue_type_script_setup_true_lang-Dyl6-T1J.js.map} +1 -1
- package/dist/{SelfProvider.vue_vue_type_script_setup_true_lang-D0GqrWsd.js → SelfProvider.vue_vue_type_script_setup_true_lang-CzhYIGaw.js} +2 -2
- package/dist/{SelfProvider.vue_vue_type_script_setup_true_lang-D0GqrWsd.js.map → SelfProvider.vue_vue_type_script_setup_true_lang-CzhYIGaw.js.map} +1 -1
- package/dist/{SelfWidgetInline-BF-RfWRJ.js → SelfWidgetInline-DAnAvyw0.js} +2 -2
- package/dist/{SelfWidgetInline-BF-RfWRJ.js.map → SelfWidgetInline-DAnAvyw0.js.map} +1 -1
- package/dist/{SelfWidgetModal-BobLtpqh.js → SelfWidgetModal-UffLLpWz.js} +3 -3
- package/dist/{SelfWidgetModal-BobLtpqh.js.map → SelfWidgetModal-UffLLpWz.js.map} +1 -1
- package/dist/{SelfWidgetPopup-DkU0aNKG.js → SelfWidgetPopup-D7e3fsdl.js} +2 -2
- package/dist/{SelfWidgetPopup-DkU0aNKG.js.map → SelfWidgetPopup-D7e3fsdl.js.map} +1 -1
- package/dist/{SelfWrap.vue_vue_type_script_setup_true_lang-D6w5CRmF.js → SelfWrap.vue_vue_type_script_setup_true_lang-kaB4C_Ui.js} +2 -2
- package/dist/{SelfWrap.vue_vue_type_script_setup_true_lang-D6w5CRmF.js.map → SelfWrap.vue_vue_type_script_setup_true_lang-kaB4C_Ui.js.map} +1 -1
- package/dist/sdk.js +1 -1
- package/dist/{sdkClient-D8xB05kr.js → sdkClient-7CpWV9KZ.js} +227 -226
- package/dist/sdkClient-7CpWV9KZ.js.map +1 -0
- package/dist/self.js +4 -4
- package/dist/widget.js +4 -4
- package/package.json +2 -2
- package/dist/sdkClient-D8xB05kr.js.map +0 -1
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
var O = Object.defineProperty;
|
|
2
|
-
var Q = (
|
|
3
|
-
var l = (
|
|
4
|
-
var n = (
|
|
2
|
+
var Q = (u, r, e) => r in u ? O(u, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[r] = e;
|
|
3
|
+
var l = (u, r) => O(u, "name", { value: r, configurable: !0 });
|
|
4
|
+
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
|
|
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 = {
|
|
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" },
|
|
12
12
|
debug: { priority: 20, color: "#00BD0C", nodeColor: "\x1B[32m" },
|
|
13
13
|
trace: { priority: 10, color: "#5233FF", nodeColor: "\x1B[35m" }
|
|
14
|
-
}, X = ["password", "token", "secret", "apikey", "api_key", "authorization", "cookie"],
|
|
15
|
-
constructor(
|
|
14
|
+
}, X = ["password", "token", "secret", "apikey", "api_key", "authorization", "cookie"], y = class y {
|
|
15
|
+
constructor(r = {}, e) {
|
|
16
16
|
n(this, "settings");
|
|
17
17
|
n(this, "enabledInBrowser", !1);
|
|
18
18
|
n(this, "context");
|
|
19
19
|
this.context = e, this.settings = {
|
|
20
|
-
enabled:
|
|
21
|
-
minLevel:
|
|
22
|
-
timestamps:
|
|
23
|
-
},
|
|
20
|
+
enabled: r.enabled ?? !0,
|
|
21
|
+
minLevel: r.minLevel ?? this.getDefaultLevel(),
|
|
22
|
+
timestamps: r.timestamps ?? !0
|
|
23
|
+
}, v && this.initBrowserLogging();
|
|
24
24
|
}
|
|
25
25
|
getDefaultLevel() {
|
|
26
|
-
if (x && typeof
|
|
27
|
-
return
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
return
|
|
26
|
+
if (x && typeof w < "u" && w.env?.LOG_LEVEL)
|
|
27
|
+
return w.env.LOG_LEVEL;
|
|
28
|
+
if (v && typeof localStorage < "u") {
|
|
29
|
+
const r = localStorage.getItem("FICTION_LOG_LEVEL");
|
|
30
|
+
if (r)
|
|
31
|
+
return r;
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return p ? "info" : "debug";
|
|
34
34
|
}
|
|
35
35
|
initBrowserLogging() {
|
|
36
|
-
if (!
|
|
36
|
+
if (!v)
|
|
37
37
|
return;
|
|
38
|
-
const e = localStorage.getItem("FICTION_LOG") === "true",
|
|
39
|
-
this.enabledInBrowser = Y || e ||
|
|
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(
|
|
40
40
|
"%cFiction WWW Logger (disabled in production)",
|
|
41
41
|
"color: #888; font-size: 12px"
|
|
42
42
|
), console.log(
|
|
43
43
|
'%cTo enable: localStorage.setItem("FICTION_LOG", "true")',
|
|
44
44
|
"color: #888; font-size: 11px"
|
|
45
|
-
),
|
|
45
|
+
), y.hasShownHelp = !0);
|
|
46
46
|
}
|
|
47
|
-
shouldLog(
|
|
48
|
-
if (!this.settings.enabled ||
|
|
47
|
+
shouldLog(r) {
|
|
48
|
+
if (!this.settings.enabled || v && !this.enabledInBrowser)
|
|
49
49
|
return !1;
|
|
50
|
-
const e = S[
|
|
51
|
-
return e >=
|
|
50
|
+
const e = S[r].priority, t = S[this.settings.minLevel].priority;
|
|
51
|
+
return e >= t;
|
|
52
52
|
}
|
|
53
53
|
formatTimestamp() {
|
|
54
54
|
return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", {
|
|
@@ -61,131 +61,131 @@ const y = globalThis.process, g = typeof window < "u", x = typeof y < "u" && !g,
|
|
|
61
61
|
formatISOTimestamp() {
|
|
62
62
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
63
63
|
}
|
|
64
|
-
redactSensitive(
|
|
65
|
-
if (typeof
|
|
66
|
-
return
|
|
67
|
-
if (Array.isArray(
|
|
68
|
-
return
|
|
64
|
+
redactSensitive(r) {
|
|
65
|
+
if (typeof r != "object" || r === null)
|
|
66
|
+
return r;
|
|
67
|
+
if (Array.isArray(r))
|
|
68
|
+
return r.map((t) => this.redactSensitive(t));
|
|
69
69
|
const e = {};
|
|
70
|
-
for (const [
|
|
71
|
-
const s =
|
|
72
|
-
X.some((i) => s.includes(i)) ? e[
|
|
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;
|
|
73
73
|
}
|
|
74
74
|
return e;
|
|
75
75
|
}
|
|
76
|
-
formatData(
|
|
77
|
-
if (
|
|
76
|
+
formatData(r, e = 3, t = 0) {
|
|
77
|
+
if (t >= e)
|
|
78
78
|
return "[Max Depth]";
|
|
79
|
-
if (
|
|
80
|
-
return
|
|
81
|
-
if (
|
|
79
|
+
if (r == null)
|
|
80
|
+
return r;
|
|
81
|
+
if (r instanceof Error)
|
|
82
82
|
return {
|
|
83
|
-
name:
|
|
84
|
-
message:
|
|
85
|
-
stack:
|
|
83
|
+
name: r.name,
|
|
84
|
+
message: r.message,
|
|
85
|
+
stack: p ? r.stack?.split(`
|
|
86
86
|
`).slice(0, 3).join(`
|
|
87
|
-
`) :
|
|
88
|
-
...
|
|
87
|
+
`) : r.stack,
|
|
88
|
+
...r
|
|
89
89
|
// Include any additional error properties
|
|
90
90
|
};
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
93
|
-
if (typeof
|
|
94
|
-
return
|
|
95
|
-
if (Array.isArray(
|
|
96
|
-
return
|
|
91
|
+
if (r instanceof Date)
|
|
92
|
+
return r.toISOString();
|
|
93
|
+
if (typeof r != "object")
|
|
94
|
+
return r;
|
|
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));
|
|
97
97
|
try {
|
|
98
|
-
const o = {}, s = Object.entries(
|
|
99
|
-
for (const [
|
|
100
|
-
o[
|
|
98
|
+
const o = {}, s = Object.entries(r), i = p ? 50 : 200;
|
|
99
|
+
for (const [c, d] of s.slice(0, i))
|
|
100
|
+
o[c] = this.formatData(d, e, t + 1);
|
|
101
101
|
return s.length > i && (o["..."] = `${s.length - i} more properties`), this.redactSensitive(o);
|
|
102
102
|
} catch {
|
|
103
103
|
return "[Unserializable]";
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
logToBrowser(
|
|
107
|
-
if (!
|
|
106
|
+
logToBrowser(r) {
|
|
107
|
+
if (!v || !this.shouldLog(r.level))
|
|
108
108
|
return;
|
|
109
|
-
const { level: e, description:
|
|
110
|
-
s !== void 0 ? console[e](`%c${a}`,
|
|
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));
|
|
111
111
|
}
|
|
112
|
-
async logToNode(
|
|
113
|
-
if (!x || !this.shouldLog(
|
|
112
|
+
async logToNode(r) {
|
|
113
|
+
if (!x || !this.shouldLog(r.level))
|
|
114
114
|
return;
|
|
115
|
-
const { level: e, description:
|
|
116
|
-
if (
|
|
115
|
+
const { level: e, description: t, context: o, data: s, error: i } = r, c = o || this.context || "www";
|
|
116
|
+
if (p) {
|
|
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} [${
|
|
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 }) : "");
|
|
122
122
|
} else
|
|
123
123
|
try {
|
|
124
|
-
const a = (await import("./index-C-0XxdQQ.js").catch(() => null))?.default,
|
|
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(
|
|
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
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));
|
|
128
128
|
} else
|
|
129
|
-
console[e](`${N} ${e.toUpperCase()} (${
|
|
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);
|
|
130
130
|
} catch {
|
|
131
|
-
console[e](`${this.formatTimestamp()} ${e.toUpperCase()} (${
|
|
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);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
log(
|
|
135
|
-
|
|
134
|
+
log(r) {
|
|
135
|
+
v ? this.logToBrowser(r) : x && this.logToNode(r).catch(console.error);
|
|
136
136
|
}
|
|
137
|
-
error(
|
|
138
|
-
this.log({ level: "error", description:
|
|
137
|
+
error(r, e) {
|
|
138
|
+
this.log({ level: "error", description: r, data: e, context: this.context });
|
|
139
139
|
}
|
|
140
|
-
warn(
|
|
141
|
-
this.log({ level: "warn", description:
|
|
140
|
+
warn(r, e) {
|
|
141
|
+
this.log({ level: "warn", description: r, data: e, context: this.context });
|
|
142
142
|
}
|
|
143
|
-
info(
|
|
144
|
-
this.log({ level: "info", description:
|
|
143
|
+
info(r, e) {
|
|
144
|
+
this.log({ level: "info", description: r, data: e, context: this.context });
|
|
145
145
|
}
|
|
146
|
-
debug(
|
|
147
|
-
this.log({ level: "debug", description:
|
|
146
|
+
debug(r, e) {
|
|
147
|
+
this.log({ level: "debug", description: r, data: e, context: this.context });
|
|
148
148
|
}
|
|
149
|
-
trace(
|
|
150
|
-
this.log({ level: "trace", description:
|
|
149
|
+
trace(r, e) {
|
|
150
|
+
this.log({ level: "trace", description: r, data: e, context: this.context });
|
|
151
151
|
}
|
|
152
152
|
isEnabled() {
|
|
153
|
-
return
|
|
153
|
+
return v ? this.enabledInBrowser : !0;
|
|
154
154
|
}
|
|
155
|
-
setLevel(
|
|
156
|
-
this.settings.minLevel =
|
|
155
|
+
setLevel(r) {
|
|
156
|
+
this.settings.minLevel = r;
|
|
157
157
|
}
|
|
158
|
-
createContextLogger(
|
|
159
|
-
const e = new
|
|
158
|
+
createContextLogger(r) {
|
|
159
|
+
const e = new y(this.settings, r);
|
|
160
160
|
return {
|
|
161
|
-
error: /* @__PURE__ */ l((
|
|
162
|
-
warn: /* @__PURE__ */ l((
|
|
163
|
-
info: /* @__PURE__ */ l((
|
|
164
|
-
debug: /* @__PURE__ */ l((
|
|
165
|
-
trace: /* @__PURE__ */ l((
|
|
161
|
+
error: /* @__PURE__ */ l((t, o) => e.error(t, o), "error"),
|
|
162
|
+
warn: /* @__PURE__ */ l((t, o) => e.warn(t, o), "warn"),
|
|
163
|
+
info: /* @__PURE__ */ l((t, o) => e.info(t, o), "info"),
|
|
164
|
+
debug: /* @__PURE__ */ l((t, o) => e.debug(t, o), "debug"),
|
|
165
|
+
trace: /* @__PURE__ */ l((t, o) => e.trace(t, o), "trace"),
|
|
166
166
|
isEnabled: /* @__PURE__ */ l(() => e.isEnabled(), "isEnabled"),
|
|
167
|
-
setLevel: /* @__PURE__ */ l((
|
|
167
|
+
setLevel: /* @__PURE__ */ l((t) => e.setLevel(t), "setLevel")
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
|
-
l(
|
|
172
|
-
let U =
|
|
173
|
-
function q(
|
|
174
|
-
return new U({},
|
|
171
|
+
l(y, "Logger"), n(y, "hasShownHelp", !1);
|
|
172
|
+
let U = y;
|
|
173
|
+
function q(u) {
|
|
174
|
+
return new U({}, u).createContextLogger(u);
|
|
175
175
|
}
|
|
176
176
|
l(q, "createLogger");
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
const g = new U();
|
|
178
|
+
g.error.bind(g);
|
|
179
|
+
g.warn.bind(g);
|
|
180
|
+
g.info.bind(g);
|
|
181
|
+
g.debug.bind(g);
|
|
182
|
+
g.trace.bind(g);
|
|
183
183
|
const A = class A {
|
|
184
|
-
constructor(
|
|
184
|
+
constructor(r, e) {
|
|
185
185
|
n(this, "name");
|
|
186
186
|
n(this, "settings");
|
|
187
187
|
n(this, "logger");
|
|
188
|
-
this.name =
|
|
188
|
+
this.name = r, this.settings = e, this.logger = q(r);
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
191
|
l(A, "SettingsObject");
|
|
@@ -203,13 +203,13 @@ const F = class F {
|
|
|
203
203
|
/**
|
|
204
204
|
* Get cookie value by name
|
|
205
205
|
*/
|
|
206
|
-
getCookie(
|
|
206
|
+
getCookie(r) {
|
|
207
207
|
if (typeof document > "u")
|
|
208
208
|
return null;
|
|
209
209
|
const e = document.cookie.split(";");
|
|
210
|
-
for (const
|
|
211
|
-
const [o, s] =
|
|
212
|
-
if (o ===
|
|
210
|
+
for (const t of e) {
|
|
211
|
+
const [o, s] = t.trim().split("=");
|
|
212
|
+
if (o === r)
|
|
213
213
|
return decodeURIComponent(s || "");
|
|
214
214
|
}
|
|
215
215
|
return null;
|
|
@@ -217,7 +217,7 @@ const F = class F {
|
|
|
217
217
|
/**
|
|
218
218
|
* Set cookie with secure defaults
|
|
219
219
|
*/
|
|
220
|
-
setCookie(
|
|
220
|
+
setCookie(r, e, t = {}) {
|
|
221
221
|
if (typeof document > "u")
|
|
222
222
|
return;
|
|
223
223
|
const {
|
|
@@ -225,25 +225,25 @@ const F = class F {
|
|
|
225
225
|
sameSite: s = "lax",
|
|
226
226
|
maxAge: i = 3600 * 24 * 7,
|
|
227
227
|
// 7 days default
|
|
228
|
-
domain:
|
|
228
|
+
domain: c,
|
|
229
229
|
path: d = "/"
|
|
230
|
-
} =
|
|
231
|
-
let a = `${
|
|
232
|
-
a += `; Path=${d}`, a += `; Max-Age=${i}`, a += `; SameSite=${s}`, o && (a += "; Secure"),
|
|
230
|
+
} = t;
|
|
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;
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
235
|
* Remove cookie by setting expired date
|
|
236
236
|
*/
|
|
237
|
-
removeCookie(
|
|
238
|
-
this.setCookie(
|
|
237
|
+
removeCookie(r, e = {}) {
|
|
238
|
+
this.setCookie(r, "", { ...e, maxAge: 0 });
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
241
|
* Get auth token with fallback to localStorage for migration
|
|
242
242
|
*/
|
|
243
243
|
getAuthToken() {
|
|
244
|
-
const
|
|
245
|
-
if (
|
|
246
|
-
return
|
|
244
|
+
const r = this.getCookie(this.tokenName);
|
|
245
|
+
if (r)
|
|
246
|
+
return r;
|
|
247
247
|
if (typeof localStorage < "u") {
|
|
248
248
|
const e = localStorage.getItem(this.fallbackStorageKey);
|
|
249
249
|
if (e)
|
|
@@ -254,9 +254,9 @@ const F = class F {
|
|
|
254
254
|
/**
|
|
255
255
|
* Set auth token in cookie with production-ready settings
|
|
256
256
|
*/
|
|
257
|
-
setAuthToken(
|
|
257
|
+
setAuthToken(r) {
|
|
258
258
|
const e = typeof window < "u" && window.location.hostname !== "localhost";
|
|
259
|
-
this.setCookie(this.tokenName,
|
|
259
|
+
this.setCookie(this.tokenName, r, {
|
|
260
260
|
secure: e,
|
|
261
261
|
sameSite: "lax",
|
|
262
262
|
maxAge: this.tokenMaxAge,
|
|
@@ -268,91 +268,92 @@ const F = class F {
|
|
|
268
268
|
* Remove auth token
|
|
269
269
|
*/
|
|
270
270
|
removeAuthToken() {
|
|
271
|
-
const
|
|
271
|
+
const r = typeof window < "u" && window.location.hostname !== "localhost";
|
|
272
272
|
this.removeCookie(this.tokenName, {
|
|
273
|
-
domain:
|
|
273
|
+
domain: r ? this.productionDomain : void 0,
|
|
274
274
|
path: "/"
|
|
275
275
|
}), typeof localStorage < "u" && localStorage.removeItem(this.fallbackStorageKey);
|
|
276
276
|
}
|
|
277
277
|
};
|
|
278
278
|
l(F, "CookieUtil");
|
|
279
279
|
let L = F;
|
|
280
|
-
const
|
|
281
|
-
function Z(
|
|
282
|
-
const e =
|
|
280
|
+
const I = new L();
|
|
281
|
+
function Z(u, r) {
|
|
282
|
+
const e = u.apiBase || (u.isDev ? "http://localhost:5555" : "https://app.fiction.com");
|
|
283
283
|
return H(e, {
|
|
284
284
|
fetch: /* @__PURE__ */ l(async (o, s) => {
|
|
285
|
-
const i = await fetch(o, {
|
|
285
|
+
const i = I.getAuthToken(), c = await fetch(o, {
|
|
286
286
|
...s,
|
|
287
287
|
headers: {
|
|
288
288
|
...s?.headers,
|
|
289
289
|
"Content-Type": "application/json",
|
|
290
|
-
Authorization
|
|
290
|
+
// Only include Authorization header if token exists
|
|
291
|
+
...i && { Authorization: `Bearer ${i}` }
|
|
291
292
|
},
|
|
292
293
|
// Use 'omit' for Bearer tokens (not cookies) to allow CORS wildcard origin
|
|
293
294
|
credentials: "omit"
|
|
294
295
|
});
|
|
295
|
-
if (
|
|
296
|
-
const
|
|
297
|
-
return Object.defineProperty(
|
|
296
|
+
if (r) {
|
|
297
|
+
const d = c.json.bind(c), a = c.clone();
|
|
298
|
+
return Object.defineProperty(a, "json", {
|
|
298
299
|
value: /* @__PURE__ */ l(async () => {
|
|
299
|
-
const
|
|
300
|
-
return typeof
|
|
300
|
+
const h = await d();
|
|
301
|
+
return typeof h == "object" && h !== null && "ok" in h && ("user" in h || "token" in h) && r(h), h;
|
|
301
302
|
}, "value")
|
|
302
|
-
}),
|
|
303
|
+
}), a;
|
|
303
304
|
}
|
|
304
|
-
return
|
|
305
|
+
return c;
|
|
305
306
|
}, "fetch")
|
|
306
307
|
});
|
|
307
308
|
}
|
|
308
309
|
l(Z, "createApiClient");
|
|
309
|
-
let ee = Symbol("clean"),
|
|
310
|
+
let ee = Symbol("clean"), f = [], m = 0;
|
|
310
311
|
const b = 4;
|
|
311
|
-
let z = /* @__PURE__ */ l((
|
|
312
|
-
let
|
|
312
|
+
let z = /* @__PURE__ */ l((u) => {
|
|
313
|
+
let r = [], e = {
|
|
313
314
|
get() {
|
|
314
315
|
return e.lc || e.listen(() => {
|
|
315
316
|
})(), e.value;
|
|
316
317
|
},
|
|
317
318
|
lc: 0,
|
|
318
|
-
listen(
|
|
319
|
-
return e.lc =
|
|
320
|
-
for (let s =
|
|
321
|
-
|
|
322
|
-
let o =
|
|
323
|
-
~o && (
|
|
319
|
+
listen(t) {
|
|
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;
|
|
323
|
+
let o = r.indexOf(t);
|
|
324
|
+
~o && (r.splice(o, 1), --e.lc || e.off());
|
|
324
325
|
};
|
|
325
326
|
},
|
|
326
|
-
notify(
|
|
327
|
-
let s = !
|
|
328
|
-
for (let i of
|
|
329
|
-
|
|
327
|
+
notify(t, o) {
|
|
328
|
+
let s = !f.length;
|
|
329
|
+
for (let i of r)
|
|
330
|
+
f.push(i, e.value, t, o);
|
|
330
331
|
if (s) {
|
|
331
|
-
for (
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
for (m = 0; m < f.length; m += b)
|
|
333
|
+
f[m](
|
|
334
|
+
f[m + 1],
|
|
335
|
+
f[m + 2],
|
|
336
|
+
f[m + 3]
|
|
336
337
|
);
|
|
337
|
-
|
|
338
|
+
f.length = 0;
|
|
338
339
|
}
|
|
339
340
|
},
|
|
340
341
|
/* It will be called on last listener unsubscribing.
|
|
341
342
|
We will redefine it in onMount and onStop. */
|
|
342
343
|
off() {
|
|
343
344
|
},
|
|
344
|
-
set(
|
|
345
|
+
set(t) {
|
|
345
346
|
let o = e.value;
|
|
346
|
-
o !==
|
|
347
|
+
o !== t && (e.value = t, e.notify(o));
|
|
347
348
|
},
|
|
348
|
-
subscribe(
|
|
349
|
-
let o = e.listen(
|
|
350
|
-
return
|
|
349
|
+
subscribe(t) {
|
|
350
|
+
let o = e.listen(t);
|
|
351
|
+
return t(e.value), o;
|
|
351
352
|
},
|
|
352
|
-
value:
|
|
353
|
+
value: u
|
|
353
354
|
};
|
|
354
355
|
return process.env.NODE_ENV !== "production" && (e[ee] = () => {
|
|
355
|
-
|
|
356
|
+
r = [], e.lc = 0, e.off();
|
|
356
357
|
}), e;
|
|
357
358
|
}, "atom");
|
|
358
359
|
const C = z(void 0), $ = z(null), j = class j {
|
|
@@ -362,14 +363,14 @@ const C = z(void 0), $ = z(null), j = class j {
|
|
|
362
363
|
/**
|
|
363
364
|
* Sync Vue reactive refs with global nanostores for cross-page persistence
|
|
364
365
|
*/
|
|
365
|
-
syncWithGlobalStores(
|
|
366
|
-
const
|
|
367
|
-
|
|
366
|
+
syncWithGlobalStores(r, e) {
|
|
367
|
+
const t = C.get(), o = $.get();
|
|
368
|
+
t && (r.value = t), o && (e.value = o), P(r, (s) => {
|
|
368
369
|
C.set(s);
|
|
369
370
|
}, { immediate: !0 }), P(e, (s) => {
|
|
370
371
|
$.set(s);
|
|
371
372
|
}, { immediate: !0 }), C.subscribe((s) => {
|
|
372
|
-
s !==
|
|
373
|
+
s !== r.value && (r.value = s);
|
|
373
374
|
}), $.subscribe((s) => {
|
|
374
375
|
s !== e.value && (e.value = s);
|
|
375
376
|
});
|
|
@@ -377,14 +378,14 @@ const C = z(void 0), $ = z(null), j = class j {
|
|
|
377
378
|
/**
|
|
378
379
|
* Load user and token from browser storage on initialization
|
|
379
380
|
*/
|
|
380
|
-
loadFromStorage(
|
|
381
|
+
loadFromStorage(r, e) {
|
|
381
382
|
if (typeof window > "u")
|
|
382
383
|
return;
|
|
383
|
-
const
|
|
384
|
-
|
|
384
|
+
const t = I.getAuthToken();
|
|
385
|
+
t && (e.value = t);
|
|
385
386
|
try {
|
|
386
387
|
const o = localStorage.getItem("fiction-user");
|
|
387
|
-
o && (
|
|
388
|
+
o && (r.value = JSON.parse(o));
|
|
388
389
|
} catch (o) {
|
|
389
390
|
this.logger.error("Failed to load user from localStorage", { data: o });
|
|
390
391
|
}
|
|
@@ -392,13 +393,13 @@ const C = z(void 0), $ = z(null), j = class j {
|
|
|
392
393
|
/**
|
|
393
394
|
* Save current user and token to browser storage
|
|
394
395
|
*/
|
|
395
|
-
saveToStorage(
|
|
396
|
+
saveToStorage(r, e) {
|
|
396
397
|
if (!(typeof window > "u")) {
|
|
397
|
-
e.value ?
|
|
398
|
+
e.value ? I.setAuthToken(e.value) : I.removeAuthToken();
|
|
398
399
|
try {
|
|
399
|
-
|
|
400
|
-
} catch (
|
|
401
|
-
this.logger.error("Failed to save user to localStorage", { data:
|
|
400
|
+
r.value ? localStorage.setItem("fiction-user", JSON.stringify(r.value)) : localStorage.removeItem("fiction-user");
|
|
401
|
+
} catch (t) {
|
|
402
|
+
this.logger.error("Failed to save user to localStorage", { data: t });
|
|
402
403
|
}
|
|
403
404
|
}
|
|
404
405
|
}
|
|
@@ -407,11 +408,11 @@ const C = z(void 0), $ = z(null), j = class j {
|
|
|
407
408
|
*/
|
|
408
409
|
clearStorage() {
|
|
409
410
|
if (!(typeof window > "u")) {
|
|
410
|
-
|
|
411
|
+
I.removeAuthToken();
|
|
411
412
|
try {
|
|
412
413
|
localStorage.removeItem("fiction-user");
|
|
413
|
-
} catch (
|
|
414
|
-
this.logger.error("Failed to clear user from localStorage", { data:
|
|
414
|
+
} catch (r) {
|
|
415
|
+
this.logger.error("Failed to clear user from localStorage", { data: r });
|
|
415
416
|
}
|
|
416
417
|
C.set(void 0), $.set(null);
|
|
417
418
|
}
|
|
@@ -419,24 +420,24 @@ const C = z(void 0), $ = z(null), j = class j {
|
|
|
419
420
|
/**
|
|
420
421
|
* Generic localStorage getter
|
|
421
422
|
*/
|
|
422
|
-
getItem(
|
|
423
|
+
getItem(r) {
|
|
423
424
|
if (typeof window > "u")
|
|
424
425
|
return null;
|
|
425
426
|
try {
|
|
426
|
-
return localStorage.getItem(
|
|
427
|
+
return localStorage.getItem(r);
|
|
427
428
|
} catch (e) {
|
|
428
|
-
return this.logger.error("Failed to get item from localStorage", { key:
|
|
429
|
+
return this.logger.error("Failed to get item from localStorage", { key: r, error: e }), null;
|
|
429
430
|
}
|
|
430
431
|
}
|
|
431
432
|
/**
|
|
432
433
|
* Generic localStorage setter
|
|
433
434
|
*/
|
|
434
|
-
setItem(
|
|
435
|
+
setItem(r, e) {
|
|
435
436
|
if (!(typeof window > "u"))
|
|
436
437
|
try {
|
|
437
|
-
localStorage.setItem(
|
|
438
|
-
} catch (
|
|
439
|
-
this.logger.error("Failed to set item in localStorage", { key:
|
|
438
|
+
localStorage.setItem(r, e);
|
|
439
|
+
} catch (t) {
|
|
440
|
+
this.logger.error("Failed to set item in localStorage", { key: r, error: t });
|
|
440
441
|
}
|
|
441
442
|
}
|
|
442
443
|
};
|
|
@@ -462,17 +463,17 @@ const D = class D extends E {
|
|
|
462
463
|
const e = this.activeUser.value;
|
|
463
464
|
if (!e?.selves)
|
|
464
465
|
return;
|
|
465
|
-
const
|
|
466
|
-
if (
|
|
467
|
-
return e.selves.find((o) => o.selfId ===
|
|
466
|
+
const t = e.primarySelfId || e.selves[0]?.selfId;
|
|
467
|
+
if (t)
|
|
468
|
+
return e.selves.find((o) => o.selfId === t);
|
|
468
469
|
}));
|
|
469
470
|
n(this, "currentOrg", G(() => {
|
|
470
471
|
const e = this.currentSelf.value;
|
|
471
472
|
if (!e?.orgId)
|
|
472
473
|
return;
|
|
473
|
-
const
|
|
474
|
-
if (
|
|
475
|
-
return
|
|
474
|
+
const t = this.activeUser.value;
|
|
475
|
+
if (t?.orgs)
|
|
476
|
+
return t.orgs.find((o) => o.orgId === e.orgId);
|
|
476
477
|
}));
|
|
477
478
|
// Initialization state
|
|
478
479
|
n(this, "initialized");
|
|
@@ -480,12 +481,12 @@ const D = class D extends E {
|
|
|
480
481
|
this.apiClient = Z(
|
|
481
482
|
{ isDev: this.isDev, apiBase: this.apiBase },
|
|
482
483
|
this.processApiResponse.bind(this)
|
|
483
|
-
), this.logger.info("FictionSDK initialized"), this.storage.loadFromStorage(this.activeUser, this.token), this.storage.syncWithGlobalStores(this.activeUser, this.token), this.initialized = new Promise((
|
|
484
|
-
this.resolveUser =
|
|
485
|
-
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((
|
|
486
|
-
this.resolveUser && (this.resolveUser(
|
|
487
|
-
}).catch((
|
|
488
|
-
this.logger.error("Auto user fetch failed", { data:
|
|
484
|
+
), this.logger.info("FictionSDK initialized"), this.storage.loadFromStorage(this.activeUser, this.token), this.storage.syncWithGlobalStores(this.activeUser, this.token), this.initialized = new Promise((t) => {
|
|
485
|
+
this.resolveUser = t;
|
|
486
|
+
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((t) => {
|
|
487
|
+
this.resolveUser && (this.resolveUser(t), this.resolveUser = void 0);
|
|
488
|
+
}).catch((t) => {
|
|
489
|
+
this.logger.error("Auto user fetch failed", { data: t }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
|
|
489
490
|
}) : this.activeUser.value ? this.resolveUser?.(this.activeUser.value) : this.resolveUser?.(void 0);
|
|
490
491
|
}
|
|
491
492
|
get isDev() {
|
|
@@ -513,19 +514,19 @@ const D = class D extends E {
|
|
|
513
514
|
})).json();
|
|
514
515
|
if (!o.ok)
|
|
515
516
|
throw this.error.value = o.error, new Error(o.error);
|
|
516
|
-
} catch (
|
|
517
|
-
this.logger.error("Send code error", { data:
|
|
518
|
-
const o =
|
|
519
|
-
throw this.error.value = o,
|
|
517
|
+
} catch (t) {
|
|
518
|
+
this.logger.error("Send code error", { data: t });
|
|
519
|
+
const o = t instanceof Error ? t.message : "Failed to send verification code";
|
|
520
|
+
throw this.error.value = o, t;
|
|
520
521
|
} finally {
|
|
521
522
|
this.loading.value = !1;
|
|
522
523
|
}
|
|
523
524
|
}
|
|
524
|
-
async verifyCode(e,
|
|
525
|
+
async verifyCode(e, t) {
|
|
525
526
|
this.loading.value = !0, this.error.value = null;
|
|
526
527
|
try {
|
|
527
528
|
const s = await (await this.api.auth["verify-code"].$post({
|
|
528
|
-
json: { email: e, code:
|
|
529
|
+
json: { email: e, code: t }
|
|
529
530
|
})).json();
|
|
530
531
|
if (!s.ok)
|
|
531
532
|
throw this.error.value = s.error, new Error(s.error);
|
|
@@ -537,11 +538,11 @@ const D = class D extends E {
|
|
|
537
538
|
this.loading.value = !1;
|
|
538
539
|
}
|
|
539
540
|
}
|
|
540
|
-
async login(e,
|
|
541
|
+
async login(e, t) {
|
|
541
542
|
this.loading.value = !0, this.error.value = null;
|
|
542
543
|
try {
|
|
543
544
|
const s = await (await this.api.auth.login.$post({
|
|
544
|
-
json: { email: e, password:
|
|
545
|
+
json: { email: e, password: t }
|
|
545
546
|
})).json();
|
|
546
547
|
if (!s.ok)
|
|
547
548
|
throw this.error.value = s.error, new Error(s.error);
|
|
@@ -567,12 +568,12 @@ const D = class D extends E {
|
|
|
567
568
|
if (this.token.value) {
|
|
568
569
|
this.loading.value = !0;
|
|
569
570
|
try {
|
|
570
|
-
const
|
|
571
|
-
if (!
|
|
572
|
-
this.error.value =
|
|
571
|
+
const t = await (await this.api.auth.me.$get()).json();
|
|
572
|
+
if (!t.ok) {
|
|
573
|
+
this.error.value = t.error, t.error.includes("Authentication") && (this.activeUser.value = void 0, this.token.value = null, this.storage.clearStorage());
|
|
573
574
|
return;
|
|
574
575
|
}
|
|
575
|
-
return
|
|
576
|
+
return t.user;
|
|
576
577
|
} catch (e) {
|
|
577
578
|
this.logger.error("Get current user error", { data: e }), this.error.value = e instanceof Error ? e.message : "Failed to get user info";
|
|
578
579
|
return;
|
|
@@ -592,8 +593,8 @@ const D = class D extends E {
|
|
|
592
593
|
return;
|
|
593
594
|
}
|
|
594
595
|
return o.data;
|
|
595
|
-
} catch (
|
|
596
|
-
this.logger.error("Get public self error", { handle: e.handle, error:
|
|
596
|
+
} catch (t) {
|
|
597
|
+
this.logger.error("Get public self error", { handle: e.handle, error: t }), this.error.value = t instanceof Error ? t.message : "Failed to fetch self";
|
|
597
598
|
return;
|
|
598
599
|
} finally {
|
|
599
600
|
this.loading.value = !1;
|
|
@@ -606,8 +607,8 @@ const D = class D extends E {
|
|
|
606
607
|
json: { email: e.email }
|
|
607
608
|
})).json();
|
|
608
609
|
return o.ok ? (this.logger.info("Auth code requested successfully", { email: e.email }), !0) : (this.error.value = o.error, this.logger.error("Failed to request auth code", { email: e.email, error: o.error }), !1);
|
|
609
|
-
} catch (
|
|
610
|
-
return this.logger.error("Request auth code error", { email: e.email, error:
|
|
610
|
+
} catch (t) {
|
|
611
|
+
return this.logger.error("Request auth code error", { email: e.email, error: t }), this.error.value = t instanceof Error ? t.message : "Failed to request auth code", !1;
|
|
611
612
|
} finally {
|
|
612
613
|
this.loading.value = !1;
|
|
613
614
|
}
|
|
@@ -622,20 +623,20 @@ const D = class D extends E {
|
|
|
622
623
|
userId: this.activeUser.value.userId,
|
|
623
624
|
orgId: e.orgId
|
|
624
625
|
}), !0) : (this.error.value = o.error, this.logger.error("Login failed", { email: e.email, error: o.error }), !1);
|
|
625
|
-
} catch (
|
|
626
|
-
return this.logger.error("Login with code error", { email: e.email, error:
|
|
626
|
+
} catch (t) {
|
|
627
|
+
return this.logger.error("Login with code error", { email: e.email, error: t }), this.error.value = t instanceof Error ? t.message : "Login failed", !1;
|
|
627
628
|
} finally {
|
|
628
629
|
this.loading.value = !1;
|
|
629
630
|
}
|
|
630
631
|
}
|
|
631
632
|
async trackUsage(e) {
|
|
632
633
|
try {
|
|
633
|
-
const
|
|
634
|
-
if (!
|
|
634
|
+
const t = this.currentSelf.value;
|
|
635
|
+
if (!t?.orgId)
|
|
635
636
|
return this.logger.error("Cannot track usage: no current self with orgId", { args: e }), !1;
|
|
636
637
|
const s = await (await this.api.usage.record.$post({
|
|
637
638
|
json: {
|
|
638
|
-
orgId:
|
|
639
|
+
orgId: t.orgId,
|
|
639
640
|
selfId: e.selfId,
|
|
640
641
|
sessionId: this.sessionId,
|
|
641
642
|
// Auto-managed by SDK
|
|
@@ -646,8 +647,8 @@ const D = class D extends E {
|
|
|
646
647
|
}
|
|
647
648
|
})).json();
|
|
648
649
|
return s.ok ? !0 : (this.logger.error("Failed to track usage", { error: s.error, args: e }), !1);
|
|
649
|
-
} catch (
|
|
650
|
-
return this.logger.error("Track usage error", { error:
|
|
650
|
+
} catch (t) {
|
|
651
|
+
return this.logger.error("Track usage error", { error: t, args: e }), !1;
|
|
651
652
|
}
|
|
652
653
|
}
|
|
653
654
|
/**
|
|
@@ -660,8 +661,8 @@ const D = class D extends E {
|
|
|
660
661
|
json: { userId: e.userId, orgId: e.orgId }
|
|
661
662
|
})).json();
|
|
662
663
|
return o.ok ? (this.logger.info("Contact resolved", { userId: e.userId, orgId: e.orgId }), !0) : (this.logger.error("Failed to auto-create contact", { error: o.error, args: e }), !1);
|
|
663
|
-
} catch (
|
|
664
|
-
return this.logger.error("Auto-create contact error", { error:
|
|
664
|
+
} catch (t) {
|
|
665
|
+
return this.logger.error("Auto-create contact error", { error: t, args: e }), !1;
|
|
665
666
|
}
|
|
666
667
|
}
|
|
667
668
|
/**
|
|
@@ -670,14 +671,14 @@ const D = class D extends E {
|
|
|
670
671
|
*/
|
|
671
672
|
async startConversation(e) {
|
|
672
673
|
try {
|
|
673
|
-
const
|
|
674
|
-
if (!
|
|
674
|
+
const t = this.currentSelf.value;
|
|
675
|
+
if (!t?.orgId) {
|
|
675
676
|
this.logger.error("Cannot start conversation: no current self with orgId", { args: e });
|
|
676
677
|
return;
|
|
677
678
|
}
|
|
678
679
|
const s = await (await this.api.conversation.start.$post({
|
|
679
680
|
json: {
|
|
680
|
-
orgId:
|
|
681
|
+
orgId: t.orgId,
|
|
681
682
|
selfId: e.selfId,
|
|
682
683
|
userId: e.userId || this.activeUser.value?.userId,
|
|
683
684
|
anonId: e.anonId
|
|
@@ -689,8 +690,8 @@ const D = class D extends E {
|
|
|
689
690
|
return;
|
|
690
691
|
}
|
|
691
692
|
return this.logger.info("Conversation started", { conversationId: s.data.conversationId }), s.data;
|
|
692
|
-
} catch (
|
|
693
|
-
this.logger.error("Start conversation error", { error:
|
|
693
|
+
} catch (t) {
|
|
694
|
+
this.logger.error("Start conversation error", { error: t, args: e });
|
|
694
695
|
return;
|
|
695
696
|
}
|
|
696
697
|
}
|
|
@@ -700,8 +701,8 @@ const D = class D extends E {
|
|
|
700
701
|
*/
|
|
701
702
|
generateAnonId() {
|
|
702
703
|
const e = "fictionAnonId";
|
|
703
|
-
let
|
|
704
|
-
return
|
|
704
|
+
let t = this.storage.getItem(e);
|
|
705
|
+
return t || (t = M({ prefix: "anon" }), this.storage.setItem(e, t)), t;
|
|
705
706
|
}
|
|
706
707
|
/**
|
|
707
708
|
* Save message to conversation
|
|
@@ -718,8 +719,8 @@ const D = class D extends E {
|
|
|
718
719
|
}
|
|
719
720
|
})).json();
|
|
720
721
|
return o.ok ? !0 : (this.logger.error("Failed to save message", { error: "error" in o ? o.error : "Unknown error", args: e }), !1);
|
|
721
|
-
} catch (
|
|
722
|
-
return this.logger.error("Save message error", { error:
|
|
722
|
+
} catch (t) {
|
|
723
|
+
return this.logger.error("Save message error", { error: t, args: e }), !1;
|
|
723
724
|
}
|
|
724
725
|
}
|
|
725
726
|
};
|
|
@@ -730,4 +731,4 @@ export {
|
|
|
730
731
|
E as S,
|
|
731
732
|
q as c
|
|
732
733
|
};
|
|
733
|
-
//# sourceMappingURL=sdkClient-
|
|
734
|
+
//# sourceMappingURL=sdkClient-7CpWV9KZ.js.map
|