@zerohash-sdk/travel-rule-js 0.7.4 → 0.7.5
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.d.ts +4 -2
- package/dist/index.js +308 -348
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -202,8 +202,10 @@ declare abstract class BaseJsSdk<Config extends BaseConfig<never> = BaseConfig>
|
|
|
202
202
|
private getEffectiveScriptUrls(): Record<string, string> {
|
|
203
203
|
// Support local development with Vite: an internal build pins the script
|
|
204
204
|
// URL for the configured env, bypassing the CDN maps entirely.
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
// Dot access, not brackets: Vite 8 replaces `import.meta.env.KEY` with its
|
|
206
|
+
// value but inlines the whole env object for a bracket lookup.
|
|
207
|
+
if (typeof import.meta !== 'undefined' && import.meta.env?.VITE_INTERNAL_BUILD === 'true') {
|
|
208
|
+
const override = import.meta.env.VITE_SCRIPT_URL;
|
|
207
209
|
if (override) return { [this.getEnvironment()]: override };
|
|
208
210
|
}
|
|
209
211
|
|
package/dist/index.js
CHANGED
|
@@ -1,351 +1,311 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
await this.loadScript(), await this.waitForWebComponent(), this.state.scriptLoaded = !0;
|
|
269
|
-
} catch (t) {
|
|
270
|
-
throw console.error("Failed to load Connect script:", t), t;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
createWebComponent() {
|
|
274
|
-
const t = document.createElement(this.webComponentTag);
|
|
275
|
-
return Object.entries(this.config).forEach(([r, o]) => {
|
|
276
|
-
o && (t[r] = o);
|
|
277
|
-
}), t;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const J = {}, x = typeof import.meta < "u" && J?.VITE_LOCAL_CDN_HOST || "http://localhost:5173", p = {
|
|
281
|
-
local: x,
|
|
282
|
-
dev: "https://sdk-cdn.dev.0hash.com",
|
|
283
|
-
cert: "https://sdk-cdn.cert.zerohash.com",
|
|
284
|
-
prod: "https://sdk-cdn.zerohash.com",
|
|
285
|
-
"eu-cert": "https://sdk-cdn.cert.zerohash.eu",
|
|
286
|
-
"eu-prod": "https://sdk-cdn.zerohash.eu"
|
|
287
|
-
}, G = "https://sdk-cdn.gating.0hash.com", K = (e, t, r = {}) => {
|
|
288
|
-
const { eu: o = !1, legacyAliases: n = !1, local: d = p.local } = r, i = (a) => `${a}/${e}/${t}`, s = {
|
|
289
|
-
local: i(d),
|
|
290
|
-
dev: i(p.dev),
|
|
291
|
-
gating: i(G),
|
|
292
|
-
cert: i(p.cert),
|
|
293
|
-
prod: i(p.prod)
|
|
294
|
-
};
|
|
295
|
-
return n && (s.sandbox = i(p.cert), s.production = i(p.prod)), o && (s["eu-cert"] = i(p["eu-cert"]), s["eu-prod"] = i(p["eu-prod"])), s;
|
|
1
|
+
var e = {
|
|
2
|
+
dev: "https://grafana-faro-collector.dev.0hash.com/collect",
|
|
3
|
+
cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
4
|
+
prod: "https://grafana-faro-collector.zerohash.com/collect",
|
|
5
|
+
"eu-cert": "https://grafana-faro-collector.cert.zerohash.eu/collect",
|
|
6
|
+
"eu-prod": "https://grafana-faro-collector.zerohash.eu/collect",
|
|
7
|
+
sandbox: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
8
|
+
production: "https://grafana-faro-collector.zerohash.com/collect"
|
|
9
|
+
}, t = (e) => {
|
|
10
|
+
if (!e || typeof e != "string") return null;
|
|
11
|
+
let t = e.split(".");
|
|
12
|
+
if (t.length < 2) return null;
|
|
13
|
+
try {
|
|
14
|
+
let e = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = e + "===".slice(0, (4 - e.length % 4) % 4), r = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), i = JSON.parse(r)?.payload?.region;
|
|
15
|
+
if (typeof i != "string") return null;
|
|
16
|
+
let a = i.toLowerCase();
|
|
17
|
+
return a === "us" || a === "eu" ? a : null;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}, n = (e, n) => t(n) === "eu" ? e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e : e, r = (e) => {
|
|
22
|
+
if (!e || typeof e != "string") return {};
|
|
23
|
+
let t = e.split(".");
|
|
24
|
+
if (t.length < 2) return {};
|
|
25
|
+
try {
|
|
26
|
+
let e = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = e + "===".slice(0, (4 - e.length % 4) % 4), r = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), i = JSON.parse(r), a = i?.payload ?? {}, o = (e) => typeof e == "string" && e.length > 0 ? e : void 0;
|
|
27
|
+
return {
|
|
28
|
+
participantCode: o(a.participant_code),
|
|
29
|
+
platformName: o(a.platform_name),
|
|
30
|
+
platformCode: o(i.platform_code),
|
|
31
|
+
region: o(a.region)
|
|
32
|
+
};
|
|
33
|
+
} catch {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}, i = (e, t, r) => e[n(t, r)] ?? e[t] ?? e.prod, a = (e, t, r) => e[n(t, r)] ?? e[t], o = () => void 0, s = () => {
|
|
37
|
+
let e = /* @__PURE__ */ new Uint8Array(8);
|
|
38
|
+
return globalThis.crypto.getRandomValues(e), Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
39
|
+
}, c = (e, t) => {
|
|
40
|
+
let n = s(), r = globalThis.__ZH_WEB_SDK_VERSION__, i = {};
|
|
41
|
+
return e.claims.participantCode && (i.participant_code = e.claims.participantCode), e.claims.platformName && (i.platform_name = e.claims.platformName), e.claims.platformCode && (i.platform_code = e.claims.platformCode), e.claims.region && (i.region = e.claims.region), r && (i.zh_web_sdk_version = r), {
|
|
42
|
+
sessionId: n,
|
|
43
|
+
payload: {
|
|
44
|
+
meta: {
|
|
45
|
+
app: {
|
|
46
|
+
name: e.appName,
|
|
47
|
+
version: t ?? "unknown",
|
|
48
|
+
environment: e.env
|
|
49
|
+
},
|
|
50
|
+
session: {
|
|
51
|
+
id: n,
|
|
52
|
+
attributes: i
|
|
53
|
+
},
|
|
54
|
+
browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
|
|
55
|
+
page: typeof window < "u" ? { url: window.location.origin } : void 0
|
|
56
|
+
},
|
|
57
|
+
logs: [{
|
|
58
|
+
message: `Failed to load the script for ${e.webComponentTag} from ${e.env} environment.`,
|
|
59
|
+
level: "error",
|
|
60
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
61
|
+
context: {
|
|
62
|
+
web_component: e.webComponentTag,
|
|
63
|
+
script_url: e.scriptUrl,
|
|
64
|
+
reason: e.reason,
|
|
65
|
+
tried_fallback: String(e.triedFallback),
|
|
66
|
+
elapsed_ms: String(e.elapsedMs)
|
|
67
|
+
}
|
|
68
|
+
}]
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}, l = (e, t, n) => {
|
|
72
|
+
if (!e || typeof fetch > "u") return;
|
|
73
|
+
let { sessionId: r, payload: i } = c(t, n);
|
|
74
|
+
try {
|
|
75
|
+
fetch(e, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
"x-faro-session-id": r
|
|
80
|
+
},
|
|
81
|
+
body: JSON.stringify(i),
|
|
82
|
+
keepalive: !0
|
|
83
|
+
}).catch(() => void 0);
|
|
84
|
+
} catch {}
|
|
85
|
+
}, u = (e) => {
|
|
86
|
+
let { webComponentTag: t, appName: n, appVersion: s, scriptUrls: c, fallbackScriptUrls: u, collectorUrls: d, env: f, jwt: p, timeoutMs: m = 15e3, onLoad: h, onError: g } = e;
|
|
87
|
+
if (typeof document > "u") return o;
|
|
88
|
+
let _ = `${t}-script-${f}`;
|
|
89
|
+
if (customElements.get(t) || document.getElementById(_)) return o;
|
|
90
|
+
let v = r(p), y = e.report ?? ((e) => l(d && a(d, f, p), e, s)), b = !1, x = 0, S, C = () => {
|
|
91
|
+
S !== void 0 && clearTimeout(S);
|
|
92
|
+
}, w = (e, r, a) => {
|
|
93
|
+
if (b) return;
|
|
94
|
+
let o = Math.round(performance.now() - x), s = {
|
|
95
|
+
webComponentTag: t,
|
|
96
|
+
appName: n,
|
|
97
|
+
env: f,
|
|
98
|
+
scriptUrl: r,
|
|
99
|
+
reason: e,
|
|
100
|
+
triedFallback: a,
|
|
101
|
+
elapsedMs: o,
|
|
102
|
+
claims: v
|
|
103
|
+
};
|
|
104
|
+
y(s);
|
|
105
|
+
let c = a ? void 0 : i(u ?? {}, f, p);
|
|
106
|
+
if (c && c !== r) {
|
|
107
|
+
T(c, !0);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
b = !0, C(), document.getElementById(_)?.remove(), g?.(s);
|
|
111
|
+
}, T = (e, n) => {
|
|
112
|
+
C(), x = performance.now();
|
|
113
|
+
let r = document.createElement("script");
|
|
114
|
+
r.id = _, r.src = e, r.type = "module", r.async = !0, r.onload = () => {
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
b || (customElements.get(t) ? (b = !0, C(), h?.()) : w("not-defined", e, n));
|
|
117
|
+
}, 0);
|
|
118
|
+
}, r.onerror = () => w("network", e, n), S = setTimeout(() => w("timeout", e, n), m), document.getElementById(_)?.remove(), document.head.appendChild(r);
|
|
119
|
+
}, E = i(c, f, p);
|
|
120
|
+
return E ? (T(E, !1), () => {
|
|
121
|
+
b = !0, C();
|
|
122
|
+
}) : o;
|
|
123
|
+
}, d = 1e4, f = class {
|
|
124
|
+
config;
|
|
125
|
+
state;
|
|
126
|
+
scriptLoadingPromise;
|
|
127
|
+
constructor(e) {
|
|
128
|
+
if (!e.jwt || typeof e.jwt != "string") throw Error("JWT token is required and must be a string.");
|
|
129
|
+
this.config = {
|
|
130
|
+
...e,
|
|
131
|
+
env: e.env || "production",
|
|
132
|
+
theme: e.theme
|
|
133
|
+
}, this.state = {
|
|
134
|
+
initialized: !1,
|
|
135
|
+
scriptLoaded: !1,
|
|
136
|
+
container: null,
|
|
137
|
+
element: null
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async render(e) {
|
|
141
|
+
if (!e || !(e instanceof HTMLElement)) throw Error(this.errorMessages.INVALID_CONTAINER);
|
|
142
|
+
if (this.state.initialized) throw Error(this.errorMessages.ALREADY_RENDERED);
|
|
143
|
+
try {
|
|
144
|
+
await this.ensureScriptLoaded();
|
|
145
|
+
let t = this.createWebComponent();
|
|
146
|
+
e.innerHTML = "", e.appendChild(t), this.state.container = e, this.state.element = t, this.state.initialized = !0;
|
|
147
|
+
} catch (e) {
|
|
148
|
+
throw console.error("Failed to render widget:", e), e;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
updateConfig(e) {
|
|
152
|
+
if (!this.state.initialized || !this.state.element) throw Error(this.errorMessages.NOT_RENDERED);
|
|
153
|
+
let t = this.state.element;
|
|
154
|
+
Object.entries(e).forEach(([e, n]) => {
|
|
155
|
+
n && (this.config[e] = n, t[e] = n);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
destroy() {
|
|
159
|
+
this.state.initialized && (this.state.element && this.state.element.parentNode && this.state.element.parentNode.removeChild(this.state.element), this.state.container && (this.state.container.innerHTML = ""), this.state.container = null, this.state.element = null, this.state.initialized = !1);
|
|
160
|
+
}
|
|
161
|
+
isRendered() {
|
|
162
|
+
return this.state.initialized;
|
|
163
|
+
}
|
|
164
|
+
getConfig() {
|
|
165
|
+
return { ...this.config };
|
|
166
|
+
}
|
|
167
|
+
getEnvironment() {
|
|
168
|
+
return this.config.env || "production";
|
|
169
|
+
}
|
|
170
|
+
getScriptId() {
|
|
171
|
+
return `${this.webComponentTag}-script-${this.getEnvironment()}`;
|
|
172
|
+
}
|
|
173
|
+
isScriptLoaded() {
|
|
174
|
+
return !!document.getElementById(this.getScriptId());
|
|
175
|
+
}
|
|
176
|
+
getWebComponent() {
|
|
177
|
+
return customElements.get(this.webComponentTag);
|
|
178
|
+
}
|
|
179
|
+
getEffectiveScriptUrls() {
|
|
180
|
+
return this.scriptUrls;
|
|
181
|
+
}
|
|
182
|
+
async loadScript() {
|
|
183
|
+
if (!(this.getWebComponent() || this.isScriptLoaded())) {
|
|
184
|
+
if (this.scriptLoadingPromise) return this.scriptLoadingPromise;
|
|
185
|
+
this.scriptLoadingPromise = new Promise((t, n) => {
|
|
186
|
+
u({
|
|
187
|
+
webComponentTag: this.webComponentTag,
|
|
188
|
+
appName: this.webComponentTag,
|
|
189
|
+
scriptUrls: this.getEffectiveScriptUrls(),
|
|
190
|
+
collectorUrls: e,
|
|
191
|
+
env: this.getEnvironment(),
|
|
192
|
+
jwt: this.config.jwt,
|
|
193
|
+
onLoad: t,
|
|
194
|
+
onError: (e) => {
|
|
195
|
+
n(Error(e.reason === "not-defined" ? this.errorMessages.WEB_COMPONENT_NOT_DEFINED : `${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
try {
|
|
200
|
+
await this.scriptLoadingPromise;
|
|
201
|
+
} catch (e) {
|
|
202
|
+
throw this.scriptLoadingPromise = void 0, e;
|
|
203
|
+
}
|
|
204
|
+
return this.scriptLoadingPromise;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async waitForWebComponent() {
|
|
208
|
+
if (!this.getWebComponent()) return new Promise((e, t) => {
|
|
209
|
+
let n = setTimeout(() => {
|
|
210
|
+
t(/* @__PURE__ */ Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
|
|
211
|
+
}, d);
|
|
212
|
+
customElements.whenDefined(this.webComponentTag).then(() => {
|
|
213
|
+
clearTimeout(n), e();
|
|
214
|
+
}).catch((e) => {
|
|
215
|
+
clearTimeout(n), t(e);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
async ensureScriptLoaded() {
|
|
220
|
+
if (!this.state.scriptLoaded) try {
|
|
221
|
+
await this.loadScript(), await this.waitForWebComponent(), this.state.scriptLoaded = !0;
|
|
222
|
+
} catch (e) {
|
|
223
|
+
throw console.error("Failed to load Connect script:", e), e;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
createWebComponent() {
|
|
227
|
+
let e = document.createElement(this.webComponentTag);
|
|
228
|
+
return Object.entries(this.config).forEach(([t, n]) => {
|
|
229
|
+
n && (e[t] = n);
|
|
230
|
+
}), e;
|
|
231
|
+
}
|
|
232
|
+
}, p = {
|
|
233
|
+
local: {
|
|
234
|
+
BASE_URL: "/",
|
|
235
|
+
DEV: !1,
|
|
236
|
+
MODE: "production",
|
|
237
|
+
PROD: !0,
|
|
238
|
+
SSR: !1,
|
|
239
|
+
VITE_ASSETS_SERVICE_URL: "http://localhost:5173/assets",
|
|
240
|
+
VITE_CONNECT_API_BASE_URL: "/api/v1",
|
|
241
|
+
VITE_CONNECT_ENV: "local",
|
|
242
|
+
VITE_CONNECT_SDK_API_BASE_URL: "/sdk/v1",
|
|
243
|
+
VITE_DYNAMIC_ENVIRONMENT_ID: "38ce0330-c85e-414a-80b4-6129c548018f",
|
|
244
|
+
VITE_FARO_COLLECTOR_URL: "https://grafana-faro-collector.dev.0hash.com/collect",
|
|
245
|
+
VITE_FEATURE_SERVER_PROXY_URL: "https://ff-edge.dev.0hash.com/api/frontend",
|
|
246
|
+
VITE_INTERNAL_BUILD: "false",
|
|
247
|
+
VITE_ONBOARDING_API_BASE_URL: "/onboarding",
|
|
248
|
+
VITE_POST_MESSAGE_COMMUNICATION_PLATFORMS: "UW6VWU",
|
|
249
|
+
VITE_REDIRECT_HANDLER_URL: "http://localhost:4202/redirect-handler/index.html",
|
|
250
|
+
VITE_SCRAPER_EXTENSION_ID_CHROMIUM: "kofibejdfkmnbobmbogndbiimkflcllf",
|
|
251
|
+
VITE_TRADE_API_BASE_URL: "/trade",
|
|
252
|
+
VITE_UNLEASH_APIKEY: "zerohash-sdk:dev.b0d8aa594e9b94564f885167881bcb9dc69332f935fcb253e656ff34"
|
|
253
|
+
}.VITE_LOCAL_CDN_HOST || "http://localhost:5173",
|
|
254
|
+
dev: "https://sdk-cdn.dev.0hash.com",
|
|
255
|
+
cert: "https://sdk-cdn.cert.zerohash.com",
|
|
256
|
+
prod: "https://sdk-cdn.zerohash.com",
|
|
257
|
+
"eu-cert": "https://sdk-cdn.cert.zerohash.eu",
|
|
258
|
+
"eu-prod": "https://sdk-cdn.zerohash.eu"
|
|
259
|
+
}, m = "https://sdk-cdn.gating.0hash.com", h = (e, t, n = {}) => {
|
|
260
|
+
let { eu: r = !1, legacyAliases: i = !1, local: a = p.local } = n, o = (n) => `${n}/${e}/${t}`, s = {
|
|
261
|
+
local: o(a),
|
|
262
|
+
dev: o(p.dev),
|
|
263
|
+
gating: o(m),
|
|
264
|
+
cert: o(p.cert),
|
|
265
|
+
prod: o(p.prod)
|
|
266
|
+
};
|
|
267
|
+
return i && (s.sandbox = o(p.cert), s.production = o(p.prod)), r && (s["eu-cert"] = o(p["eu-cert"]), s["eu-prod"] = o(p["eu-prod"])), s;
|
|
296
268
|
};
|
|
297
|
-
|
|
269
|
+
({
|
|
270
|
+
LOADED: "travel_rule_loaded",
|
|
271
|
+
COMPLETED: "travel_rule_completed"
|
|
272
|
+
}).LOADED;
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region ../../../common/callbacks/dist/shared/models.js
|
|
275
|
+
var g;
|
|
298
276
|
(function(e) {
|
|
299
|
-
|
|
300
|
-
})(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return super.getConfig();
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Check if the TravelRule widget is currently rendered
|
|
335
|
-
* @returns True if the widget is rendered, false otherwise
|
|
336
|
-
*/
|
|
337
|
-
isRendered() {
|
|
338
|
-
return super.isRendered();
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Destroy the TravelRule widget and clean up resources
|
|
342
|
-
*/
|
|
343
|
-
destroy() {
|
|
344
|
-
return super.destroy();
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
export {
|
|
348
|
-
O as ErrorCode,
|
|
349
|
-
Y as TravelRule,
|
|
350
|
-
Y as default
|
|
277
|
+
e.NETWORK_ERROR = "network_error", e.AUTH_ERROR = "auth_error", e.NOT_FOUND_ERROR = "not_found_error", e.VALIDATION_ERROR = "validation_error", e.SERVER_ERROR = "server_error", e.CLIENT_ERROR = "client_error", e.UNKNOWN_ERROR = "unknown_error";
|
|
278
|
+
})(g ||= {});
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/lib/travel-rule.ts
|
|
281
|
+
var _ = class extends f {
|
|
282
|
+
errorMessages = {
|
|
283
|
+
ALREADY_RENDERED: "TravelRule widget is already rendered. Call destroy() before rendering again.",
|
|
284
|
+
NOT_RENDERED: "TravelRule widget is not rendered. Call render() first.",
|
|
285
|
+
INVALID_CONTAINER: "Invalid container element provided.",
|
|
286
|
+
SCRIPT_LOAD_FAILED: "Failed to load the Zerohash TravelRule script.",
|
|
287
|
+
WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
|
|
288
|
+
};
|
|
289
|
+
scriptUrls = h("travel-rule-web", "index.js", {
|
|
290
|
+
legacyAliases: !0,
|
|
291
|
+
eu: !0
|
|
292
|
+
});
|
|
293
|
+
webComponentTag = "zerohash-travel-rule";
|
|
294
|
+
render(e) {
|
|
295
|
+
return super.render(e);
|
|
296
|
+
}
|
|
297
|
+
updateConfig(e) {
|
|
298
|
+
return super.updateConfig(e);
|
|
299
|
+
}
|
|
300
|
+
getConfig() {
|
|
301
|
+
return super.getConfig();
|
|
302
|
+
}
|
|
303
|
+
isRendered() {
|
|
304
|
+
return super.isRendered();
|
|
305
|
+
}
|
|
306
|
+
destroy() {
|
|
307
|
+
return super.destroy();
|
|
308
|
+
}
|
|
351
309
|
};
|
|
310
|
+
//#endregion
|
|
311
|
+
export { g as ErrorCode, _ as TravelRule, _ as default };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.TravelRule={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=`JWT token is required and must be a string.`,n={dev:`https://grafana-faro-collector.dev.0hash.com/collect`,cert:`https://grafana-faro-collector.cert.zerohash.com/collect`,prod:`https://grafana-faro-collector.zerohash.com/collect`,"eu-cert":`https://grafana-faro-collector.cert.zerohash.eu/collect`,"eu-prod":`https://grafana-faro-collector.zerohash.eu/collect`,sandbox:`https://grafana-faro-collector.cert.zerohash.com/collect`,production:`https://grafana-faro-collector.zerohash.com/collect`},r=e=>{if(!e||typeof e!=`string`)return null;let t=e.split(`.`);if(t.length<2)return null;try{let e=t[1].replace(/-/g,`+`).replace(/_/g,`/`),n=e+`===`.slice(0,(4-e.length%4)%4),r=typeof atob<`u`?atob(n):Buffer.from(n,`base64`).toString(`utf-8`),i=JSON.parse(r)?.payload?.region;if(typeof i!=`string`)return null;let a=i.toLowerCase();return a===`us`||a===`eu`?a:null}catch{return null}},i=(e,t)=>r(t)===`eu`?e===`cert`?`eu-cert`:e===`prod`?`eu-prod`:e:e,a=e=>{if(!e||typeof e!=`string`)return{};let t=e.split(`.`);if(t.length<2)return{};try{let e=t[1].replace(/-/g,`+`).replace(/_/g,`/`),n=e+`===`.slice(0,(4-e.length%4)%4),r=typeof atob<`u`?atob(n):Buffer.from(n,`base64`).toString(`utf-8`),i=JSON.parse(r),a=i?.payload??{},o=e=>typeof e==`string`&&e.length>0?e:void 0;return{participantCode:o(a.participant_code),platformName:o(a.platform_name),platformCode:o(i.platform_code),region:o(a.region)}}catch{return{}}},o=(e,t,n)=>e[i(t,n)]??e[t]??e.prod,s=(e,t,n)=>e[i(t,n)]??e[t],c=()=>void 0,l=()=>{let e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)},u=(e,t)=>{let n=l(),r=globalThis.__ZH_WEB_SDK_VERSION__,i={};return e.claims.participantCode&&(i.participant_code=e.claims.participantCode),e.claims.platformName&&(i.platform_name=e.claims.platformName),e.claims.platformCode&&(i.platform_code=e.claims.platformCode),e.claims.region&&(i.region=e.claims.region),r&&(i.zh_web_sdk_version=r),{sessionId:n,payload:{meta:{app:{name:e.appName,version:t??`unknown`,environment:e.env},session:{id:n,attributes:i},browser:typeof navigator<`u`?{userAgent:navigator.userAgent}:void 0,page:typeof window<`u`?{url:window.location.origin}:void 0},logs:[{message:`Failed to load the script for ${e.webComponentTag} from ${e.env} environment.`,level:`error`,timestamp:new Date().toISOString(),context:{web_component:e.webComponentTag,script_url:e.scriptUrl,reason:e.reason,tried_fallback:String(e.triedFallback),elapsed_ms:String(e.elapsedMs)}}]}}},d=(e,t,n)=>{if(!e||typeof fetch>`u`)return;let{sessionId:r,payload:i}=u(t,n);try{fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`,"x-faro-session-id":r},body:JSON.stringify(i),keepalive:!0}).catch(()=>void 0)}catch{}},f=e=>{let{webComponentTag:t,appName:n,appVersion:r,scriptUrls:i,fallbackScriptUrls:l,collectorUrls:u,env:f,jwt:p,timeoutMs:m=15e3,onLoad:h,onError:g}=e;if(typeof document>`u`)return c;let _=`${t}-script-${f}`;if(customElements.get(t)||document.getElementById(_))return c;let v=a(p),y=e.report??(e=>d(u&&s(u,f,p),e,r)),b=!1,x=0,S,C=()=>{S!==void 0&&clearTimeout(S)},w=(e,r,i)=>{if(b)return;let a=Math.round(performance.now()-x),s={webComponentTag:t,appName:n,env:f,scriptUrl:r,reason:e,triedFallback:i,elapsedMs:a,claims:v};y(s);let c=i?void 0:o(l??{},f,p);if(c&&c!==r){T(c,!0);return}b=!0,C(),document.getElementById(_)?.remove(),g?.(s)},T=(e,n)=>{C(),x=performance.now();let r=document.createElement(`script`);r.id=_,r.src=e,r.type=`module`,r.async=!0,r.onload=()=>{setTimeout(()=>{b||(customElements.get(t)?(b=!0,C(),h?.()):w(`not-defined`,e,n))},0)},r.onerror=()=>w(`network`,e,n),S=setTimeout(()=>w(`timeout`,e,n),m),document.getElementById(_)?.remove(),document.head.appendChild(r)},E=o(i,f,p);return E?(T(E,!1),()=>{b=!0,C()}):c},p=1e4,m=class{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!=`string`)throw Error(t);this.config={...e,env:e.env||`production`,theme:e.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(e){if(!e||!(e instanceof HTMLElement))throw Error(this.errorMessages.INVALID_CONTAINER);if(this.state.initialized)throw Error(this.errorMessages.ALREADY_RENDERED);try{await this.ensureScriptLoaded();let t=this.createWebComponent();e.innerHTML=``,e.appendChild(t),this.state.container=e,this.state.element=t,this.state.initialized=!0}catch(e){throw console.error(`Failed to render widget:`,e),e}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw Error(this.errorMessages.NOT_RENDERED);let t=this.state.element;Object.entries(e).forEach(([e,n])=>{n&&(this.config[e]=n,t[e]=n)})}destroy(){this.state.initialized&&(this.state.element&&this.state.element.parentNode&&this.state.element.parentNode.removeChild(this.state.element),this.state.container&&(this.state.container.innerHTML=``),this.state.container=null,this.state.element=null,this.state.initialized=!1)}isRendered(){return this.state.initialized}getConfig(){return{...this.config}}getEnvironment(){return this.config.env||`production`}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getEffectiveScriptUrls(){return this.scriptUrls}async loadScript(){if(!(this.getWebComponent()||this.isScriptLoaded())){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((e,t)=>{f({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:n,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:e,onError:e=>{t(Error(e.reason===`not-defined`?this.errorMessages.WEB_COMPONENT_NOT_DEFINED:`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))}})});try{await this.scriptLoadingPromise}catch(e){throw this.scriptLoadingPromise=void 0,e}return this.scriptLoadingPromise}}async waitForWebComponent(){if(!this.getWebComponent())return new Promise((e,t)=>{let n=setTimeout(()=>{t(Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},p);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(n),e()}).catch(e=>{clearTimeout(n),t(e)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(e){throw console.error(`Failed to load Connect script:`,e),e}}createWebComponent(){let e=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([t,n])=>{n&&(e[t]=n)}),e}},h={local:{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ASSETS_SERVICE_URL:`http://localhost:5173/assets`,VITE_CONNECT_API_BASE_URL:`/api/v1`,VITE_CONNECT_ENV:`local`,VITE_CONNECT_SDK_API_BASE_URL:`/sdk/v1`,VITE_DYNAMIC_ENVIRONMENT_ID:`38ce0330-c85e-414a-80b4-6129c548018f`,VITE_FARO_COLLECTOR_URL:`https://grafana-faro-collector.dev.0hash.com/collect`,VITE_FEATURE_SERVER_PROXY_URL:`https://ff-edge.dev.0hash.com/api/frontend`,VITE_INTERNAL_BUILD:`false`,VITE_ONBOARDING_API_BASE_URL:`/onboarding`,VITE_POST_MESSAGE_COMMUNICATION_PLATFORMS:`UW6VWU`,VITE_REDIRECT_HANDLER_URL:`http://localhost:4202/redirect-handler/index.html`,VITE_SCRAPER_EXTENSION_ID_CHROMIUM:`kofibejdfkmnbobmbogndbiimkflcllf`,VITE_TRADE_API_BASE_URL:`/trade`,VITE_UNLEASH_APIKEY:`zerohash-sdk:dev.b0d8aa594e9b94564f885167881bcb9dc69332f935fcb253e656ff34`}.VITE_LOCAL_CDN_HOST||`http://localhost:5173`,dev:`https://sdk-cdn.dev.0hash.com`,cert:`https://sdk-cdn.cert.zerohash.com`,prod:`https://sdk-cdn.zerohash.com`,"eu-cert":`https://sdk-cdn.cert.zerohash.eu`,"eu-prod":`https://sdk-cdn.zerohash.eu`},g=`https://sdk-cdn.gating.0hash.com`,_=(e,t,n={})=>{let{eu:r=!1,legacyAliases:i=!1,local:a=h.local}=n,o=n=>`${n}/${e}/${t}`,s={local:o(a),dev:o(h.dev),gating:o(g),cert:o(h.cert),prod:o(h.prod)};return i&&(s.sandbox=o(h.cert),s.production=o(h.prod)),r&&(s[`eu-cert`]=o(h[`eu-cert`]),s[`eu-prod`]=o(h[`eu-prod`])),s};({LOADED:`travel_rule_loaded`,COMPLETED:`travel_rule_completed`}).LOADED;var v;(function(e){e.NETWORK_ERROR=`network_error`,e.AUTH_ERROR=`auth_error`,e.NOT_FOUND_ERROR=`not_found_error`,e.VALIDATION_ERROR=`validation_error`,e.SERVER_ERROR=`server_error`,e.CLIENT_ERROR=`client_error`,e.UNKNOWN_ERROR=`unknown_error`})(v||={});var y=class extends m{errorMessages={ALREADY_RENDERED:`TravelRule widget is already rendered. Call destroy() before rendering again.`,NOT_RENDERED:`TravelRule widget is not rendered. Call render() first.`,INVALID_CONTAINER:`Invalid container element provided.`,SCRIPT_LOAD_FAILED:`Failed to load the Zerohash TravelRule script.`,WEB_COMPONENT_NOT_DEFINED:`Web component is not defined. Script may not be loaded.`};scriptUrls=_(`travel-rule-web`,`index.js`,{legacyAliases:!0,eu:!0});webComponentTag=`zerohash-travel-rule`;render(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}};Object.defineProperty(e,"ErrorCode",{enumerable:!0,get:function(){return v}}),e.TravelRule=y,e.default=y});
|