@zerohash-sdk/fund-react 1.7.0 → 1.8.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.d.ts CHANGED
@@ -163,6 +163,12 @@ declare interface FundProps {
163
163
  * ```
164
164
  */
165
165
  theme?: Theme;
166
+ /**
167
+ * Live branding override (`{ theme?, colors?: { accent? } }`) for previewing an
168
+ * unsaved draft theme (e.g. from a host theme editor). Pushed into the SDK and
169
+ * applied over the JWT `theme` claim, per-field. Mainly for internal preview UIs.
170
+ */
171
+ branding?: unknown;
166
172
  /**
167
173
  * Runs the SDK in Pay mode.
168
174
  *
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsxs as W, jsx as _ } from "react/jsx-runtime";
1
+ import { jsxs as W, jsx as y } from "react/jsx-runtime";
2
2
  import j, { useEffect as B, useState as z, useCallback as D, useRef as M } from "react";
3
3
  const $ = {
4
4
  dev: "https://grafana-faro-collector.dev.0hash.com/collect",
@@ -15,11 +15,11 @@ const $ = {
15
15
  if (t.length < 2)
16
16
  return null;
17
17
  try {
18
- 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"), c = JSON.parse(a)?.payload?.region;
18
+ const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), n = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), c = JSON.parse(n)?.payload?.region;
19
19
  if (typeof c != "string")
20
20
  return null;
21
- const n = c.toLowerCase();
22
- return n === "us" || n === "eu" ? n : null;
21
+ const a = c.toLowerCase();
22
+ return a === "us" || a === "eu" ? a : null;
23
23
  } catch {
24
24
  return null;
25
25
  }
@@ -30,12 +30,12 @@ const $ = {
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"), i = JSON.parse(a), c = i?.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), n = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), i = JSON.parse(n), c = i?.payload ?? {}, a = (s) => typeof s == "string" && s.length > 0 ? s : void 0;
34
34
  return {
35
- participantCode: n(c.participant_code),
36
- platformName: n(c.platform_name),
37
- platformCode: n(i.platform_code),
38
- region: n(c.region)
35
+ participantCode: a(c.participant_code),
36
+ platformName: a(c.platform_name),
37
+ platformCode: a(i.platform_code),
38
+ region: a(c.region)
39
39
  };
40
40
  } catch {
41
41
  return {};
@@ -51,12 +51,12 @@ const $ = {
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
53
  }, K = (e, t) => {
54
- const o = H(), r = globalThis.__ZH_WEB_SDK_VERSION__, a = {};
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);
54
+ const o = H(), r = globalThis.__ZH_WEB_SDK_VERSION__, n = {};
55
+ e.claims.participantCode && (n.participant_code = e.claims.participantCode), e.claims.platformName && (n.platform_name = e.claims.platformName), e.claims.platformCode && (n.platform_code = e.claims.platformCode), e.claims.region && (n.region = e.claims.region), r && (n.zh_web_sdk_version = r);
56
56
  const i = {
57
57
  meta: {
58
58
  app: { name: e.appName, version: t ?? "unknown", environment: e.env },
59
- session: { id: o, attributes: a },
59
+ session: { id: o, attributes: n },
60
60
  browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
61
61
  page: typeof window < "u" ? { url: window.location.origin } : void 0
62
62
  },
@@ -79,59 +79,59 @@ const $ = {
79
79
  }, G = (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: n } = K(t, o);
83
83
  try {
84
84
  fetch(e, {
85
85
  method: "POST",
86
86
  headers: { "Content-Type": "application/json", "x-faro-session-id": r },
87
- body: JSON.stringify(a),
87
+ body: JSON.stringify(n),
88
88
  keepalive: !0
89
89
  }).catch(() => {
90
90
  });
91
91
  } catch {
92
92
  }
93
93
  }, Z = (e) => {
94
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: c, env: n, jwt: s, timeoutMs: m = 15e3, onLoad: g, onError: h } = e;
94
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs: g = 15e3, onLoad: _, onError: f } = e;
95
95
  if (typeof document > "u")
96
96
  return x;
97
- const d = `${t}-script-${n}`;
97
+ const d = `${t}-script-${a}`;
98
98
  if (customElements.get(t) || document.getElementById(d))
99
99
  return x;
100
- const S = J(s), v = e.report ?? ((p) => G(c && P(c, n, s), p, r));
101
- let f = !1, w = 0, C;
102
- const R = () => {
100
+ const b = J(s), v = e.report ?? ((p) => G(c && P(c, a, s), p, r));
101
+ let m = !1, w = 0, C;
102
+ const S = () => {
103
103
  C !== void 0 && clearTimeout(C);
104
- }, k = (p, y, l) => {
105
- if (f)
104
+ }, k = (p, h, l) => {
105
+ if (m)
106
106
  return;
107
107
  const U = Math.round(performance.now() - w), T = {
108
108
  webComponentTag: t,
109
109
  appName: o,
110
- env: n,
111
- scriptUrl: y,
110
+ env: a,
111
+ scriptUrl: h,
112
112
  reason: p,
113
113
  triedFallback: l,
114
114
  elapsedMs: U,
115
- claims: S
115
+ claims: b
116
116
  };
117
117
  v(T);
118
- const O = l ? void 0 : F(i ?? {}, n, s);
119
- if (O && O !== y) {
118
+ const O = l ? void 0 : F(i ?? {}, a, s);
119
+ if (O && O !== h) {
120
120
  E(O, !0);
121
121
  return;
122
122
  }
123
- f = !0, R(), document.getElementById(d)?.remove(), h?.(T);
124
- }, E = (p, y) => {
125
- R(), w = performance.now();
123
+ m = !0, S(), document.getElementById(d)?.remove(), f?.(T);
124
+ }, E = (p, h) => {
125
+ S(), w = performance.now();
126
126
  const l = document.createElement("script");
127
127
  l.id = d, l.src = p, l.type = "module", l.async = !0, l.onload = () => {
128
128
  setTimeout(() => {
129
- f || (customElements.get(t) ? (f = !0, R(), g?.()) : k("not-defined", p, y));
129
+ m || (customElements.get(t) ? (m = !0, S(), _?.()) : k("not-defined", p, h));
130
130
  }, 0);
131
- }, l.onerror = () => k("network", p, y), C = setTimeout(() => k("timeout", p, y), m), document.getElementById(d)?.remove(), document.head.appendChild(l);
132
- }, N = F(a, n, s);
131
+ }, l.onerror = () => k("network", p, h), C = setTimeout(() => k("timeout", p, h), g), document.getElementById(d)?.remove(), document.head.appendChild(l);
132
+ }, N = F(n, a, s);
133
133
  return N ? (E(N, !1), () => {
134
- f = !0, R();
134
+ m = !0, S();
135
135
  }) : x;
136
136
  }, u = {
137
137
  local: "http://localhost:5173",
@@ -141,19 +141,19 @@ const $ = {
141
141
  "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
142
142
  "eu-prod": "https://sdk-cdn.zerohash.eu"
143
143
  }, q = (e, t, o = {}) => {
144
- const { eu: r = !1, legacyAliases: a = !1, local: i = u.local } = o, c = (s) => `${s}/${e}/${t}`, n = {
144
+ const { eu: r = !1, legacyAliases: n = !1, local: i = u.local } = o, c = (s) => `${s}/${e}/${t}`, a = {
145
145
  local: c(i),
146
146
  dev: c(u.dev),
147
147
  cert: c(u.cert),
148
148
  prod: c(u.prod)
149
149
  };
150
- return a && (n.sandbox = c(u.cert), n.production = c(u.prod)), r && (n["eu-cert"] = c(u["eu-cert"]), n["eu-prod"] = c(u["eu-prod"])), n;
150
+ return n && (a.sandbox = c(u.cert), a.production = c(u.prod)), r && (a["eu-cert"] = c(u["eu-cert"]), a["eu-prod"] = c(u["eu-prod"])), a;
151
151
  };
152
152
  var L;
153
153
  (function(e) {
154
154
  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";
155
155
  })(L || (L = {}));
156
- const b = {
156
+ const R = {
157
157
  evergreen: "#00381D",
158
158
  green: "#CCFFD0",
159
159
  offBlack: "#1C1B1C",
@@ -168,18 +168,18 @@ const b = {
168
168
  padding: "32px 24px",
169
169
  textAlign: "center",
170
170
  fontFamily: "inherit",
171
- color: b.offBlack,
171
+ color: R.offBlack,
172
172
  background: "#FFFFFF",
173
- border: `1px solid ${b.grayLight}`,
173
+ border: `1px solid ${R.grayLight}`,
174
174
  borderRadius: "12px"
175
- }, children: [_("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _("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" }) }), _("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), _("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), _("button", { type: "button", onClick: e, style: {
175
+ }, children: [y("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: y("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: R.evergreen, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }), y("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), y("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), y("button", { type: "button", onClick: e, style: {
176
176
  marginTop: "8px",
177
177
  padding: "8px 20px",
178
178
  fontSize: "14px",
179
179
  fontWeight: 600,
180
180
  fontFamily: "inherit",
181
- color: b.green,
182
- background: b.evergreen,
181
+ color: R.green,
182
+ background: R.evergreen,
183
183
  border: "none",
184
184
  borderRadius: "8px",
185
185
  cursor: "pointer"
@@ -187,64 +187,65 @@ const b = {
187
187
  B(() => {
188
188
  const o = e.current;
189
189
  if (o)
190
- for (const [r, a] of Object.entries(t))
191
- a !== void 0 && (o[r] = a);
190
+ for (const [r, n] of Object.entries(t))
191
+ n !== void 0 && (o[r] = n);
192
192
  });
193
193
  }, Y = (e) => {
194
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: c, env: n, jwt: s, timeoutMs: m } = e, [g, h] = z(!1), [d, S] = z(0);
195
- B(() => (h(!1), Z({
194
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs: g } = e, [_, f] = z(!1), [d, b] = z(0);
195
+ B(() => (f(!1), Z({
196
196
  webComponentTag: t,
197
197
  appName: o ?? t,
198
198
  appVersion: r,
199
- scriptUrls: a,
199
+ scriptUrls: n,
200
200
  fallbackScriptUrls: i,
201
201
  collectorUrls: c ?? $,
202
- env: n,
202
+ env: a,
203
203
  jwt: s,
204
- timeoutMs: m,
205
- onError: () => h(!0)
204
+ timeoutMs: g,
205
+ onError: () => f(!0)
206
206
  })), [
207
207
  t,
208
208
  o,
209
209
  r,
210
- a,
210
+ n,
211
211
  i,
212
212
  c,
213
- n,
213
+ a,
214
214
  s,
215
- m,
215
+ g,
216
216
  d
217
217
  ]);
218
- const v = D(() => S((f) => f + 1), []);
219
- return { loadFailed: g, retry: v };
218
+ const v = D(() => b((m) => m + 1), []);
219
+ return { loadFailed: _, retry: v };
220
220
  }, ee = q("fund-web", "index.js", { eu: !0 }), A = "zerohash-fund", re = ({
221
221
  jwt: e,
222
222
  env: t = "prod",
223
223
  theme: o,
224
- isPay: r = !1,
225
- onCompleted: a,
226
- onError: i,
227
- onClose: c,
228
- onLoaded: n,
229
- onEvent: s,
230
- ...m
224
+ branding: r,
225
+ isPay: n = !1,
226
+ onCompleted: i,
227
+ onError: c,
228
+ onClose: a,
229
+ onLoaded: s,
230
+ onEvent: g,
231
+ ..._
231
232
  }) => {
232
- const g = M(null);
233
- X(g, { isPay: r, theme: o, onCompleted: a, onError: i, onClose: c, onLoaded: n, onEvent: s });
234
- const { loadFailed: h, retry: d } = Y({
233
+ const f = M(null);
234
+ X(f, { isPay: n, theme: o, branding: r, onCompleted: i, onError: c, onClose: a, onLoaded: s, onEvent: g });
235
+ const { loadFailed: d, retry: b } = Y({
235
236
  webComponentTag: A,
236
237
  scriptUrls: ee,
237
238
  // fallbackScriptUrls: FALLBACK_SCRIPT_URLS, // enable once the host is confirmed (AUTH-3095)
238
239
  env: t,
239
240
  jwt: e
240
241
  });
241
- return h ? /* @__PURE__ */ _(Q, { onRetry: d }) : j.createElement(A, {
242
- ref: g,
242
+ return d ? /* @__PURE__ */ y(Q, { onRetry: b }) : j.createElement(A, {
243
+ ref: f,
243
244
  jwt: e,
244
245
  env: t,
245
246
  theme: o,
246
- ispay: r ? "true" : void 0,
247
- ...m
247
+ ispay: n ? "true" : void 0,
248
+ ..._
248
249
  });
249
250
  };
250
251
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/fund-react",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",