@connect-xyz/auth-react 0.80.5 → 0.82.0
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 +81 -63
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
1
|
+
import { jsxs as W, jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import A, { useEffect as I, useState as N, useCallback as j, useRef as M } from "react";
|
|
3
|
+
const y = {
|
|
4
4
|
evergreen: "#00381D",
|
|
5
5
|
green: "#CCFFD0",
|
|
6
6
|
offBlack: "#1C1B1C",
|
|
7
7
|
grayLight: "#EBEBE9"
|
|
8
|
-
}, V = ({ onRetry: e }) =>
|
|
8
|
+
}, V = ({ onRetry: e, onClose: t }) => W("div", { role: "alert", style: {
|
|
9
|
+
position: "relative",
|
|
9
10
|
display: "flex",
|
|
10
11
|
flexDirection: "column",
|
|
11
12
|
alignItems: "center",
|
|
@@ -15,23 +16,34 @@ const _ = {
|
|
|
15
16
|
padding: "32px 24px",
|
|
16
17
|
textAlign: "center",
|
|
17
18
|
fontFamily: "inherit",
|
|
18
|
-
color:
|
|
19
|
+
color: y.offBlack,
|
|
19
20
|
background: "#FFFFFF",
|
|
20
|
-
border: `1px solid ${
|
|
21
|
+
border: `1px solid ${y.grayLight}`,
|
|
21
22
|
borderRadius: "12px"
|
|
22
|
-
}, children: [
|
|
23
|
+
}, children: [t && d("button", { type: "button", onClick: t, "aria-label": "Close", style: {
|
|
24
|
+
position: "absolute",
|
|
25
|
+
top: "12px",
|
|
26
|
+
right: "12px",
|
|
27
|
+
display: "flex",
|
|
28
|
+
padding: "4px",
|
|
29
|
+
color: y.offBlack,
|
|
30
|
+
background: "none",
|
|
31
|
+
border: "none",
|
|
32
|
+
cursor: "pointer",
|
|
33
|
+
lineHeight: 0
|
|
34
|
+
}, children: d("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: d("path", { d: "M18 6L6 18M6 6l12 12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), d("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: d("path", { 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", stroke: y.evergreen, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }), d("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), d("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), d("button", { type: "button", onClick: e, style: {
|
|
23
35
|
marginTop: "8px",
|
|
24
36
|
padding: "8px 20px",
|
|
25
37
|
fontSize: "14px",
|
|
26
38
|
fontWeight: 600,
|
|
27
39
|
fontFamily: "inherit",
|
|
28
|
-
color:
|
|
29
|
-
background:
|
|
40
|
+
color: y.green,
|
|
41
|
+
background: y.evergreen,
|
|
30
42
|
border: "none",
|
|
31
43
|
borderRadius: "8px",
|
|
32
44
|
cursor: "pointer"
|
|
33
45
|
}, children: "Try again" })] }), D = (e, t) => {
|
|
34
|
-
|
|
46
|
+
I(() => {
|
|
35
47
|
const o = e.current;
|
|
36
48
|
if (o)
|
|
37
49
|
for (const [n, r] of Object.entries(t))
|
|
@@ -60,7 +72,7 @@ const _ = {
|
|
|
60
72
|
} catch {
|
|
61
73
|
return null;
|
|
62
74
|
}
|
|
63
|
-
},
|
|
75
|
+
}, z = (e, t) => J(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, $ = (e) => {
|
|
64
76
|
if (!e || typeof e != "string")
|
|
65
77
|
return {};
|
|
66
78
|
const t = e.split(".");
|
|
@@ -77,18 +89,18 @@ const _ = {
|
|
|
77
89
|
} catch {
|
|
78
90
|
return {};
|
|
79
91
|
}
|
|
80
|
-
},
|
|
81
|
-
const n =
|
|
92
|
+
}, L = (e, t, o) => {
|
|
93
|
+
const n = z(t, o);
|
|
82
94
|
return e[n] ?? e[t] ?? e.prod;
|
|
83
|
-
},
|
|
84
|
-
const n =
|
|
95
|
+
}, H = (e, t, o) => {
|
|
96
|
+
const n = z(t, o);
|
|
85
97
|
return e[n] ?? e[t];
|
|
86
|
-
},
|
|
87
|
-
},
|
|
98
|
+
}, C = () => {
|
|
99
|
+
}, K = () => {
|
|
88
100
|
const e = new Uint8Array(8);
|
|
89
101
|
return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
|
|
90
102
|
}, G = (e, t) => {
|
|
91
|
-
const o =
|
|
103
|
+
const o = K(), n = globalThis.__ZH_WEB_SDK_VERSION__, r = {};
|
|
92
104
|
e.claims.participantCode && (r.participant_code = e.claims.participantCode), e.claims.platformName && (r.platform_name = e.claims.platformName), e.claims.platformCode && (r.platform_code = e.claims.platformCode), e.claims.region && (r.region = e.claims.region), n && (r.zh_web_sdk_version = n);
|
|
93
105
|
const i = {
|
|
94
106
|
meta: {
|
|
@@ -128,56 +140,56 @@ const _ = {
|
|
|
128
140
|
} catch {
|
|
129
141
|
}
|
|
130
142
|
}, q = (e) => {
|
|
131
|
-
const { webComponentTag: t, appName: o, appVersion: n, scriptUrls: r, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs:
|
|
143
|
+
const { webComponentTag: t, appName: o, appVersion: n, scriptUrls: r, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs: u = 15e3, onLoad: b, onError: m } = e;
|
|
132
144
|
if (typeof document > "u")
|
|
133
|
-
return
|
|
134
|
-
const
|
|
135
|
-
if (customElements.get(t) || document.getElementById(
|
|
136
|
-
return
|
|
137
|
-
const R = $(s),
|
|
138
|
-
let
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
},
|
|
142
|
-
if (
|
|
145
|
+
return C;
|
|
146
|
+
const g = `${t}-script-${a}`;
|
|
147
|
+
if (customElements.get(t) || document.getElementById(g))
|
|
148
|
+
return C;
|
|
149
|
+
const R = $(s), x = e.report ?? ((p) => Z(c && H(c, a, s), p, n));
|
|
150
|
+
let f = !1, w = 0, S;
|
|
151
|
+
const _ = () => {
|
|
152
|
+
S !== void 0 && clearTimeout(S);
|
|
153
|
+
}, k = (p, h, l) => {
|
|
154
|
+
if (f)
|
|
143
155
|
return;
|
|
144
|
-
const U = Math.round(performance.now() - w),
|
|
156
|
+
const U = Math.round(performance.now() - w), T = {
|
|
145
157
|
webComponentTag: t,
|
|
146
158
|
appName: o,
|
|
147
159
|
env: a,
|
|
148
|
-
scriptUrl:
|
|
149
|
-
reason:
|
|
160
|
+
scriptUrl: h,
|
|
161
|
+
reason: p,
|
|
150
162
|
triedFallback: l,
|
|
151
163
|
elapsedMs: U,
|
|
152
164
|
claims: R
|
|
153
165
|
};
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
|
|
166
|
+
x(T);
|
|
167
|
+
const v = l ? void 0 : L(i ?? {}, a, s);
|
|
168
|
+
if (v && v !== h) {
|
|
169
|
+
E(v, !0);
|
|
158
170
|
return;
|
|
159
171
|
}
|
|
160
|
-
|
|
161
|
-
},
|
|
162
|
-
|
|
172
|
+
f = !0, _(), document.getElementById(g)?.remove(), m?.(T);
|
|
173
|
+
}, E = (p, h) => {
|
|
174
|
+
_(), w = performance.now();
|
|
163
175
|
const l = document.createElement("script");
|
|
164
|
-
l.id =
|
|
176
|
+
l.id = g, l.src = p, l.type = "module", l.async = !0, l.onload = () => {
|
|
165
177
|
setTimeout(() => {
|
|
166
|
-
|
|
178
|
+
f || (customElements.get(t) ? (f = !0, _(), b?.()) : k("not-defined", p, h));
|
|
167
179
|
}, 0);
|
|
168
|
-
}, l.onerror = () =>
|
|
169
|
-
},
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
}) :
|
|
180
|
+
}, l.onerror = () => k("network", p, h), S = setTimeout(() => k("timeout", p, h), u), document.getElementById(g)?.remove(), document.head.appendChild(l);
|
|
181
|
+
}, O = L(r, a, s);
|
|
182
|
+
return O ? (E(O, !1), () => {
|
|
183
|
+
f = !0, _();
|
|
184
|
+
}) : C;
|
|
173
185
|
};
|
|
174
|
-
var
|
|
186
|
+
var F;
|
|
175
187
|
(function(e) {
|
|
176
188
|
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";
|
|
177
|
-
})(
|
|
189
|
+
})(F || (F = {}));
|
|
178
190
|
const Q = (e) => {
|
|
179
|
-
const { webComponentTag: t, appName: o, appVersion: n, scriptUrls: r, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs:
|
|
180
|
-
|
|
191
|
+
const { webComponentTag: t, appName: o, appVersion: n, scriptUrls: r, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs: u } = e, [b, m] = N(!1), [g, R] = N(0);
|
|
192
|
+
I(() => (m(!1), q({
|
|
181
193
|
webComponentTag: t,
|
|
182
194
|
appName: o ?? t,
|
|
183
195
|
appVersion: n,
|
|
@@ -186,8 +198,8 @@ const Q = (e) => {
|
|
|
186
198
|
collectorUrls: c ?? P,
|
|
187
199
|
env: a,
|
|
188
200
|
jwt: s,
|
|
189
|
-
timeoutMs:
|
|
190
|
-
onError: () =>
|
|
201
|
+
timeoutMs: u,
|
|
202
|
+
onError: () => m(!0)
|
|
191
203
|
})), [
|
|
192
204
|
t,
|
|
193
205
|
o,
|
|
@@ -197,15 +209,15 @@ const Q = (e) => {
|
|
|
197
209
|
c,
|
|
198
210
|
a,
|
|
199
211
|
s,
|
|
200
|
-
|
|
201
|
-
|
|
212
|
+
u,
|
|
213
|
+
g
|
|
202
214
|
]);
|
|
203
|
-
const
|
|
204
|
-
return { loadFailed:
|
|
215
|
+
const x = j(() => R((f) => f + 1), []);
|
|
216
|
+
return { loadFailed: b, retry: x };
|
|
205
217
|
}, X = {
|
|
206
218
|
sandbox: "https://sdk.sandbox.connect.xyz/auth-web/index.js",
|
|
207
219
|
production: "https://sdk.connect.xyz/auth-web/index.js"
|
|
208
|
-
},
|
|
220
|
+
}, B = "connect-auth", Y = X, oe = ({
|
|
209
221
|
jwt: e,
|
|
210
222
|
env: t = "production",
|
|
211
223
|
theme: o,
|
|
@@ -216,16 +228,22 @@ const Q = (e) => {
|
|
|
216
228
|
onLoaded: a,
|
|
217
229
|
...s
|
|
218
230
|
}) => {
|
|
219
|
-
const
|
|
220
|
-
D(
|
|
221
|
-
const { loadFailed:
|
|
222
|
-
webComponentTag:
|
|
231
|
+
const u = M(null);
|
|
232
|
+
D(u, { theme: o, onError: n, onClose: r, onDeposit: i, onEvent: c, onLoaded: a });
|
|
233
|
+
const { loadFailed: b, retry: m } = Q({
|
|
234
|
+
webComponentTag: B,
|
|
223
235
|
scriptUrls: Y,
|
|
224
236
|
env: t,
|
|
225
237
|
jwt: e
|
|
226
238
|
});
|
|
227
|
-
return
|
|
228
|
-
|
|
239
|
+
return b ? /* @__PURE__ */ d(
|
|
240
|
+
V,
|
|
241
|
+
{
|
|
242
|
+
onRetry: m,
|
|
243
|
+
onClose: r
|
|
244
|
+
}
|
|
245
|
+
) : A.createElement(B, {
|
|
246
|
+
ref: u,
|
|
229
247
|
jwt: e,
|
|
230
248
|
env: t,
|
|
231
249
|
theme: o,
|