@zerohash-sdk/csp-crypto-withdrawals-js 1.6.1 → 1.6.3
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 +2 -2
- package/dist/index.d.ts +35 -10
- package/dist/index.js +98 -90
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,14 +21,14 @@ import { CspCryptoWithdrawals } from '@zerohash-sdk/csp-crypto-withdrawals-js';
|
|
|
21
21
|
```html
|
|
22
22
|
<script
|
|
23
23
|
type="module"
|
|
24
|
-
src="https://sdk.
|
|
24
|
+
src="https://sdk-cdn.zerohash.com/csp-crypto-withdrawals-web/index.js"
|
|
25
25
|
></script>
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
Or import directly in your JavaScript code:
|
|
29
29
|
|
|
30
30
|
```javascript
|
|
31
|
-
import { CspCryptoWithdrawals } from 'https://sdk.
|
|
31
|
+
import { CspCryptoWithdrawals } from 'https://sdk-cdn.zerohash.com/csp-crypto-withdrawals-web/index.js';
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## Getting Started
|
package/dist/index.d.ts
CHANGED
|
@@ -318,6 +318,11 @@ declare type CommonCallbacks<TEvent = AppEvent> = {
|
|
|
318
318
|
onEvent?: (event: TEvent) => void;
|
|
319
319
|
/** Called when the widget has loaded and is ready */
|
|
320
320
|
onLoaded?: () => void;
|
|
321
|
+
/**
|
|
322
|
+
* Called when a deposit reaches a terminal state (success/failure/verifying).
|
|
323
|
+
* Optional — only SDKs that drive the integrations deposit flow emit it.
|
|
324
|
+
*/
|
|
325
|
+
onDeposit?: (deposit: DepositCompletedPayload) => void;
|
|
321
326
|
};
|
|
322
327
|
|
|
323
328
|
/**
|
|
@@ -355,16 +360,7 @@ declare class CspCryptoWithdrawals extends BaseJsSdk<CspCryptoWithdrawalsConfig>
|
|
|
355
360
|
SCRIPT_LOAD_FAILED: string;
|
|
356
361
|
WEB_COMPONENT_NOT_DEFINED: string;
|
|
357
362
|
};
|
|
358
|
-
protected scriptUrls:
|
|
359
|
-
local: string;
|
|
360
|
-
dev: string;
|
|
361
|
-
cert: string;
|
|
362
|
-
prod: string;
|
|
363
|
-
sandbox: string;
|
|
364
|
-
production: string;
|
|
365
|
-
'eu-cert': string;
|
|
366
|
-
'eu-prod': string;
|
|
367
|
-
};
|
|
363
|
+
protected scriptUrls: Record<string, string>;
|
|
368
364
|
protected webComponentTag: string;
|
|
369
365
|
render(container: HTMLElement): Promise<void>;
|
|
370
366
|
updateConfig(config: Partial<CspCryptoWithdrawalsConfig>): void;
|
|
@@ -406,6 +402,35 @@ declare type CspCryptoWithdrawalsEvent = AppEvent<CspCryptoWithdrawalsEventType>
|
|
|
406
402
|
*/
|
|
407
403
|
declare type CspCryptoWithdrawalsEventType = string;
|
|
408
404
|
|
|
405
|
+
/**
|
|
406
|
+
* Deposit completed payload — emitted by SDKs that drive a deposit through
|
|
407
|
+
* the integrations flow. Lives on `CommonCallbacks` because both Auth and
|
|
408
|
+
* any SDK embedding `@zerohash/integrations-flow` (e.g. fund with `useAuth`)
|
|
409
|
+
* resolve through the same deposit-status hook.
|
|
410
|
+
*/
|
|
411
|
+
declare type DepositCompletedPayload = {
|
|
412
|
+
data: {
|
|
413
|
+
depositId: string;
|
|
414
|
+
status: DepositStatus;
|
|
415
|
+
assetId: string;
|
|
416
|
+
networkId: string;
|
|
417
|
+
amount?: string;
|
|
418
|
+
accountMatchingValidation?: {
|
|
419
|
+
status: 'PENDING' | 'VALID' | 'INVALID' | 'ERROR';
|
|
420
|
+
reason?: string;
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Deposit status object — shared across SDKs that surface deposit completion.
|
|
427
|
+
*/
|
|
428
|
+
declare type DepositStatus = {
|
|
429
|
+
value: string;
|
|
430
|
+
details: string;
|
|
431
|
+
occurredAt: string;
|
|
432
|
+
};
|
|
433
|
+
|
|
409
434
|
/**
|
|
410
435
|
* Environment configuration for the SDK
|
|
411
436
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const T = "production", W = "JWT token is required and must be a string.", M = {
|
|
2
2
|
dev: "https://grafana-faro-collector.dev.0hash.com/collect",
|
|
3
3
|
cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
4
4
|
prod: "https://grafana-faro-collector.zerohash.com/collect",
|
|
@@ -6,55 +6,55 @@ const R = "production", z = "JWT token is required and must be a string.", W = {
|
|
|
6
6
|
"eu-prod": "https://grafana-faro-collector.zerohash.eu/collect",
|
|
7
7
|
sandbox: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
8
8
|
production: "https://grafana-faro-collector.zerohash.com/collect"
|
|
9
|
-
},
|
|
9
|
+
}, P = (e) => {
|
|
10
10
|
if (!e || typeof e != "string")
|
|
11
11
|
return null;
|
|
12
12
|
const t = e.split(".");
|
|
13
13
|
if (t.length < 2)
|
|
14
14
|
return null;
|
|
15
15
|
try {
|
|
16
|
-
const r = t[1].replace(/-/g, "+").replace(/_/g, "/"),
|
|
17
|
-
if (typeof
|
|
16
|
+
const r = t[1].replace(/-/g, "+").replace(/_/g, "/"), o = r + "===".slice(0, (4 - r.length % 4) % 4), n = typeof atob < "u" ? atob(o) : Buffer.from(o, "base64").toString("utf-8"), i = JSON.parse(n)?.payload?.region;
|
|
17
|
+
if (typeof i != "string")
|
|
18
18
|
return null;
|
|
19
|
-
const s =
|
|
19
|
+
const s = i.toLowerCase();
|
|
20
20
|
return s === "us" || s === "eu" ? s : null;
|
|
21
21
|
} catch {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
|
-
}, O = (e, t) =>
|
|
24
|
+
}, O = (e, t) => P(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, U = (e) => {
|
|
25
25
|
if (!e || typeof e != "string")
|
|
26
26
|
return {};
|
|
27
27
|
const t = e.split(".");
|
|
28
28
|
if (t.length < 2)
|
|
29
29
|
return {};
|
|
30
30
|
try {
|
|
31
|
-
const r = t[1].replace(/-/g, "+").replace(/_/g, "/"),
|
|
31
|
+
const r = t[1].replace(/-/g, "+").replace(/_/g, "/"), o = r + "===".slice(0, (4 - r.length % 4) % 4), n = typeof atob < "u" ? atob(o) : Buffer.from(o, "base64").toString("utf-8"), a = JSON.parse(n), i = a?.payload ?? {}, s = (c) => typeof c == "string" && c.length > 0 ? c : void 0;
|
|
32
32
|
return {
|
|
33
|
-
participantCode: s(
|
|
34
|
-
platformName: s(
|
|
33
|
+
participantCode: s(i.participant_code),
|
|
34
|
+
platformName: s(i.platform_name),
|
|
35
35
|
platformCode: s(a.platform_code),
|
|
36
|
-
region: s(
|
|
36
|
+
region: s(i.region)
|
|
37
37
|
};
|
|
38
38
|
} catch {
|
|
39
39
|
return {};
|
|
40
40
|
}
|
|
41
|
-
},
|
|
42
|
-
const
|
|
43
|
-
return e[
|
|
44
|
-
},
|
|
45
|
-
const
|
|
46
|
-
return e[
|
|
47
|
-
},
|
|
48
|
-
},
|
|
41
|
+
}, N = (e, t, r) => {
|
|
42
|
+
const o = O(t, r);
|
|
43
|
+
return e[o] ?? e[t] ?? e.prod;
|
|
44
|
+
}, k = (e, t, r) => {
|
|
45
|
+
const o = O(t, r);
|
|
46
|
+
return e[o] ?? e[t];
|
|
47
|
+
}, _ = () => {
|
|
48
|
+
}, F = () => {
|
|
49
49
|
const e = new Uint8Array(8);
|
|
50
50
|
return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
|
|
51
|
-
},
|
|
52
|
-
const r =
|
|
53
|
-
e.claims.participantCode && (
|
|
51
|
+
}, $ = (e, t) => {
|
|
52
|
+
const r = F(), o = globalThis.__ZH_WEB_SDK_VERSION__, n = {};
|
|
53
|
+
e.claims.participantCode && (n.participant_code = e.claims.participantCode), e.claims.platformName && (n.platform_name = e.claims.platformName), e.claims.platformCode && (n.platform_code = e.claims.platformCode), e.claims.region && (n.region = e.claims.region), o && (n.zh_web_sdk_version = o);
|
|
54
54
|
const a = {
|
|
55
55
|
meta: {
|
|
56
56
|
app: { name: e.appName, version: t ?? "unknown", environment: e.env },
|
|
57
|
-
session: { id: r, attributes:
|
|
57
|
+
session: { id: r, attributes: n },
|
|
58
58
|
browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
|
|
59
59
|
page: typeof window < "u" ? { url: window.location.origin } : void 0
|
|
60
60
|
},
|
|
@@ -74,74 +74,74 @@ const R = "production", z = "JWT token is required and must be a string.", W = {
|
|
|
74
74
|
]
|
|
75
75
|
};
|
|
76
76
|
return { sessionId: r, payload: a };
|
|
77
|
-
},
|
|
77
|
+
}, B = (e, t, r) => {
|
|
78
78
|
if (!e || typeof fetch > "u")
|
|
79
79
|
return;
|
|
80
|
-
const { sessionId:
|
|
80
|
+
const { sessionId: o, payload: n } = $(t, r);
|
|
81
81
|
try {
|
|
82
82
|
fetch(e, {
|
|
83
83
|
method: "POST",
|
|
84
|
-
headers: { "Content-Type": "application/json", "x-faro-session-id":
|
|
85
|
-
body: JSON.stringify(
|
|
84
|
+
headers: { "Content-Type": "application/json", "x-faro-session-id": o },
|
|
85
|
+
body: JSON.stringify(n),
|
|
86
86
|
keepalive: !0
|
|
87
87
|
}).catch(() => {
|
|
88
88
|
});
|
|
89
89
|
} catch {
|
|
90
90
|
}
|
|
91
|
-
},
|
|
92
|
-
const { webComponentTag: t, appName: r, appVersion:
|
|
91
|
+
}, V = (e) => {
|
|
92
|
+
const { webComponentTag: t, appName: r, appVersion: o, scriptUrls: n, fallbackScriptUrls: a, collectorUrls: i, env: s, jwt: c, timeoutMs: L = 15e3, onLoad: v, onError: I } = e;
|
|
93
93
|
if (typeof document > "u")
|
|
94
|
-
return
|
|
94
|
+
return _;
|
|
95
95
|
const m = `${t}-script-${s}`;
|
|
96
96
|
if (customElements.get(t) || document.getElementById(m))
|
|
97
|
-
return
|
|
98
|
-
const
|
|
99
|
-
let h = !1,
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
},
|
|
97
|
+
return _;
|
|
98
|
+
const A = U(c), D = e.report ?? ((l) => B(i && k(i, s, c), l, o));
|
|
99
|
+
let h = !1, C = 0, g;
|
|
100
|
+
const f = () => {
|
|
101
|
+
g !== void 0 && clearTimeout(g);
|
|
102
|
+
}, E = (l, u, d) => {
|
|
103
103
|
if (h)
|
|
104
104
|
return;
|
|
105
|
-
const
|
|
105
|
+
const z = Math.round(performance.now() - C), b = {
|
|
106
106
|
webComponentTag: t,
|
|
107
107
|
appName: r,
|
|
108
108
|
env: s,
|
|
109
|
-
scriptUrl:
|
|
109
|
+
scriptUrl: u,
|
|
110
110
|
reason: l,
|
|
111
|
-
triedFallback:
|
|
112
|
-
elapsedMs:
|
|
113
|
-
claims:
|
|
111
|
+
triedFallback: d,
|
|
112
|
+
elapsedMs: z,
|
|
113
|
+
claims: A
|
|
114
114
|
};
|
|
115
|
-
D(
|
|
116
|
-
const w =
|
|
117
|
-
if (w && w !==
|
|
118
|
-
|
|
115
|
+
D(b);
|
|
116
|
+
const w = d ? void 0 : N(a ?? {}, s, c);
|
|
117
|
+
if (w && w !== u) {
|
|
118
|
+
y(w, !0);
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
h = !0,
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
121
|
+
h = !0, f(), document.getElementById(m)?.remove(), I?.(b);
|
|
122
|
+
}, y = (l, u) => {
|
|
123
|
+
f(), C = performance.now();
|
|
124
|
+
const d = document.createElement("script");
|
|
125
|
+
d.id = m, d.src = l, d.type = "module", d.async = !0, d.onload = () => {
|
|
126
126
|
setTimeout(() => {
|
|
127
|
-
h || (customElements.get(t) ? (h = !0,
|
|
127
|
+
h || (customElements.get(t) ? (h = !0, f(), v?.()) : E("not-defined", l, u));
|
|
128
128
|
}, 0);
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
return
|
|
132
|
-
h = !0,
|
|
133
|
-
}) :
|
|
129
|
+
}, d.onerror = () => E("network", l, u), g = setTimeout(() => E("timeout", l, u), L), document.getElementById(m)?.remove(), document.head.appendChild(d);
|
|
130
|
+
}, R = N(n, s, c);
|
|
131
|
+
return R ? (y(R, !1), () => {
|
|
132
|
+
h = !0, f();
|
|
133
|
+
}) : _;
|
|
134
134
|
};
|
|
135
|
-
class
|
|
135
|
+
class j {
|
|
136
136
|
config;
|
|
137
137
|
state;
|
|
138
138
|
scriptLoadingPromise;
|
|
139
139
|
constructor(t) {
|
|
140
140
|
if (!t.jwt || typeof t.jwt != "string")
|
|
141
|
-
throw new Error(
|
|
141
|
+
throw new Error(W);
|
|
142
142
|
this.config = {
|
|
143
143
|
...t,
|
|
144
|
-
env: t.env ||
|
|
144
|
+
env: t.env || T,
|
|
145
145
|
theme: t.theme
|
|
146
146
|
}, this.state = {
|
|
147
147
|
initialized: !1,
|
|
@@ -177,8 +177,8 @@ class B {
|
|
|
177
177
|
if (!this.state.initialized || !this.state.element)
|
|
178
178
|
throw new Error(this.errorMessages.NOT_RENDERED);
|
|
179
179
|
const r = this.state.element;
|
|
180
|
-
Object.entries(t).forEach(([
|
|
181
|
-
|
|
180
|
+
Object.entries(t).forEach(([o, n]) => {
|
|
181
|
+
n && (this.config[o] = n, r[o] = n);
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
@@ -202,7 +202,7 @@ class B {
|
|
|
202
202
|
return { ...this.config };
|
|
203
203
|
}
|
|
204
204
|
getEnvironment() {
|
|
205
|
-
return this.config.env ||
|
|
205
|
+
return this.config.env || T;
|
|
206
206
|
}
|
|
207
207
|
getScriptId() {
|
|
208
208
|
return `${this.webComponentTag}-script-${this.getEnvironment()}`;
|
|
@@ -221,16 +221,16 @@ class B {
|
|
|
221
221
|
if (this.scriptLoadingPromise)
|
|
222
222
|
return this.scriptLoadingPromise;
|
|
223
223
|
this.scriptLoadingPromise = new Promise((t, r) => {
|
|
224
|
-
|
|
224
|
+
V({
|
|
225
225
|
webComponentTag: this.webComponentTag,
|
|
226
226
|
appName: this.webComponentTag,
|
|
227
227
|
scriptUrls: this.getEffectiveScriptUrls(),
|
|
228
|
-
collectorUrls:
|
|
228
|
+
collectorUrls: M,
|
|
229
229
|
env: this.getEnvironment(),
|
|
230
230
|
jwt: this.config.jwt,
|
|
231
231
|
onLoad: t,
|
|
232
|
-
onError: (
|
|
233
|
-
r(new Error(
|
|
232
|
+
onError: (o) => {
|
|
233
|
+
r(new Error(o.reason === "not-defined" ? this.errorMessages.WEB_COMPONENT_NOT_DEFINED : `${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
});
|
|
@@ -244,14 +244,14 @@ class B {
|
|
|
244
244
|
}
|
|
245
245
|
async waitForWebComponent(t = 5e3) {
|
|
246
246
|
if (!this.getWebComponent())
|
|
247
|
-
return new Promise((r,
|
|
248
|
-
const
|
|
249
|
-
|
|
247
|
+
return new Promise((r, o) => {
|
|
248
|
+
const n = setTimeout(() => {
|
|
249
|
+
o(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
|
|
250
250
|
}, t);
|
|
251
251
|
customElements.whenDefined(this.webComponentTag).then(() => {
|
|
252
|
-
clearTimeout(
|
|
252
|
+
clearTimeout(n), r();
|
|
253
253
|
}).catch((a) => {
|
|
254
|
-
clearTimeout(
|
|
254
|
+
clearTimeout(n), o(a);
|
|
255
255
|
});
|
|
256
256
|
});
|
|
257
257
|
}
|
|
@@ -268,16 +268,32 @@ class B {
|
|
|
268
268
|
}
|
|
269
269
|
createWebComponent() {
|
|
270
270
|
const t = document.createElement(this.webComponentTag);
|
|
271
|
-
return Object.entries(this.config).forEach(([r,
|
|
272
|
-
|
|
271
|
+
return Object.entries(this.config).forEach(([r, o]) => {
|
|
272
|
+
o && (t[r] = o);
|
|
273
273
|
}), t;
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
|
-
|
|
276
|
+
const p = {
|
|
277
|
+
local: "http://localhost:5173",
|
|
278
|
+
dev: "https://sdk-cdn.dev.0hash.com",
|
|
279
|
+
cert: "https://sdk-cdn.cert.zerohash.com",
|
|
280
|
+
prod: "https://sdk-cdn.zerohash.com",
|
|
281
|
+
"eu-cert": "https://sdk-cdn.cert.zerohash.eu",
|
|
282
|
+
"eu-prod": "https://sdk-cdn.zerohash.eu"
|
|
283
|
+
}, J = (e, t, r = {}) => {
|
|
284
|
+
const { eu: o = !1, legacyAliases: n = !1, local: a = p.local } = r, i = (c) => `${c}/${e}/${t}`, s = {
|
|
285
|
+
local: i(a),
|
|
286
|
+
dev: i(p.dev),
|
|
287
|
+
cert: i(p.cert),
|
|
288
|
+
prod: i(p.prod)
|
|
289
|
+
};
|
|
290
|
+
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;
|
|
291
|
+
};
|
|
292
|
+
var S;
|
|
277
293
|
(function(e) {
|
|
278
294
|
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";
|
|
279
|
-
})(
|
|
280
|
-
class
|
|
295
|
+
})(S || (S = {}));
|
|
296
|
+
class x extends j {
|
|
281
297
|
errorMessages = {
|
|
282
298
|
ALREADY_RENDERED: "CspCryptoWithdrawals widget is already rendered. Call destroy() before rendering again.",
|
|
283
299
|
NOT_RENDERED: "CspCryptoWithdrawals widget is not rendered. Call render() first.",
|
|
@@ -285,18 +301,10 @@ class V extends B {
|
|
|
285
301
|
SCRIPT_LOAD_FAILED: "Failed to load the Connect CspCryptoWithdrawals script.",
|
|
286
302
|
WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
|
|
287
303
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
dev: "https://connect-sdk.dev.0hash.com/csp-crypto-withdrawals-web/index.js",
|
|
293
|
-
cert: "https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",
|
|
294
|
-
prod: "https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js",
|
|
295
|
-
sandbox: "https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",
|
|
296
|
-
production: "https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js",
|
|
297
|
-
"eu-cert": "https://sdk-cdn.cert.zerohash.eu/csp-crypto-withdrawals-web/index.js",
|
|
298
|
-
"eu-prod": "https://sdk-cdn.zerohash.eu/csp-crypto-withdrawals-web/index.js"
|
|
299
|
-
};
|
|
304
|
+
scriptUrls = J("csp-crypto-withdrawals-web", "index.js", {
|
|
305
|
+
legacyAliases: !0,
|
|
306
|
+
eu: !0
|
|
307
|
+
});
|
|
300
308
|
webComponentTag = "zerohash-csp-crypto-withdrawals";
|
|
301
309
|
render(t) {
|
|
302
310
|
return super.render(t);
|
|
@@ -315,7 +323,7 @@ class V extends B {
|
|
|
315
323
|
}
|
|
316
324
|
}
|
|
317
325
|
export {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
326
|
+
x as CspCryptoWithdrawals,
|
|
327
|
+
S as ErrorCode,
|
|
328
|
+
x as default
|
|
321
329
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.CspCryptoWithdrawals={}))})(this,(function(c){"use strict";const h="production",v="JWT token is required and must be a string.",I={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"},A=e=>{if(!e||typeof e!="string")return null;const t=e.split(".");if(t.length<2)return null;try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),o=r+"===".slice(0,(4-r.length%4)%4),n=typeof atob<"u"?atob(o):Buffer.from(o,"base64").toString("utf-8"),i=JSON.parse(n)?.payload?.region;if(typeof i!="string")return null;const s=i.toLowerCase();return s==="us"||s==="eu"?s:null}catch{return null}},b=(e,t)=>A(t)!=="eu"?e:e==="cert"?"eu-cert":e==="prod"?"eu-prod":e,D=e=>{if(!e||typeof e!="string")return{};const t=e.split(".");if(t.length<2)return{};try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),o=r+"===".slice(0,(4-r.length%4)%4),n=typeof atob<"u"?atob(o):Buffer.from(o,"base64").toString("utf-8"),a=JSON.parse(n),i=a?.payload??{},s=d=>typeof d=="string"&&d.length>0?d:void 0;return{participantCode:s(i.participant_code),platformName:s(i.platform_name),platformCode:s(a.platform_code),region:s(i.region)}}catch{return{}}},R=(e,t,r)=>{const o=b(t,r);return e[o]??e[t]??e.prod},W=(e,t,r)=>{const o=b(t,r);return e[o]??e[t]},w=()=>{},z=()=>{const e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")},M=(e,t)=>{const r=z(),o=globalThis.__ZH_WEB_SDK_VERSION__,n={};e.claims.participantCode&&(n.participant_code=e.claims.participantCode),e.claims.platformName&&(n.platform_name=e.claims.platformName),e.claims.platformCode&&(n.platform_code=e.claims.platformCode),e.claims.region&&(n.region=e.claims.region),o&&(n.zh_web_sdk_version=o);const a={meta:{app:{name:e.appName,version:t??"unknown",environment:e.env},session:{id:r,attributes:n},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)}}]};return{sessionId:r,payload:a}},P=(e,t,r)=>{if(!e||typeof fetch>"u")return;const{sessionId:o,payload:n}=M(t,r);try{fetch(e,{method:"POST",headers:{"Content-Type":"application/json","x-faro-session-id":o},body:JSON.stringify(n),keepalive:!0}).catch(()=>{})}catch{}},U=e=>{const{webComponentTag:t,appName:r,appVersion:o,scriptUrls:n,fallbackScriptUrls:a,collectorUrls:i,env:s,jwt:d,timeoutMs:$=15e3,onLoad:j,onError:B}=e;if(typeof document>"u")return w;const g=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(g))return w;const V=D(d),J=e.report??(u=>P(i&&W(i,s,d),u,o));let f=!1,N=0,_;const E=()=>{_!==void 0&&clearTimeout(_)},C=(u,m,l)=>{if(f)return;const H=Math.round(performance.now()-N),L={webComponentTag:t,appName:r,env:s,scriptUrl:m,reason:u,triedFallback:l,elapsedMs:H,claims:V};J(L);const y=l?void 0:R(a??{},s,d);if(y&&y!==m){S(y,!0);return}f=!0,E(),document.getElementById(g)?.remove(),B?.(L)},S=(u,m)=>{E(),N=performance.now();const l=document.createElement("script");l.id=g,l.src=u,l.type="module",l.async=!0,l.onload=()=>{setTimeout(()=>{f||(customElements.get(t)?(f=!0,E(),j?.()):C("not-defined",u,m))},0)},l.onerror=()=>C("network",u,m),_=setTimeout(()=>C("timeout",u,m),$),document.getElementById(g)?.remove(),document.head.appendChild(l)},O=R(n,s,d);return O?(S(O,!1),()=>{f=!0,E()}):w};class k{config;state;scriptLoadingPromise;constructor(t){if(!t.jwt||typeof t.jwt!="string")throw new Error(v);this.config={...t,env:t.env||h,theme:t.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(t){if(!t||!(t instanceof HTMLElement))throw new Error(this.errorMessages.INVALID_CONTAINER);if(this.state.initialized)throw new Error(this.errorMessages.ALREADY_RENDERED);try{await this.ensureScriptLoaded();const r=this.createWebComponent();t.innerHTML="",t.appendChild(r),this.state.container=t,this.state.element=r,this.state.initialized=!0}catch(r){throw console.error("Failed to render widget:",r),r}}updateConfig(t){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const r=this.state.element;Object.entries(t).forEach(([o,n])=>{n&&(this.config[o]=n,r[o]=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||h}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((t,r)=>{U({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:I,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:t,onError:o=>{r(new Error(o.reason==="not-defined"?this.errorMessages.WEB_COMPONENT_NOT_DEFINED:`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))}})});try{await this.scriptLoadingPromise}catch(t){throw this.scriptLoadingPromise=void 0,t}return this.scriptLoadingPromise}}async waitForWebComponent(t=5e3){if(!this.getWebComponent())return new Promise((r,o)=>{const n=setTimeout(()=>{o(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},t);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(n),r()}).catch(a=>{clearTimeout(n),o(a)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(t){throw console.error("Failed to load Connect script:",t),t}}createWebComponent(){const t=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([r,o])=>{o&&(t[r]=o)}),t}}const p={local:"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"},F=(e,t,r={})=>{const{eu:o=!1,legacyAliases:n=!1,local:a=p.local}=r,i=d=>`${d}/${e}/${t}`,s={local:i(a),dev:i(p.dev),cert:i(p.cert),prod:i(p.prod)};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};c.ErrorCode=void 0,(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"})(c.ErrorCode||(c.ErrorCode={}));class T extends k{errorMessages={ALREADY_RENDERED:"CspCryptoWithdrawals widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"CspCryptoWithdrawals widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect CspCryptoWithdrawals script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls=F("csp-crypto-withdrawals-web","index.js",{legacyAliases:!0,eu:!0});webComponentTag="zerohash-csp-crypto-withdrawals";render(t){return super.render(t)}updateConfig(t){return super.updateConfig(t)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}c.CspCryptoWithdrawals=T,c.default=T,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|