@superfeedback/widget 0.0.24 → 0.0.26
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/index.iife.js +5 -5
- package/dist/index.js +42 -36
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,15 +7,15 @@ var VISITOR_ID_KEY = "sf_visitor_id", SessionTracker = class {
|
|
|
7
7
|
#i;
|
|
8
8
|
#a = 0;
|
|
9
9
|
#o = !0;
|
|
10
|
-
constructor(e,
|
|
11
|
-
this.#e = e, this.#t =
|
|
10
|
+
constructor(e, i) {
|
|
11
|
+
this.#e = e, this.#t = i, this.#i = Date.now(), this.#n = this.#s(), this.#r = crypto.randomUUID(), this.#m();
|
|
12
12
|
}
|
|
13
13
|
#s() {
|
|
14
14
|
try {
|
|
15
15
|
let e = localStorage.getItem(VISITOR_ID_KEY);
|
|
16
16
|
if (e) return e;
|
|
17
|
-
let
|
|
18
|
-
return localStorage.setItem(VISITOR_ID_KEY,
|
|
17
|
+
let a = crypto.randomUUID();
|
|
18
|
+
return localStorage.setItem(VISITOR_ID_KEY, a), a;
|
|
19
19
|
} catch {
|
|
20
20
|
return crypto.randomUUID();
|
|
21
21
|
}
|
|
@@ -45,11 +45,11 @@ var VISITOR_ID_KEY = "sf_visitor_id", SessionTracker = class {
|
|
|
45
45
|
}
|
|
46
46
|
#f() {
|
|
47
47
|
if (this.#u() < 1e3) return;
|
|
48
|
-
let e = this.#d(),
|
|
49
|
-
fetch(
|
|
48
|
+
let e = this.#d(), i = `${this.#t}/api/external/v1/apps/${this.#e}/sessions`, a = JSON.stringify(e);
|
|
49
|
+
fetch(i, {
|
|
50
50
|
method: "POST",
|
|
51
51
|
headers: { "Content-Type": "application/json" },
|
|
52
|
-
body:
|
|
52
|
+
body: a,
|
|
53
53
|
keepalive: !0,
|
|
54
54
|
credentials: "omit"
|
|
55
55
|
}).catch(() => {}), this.#a = 0, this.#i = Date.now();
|
|
@@ -70,17 +70,21 @@ var VISITOR_ID_KEY = "sf_visitor_id", SessionTracker = class {
|
|
|
70
70
|
this.#f();
|
|
71
71
|
}
|
|
72
72
|
}, __widgetBaseUrl = null;
|
|
73
|
-
typeof document < "u" && document.currentScript && (__widgetBaseUrl = document.currentScript.src);
|
|
73
|
+
typeof document < "u" && document.currentScript && (__widgetBaseUrl = document.currentScript.src), console.log(__widgetBaseUrl);
|
|
74
|
+
function buildUrl(e, i) {
|
|
75
|
+
let a = new URL(e);
|
|
76
|
+
return a.pathname = a.pathname.replace(/\/$/, "") + i, a.href;
|
|
77
|
+
}
|
|
74
78
|
function loadScript(e) {
|
|
75
|
-
return new Promise((
|
|
76
|
-
let
|
|
77
|
-
|
|
79
|
+
return new Promise((i, a) => {
|
|
80
|
+
let o = document.createElement("script");
|
|
81
|
+
o.src = e, o.onload = () => i(), o.onerror = () => a(/* @__PURE__ */ Error(`Failed to load: ${e}`)), document.head.appendChild(o);
|
|
78
82
|
});
|
|
79
83
|
}
|
|
80
84
|
var iifeLoader = async () => {
|
|
81
85
|
if (window.__superfeedback_widget) return window.__superfeedback_widget;
|
|
82
86
|
if (!__widgetBaseUrl) throw Error("Cannot determine widget chunk URL");
|
|
83
|
-
await loadScript(
|
|
87
|
+
console.log("load widget from base_url:", __widgetBaseUrl), await loadScript(buildUrl(__widgetBaseUrl, "/dist/widget.iife.js"));
|
|
84
88
|
let e = window.__superfeedback_widget;
|
|
85
89
|
if (!e) throw Error("Widget chunk failed to register");
|
|
86
90
|
return e;
|
|
@@ -90,7 +94,7 @@ var iifeLoader = async () => {
|
|
|
90
94
|
} catch {
|
|
91
95
|
return iifeLoader();
|
|
92
96
|
}
|
|
93
|
-
}, Superfeedback = class
|
|
97
|
+
}, Superfeedback = class i {
|
|
94
98
|
static #e = null;
|
|
95
99
|
static #t = "superfeedback-widget";
|
|
96
100
|
#n = null;
|
|
@@ -98,51 +102,53 @@ var iifeLoader = async () => {
|
|
|
98
102
|
#i = null;
|
|
99
103
|
#a = !1;
|
|
100
104
|
constructor(e) {
|
|
101
|
-
if (this.#r = document.createElement("div"), this.#r.id =
|
|
105
|
+
if (this.#r = document.createElement("div"), this.#r.id = i.#t, this.#r.style.position = "fixed", this.#r.style.bottom = "20px", this.#r.style.right = "20px", this.#r.style.zIndex = "9999", document.body.appendChild(this.#r), e.appId && (this.#i = new SessionTracker(e.appId, "https://app.superfeedback.ai")), !e.appId && !e.projectId) {
|
|
102
106
|
console.error("Superfeedback: appId or projectId is required");
|
|
103
107
|
return;
|
|
104
108
|
}
|
|
105
109
|
this.#o(e);
|
|
106
110
|
}
|
|
107
|
-
async #o(
|
|
111
|
+
async #o(i) {
|
|
108
112
|
if (this.#a) return;
|
|
109
113
|
this.#a = !0;
|
|
110
|
-
let
|
|
111
|
-
if (!
|
|
112
|
-
let [
|
|
113
|
-
if (
|
|
114
|
-
console.error("Superfeedback: Failed to resolve projectId from appId",
|
|
114
|
+
let a = i.projectId;
|
|
115
|
+
if (!a && i.appId) {
|
|
116
|
+
let [o, s] = await tryCatchAsync(this.#s(i.appId));
|
|
117
|
+
if (s) {
|
|
118
|
+
console.error("Superfeedback: Failed to resolve projectId from appId", s), this.#a = !1;
|
|
115
119
|
return;
|
|
116
120
|
}
|
|
117
|
-
|
|
121
|
+
a = o;
|
|
118
122
|
}
|
|
119
|
-
if (!
|
|
123
|
+
if (!a) {
|
|
120
124
|
console.log("Superfeedback: Could not determine projectId"), this.#a = !1;
|
|
121
125
|
return;
|
|
122
126
|
}
|
|
123
|
-
let [
|
|
124
|
-
if (
|
|
125
|
-
|
|
127
|
+
let [o, s] = await tryCatchAsync(loadWidgetModule());
|
|
128
|
+
if (s || !this.#r) {
|
|
129
|
+
s && console.error("Superfeedback: Failed to load widget", s), this.#r || console.error("Superfeedback: Container element not found"), this.#a = !1;
|
|
126
130
|
return;
|
|
127
131
|
}
|
|
128
|
-
let { createApp:
|
|
129
|
-
projectId:
|
|
130
|
-
previewMode:
|
|
131
|
-
config:
|
|
132
|
-
strategy:
|
|
132
|
+
let { createApp: c, Root: l } = o, u = c(l, {
|
|
133
|
+
projectId: a,
|
|
134
|
+
previewMode: i.previewMode,
|
|
135
|
+
config: i.config,
|
|
136
|
+
strategy: i.strategy
|
|
133
137
|
});
|
|
134
|
-
this.#n =
|
|
138
|
+
this.#n = u, u.mount(this.#r), this.#a = !1;
|
|
135
139
|
}
|
|
136
140
|
async #s(e) {
|
|
137
|
-
let
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
let i = "https://app.superfeedback.ai";
|
|
142
|
+
console.log("resolve project_id with url:", i);
|
|
143
|
+
let a = await fetch(`${i}/api/external/v1/apps/${e}/config`);
|
|
144
|
+
if (!a.ok) throw Error(`Failed to resolve appId: ${a.statusText}`);
|
|
145
|
+
return (await a.json()).projectId;
|
|
140
146
|
}
|
|
141
147
|
static init(e) {
|
|
142
|
-
return
|
|
148
|
+
return i.#e ||= new i(e), i.#e;
|
|
143
149
|
}
|
|
144
150
|
destroy() {
|
|
145
|
-
this.#i &&= (this.#i.destroy(), null), this.#n &&= (this.#n.unmount(), null), this.#r &&= (this.#r.remove(), null),
|
|
151
|
+
this.#i &&= (this.#i.destroy(), null), this.#n &&= (this.#n.unmount(), null), this.#r &&= (this.#r.remove(), null), i.#e = null;
|
|
146
152
|
}
|
|
147
153
|
};
|
|
148
154
|
function getAppIdFromScript() {
|