@zerohash-sdk/crypto-sell-react 1.10.2 → 1.11.1

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 +48 -47
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs as W, jsx as y } from "react/jsx-runtime";
2
- import j, { useEffect as B, useState as z, useCallback as D, useRef as M } from "react";
2
+ import D, { useEffect as I, useState as z, useCallback as j, useRef as M } from "react";
3
3
  const $ = {
4
4
  dev: "https://grafana-faro-collector.dev.0hash.com/collect",
5
5
  cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
@@ -23,37 +23,37 @@ const $ = {
23
23
  } catch {
24
24
  return null;
25
25
  }
26
- }, I = (e, t) => V(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, P = (e) => {
26
+ }, B = (e, t) => V(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, P = (e) => {
27
27
  if (!e || typeof e != "string")
28
28
  return {};
29
29
  const t = e.split(".");
30
30
  if (t.length < 2)
31
31
  return {};
32
32
  try {
33
- const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), a = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), l = JSON.parse(a), c = l?.payload ?? {}, n = (s) => typeof s == "string" && s.length > 0 ? s : void 0;
33
+ const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), a = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), i = JSON.parse(a), c = i?.payload ?? {}, n = (s) => typeof s == "string" && s.length > 0 ? s : void 0;
34
34
  return {
35
35
  participantCode: n(c.participant_code),
36
36
  platformName: n(c.platform_name),
37
- platformCode: n(l.platform_code),
37
+ platformCode: n(i.platform_code),
38
38
  region: n(c.region)
39
39
  };
40
40
  } catch {
41
41
  return {};
42
42
  }
43
43
  }, L = (e, t, o) => {
44
- const r = I(t, o);
44
+ const r = B(t, o);
45
45
  return e[r] ?? e[t] ?? e.prod;
46
46
  }, J = (e, t, o) => {
47
- const r = I(t, o);
47
+ const r = B(t, o);
48
48
  return e[r] ?? e[t];
49
49
  }, x = () => {
50
50
  }, H = () => {
51
51
  const e = new Uint8Array(8);
52
52
  return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
53
- }, K = (e, t) => {
53
+ }, G = (e, t) => {
54
54
  const o = H(), r = globalThis.__ZH_WEB_SDK_VERSION__, a = {};
55
55
  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), r && (a.zh_web_sdk_version = r);
56
- const l = {
56
+ const i = {
57
57
  meta: {
58
58
  app: { name: e.appName, version: t ?? "unknown", environment: e.env },
59
59
  session: { id: o, attributes: a },
@@ -75,11 +75,11 @@ const $ = {
75
75
  }
76
76
  ]
77
77
  };
78
- return { sessionId: o, payload: l };
79
- }, G = (e, t, o) => {
78
+ return { sessionId: o, payload: i };
79
+ }, K = (e, t, o) => {
80
80
  if (!e || typeof fetch > "u")
81
81
  return;
82
- const { sessionId: r, payload: a } = K(t, o);
82
+ const { sessionId: r, payload: a } = G(t, o);
83
83
  try {
84
84
  fetch(e, {
85
85
  method: "POST",
@@ -91,46 +91,46 @@ const $ = {
91
91
  } catch {
92
92
  }
93
93
  }, Z = (e) => {
94
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: l, collectorUrls: c, env: n, jwt: s, timeoutMs: u = 15e3, onLoad: _, onError: m } = e;
94
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: c, env: n, jwt: s, timeoutMs: u = 15e3, onLoad: _, onError: m } = e;
95
95
  if (typeof document > "u")
96
96
  return x;
97
97
  const g = `${t}-script-${n}`;
98
98
  if (customElements.get(t) || document.getElementById(g))
99
99
  return x;
100
- const S = P(s), v = e.report ?? ((d) => G(c && J(c, n, s), d, r));
101
- let f = !1, w = 0, C;
100
+ const S = P(s), v = e.report ?? ((d) => K(c && J(c, n, s), d, r));
101
+ let f = !1, N = 0, C;
102
102
  const R = () => {
103
103
  C !== void 0 && clearTimeout(C);
104
- }, k = (d, h, i) => {
104
+ }, k = (d, h, l) => {
105
105
  if (f)
106
106
  return;
107
- const U = Math.round(performance.now() - w), T = {
107
+ const U = Math.round(performance.now() - N), E = {
108
108
  webComponentTag: t,
109
109
  appName: o,
110
110
  env: n,
111
111
  scriptUrl: h,
112
112
  reason: d,
113
- triedFallback: i,
113
+ triedFallback: l,
114
114
  elapsedMs: U,
115
115
  claims: S
116
116
  };
117
- v(T);
118
- const O = i ? void 0 : L(l ?? {}, n, s);
117
+ v(E);
118
+ const O = l ? void 0 : L(i ?? {}, n, s);
119
119
  if (O && O !== h) {
120
- E(O, !0);
120
+ T(O, !0);
121
121
  return;
122
122
  }
123
- f = !0, R(), document.getElementById(g)?.remove(), m?.(T);
124
- }, E = (d, h) => {
125
- R(), w = performance.now();
126
- const i = document.createElement("script");
127
- i.id = g, i.src = d, i.type = "module", i.async = !0, i.onload = () => {
123
+ f = !0, R(), document.getElementById(g)?.remove(), m?.(E);
124
+ }, T = (d, h) => {
125
+ R(), N = performance.now();
126
+ const l = document.createElement("script");
127
+ l.id = g, l.src = d, l.type = "module", l.async = !0, l.onload = () => {
128
128
  setTimeout(() => {
129
129
  f || (customElements.get(t) ? (f = !0, R(), _?.()) : k("not-defined", d, h));
130
130
  }, 0);
131
- }, i.onerror = () => k("network", d, h), C = setTimeout(() => k("timeout", d, h), u), document.getElementById(g)?.remove(), document.head.appendChild(i);
132
- }, N = L(a, n, s);
133
- return N ? (E(N, !1), () => {
131
+ }, l.onerror = () => k("network", d, h), C = setTimeout(() => k("timeout", d, h), u), document.getElementById(g)?.remove(), document.head.appendChild(l);
132
+ }, w = L(a, n, s);
133
+ return w ? (T(w, !1), () => {
134
134
  f = !0, R();
135
135
  }) : x;
136
136
  }, p = {
@@ -140,10 +140,11 @@ const $ = {
140
140
  prod: "https://sdk-cdn.zerohash.com",
141
141
  "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
142
142
  "eu-prod": "https://sdk-cdn.zerohash.eu"
143
- }, q = (e, t, o = {}) => {
144
- const { eu: r = !1, legacyAliases: a = !1, local: l = p.local } = o, c = (s) => `${s}/${e}/${t}`, n = {
145
- local: c(l),
143
+ }, q = "https://sdk-cdn.gating.0hash.com", Q = (e, t, o = {}) => {
144
+ const { eu: r = !1, legacyAliases: a = !1, local: i = p.local } = o, c = (s) => `${s}/${e}/${t}`, n = {
145
+ local: c(i),
146
146
  dev: c(p.dev),
147
+ gating: c(q),
147
148
  cert: c(p.cert),
148
149
  prod: c(p.prod)
149
150
  };
@@ -158,7 +159,7 @@ const b = {
158
159
  green: "#CCFFD0",
159
160
  offBlack: "#1C1B1C",
160
161
  grayLight: "#EBEBE9"
161
- }, Q = ({ onRetry: e }) => W("div", { role: "alert", style: {
162
+ }, X = ({ onRetry: e }) => W("div", { role: "alert", style: {
162
163
  display: "flex",
163
164
  flexDirection: "column",
164
165
  alignItems: "center",
@@ -183,21 +184,21 @@ const b = {
183
184
  border: "none",
184
185
  borderRadius: "8px",
185
186
  cursor: "pointer"
186
- }, children: "Try again" })] }), X = (e, t) => {
187
- B(() => {
187
+ }, children: "Try again" })] }), Y = (e, t) => {
188
+ I(() => {
188
189
  const o = e.current;
189
190
  if (o)
190
191
  for (const [r, a] of Object.entries(t))
191
192
  a !== void 0 && (o[r] = a);
192
193
  });
193
- }, Y = (e) => {
194
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: l, collectorUrls: c, env: n, jwt: s, timeoutMs: u } = e, [_, m] = z(!1), [g, S] = z(0);
195
- B(() => (m(!1), Z({
194
+ }, ee = (e) => {
195
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: c, env: n, jwt: s, timeoutMs: u } = e, [_, m] = z(!1), [g, S] = z(0);
196
+ I(() => (m(!1), Z({
196
197
  webComponentTag: t,
197
198
  appName: o ?? t,
198
199
  appVersion: r,
199
200
  scriptUrls: a,
200
- fallbackScriptUrls: l,
201
+ fallbackScriptUrls: i,
201
202
  collectorUrls: c ?? $,
202
203
  env: n,
203
204
  jwt: s,
@@ -208,35 +209,35 @@ const b = {
208
209
  o,
209
210
  r,
210
211
  a,
211
- l,
212
+ i,
212
213
  c,
213
214
  n,
214
215
  s,
215
216
  u,
216
217
  g
217
218
  ]);
218
- const v = D(() => S((f) => f + 1), []);
219
+ const v = j(() => S((f) => f + 1), []);
219
220
  return { loadFailed: _, retry: v };
220
- }, ee = q("crypto-sell-web", "index.js"), A = "zerohash-crypto-sell", re = ({
221
+ }, te = Q("crypto-sell-web", "index.js"), A = "zerohash-crypto-sell", ne = ({
221
222
  jwt: e,
222
223
  env: t = "prod",
223
224
  theme: o,
224
225
  onCompleted: r,
225
226
  onError: a,
226
- onClose: l,
227
+ onClose: i,
227
228
  onLoaded: c,
228
229
  onEvent: n,
229
230
  ...s
230
231
  }) => {
231
232
  const u = M(null);
232
- X(u, { theme: o, onCompleted: r, onError: a, onClose: l, onLoaded: c, onEvent: n });
233
- const { loadFailed: _, retry: m } = Y({
233
+ Y(u, { theme: o, onCompleted: r, onError: a, onClose: i, onLoaded: c, onEvent: n });
234
+ const { loadFailed: _, retry: m } = ee({
234
235
  webComponentTag: A,
235
- scriptUrls: ee,
236
+ scriptUrls: te,
236
237
  env: t,
237
238
  jwt: e
238
239
  });
239
- return _ ? /* @__PURE__ */ y(Q, { onRetry: m }) : j.createElement(A, {
240
+ return _ ? /* @__PURE__ */ y(X, { onRetry: m }) : D.createElement(A, {
240
241
  ref: u,
241
242
  jwt: e,
242
243
  env: t,
@@ -245,5 +246,5 @@ const b = {
245
246
  });
246
247
  };
247
248
  export {
248
- re as CryptoSell
249
+ ne as CryptoSell
249
250
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/crypto-sell-react",
3
- "version": "1.10.2",
3
+ "version": "1.11.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",