@zerohash-sdk/onboarding-react 1.11.7 → 1.13.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/README.md +9 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +96 -78
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,6 +139,15 @@ export default App;
|
|
|
139
139
|
| `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
|
|
140
140
|
| `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
|
|
141
141
|
|
|
142
|
+
## JWT & token renewal
|
|
143
|
+
|
|
144
|
+
The `jwt` prop is what the widget uses to authenticate.
|
|
145
|
+
|
|
146
|
+
**The SDK does not support refresh tokens.** It does not renew or re-authenticate
|
|
147
|
+
a token on its own — there is no built-in token-refresh mechanism. Token renewal
|
|
148
|
+
is handled entirely by the host: obtain a new JWT from your backend and pass it
|
|
149
|
+
as the `jwt` prop.
|
|
150
|
+
|
|
142
151
|
## More Information & Support
|
|
143
152
|
|
|
144
153
|
For comprehensive documentation or support about Connect, visit our [Documentation Page](https://docs.zerohash.com/).
|
package/dist/index.d.ts
CHANGED
|
@@ -19,8 +19,10 @@ declare type AppEvent<TType extends string = string, TData = Record<string, unkn
|
|
|
19
19
|
* - `"dev"` - Development environment for early-stage testing
|
|
20
20
|
* - `"cert"` - Certificate/staging environment for integration testing
|
|
21
21
|
* - `"prod"` - Live production environment for real applications
|
|
22
|
+
*
|
|
23
|
+
* Exported so integrators can type the `env` prop (ID-4534).
|
|
22
24
|
*/
|
|
23
|
-
declare type Environment = 'local' | 'dev' | 'cert' | 'prod';
|
|
25
|
+
export declare type Environment = 'local' | 'dev' | 'cert' | 'prod';
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* Generic error codes for all Connect applications
|
|
@@ -57,7 +59,7 @@ declare type ErrorPayload = {
|
|
|
57
59
|
*
|
|
58
60
|
* @param props - Component properties
|
|
59
61
|
* @param jwt - JWT token for authentication (required)
|
|
60
|
-
* @param env - Target environment ("local" | "dev" | "cert" | "prod"
|
|
62
|
+
* @param env - Target environment ("local" | "dev" | "cert" | "prod"). Omit for prod; init-only
|
|
61
63
|
* @param theme - Theme mode ("auto" | "light" | "dark", defaults to "auto")
|
|
62
64
|
* @param onCompleted - Callback invoked when the sell flow is successfully completed
|
|
63
65
|
* @param onError - Callback invoked when an error occurs
|
|
@@ -107,6 +109,10 @@ declare interface OnboardingProps {
|
|
|
107
109
|
* This token should be obtained from your backend and contain the necessary
|
|
108
110
|
* claims for user identification and authorization.
|
|
109
111
|
*
|
|
112
|
+
* The SDK does not support refresh tokens and does not renew tokens on its
|
|
113
|
+
* own. To handle renewal, fetch a new JWT from your backend and pass it as
|
|
114
|
+
* this prop.
|
|
115
|
+
*
|
|
110
116
|
* @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
111
117
|
*/
|
|
112
118
|
jwt: string;
|
|
@@ -115,6 +121,10 @@ declare interface OnboardingProps {
|
|
|
115
121
|
*
|
|
116
122
|
* @default "prod"
|
|
117
123
|
*
|
|
124
|
+
* Omit for production. `env` is init-only: it's read once when the widget
|
|
125
|
+
* mounts and locks the iframe URL — changing it afterward has no effect.
|
|
126
|
+
* Region (EU) routing is derived from the JWT, not from `env`.
|
|
127
|
+
*
|
|
118
128
|
* Available environments:
|
|
119
129
|
* - `"local"` - Local development environment
|
|
120
130
|
* - `"dev"` - Development environment
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsxs as W, jsx as
|
|
2
|
-
import
|
|
1
|
+
import { jsxs as W, jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import M, { useEffect as A, useState as L, useCallback as j, useRef as D } 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
|
-
},
|
|
26
|
+
}, I = (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"),
|
|
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"), s = JSON.parse(a), c = s?.payload ?? {}, n = (i) => typeof i == "string" && i.length > 0 ? i : void 0;
|
|
34
34
|
return {
|
|
35
35
|
participantCode: n(c.participant_code),
|
|
36
36
|
platformName: n(c.platform_name),
|
|
37
|
-
platformCode: n(
|
|
37
|
+
platformCode: n(s.platform_code),
|
|
38
38
|
region: n(c.region)
|
|
39
39
|
};
|
|
40
40
|
} catch {
|
|
41
41
|
return {};
|
|
42
42
|
}
|
|
43
|
-
},
|
|
44
|
-
const r =
|
|
43
|
+
}, z = (e, t, o) => {
|
|
44
|
+
const r = I(t, o);
|
|
45
45
|
return e[r] ?? e[t] ?? e.prod;
|
|
46
|
-
},
|
|
47
|
-
const r =
|
|
46
|
+
}, H = (e, t, o) => {
|
|
47
|
+
const r = I(t, o);
|
|
48
48
|
return e[r] ?? e[t];
|
|
49
|
-
},
|
|
50
|
-
},
|
|
49
|
+
}, O = () => {
|
|
50
|
+
}, J = () => {
|
|
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
|
}, G = (e, t) => {
|
|
54
|
-
const o =
|
|
54
|
+
const o = J(), 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
|
|
56
|
+
const s = {
|
|
57
57
|
meta: {
|
|
58
58
|
app: { name: e.appName, version: t ?? "unknown", environment: e.env },
|
|
59
59
|
session: { id: o, attributes: a },
|
|
@@ -75,7 +75,7 @@ const $ = {
|
|
|
75
75
|
}
|
|
76
76
|
]
|
|
77
77
|
};
|
|
78
|
-
return { sessionId: o, payload:
|
|
78
|
+
return { sessionId: o, payload: s };
|
|
79
79
|
}, K = (e, t, o) => {
|
|
80
80
|
if (!e || typeof fetch > "u")
|
|
81
81
|
return;
|
|
@@ -91,49 +91,49 @@ const $ = {
|
|
|
91
91
|
} catch {
|
|
92
92
|
}
|
|
93
93
|
}, Z = (e) => {
|
|
94
|
-
const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls:
|
|
94
|
+
const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: s, collectorUrls: c, env: n, jwt: i, timeoutMs: f = 15e3, onLoad: _, onError: g } = e;
|
|
95
95
|
if (typeof document > "u")
|
|
96
|
-
return
|
|
97
|
-
const
|
|
98
|
-
if (customElements.get(t) || document.getElementById(
|
|
99
|
-
return
|
|
100
|
-
const S = P(
|
|
101
|
-
let
|
|
96
|
+
return O;
|
|
97
|
+
const h = `${t}-script-${n}`;
|
|
98
|
+
if (customElements.get(t) || document.getElementById(h))
|
|
99
|
+
return O;
|
|
100
|
+
const S = P(i), k = e.report ?? ((p) => K(c && H(c, n, i), p, r));
|
|
101
|
+
let m = !1, w = 0, v;
|
|
102
102
|
const R = () => {
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
if (
|
|
103
|
+
v !== void 0 && clearTimeout(v);
|
|
104
|
+
}, x = (p, y, l) => {
|
|
105
|
+
if (m)
|
|
106
106
|
return;
|
|
107
|
-
const U = Math.round(performance.now() -
|
|
107
|
+
const U = Math.round(performance.now() - w), E = {
|
|
108
108
|
webComponentTag: t,
|
|
109
109
|
appName: o,
|
|
110
110
|
env: n,
|
|
111
|
-
scriptUrl:
|
|
112
|
-
reason:
|
|
111
|
+
scriptUrl: y,
|
|
112
|
+
reason: p,
|
|
113
113
|
triedFallback: l,
|
|
114
114
|
elapsedMs: U,
|
|
115
115
|
claims: S
|
|
116
116
|
};
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
|
|
117
|
+
k(E);
|
|
118
|
+
const C = l ? void 0 : z(s ?? {}, n, i);
|
|
119
|
+
if (C && C !== y) {
|
|
120
|
+
N(C, !0);
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
R(),
|
|
123
|
+
m = !0, R(), document.getElementById(h)?.remove(), g?.(E);
|
|
124
|
+
}, N = (p, y) => {
|
|
125
|
+
R(), w = performance.now();
|
|
126
126
|
const l = document.createElement("script");
|
|
127
|
-
l.id =
|
|
127
|
+
l.id = h, l.src = p, l.type = "module", l.async = !0, l.onload = () => {
|
|
128
128
|
setTimeout(() => {
|
|
129
|
-
|
|
129
|
+
m || (customElements.get(t) ? (m = !0, R(), _?.()) : x("not-defined", p, y));
|
|
130
130
|
}, 0);
|
|
131
|
-
}, l.onerror = () =>
|
|
132
|
-
},
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
}) :
|
|
136
|
-
},
|
|
131
|
+
}, l.onerror = () => x("network", p, y), v = setTimeout(() => x("timeout", p, y), f), document.getElementById(h)?.remove(), document.head.appendChild(l);
|
|
132
|
+
}, T = z(a, n, i);
|
|
133
|
+
return T ? (N(T, !1), () => {
|
|
134
|
+
m = !0, R();
|
|
135
|
+
}) : O;
|
|
136
|
+
}, u = {
|
|
137
137
|
local: "http://localhost:5173",
|
|
138
138
|
dev: "https://sdk-cdn.dev.0hash.com",
|
|
139
139
|
cert: "https://sdk-cdn.cert.zerohash.com",
|
|
@@ -141,25 +141,26 @@ const $ = {
|
|
|
141
141
|
"eu-cert": "https://sdk-cdn.cert.zerohash.eu",
|
|
142
142
|
"eu-prod": "https://sdk-cdn.zerohash.eu"
|
|
143
143
|
}, q = "https://sdk-cdn.gating.0hash.com", Q = (e, t, o = {}) => {
|
|
144
|
-
const { eu: r = !1, legacyAliases: a = !1, local:
|
|
145
|
-
local: c(
|
|
146
|
-
dev: c(
|
|
144
|
+
const { eu: r = !1, legacyAliases: a = !1, local: s = u.local } = o, c = (i) => `${i}/${e}/${t}`, n = {
|
|
145
|
+
local: c(s),
|
|
146
|
+
dev: c(u.dev),
|
|
147
147
|
gating: c(q),
|
|
148
|
-
cert: c(
|
|
149
|
-
prod: c(
|
|
148
|
+
cert: c(u.cert),
|
|
149
|
+
prod: c(u.prod)
|
|
150
150
|
};
|
|
151
|
-
return a && (n.sandbox = c(
|
|
151
|
+
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;
|
|
152
152
|
};
|
|
153
153
|
var F;
|
|
154
154
|
(function(e) {
|
|
155
155
|
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";
|
|
156
156
|
})(F || (F = {}));
|
|
157
|
-
const
|
|
157
|
+
const b = {
|
|
158
158
|
evergreen: "#00381D",
|
|
159
159
|
green: "#CCFFD0",
|
|
160
160
|
offBlack: "#1C1B1C",
|
|
161
161
|
grayLight: "#EBEBE9"
|
|
162
|
-
}, X = ({ onRetry: e }) => W("div", { role: "alert", style: {
|
|
162
|
+
}, X = ({ onRetry: e, onClose: t }) => W("div", { role: "alert", style: {
|
|
163
|
+
position: "relative",
|
|
163
164
|
display: "flex",
|
|
164
165
|
flexDirection: "column",
|
|
165
166
|
alignItems: "center",
|
|
@@ -169,80 +170,97 @@ const _ = {
|
|
|
169
170
|
padding: "32px 24px",
|
|
170
171
|
textAlign: "center",
|
|
171
172
|
fontFamily: "inherit",
|
|
172
|
-
color:
|
|
173
|
+
color: b.offBlack,
|
|
173
174
|
background: "#FFFFFF",
|
|
174
|
-
border: `1px solid ${
|
|
175
|
+
border: `1px solid ${b.grayLight}`,
|
|
175
176
|
borderRadius: "12px"
|
|
176
|
-
}, children: [
|
|
177
|
+
}, children: [t && d("button", { type: "button", onClick: t, "aria-label": "Close", style: {
|
|
178
|
+
position: "absolute",
|
|
179
|
+
top: "12px",
|
|
180
|
+
right: "12px",
|
|
181
|
+
display: "flex",
|
|
182
|
+
padding: "4px",
|
|
183
|
+
color: b.offBlack,
|
|
184
|
+
background: "none",
|
|
185
|
+
border: "none",
|
|
186
|
+
cursor: "pointer",
|
|
187
|
+
lineHeight: 0
|
|
188
|
+
}, 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: b.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: {
|
|
177
189
|
marginTop: "8px",
|
|
178
190
|
padding: "8px 20px",
|
|
179
191
|
fontSize: "14px",
|
|
180
192
|
fontWeight: 600,
|
|
181
193
|
fontFamily: "inherit",
|
|
182
|
-
color:
|
|
183
|
-
background:
|
|
194
|
+
color: b.green,
|
|
195
|
+
background: b.evergreen,
|
|
184
196
|
border: "none",
|
|
185
197
|
borderRadius: "8px",
|
|
186
198
|
cursor: "pointer"
|
|
187
199
|
}, children: "Try again" })] }), Y = (e, t) => {
|
|
188
|
-
|
|
200
|
+
A(() => {
|
|
189
201
|
const o = e.current;
|
|
190
202
|
if (o)
|
|
191
203
|
for (const [r, a] of Object.entries(t))
|
|
192
204
|
a !== void 0 && (o[r] = a);
|
|
193
205
|
});
|
|
194
206
|
}, ee = (e) => {
|
|
195
|
-
const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls:
|
|
196
|
-
|
|
207
|
+
const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: s, collectorUrls: c, env: n, jwt: i, timeoutMs: f } = e, [_, g] = L(!1), [h, S] = L(0);
|
|
208
|
+
A(() => (g(!1), Z({
|
|
197
209
|
webComponentTag: t,
|
|
198
210
|
appName: o ?? t,
|
|
199
211
|
appVersion: r,
|
|
200
212
|
scriptUrls: a,
|
|
201
|
-
fallbackScriptUrls:
|
|
213
|
+
fallbackScriptUrls: s,
|
|
202
214
|
collectorUrls: c ?? $,
|
|
203
215
|
env: n,
|
|
204
|
-
jwt:
|
|
205
|
-
timeoutMs:
|
|
206
|
-
onError: () =>
|
|
216
|
+
jwt: i,
|
|
217
|
+
timeoutMs: f,
|
|
218
|
+
onError: () => g(!0)
|
|
207
219
|
})), [
|
|
208
220
|
t,
|
|
209
221
|
o,
|
|
210
222
|
r,
|
|
211
223
|
a,
|
|
212
|
-
|
|
224
|
+
s,
|
|
213
225
|
c,
|
|
214
226
|
n,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
227
|
+
i,
|
|
228
|
+
f,
|
|
229
|
+
h
|
|
218
230
|
]);
|
|
219
|
-
const
|
|
220
|
-
return { loadFailed:
|
|
221
|
-
}, te = Q("onboarding-web", "index.js", { eu: !0 }),
|
|
231
|
+
const k = j(() => S((m) => m + 1), []);
|
|
232
|
+
return { loadFailed: _, retry: k };
|
|
233
|
+
}, te = Q("onboarding-web", "index.js", { eu: !0 }), B = "zerohash-onboarding", ne = ({
|
|
222
234
|
jwt: e,
|
|
223
235
|
env: t = "prod",
|
|
224
236
|
theme: o,
|
|
225
237
|
onCompleted: r,
|
|
226
238
|
onError: a,
|
|
227
|
-
onClose:
|
|
239
|
+
onClose: s,
|
|
228
240
|
onLoaded: c,
|
|
229
241
|
onEvent: n,
|
|
230
|
-
...
|
|
242
|
+
...i
|
|
231
243
|
}) => {
|
|
232
|
-
const
|
|
233
|
-
Y(
|
|
234
|
-
const { loadFailed:
|
|
235
|
-
webComponentTag:
|
|
244
|
+
const f = D(null);
|
|
245
|
+
Y(f, { theme: o, onCompleted: r, onError: a, onClose: s, onLoaded: c, onEvent: n });
|
|
246
|
+
const { loadFailed: _, retry: g } = ee({
|
|
247
|
+
webComponentTag: B,
|
|
236
248
|
scriptUrls: te,
|
|
237
249
|
env: t,
|
|
238
250
|
jwt: e
|
|
239
251
|
});
|
|
240
|
-
return
|
|
241
|
-
|
|
252
|
+
return _ ? /* @__PURE__ */ d(
|
|
253
|
+
X,
|
|
254
|
+
{
|
|
255
|
+
onRetry: g,
|
|
256
|
+
onClose: s
|
|
257
|
+
}
|
|
258
|
+
) : M.createElement(B, {
|
|
259
|
+
ref: f,
|
|
242
260
|
jwt: e,
|
|
243
261
|
env: t,
|
|
244
262
|
theme: o,
|
|
245
|
-
...
|
|
263
|
+
...i
|
|
246
264
|
});
|
|
247
265
|
};
|
|
248
266
|
export {
|