@zerohash-sdk/fiat-account-link-react 1.4.2 → 1.6.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 +229 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,40 +1,239 @@
1
- import k, { useRef as m, useEffect as u } from "react";
2
- const x = {
1
+ import { jsxs as U, jsx as h } from "react/jsx-runtime";
2
+ import W, { useEffect as B, useState as T, useCallback as j, useRef as M } from "react";
3
+ const b = {
4
+ evergreen: "#00381D",
5
+ green: "#CCFFD0",
6
+ offBlack: "#1C1B1C",
7
+ grayLight: "#EBEBE9"
8
+ }, D = ({ onRetry: e }) => U("div", { role: "alert", style: {
9
+ display: "flex",
10
+ flexDirection: "column",
11
+ alignItems: "center",
12
+ gap: "8px",
13
+ maxWidth: "360px",
14
+ margin: "0 auto",
15
+ padding: "32px 24px",
16
+ textAlign: "center",
17
+ fontFamily: "inherit",
18
+ color: b.offBlack,
19
+ background: "#FFFFFF",
20
+ border: `1px solid ${b.grayLight}`,
21
+ 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: b.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
+ marginTop: "8px",
24
+ padding: "8px 20px",
25
+ fontSize: "14px",
26
+ fontWeight: 600,
27
+ fontFamily: "inherit",
28
+ color: b.green,
29
+ background: b.evergreen,
30
+ border: "none",
31
+ borderRadius: "8px",
32
+ cursor: "pointer"
33
+ }, children: "Try again" })] }), V = (e, t) => {
34
+ B(() => {
35
+ const o = e.current;
36
+ if (o)
37
+ for (const [n, r] of Object.entries(t))
38
+ r !== void 0 && (o[n] = r);
39
+ });
40
+ }, P = {
41
+ dev: "https://grafana-faro-collector.dev.0hash.com/collect",
42
+ cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
43
+ prod: "https://grafana-faro-collector.zerohash.com/collect",
44
+ "eu-cert": "https://grafana-faro-collector.cert.zerohash.eu/collect",
45
+ "eu-prod": "https://grafana-faro-collector.zerohash.eu/collect",
46
+ sandbox: "https://grafana-faro-collector.cert.zerohash.com/collect",
47
+ production: "https://grafana-faro-collector.zerohash.com/collect"
48
+ }, J = (e) => {
49
+ if (!e || typeof e != "string")
50
+ return null;
51
+ const t = e.split(".");
52
+ if (t.length < 2)
53
+ return null;
54
+ try {
55
+ const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = o + "===".slice(0, (4 - o.length % 4) % 4), r = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), c = JSON.parse(r)?.payload?.region;
56
+ if (typeof c != "string")
57
+ return null;
58
+ const a = c.toLowerCase();
59
+ return a === "us" || a === "eu" ? a : null;
60
+ } catch {
61
+ return null;
62
+ }
63
+ }, I = (e, t) => J(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, $ = (e) => {
64
+ if (!e || typeof e != "string")
65
+ return {};
66
+ const t = e.split(".");
67
+ if (t.length < 2)
68
+ return {};
69
+ try {
70
+ const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = o + "===".slice(0, (4 - o.length % 4) % 4), r = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), i = JSON.parse(r), c = i?.payload ?? {}, a = (s) => typeof s == "string" && s.length > 0 ? s : void 0;
71
+ return {
72
+ participantCode: a(c.participant_code),
73
+ platformName: a(c.platform_name),
74
+ platformCode: a(i.platform_code),
75
+ region: a(c.region)
76
+ };
77
+ } catch {
78
+ return {};
79
+ }
80
+ }, L = (e, t, o) => {
81
+ const n = I(t, o);
82
+ return e[n] ?? e[t] ?? e.prod;
83
+ }, K = (e, t, o) => {
84
+ const n = I(t, o);
85
+ return e[n] ?? e[t];
86
+ }, w = () => {
87
+ }, H = () => {
88
+ const e = new Uint8Array(8);
89
+ return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
90
+ }, G = (e, t) => {
91
+ const o = H(), n = globalThis.__ZH_WEB_SDK_VERSION__, r = {};
92
+ 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
+ const i = {
94
+ meta: {
95
+ app: { name: e.appName, version: t ?? "unknown", environment: e.env },
96
+ session: { id: o, attributes: r },
97
+ browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
98
+ page: typeof window < "u" ? { url: window.location.origin } : void 0
99
+ },
100
+ logs: [
101
+ {
102
+ message: `Failed to load the script for ${e.webComponentTag} from ${e.env} environment.`,
103
+ level: "error",
104
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
105
+ context: {
106
+ web_component: e.webComponentTag,
107
+ script_url: e.scriptUrl,
108
+ reason: e.reason,
109
+ tried_fallback: String(e.triedFallback),
110
+ elapsed_ms: String(e.elapsedMs)
111
+ }
112
+ }
113
+ ]
114
+ };
115
+ return { sessionId: o, payload: i };
116
+ }, Z = (e, t, o) => {
117
+ if (!e || typeof fetch > "u")
118
+ return;
119
+ const { sessionId: n, payload: r } = G(t, o);
120
+ try {
121
+ fetch(e, {
122
+ method: "POST",
123
+ headers: { "Content-Type": "application/json", "x-faro-session-id": n },
124
+ body: JSON.stringify(r),
125
+ keepalive: !0
126
+ }).catch(() => {
127
+ });
128
+ } catch {
129
+ }
130
+ }, 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;
132
+ if (typeof document > "u")
133
+ return w;
134
+ const m = `${t}-script-${a}`;
135
+ if (customElements.get(t) || document.getElementById(m))
136
+ return w;
137
+ const R = $(s), S = e.report ?? ((d) => Z(c && K(c, a, s), d, n));
138
+ let u = !1, C = 0, k;
139
+ const _ = () => {
140
+ k !== void 0 && clearTimeout(k);
141
+ }, x = (d, g, l) => {
142
+ if (u)
143
+ return;
144
+ const A = Math.round(performance.now() - C), N = {
145
+ webComponentTag: t,
146
+ appName: o,
147
+ env: a,
148
+ scriptUrl: g,
149
+ reason: d,
150
+ triedFallback: l,
151
+ elapsedMs: A,
152
+ claims: R
153
+ };
154
+ S(N);
155
+ const v = l ? void 0 : L(i ?? {}, a, s);
156
+ if (v && v !== g) {
157
+ O(v, !0);
158
+ return;
159
+ }
160
+ u = !0, _(), document.getElementById(m)?.remove(), f?.(N);
161
+ }, O = (d, g) => {
162
+ _(), C = performance.now();
163
+ const l = document.createElement("script");
164
+ l.id = m, l.src = d, l.type = "module", l.async = !0, l.onload = () => {
165
+ setTimeout(() => {
166
+ u || (customElements.get(t) ? (u = !0, _(), y?.()) : x("not-defined", d, g));
167
+ }, 0);
168
+ }, l.onerror = () => x("network", d, g), k = setTimeout(() => x("timeout", d, g), p), document.getElementById(m)?.remove(), document.head.appendChild(l);
169
+ }, E = L(r, a, s);
170
+ return E ? (O(E, !1), () => {
171
+ u = !0, _();
172
+ }) : w;
173
+ };
174
+ var F;
175
+ (function(e) {
176
+ 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
+ })(F || (F = {}));
178
+ 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] = T(!1), [m, R] = T(0);
180
+ B(() => (f(!1), q({
181
+ webComponentTag: t,
182
+ appName: o ?? t,
183
+ appVersion: n,
184
+ scriptUrls: r,
185
+ fallbackScriptUrls: i,
186
+ collectorUrls: c ?? P,
187
+ env: a,
188
+ jwt: s,
189
+ timeoutMs: p,
190
+ onError: () => f(!0)
191
+ })), [
192
+ t,
193
+ o,
194
+ n,
195
+ r,
196
+ i,
197
+ c,
198
+ a,
199
+ s,
200
+ p,
201
+ m
202
+ ]);
203
+ const S = j(() => R((u) => u + 1), []);
204
+ return { loadFailed: y, retry: S };
205
+ }, X = {
3
206
  local: "http://localhost:4208/fiat-account-link-web/index.js",
4
207
  dev: "https://connect-sdk.dev.0hash.com/fiat-account-link-web/index.js",
5
208
  cert: "https://sdk.sandbox.connect.xyz/fiat-account-link-web/index.js",
6
209
  prod: "https://sdk.connect.xyz/fiat-account-link-web/index.js"
7
- }, b = "zerohash-fiat-account-link-script", p = "zerohash-fiat-account-link", y = (i = "prod") => x[i], R = ({
8
- jwt: i,
9
- env: e = "prod",
10
- theme: n,
11
- onCompleted: o,
210
+ }, z = "zerohash-fiat-account-link", te = ({
211
+ jwt: e,
212
+ env: t = "prod",
213
+ theme: o,
214
+ onCompleted: n,
12
215
  onError: r,
13
- onClose: s,
14
- onLoaded: a,
15
- onEvent: d,
16
- ...h
216
+ onClose: i,
217
+ onLoaded: c,
218
+ onEvent: a,
219
+ ...s
17
220
  }) => {
18
- const f = m(null);
19
- return u(() => {
20
- const t = f.current;
21
- t && (n !== void 0 && (t.theme = n), o && (t.onCompleted = o), r && (t.onError = r), s && (t.onClose = s), a && (t.onLoaded = a), d && (t.onEvent = d));
22
- }, [n, o, r, s, a, d]), u(() => {
23
- const t = y(e), l = `${b}-${e}`;
24
- if (document.getElementById(l))
25
- return;
26
- const c = document.createElement("script");
27
- c.id = l, c.src = t, c.type = "module", c.async = !0, c.onerror = () => {
28
- console.error(`Failed to load the script for ${p} from ${e} environment.`);
29
- }, document.head.appendChild(c);
30
- }, [e]), k.createElement(p, {
31
- ref: f,
32
- jwt: i,
33
- env: e,
34
- theme: n,
35
- ...h
221
+ const p = M(null);
222
+ V(p, { theme: o, onCompleted: n, onError: r, onClose: i, onLoaded: c, onEvent: a });
223
+ const { loadFailed: y, retry: f } = Q({
224
+ webComponentTag: z,
225
+ scriptUrls: X,
226
+ env: t,
227
+ jwt: e
228
+ });
229
+ return y ? /* @__PURE__ */ h(D, { onRetry: f }) : W.createElement(z, {
230
+ ref: p,
231
+ jwt: e,
232
+ env: t,
233
+ theme: o,
234
+ ...s
36
235
  });
37
236
  };
38
237
  export {
39
- R as FiatAccountLink
238
+ te as FiatAccountLink
40
239
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/fiat-account-link-react",
3
- "version": "1.4.2",
3
+ "version": "1.6.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",