@connect-xyz/auth-react 0.84.17 → 0.84.18
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.js +90 -77
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as t } from "react/jsx-runtime";
|
|
2
|
-
import n, { useCallback as r, useEffect as i,
|
|
2
|
+
import n, { useCallback as r, useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
3
3
|
//#region ../../../common/js-sdk-base/dist/constants.js
|
|
4
|
-
var
|
|
4
|
+
var c = {
|
|
5
5
|
dev: "https://grafana-faro-collector.dev.0hash.com/collect",
|
|
6
6
|
cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
7
7
|
prod: "https://grafana-faro-collector.zerohash.com/collect",
|
|
@@ -9,26 +9,26 @@ var s = {
|
|
|
9
9
|
"eu-prod": "https://grafana-faro-collector.zerohash.eu/collect",
|
|
10
10
|
sandbox: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
11
11
|
production: "https://grafana-faro-collector.zerohash.com/collect"
|
|
12
|
-
},
|
|
12
|
+
}, l = (e) => typeof e == "object" && !!e && !Array.isArray(e), u = (e) => {
|
|
13
13
|
if (!e || typeof e != "string") return null;
|
|
14
14
|
let t = e.split(".");
|
|
15
15
|
if (t.length < 2) return null;
|
|
16
16
|
try {
|
|
17
|
-
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 =
|
|
17
|
+
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 = l(i) ? i.payload : void 0, o = l(a) ? a.region : void 0;
|
|
18
18
|
if (typeof o != "string") return null;
|
|
19
19
|
let s = o.toLowerCase();
|
|
20
20
|
return s === "us" || s === "eu" ? s : null;
|
|
21
21
|
} catch {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
|
-
},
|
|
24
|
+
}, d = (e, t) => u(t) === "eu" ? e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e : e, f = (e) => {
|
|
25
25
|
if (!e || typeof e != "string") return {};
|
|
26
26
|
let t = e.split(".");
|
|
27
27
|
if (t.length < 2) return {};
|
|
28
28
|
try {
|
|
29
29
|
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);
|
|
30
|
-
if (!
|
|
31
|
-
let a =
|
|
30
|
+
if (!l(i)) return {};
|
|
31
|
+
let a = l(i.payload) ? i.payload : {}, o = (e) => typeof e == "string" && e.length > 0 ? e : void 0;
|
|
32
32
|
return {
|
|
33
33
|
participantCode: o(a.participant_code),
|
|
34
34
|
platformName: o(a.platform_name),
|
|
@@ -38,11 +38,11 @@ var s = {
|
|
|
38
38
|
} catch {
|
|
39
39
|
return {};
|
|
40
40
|
}
|
|
41
|
-
},
|
|
41
|
+
}, p = (e, t, n) => e[d(t, n)] ?? e[t] ?? e.prod, m = (e, t, n) => e[d(t, n)] ?? e[t], h = () => void 0, g = () => {
|
|
42
42
|
let e = /* @__PURE__ */ new Uint8Array(8);
|
|
43
43
|
return globalThis.crypto.getRandomValues(e), Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
44
|
-
},
|
|
45
|
-
let n =
|
|
44
|
+
}, _ = (e, t) => {
|
|
45
|
+
let n = g(), r = Reflect.get(globalThis, "__ZH_WEB_SDK_VERSION__"), i = typeof r == "string" ? r : void 0, a = {};
|
|
46
46
|
return e.claims.participantCode && (a.participant_code = e.claims.participantCode), e.claims.platformName && (a.platform_name = e.claims.platformName), e.claims.platformCode && (a.platform_code = e.claims.platformCode), e.claims.region && (a.region = e.claims.region), i && (a.zh_web_sdk_version = i), {
|
|
47
47
|
sessionId: n,
|
|
48
48
|
payload: {
|
|
@@ -73,26 +73,28 @@ var s = {
|
|
|
73
73
|
}]
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
},
|
|
76
|
+
}, v = (e, t, n) => {
|
|
77
77
|
if (!e || typeof fetch > "u") return;
|
|
78
|
-
let { sessionId: r, payload: i } =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
let { sessionId: r, payload: i } = _(t, n);
|
|
79
|
+
(async () => {
|
|
80
|
+
try {
|
|
81
|
+
await fetch(e, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: {
|
|
84
|
+
"Content-Type": "application/json",
|
|
85
|
+
"x-faro-session-id": r
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify(i),
|
|
88
|
+
keepalive: !0
|
|
89
|
+
});
|
|
90
|
+
} catch {}
|
|
91
|
+
})();
|
|
92
|
+
}, y = (e) => {
|
|
93
|
+
let { webComponentTag: t, appName: n, appVersion: r, scriptUrls: i, fallbackScriptUrls: a, collectorUrls: o, env: s, jwt: c, timeoutMs: l = 15e3, onLoad: u, onError: d } = e;
|
|
94
|
+
if (typeof document > "u") return h;
|
|
93
95
|
let g = `${t}-script-${s}`;
|
|
94
|
-
if (customElements.get(t) || document.getElementById(g)) return
|
|
95
|
-
let
|
|
96
|
+
if (customElements.get(t) || document.getElementById(g)) return h;
|
|
97
|
+
let _ = f(c), y = e.report ?? ((e) => v(o && m(o, s, c), e, r)), b = !1, x = 0, S, C = () => {
|
|
96
98
|
S !== void 0 && clearTimeout(S);
|
|
97
99
|
}, w = (e, r, i) => {
|
|
98
100
|
if (b) return;
|
|
@@ -104,15 +106,15 @@ var s = {
|
|
|
104
106
|
reason: e,
|
|
105
107
|
triedFallback: i,
|
|
106
108
|
elapsedMs: o,
|
|
107
|
-
claims:
|
|
109
|
+
claims: _
|
|
108
110
|
};
|
|
109
111
|
y(l);
|
|
110
|
-
let u = i ? void 0 :
|
|
112
|
+
let u = i ? void 0 : p(a ?? {}, s, c);
|
|
111
113
|
if (u && u !== r) {
|
|
112
114
|
T(u, !0);
|
|
113
115
|
return;
|
|
114
116
|
}
|
|
115
|
-
b = !0, C(), document.getElementById(g)?.remove(),
|
|
117
|
+
b = !0, C(), document.getElementById(g)?.remove(), d?.(l);
|
|
116
118
|
}, T = (e, n) => {
|
|
117
119
|
C(), x = performance.now();
|
|
118
120
|
let r = document.createElement("script");
|
|
@@ -121,13 +123,13 @@ var s = {
|
|
|
121
123
|
b || (customElements.get(t) ? (b = !0, C(), u?.()) : w("not-defined", e, n));
|
|
122
124
|
}, 0);
|
|
123
125
|
}), r.addEventListener("error", () => w("network", e, n)), S = setTimeout(() => w("timeout", e, n), l), document.getElementById(g)?.remove(), document.head.appendChild(r);
|
|
124
|
-
}, E =
|
|
126
|
+
}, E = p(i, s, c);
|
|
125
127
|
return E ? (T(E, !1), () => {
|
|
126
128
|
b = !0, C();
|
|
127
|
-
}) :
|
|
128
|
-
},
|
|
129
|
+
}) : h;
|
|
130
|
+
}, b = () => {
|
|
129
131
|
if (typeof __ZH_SDK_PACKAGE_VERSION__ == "string" && __ZH_SDK_PACKAGE_VERSION__) return __ZH_SDK_PACKAGE_VERSION__;
|
|
130
|
-
},
|
|
132
|
+
}, x = {
|
|
131
133
|
local: {
|
|
132
134
|
BASE_URL: "/",
|
|
133
135
|
DEV: !1,
|
|
@@ -156,24 +158,24 @@ var s = {
|
|
|
156
158
|
"eu-cert": "https://sdk-cdn.cert.zerohash.eu",
|
|
157
159
|
"eu-prod": "https://sdk-cdn.zerohash.eu"
|
|
158
160
|
};
|
|
159
|
-
[...Object.entries(
|
|
161
|
+
[...Object.entries(x).filter(([e]) => e !== "local").map(([, e]) => e)], {
|
|
160
162
|
LOADED: "travel_rule_loaded",
|
|
161
163
|
COMPLETED: "travel_rule_completed"
|
|
162
164
|
}.LOADED;
|
|
163
165
|
//#endregion
|
|
164
166
|
//#region ../../../common/callbacks/dist/shared/models.js
|
|
165
|
-
var
|
|
167
|
+
var S;
|
|
166
168
|
(function(e) {
|
|
167
169
|
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";
|
|
168
|
-
})(
|
|
170
|
+
})(S ||= {});
|
|
169
171
|
//#endregion
|
|
170
172
|
//#region ../../../common/react-sdk-base/dist/script-load-fallback.js
|
|
171
|
-
var
|
|
173
|
+
var C = {
|
|
172
174
|
evergreen: "#00381D",
|
|
173
175
|
green: "#CCFFD0",
|
|
174
176
|
offBlack: "#1C1B1C",
|
|
175
177
|
grayLight: "#EBEBE9"
|
|
176
|
-
},
|
|
178
|
+
}, w = ({ onRetry: n, onClose: r }) => t("div", {
|
|
177
179
|
role: "alert",
|
|
178
180
|
style: {
|
|
179
181
|
position: "relative",
|
|
@@ -186,9 +188,9 @@ var S = {
|
|
|
186
188
|
padding: "32px 24px",
|
|
187
189
|
textAlign: "center",
|
|
188
190
|
fontFamily: "inherit",
|
|
189
|
-
color:
|
|
191
|
+
color: C.offBlack,
|
|
190
192
|
background: "#FFFFFF",
|
|
191
|
-
border: `1px solid ${
|
|
193
|
+
border: `1px solid ${C.grayLight}`,
|
|
192
194
|
borderRadius: "12px"
|
|
193
195
|
},
|
|
194
196
|
children: [
|
|
@@ -202,7 +204,7 @@ var S = {
|
|
|
202
204
|
right: "12px",
|
|
203
205
|
display: "flex",
|
|
204
206
|
padding: "4px",
|
|
205
|
-
color:
|
|
207
|
+
color: C.offBlack,
|
|
206
208
|
background: "none",
|
|
207
209
|
border: "none",
|
|
208
210
|
cursor: "pointer",
|
|
@@ -231,7 +233,7 @@ var S = {
|
|
|
231
233
|
"aria-hidden": "true",
|
|
232
234
|
children: e("path", {
|
|
233
235
|
d: "M12 9v4m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z",
|
|
234
|
-
stroke:
|
|
236
|
+
stroke: C.evergreen,
|
|
235
237
|
strokeWidth: "1.5",
|
|
236
238
|
strokeLinecap: "round",
|
|
237
239
|
strokeLinejoin: "round"
|
|
@@ -262,8 +264,8 @@ var S = {
|
|
|
262
264
|
fontSize: "14px",
|
|
263
265
|
fontWeight: 600,
|
|
264
266
|
fontFamily: "inherit",
|
|
265
|
-
color:
|
|
266
|
-
background:
|
|
267
|
+
color: C.green,
|
|
268
|
+
background: C.evergreen,
|
|
267
269
|
border: "none",
|
|
268
270
|
borderRadius: "8px",
|
|
269
271
|
cursor: "pointer"
|
|
@@ -271,69 +273,80 @@ var S = {
|
|
|
271
273
|
children: "Try again"
|
|
272
274
|
})
|
|
273
275
|
]
|
|
274
|
-
}),
|
|
276
|
+
}), T = (e, t) => {
|
|
275
277
|
i(() => {
|
|
276
278
|
let n = e.current;
|
|
277
279
|
if (n) for (let [e, r] of Object.entries(t)) r !== void 0 && Reflect.set(n, e, r);
|
|
278
280
|
});
|
|
279
|
-
},
|
|
280
|
-
let { webComponentTag: t, appName: n, appVersion:
|
|
281
|
-
return i(() => (h(!1), v({
|
|
281
|
+
}, E = (e) => {
|
|
282
|
+
let { webComponentTag: t, appName: n, appVersion: o, scriptUrls: l, fallbackScriptUrls: u, collectorUrls: d, env: f, jwt: p, timeoutMs: m } = e, [h, g] = s(0), _ = a(() => ({
|
|
282
283
|
webComponentTag: t,
|
|
283
284
|
appName: n ?? t,
|
|
284
|
-
appVersion:
|
|
285
|
-
scriptUrls:
|
|
286
|
-
fallbackScriptUrls:
|
|
287
|
-
collectorUrls:
|
|
288
|
-
env:
|
|
289
|
-
jwt:
|
|
290
|
-
timeoutMs:
|
|
291
|
-
|
|
292
|
-
})
|
|
285
|
+
appVersion: o,
|
|
286
|
+
scriptUrls: l,
|
|
287
|
+
fallbackScriptUrls: u,
|
|
288
|
+
collectorUrls: d ?? c,
|
|
289
|
+
env: f,
|
|
290
|
+
jwt: p,
|
|
291
|
+
timeoutMs: m,
|
|
292
|
+
retryNonce: h
|
|
293
|
+
}), [
|
|
293
294
|
t,
|
|
294
295
|
n,
|
|
295
|
-
|
|
296
|
-
c,
|
|
296
|
+
o,
|
|
297
297
|
l,
|
|
298
298
|
u,
|
|
299
299
|
d,
|
|
300
300
|
f,
|
|
301
301
|
p,
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
302
|
+
m,
|
|
303
|
+
h
|
|
304
|
+
]), [v, b] = s(null), x = v === _;
|
|
305
|
+
return i(() => y({
|
|
306
|
+
webComponentTag: _.webComponentTag,
|
|
307
|
+
appName: _.appName,
|
|
308
|
+
appVersion: _.appVersion,
|
|
309
|
+
scriptUrls: _.scriptUrls,
|
|
310
|
+
fallbackScriptUrls: _.fallbackScriptUrls,
|
|
311
|
+
collectorUrls: _.collectorUrls,
|
|
312
|
+
env: _.env,
|
|
313
|
+
jwt: _.jwt,
|
|
314
|
+
timeoutMs: _.timeoutMs,
|
|
315
|
+
onError: () => b(_)
|
|
316
|
+
}), [_]), {
|
|
317
|
+
loadFailed: x,
|
|
318
|
+
retry: r(() => g((e) => e + 1), [])
|
|
306
319
|
};
|
|
307
|
-
},
|
|
320
|
+
}, D = {
|
|
308
321
|
sandbox: "https://sdk.sandbox.connect.xyz/auth-web/index.js",
|
|
309
322
|
production: "https://sdk.connect.xyz/auth-web/index.js"
|
|
310
|
-
},
|
|
311
|
-
let f =
|
|
312
|
-
|
|
323
|
+
}, O = "connect-auth", k = D, A = ({ jwt: t, env: r = "production", theme: i, onError: a, onClose: s, onDeposit: c, onEvent: l, onLoaded: u, ...d }) => {
|
|
324
|
+
let f = o(null);
|
|
325
|
+
T(f, {
|
|
313
326
|
theme: i,
|
|
314
|
-
onError:
|
|
327
|
+
onError: a,
|
|
315
328
|
onClose: s,
|
|
316
329
|
onDeposit: c,
|
|
317
330
|
onEvent: l,
|
|
318
331
|
onLoaded: u
|
|
319
332
|
});
|
|
320
|
-
let { loadFailed: p, retry: m } =
|
|
321
|
-
webComponentTag:
|
|
322
|
-
scriptUrls:
|
|
333
|
+
let { loadFailed: p, retry: m } = E({
|
|
334
|
+
webComponentTag: O,
|
|
335
|
+
scriptUrls: k,
|
|
323
336
|
env: r,
|
|
324
337
|
jwt: t
|
|
325
338
|
});
|
|
326
|
-
return p ? /* @__PURE__ */ e(
|
|
339
|
+
return p ? /* @__PURE__ */ e(w, {
|
|
327
340
|
onRetry: m,
|
|
328
341
|
onClose: s
|
|
329
|
-
}) : n.createElement(
|
|
342
|
+
}) : n.createElement(O, {
|
|
330
343
|
ref: f,
|
|
331
344
|
jwt: t,
|
|
332
345
|
env: r,
|
|
333
|
-
sdkversion:
|
|
346
|
+
sdkversion: b(),
|
|
334
347
|
theme: i,
|
|
335
348
|
...d
|
|
336
349
|
});
|
|
337
350
|
};
|
|
338
351
|
//#endregion
|
|
339
|
-
export {
|
|
352
|
+
export { A as Auth };
|