@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.
Files changed (2) hide show
  1. package/dist/index.js +81 -63
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
- import { jsxs as A, jsx as h } from "react/jsx-runtime";
2
- import W, { useEffect as z, useState as N, useCallback as j, useRef as M } from "react";
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 }) => A("div", { role: "alert", style: {
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: _.offBlack,
19
+ color: y.offBlack,
19
20
  background: "#FFFFFF",
20
- border: `1px solid ${_.grayLight}`,
21
+ border: `1px solid ${y.grayLight}`,
21
22
  borderRadius: "12px"
22
- }, children: [h("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: h("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: _.evergreen, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }), h("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), h("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), h("button", { type: "button", onClick: e, style: {
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: _.green,
29
- background: _.evergreen,
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
- z(() => {
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
- }, B = (e, t) => J(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, $ = (e) => {
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
- }, F = (e, t, o) => {
81
- const n = B(t, o);
92
+ }, L = (e, t, o) => {
93
+ const n = z(t, o);
82
94
  return e[n] ?? e[t] ?? e.prod;
83
- }, K = (e, t, o) => {
84
- const n = B(t, o);
95
+ }, H = (e, t, o) => {
96
+ const n = z(t, o);
85
97
  return e[n] ?? e[t];
86
- }, v = () => {
87
- }, H = () => {
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 = H(), n = globalThis.__ZH_WEB_SDK_VERSION__, r = {};
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: p = 15e3, onLoad: y, onError: f } = e;
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 v;
134
- const m = `${t}-script-${a}`;
135
- if (customElements.get(t) || document.getElementById(m))
136
- return v;
137
- const R = $(s), S = e.report ?? ((d) => Z(c && K(c, a, s), d, n));
138
- let u = !1, w = 0, x;
139
- const b = () => {
140
- x !== void 0 && clearTimeout(x);
141
- }, C = (d, g, l) => {
142
- if (u)
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), k = {
156
+ const U = Math.round(performance.now() - w), T = {
145
157
  webComponentTag: t,
146
158
  appName: o,
147
159
  env: a,
148
- scriptUrl: g,
149
- reason: d,
160
+ scriptUrl: h,
161
+ reason: p,
150
162
  triedFallback: l,
151
163
  elapsedMs: U,
152
164
  claims: R
153
165
  };
154
- S(k);
155
- const E = l ? void 0 : F(i ?? {}, a, s);
156
- if (E && E !== g) {
157
- O(E, !0);
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
- u = !0, b(), document.getElementById(m)?.remove(), f?.(k);
161
- }, O = (d, g) => {
162
- b(), w = performance.now();
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 = m, l.src = d, l.type = "module", l.async = !0, l.onload = () => {
176
+ l.id = g, l.src = p, l.type = "module", l.async = !0, l.onload = () => {
165
177
  setTimeout(() => {
166
- u || (customElements.get(t) ? (u = !0, b(), y?.()) : C("not-defined", d, g));
178
+ f || (customElements.get(t) ? (f = !0, _(), b?.()) : k("not-defined", p, h));
167
179
  }, 0);
168
- }, l.onerror = () => C("network", d, g), x = setTimeout(() => C("timeout", d, g), p), document.getElementById(m)?.remove(), document.head.appendChild(l);
169
- }, T = F(r, a, s);
170
- return T ? (O(T, !1), () => {
171
- u = !0, b();
172
- }) : v;
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 L;
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
- })(L || (L = {}));
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: p } = e, [y, f] = N(!1), [m, R] = N(0);
180
- z(() => (f(!1), q({
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: p,
190
- onError: () => f(!0)
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
- p,
201
- m
212
+ u,
213
+ g
202
214
  ]);
203
- const S = j(() => R((u) => u + 1), []);
204
- return { loadFailed: y, retry: S };
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
- }, I = "connect-auth", Y = X, oe = ({
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 p = M(null);
220
- D(p, { theme: o, onError: n, onClose: r, onDeposit: i, onEvent: c, onLoaded: a });
221
- const { loadFailed: y, retry: f } = Q({
222
- webComponentTag: I,
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 y ? /* @__PURE__ */ h(V, { onRetry: f }) : W.createElement(I, {
228
- ref: p,
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connect-xyz/auth-react",
3
- "version": "0.80.5",
3
+ "version": "0.82.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",