@superfeedback/widget 0.0.18 → 0.0.20
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/README.md +4 -4
- package/dist/dist-CU9w03k6.js +9483 -0
- package/dist/index.d.ts +4 -11
- package/dist/index.iife.js +23 -1
- package/dist/index.js +102 -80
- package/dist/vue/index.js +15455 -0
- package/dist/vue/root.vue.d.ts +15 -0
- package/dist/vue/style.css +2 -0
- package/dist/vue/vue.d.ts +22 -0
- package/dist/widget.d.ts +4 -6
- package/dist/widget.iife.js +5 -5
- package/dist/widget.js +5812 -15430
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,126 +1,148 @@
|
|
|
1
|
+
import { t as tryCatchAsync } from "./dist-CU9w03k6.js";
|
|
1
2
|
var VISITOR_ID_KEY = "sf_visitor_id", SessionTracker = class {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(e,
|
|
10
|
-
this
|
|
11
|
-
}
|
|
12
|
-
|
|
3
|
+
#e;
|
|
4
|
+
#t;
|
|
5
|
+
#n;
|
|
6
|
+
#r;
|
|
7
|
+
#i;
|
|
8
|
+
#a = 0;
|
|
9
|
+
#o = !0;
|
|
10
|
+
constructor(e, r) {
|
|
11
|
+
this.#e = e, this.#t = r, this.#i = Date.now(), this.#n = this.#s(), this.#r = crypto.randomUUID(), this.#m();
|
|
12
|
+
}
|
|
13
|
+
#s() {
|
|
13
14
|
try {
|
|
14
|
-
let
|
|
15
|
-
if (
|
|
16
|
-
let
|
|
17
|
-
return localStorage.setItem(VISITOR_ID_KEY,
|
|
15
|
+
let e = localStorage.getItem(VISITOR_ID_KEY);
|
|
16
|
+
if (e) return e;
|
|
17
|
+
let i = crypto.randomUUID();
|
|
18
|
+
return localStorage.setItem(VISITOR_ID_KEY, i), i;
|
|
18
19
|
} catch {
|
|
19
20
|
return crypto.randomUUID();
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
#c() {
|
|
23
24
|
let e = navigator.userAgent;
|
|
24
25
|
return e.includes("Windows") ? "Windows" : e.includes("Mac OS") ? "macOS" : e.includes("Linux") ? "Linux" : e.includes("Android") ? "Android" : e.includes("iOS") || e.includes("iPhone") || e.includes("iPad") ? "iOS" : "Unknown";
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
#l() {
|
|
27
28
|
let e = navigator.userAgent;
|
|
28
29
|
return /Tablet|iPad/i.test(e) ? "tablet" : /Mobile|iPhone|Android.*Mobile/i.test(e) ? "mobile" : "desktop";
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
let e = this
|
|
32
|
-
return this
|
|
31
|
+
#u() {
|
|
32
|
+
let e = this.#o ? Date.now() - this.#i : 0;
|
|
33
|
+
return this.#a + e;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
#d() {
|
|
35
36
|
return {
|
|
36
|
-
appId: this
|
|
37
|
-
visitorId: this
|
|
38
|
-
sessionId: this
|
|
39
|
-
sessionDurationMs: this
|
|
37
|
+
appId: this.#e,
|
|
38
|
+
visitorId: this.#n,
|
|
39
|
+
sessionId: this.#r,
|
|
40
|
+
sessionDurationMs: this.#u(),
|
|
40
41
|
userAgent: navigator.userAgent,
|
|
41
|
-
os: this
|
|
42
|
-
deviceType: this
|
|
42
|
+
os: this.#c(),
|
|
43
|
+
deviceType: this.#l()
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
if (this
|
|
47
|
-
let e = this
|
|
48
|
-
fetch(
|
|
46
|
+
#f() {
|
|
47
|
+
if (this.#u() < 1e3) return;
|
|
48
|
+
let e = this.#d(), r = `${this.#t}/api/external/v1/apps/${this.#e}/sessions`, i = JSON.stringify(e);
|
|
49
|
+
fetch(r, {
|
|
49
50
|
method: "POST",
|
|
50
51
|
headers: { "Content-Type": "application/json" },
|
|
51
|
-
body:
|
|
52
|
+
body: i,
|
|
52
53
|
keepalive: !0,
|
|
53
54
|
credentials: "omit"
|
|
54
|
-
}).catch(() => {}), this
|
|
55
|
+
}).catch(() => {}), this.#a = 0, this.#i = Date.now();
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
document.visibilityState === "hidden" ? (this
|
|
57
|
+
#p() {
|
|
58
|
+
document.visibilityState === "hidden" ? (this.#a += Date.now() - this.#i, this.#o = !1, this.#f()) : (this.#o = !0, this.#i = Date.now());
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
+
#m() {
|
|
60
61
|
window.addEventListener("beforeunload", () => {
|
|
61
|
-
this
|
|
62
|
+
this.#f();
|
|
62
63
|
}), document.addEventListener("visibilitychange", () => {
|
|
63
|
-
this
|
|
64
|
+
this.#p();
|
|
64
65
|
}), window.addEventListener("pagehide", () => {
|
|
65
|
-
this
|
|
66
|
+
this.#f();
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
69
|
destroy() {
|
|
69
|
-
this
|
|
70
|
+
this.#f();
|
|
70
71
|
}
|
|
71
72
|
}, __widgetBaseUrl = null;
|
|
72
73
|
typeof document < "u" && document.currentScript && (__widgetBaseUrl = document.currentScript.src);
|
|
73
74
|
function loadScript(e) {
|
|
74
|
-
return new Promise((
|
|
75
|
-
let
|
|
76
|
-
|
|
75
|
+
return new Promise((r, i) => {
|
|
76
|
+
let a = document.createElement("script");
|
|
77
|
+
a.src = e, a.onload = () => r(), a.onerror = () => i(/* @__PURE__ */ Error(`Failed to load: ${e}`)), document.head.appendChild(a);
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
|
-
async
|
|
80
|
+
var iifeLoader = async () => {
|
|
81
|
+
if (window.__superfeedback_widget) return window.__superfeedback_widget;
|
|
82
|
+
if (!__widgetBaseUrl) throw Error("Cannot determine widget chunk URL");
|
|
83
|
+
await loadScript(`${__widgetBaseUrl}/dist/widget.iife.js`);
|
|
84
|
+
let e = window.__superfeedback_widget;
|
|
85
|
+
if (!e) throw Error("Widget chunk failed to register");
|
|
86
|
+
return e;
|
|
87
|
+
}, loadWidgetModule = async () => {
|
|
80
88
|
try {
|
|
81
89
|
return await import("./widget.js");
|
|
82
90
|
} catch {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
config: e.config,
|
|
109
|
-
strategy: e.strategy
|
|
110
|
-
});
|
|
111
|
-
this.app = s, s.mount(this.container);
|
|
112
|
-
} catch (e) {
|
|
113
|
-
console.error("Superfeedback: Failed to load widget", e);
|
|
114
|
-
} finally {
|
|
115
|
-
this.isLoading = !1;
|
|
91
|
+
return iifeLoader();
|
|
92
|
+
}
|
|
93
|
+
}, Superfeedback = class r {
|
|
94
|
+
static #e = null;
|
|
95
|
+
static #t = "superfeedback-widget";
|
|
96
|
+
#n = null;
|
|
97
|
+
#r = null;
|
|
98
|
+
#i = null;
|
|
99
|
+
#a = !1;
|
|
100
|
+
constructor(e) {
|
|
101
|
+
if (this.#r = document.createElement("div"), this.#r.id = r.#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
|
+
console.error("Superfeedback: appId or projectId is required");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
this.#o(e);
|
|
106
|
+
}
|
|
107
|
+
async #o(r) {
|
|
108
|
+
if (this.#a) return;
|
|
109
|
+
this.#a = !0;
|
|
110
|
+
let i = r.projectId;
|
|
111
|
+
if (!i && r.appId) {
|
|
112
|
+
let [a, o] = await tryCatchAsync(this.#s(r.appId));
|
|
113
|
+
if (o) {
|
|
114
|
+
console.error("Superfeedback: Failed to resolve projectId from appId", o), this.#a = !1;
|
|
115
|
+
return;
|
|
116
116
|
}
|
|
117
|
+
i = a;
|
|
118
|
+
}
|
|
119
|
+
if (!i) {
|
|
120
|
+
console.error("Superfeedback: Could not determine projectId"), this.#a = !1;
|
|
121
|
+
return;
|
|
117
122
|
}
|
|
123
|
+
let [a, o] = await tryCatchAsync(loadWidgetModule());
|
|
124
|
+
if (o || !this.#r) {
|
|
125
|
+
o && console.error("Superfeedback: Failed to load widget", o), this.#r || console.error("Superfeedback: Container element not found"), this.#a = !1;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
let { createApp: s, Root: c } = a, l = s(c, {
|
|
129
|
+
projectId: i,
|
|
130
|
+
previewMode: r.previewMode,
|
|
131
|
+
config: r.config,
|
|
132
|
+
strategy: r.strategy
|
|
133
|
+
});
|
|
134
|
+
this.#n = l, l.mount(this.#r), this.#a = !1;
|
|
135
|
+
}
|
|
136
|
+
async #s(e) {
|
|
137
|
+
let r = await fetch(`https://app.superfeedback.ai/external/v1/apps/${e}/config`);
|
|
138
|
+
if (!r.ok) throw Error(`Failed to resolve appId: ${r.statusText}`);
|
|
139
|
+
return (await r.json()).projectId;
|
|
118
140
|
}
|
|
119
|
-
static init(
|
|
120
|
-
return e
|
|
141
|
+
static init(e) {
|
|
142
|
+
return r.#e ||= new r(e), r.#e;
|
|
121
143
|
}
|
|
122
144
|
destroy() {
|
|
123
|
-
this
|
|
145
|
+
this.#i &&= (this.#i.destroy(), null), this.#n &&= (this.#n.unmount(), null), this.#r &&= (this.#r.remove(), null), r.#e = null;
|
|
124
146
|
}
|
|
125
147
|
};
|
|
126
148
|
function getAppIdFromScript() {
|