@zerohash-sdk/fund-withdrawals-js 0.5.0 → 0.5.2

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 CHANGED
@@ -19,14 +19,14 @@ import { FundWithdrawals } from '@zerohash-sdk/fund-withdrawals-js';
19
19
  ```html
20
20
  <script
21
21
  type="module"
22
- src="https://sdk.connect.xyz/fund-withdrawals-web/index.js"
22
+ src="https://sdk-cdn.zerohash.com/fund-withdrawals-web/index.js"
23
23
  ></script>
24
24
  ```
25
25
 
26
26
  Or import directly:
27
27
 
28
28
  ```javascript
29
- import { FundWithdrawals } from 'https://sdk.connect.xyz/fund-withdrawals-web/index.js';
29
+ import { FundWithdrawals } from 'https://sdk-cdn.zerohash.com/fund-withdrawals-web/index.js';
30
30
  ```
31
31
 
32
32
  ## Getting Started
package/dist/index.d.ts CHANGED
@@ -318,6 +318,40 @@ declare type CommonCallbacks<TEvent = AppEvent> = {
318
318
  onEvent?: (event: TEvent) => void;
319
319
  /** Called when the widget has loaded and is ready */
320
320
  onLoaded?: () => void;
321
+ /**
322
+ * Called when a deposit reaches a terminal state (success/failure/verifying).
323
+ * Optional — only SDKs that drive the integrations deposit flow emit it.
324
+ */
325
+ onDeposit?: (deposit: DepositCompletedPayload) => void;
326
+ };
327
+
328
+ /**
329
+ * Deposit completed payload — emitted by SDKs that drive a deposit through
330
+ * the integrations flow. Lives on `CommonCallbacks` because both Auth and
331
+ * any SDK embedding `@zerohash/integrations-flow` (e.g. fund with `useAuth`)
332
+ * resolve through the same deposit-status hook.
333
+ */
334
+ declare type DepositCompletedPayload = {
335
+ data: {
336
+ depositId: string;
337
+ status: DepositStatus;
338
+ assetId: string;
339
+ networkId: string;
340
+ amount?: string;
341
+ accountMatchingValidation?: {
342
+ status: 'PENDING' | 'VALID' | 'INVALID' | 'ERROR';
343
+ reason?: string;
344
+ };
345
+ };
346
+ };
347
+
348
+ /**
349
+ * Deposit status object — shared across SDKs that surface deposit completion.
350
+ */
351
+ declare type DepositStatus = {
352
+ value: string;
353
+ details: string;
354
+ occurredAt: string;
321
355
  };
322
356
 
323
357
  /**
@@ -384,16 +418,7 @@ declare class FundWithdrawals extends BaseJsSdk<FundWithdrawalsConfig> {
384
418
  SCRIPT_LOAD_FAILED: string;
385
419
  WEB_COMPONENT_NOT_DEFINED: string;
386
420
  };
387
- protected scriptUrls: {
388
- local: string;
389
- dev: string;
390
- cert: string;
391
- prod: string;
392
- sandbox: string;
393
- production: string;
394
- 'eu-cert': string;
395
- 'eu-prod': string;
396
- };
421
+ protected scriptUrls: Record<string, string>;
397
422
  protected webComponentTag: string;
398
423
  render(container: HTMLElement): Promise<void>;
399
424
  updateConfig(config: Partial<FundWithdrawalsConfig>): void;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const C = "production", z = "JWT token is required and must be a string.", W = {
1
+ const T = "production", W = "JWT token is required and must be a string.", F = {
2
2
  dev: "https://grafana-faro-collector.dev.0hash.com/collect",
3
3
  cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
4
4
  prod: "https://grafana-faro-collector.zerohash.com/collect",
@@ -6,50 +6,50 @@ const C = "production", z = "JWT token is required and must be a string.", W = {
6
6
  "eu-prod": "https://grafana-faro-collector.zerohash.eu/collect",
7
7
  sandbox: "https://grafana-faro-collector.cert.zerohash.com/collect",
8
8
  production: "https://grafana-faro-collector.zerohash.com/collect"
9
- }, x = (e) => {
9
+ }, M = (e) => {
10
10
  if (!e || typeof e != "string")
11
11
  return null;
12
12
  const t = e.split(".");
13
13
  if (t.length < 2)
14
14
  return null;
15
15
  try {
16
- const r = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = r + "===".slice(0, (4 - r.length % 4) % 4), o = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), d = JSON.parse(o)?.payload?.region;
17
- if (typeof d != "string")
16
+ const r = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = r + "===".slice(0, (4 - r.length % 4) % 4), o = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), i = JSON.parse(o)?.payload?.region;
17
+ if (typeof i != "string")
18
18
  return null;
19
- const s = d.toLowerCase();
19
+ const s = i.toLowerCase();
20
20
  return s === "us" || s === "eu" ? s : null;
21
21
  } catch {
22
22
  return null;
23
23
  }
24
- }, O = (e, t) => x(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, F = (e) => {
24
+ }, O = (e, t) => M(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, P = (e) => {
25
25
  if (!e || typeof e != "string")
26
26
  return {};
27
27
  const t = e.split(".");
28
28
  if (t.length < 2)
29
29
  return {};
30
30
  try {
31
- const r = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = r + "===".slice(0, (4 - r.length % 4) % 4), o = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), a = JSON.parse(o), d = a?.payload ?? {}, s = (c) => typeof c == "string" && c.length > 0 ? c : void 0;
31
+ const r = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = r + "===".slice(0, (4 - r.length % 4) % 4), o = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), a = JSON.parse(o), i = a?.payload ?? {}, s = (c) => typeof c == "string" && c.length > 0 ? c : void 0;
32
32
  return {
33
- participantCode: s(d.participant_code),
34
- platformName: s(d.platform_name),
33
+ participantCode: s(i.participant_code),
34
+ platformName: s(i.platform_name),
35
35
  platformCode: s(a.platform_code),
36
- region: s(d.region)
36
+ region: s(i.region)
37
37
  };
38
38
  } catch {
39
39
  return {};
40
40
  }
41
- }, T = (e, t, r) => {
41
+ }, N = (e, t, r) => {
42
42
  const n = O(t, r);
43
43
  return e[n] ?? e[t] ?? e.prod;
44
- }, M = (e, t, r) => {
44
+ }, U = (e, t, r) => {
45
45
  const n = O(t, r);
46
46
  return e[n] ?? e[t];
47
- }, E = () => {
48
- }, j = () => {
47
+ }, _ = () => {
48
+ }, k = () => {
49
49
  const e = new Uint8Array(8);
50
50
  return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
51
- }, k = (e, t) => {
52
- const r = j(), n = globalThis.__ZH_WEB_SDK_VERSION__, o = {};
51
+ }, $ = (e, t) => {
52
+ const r = k(), n = globalThis.__ZH_WEB_SDK_VERSION__, o = {};
53
53
  e.claims.participantCode && (o.participant_code = e.claims.participantCode), e.claims.platformName && (o.platform_name = e.claims.platformName), e.claims.platformCode && (o.platform_code = e.claims.platformCode), e.claims.region && (o.region = e.claims.region), n && (o.zh_web_sdk_version = n);
54
54
  const a = {
55
55
  meta: {
@@ -74,10 +74,10 @@ const C = "production", z = "JWT token is required and must be a string.", W = {
74
74
  ]
75
75
  };
76
76
  return { sessionId: r, payload: a };
77
- }, P = (e, t, r) => {
77
+ }, B = (e, t, r) => {
78
78
  if (!e || typeof fetch > "u")
79
79
  return;
80
- const { sessionId: n, payload: o } = k(t, r);
80
+ const { sessionId: n, payload: o } = $(t, r);
81
81
  try {
82
82
  fetch(e, {
83
83
  method: "POST",
@@ -88,60 +88,60 @@ const C = "production", z = "JWT token is required and must be a string.", W = {
88
88
  });
89
89
  } catch {
90
90
  }
91
- }, U = (e) => {
92
- const { webComponentTag: t, appName: r, appVersion: n, scriptUrls: o, fallbackScriptUrls: a, collectorUrls: d, env: s, jwt: c, timeoutMs: S = 15e3, onLoad: L, onError: I } = e;
91
+ }, V = (e) => {
92
+ const { webComponentTag: t, appName: r, appVersion: n, scriptUrls: o, fallbackScriptUrls: a, collectorUrls: i, env: s, jwt: c, timeoutMs: L = 15e3, onLoad: v, onError: I } = e;
93
93
  if (typeof document > "u")
94
- return E;
95
- const h = `${t}-script-${s}`;
96
- if (customElements.get(t) || document.getElementById(h))
97
- return E;
98
- const v = F(c), D = e.report ?? ((l) => P(d && M(d, s, c), l, n));
99
- let u = !1, _ = 0, f;
100
- const m = () => {
101
- f !== void 0 && clearTimeout(f);
102
- }, g = (l, p, i) => {
103
- if (u)
94
+ return _;
95
+ const m = `${t}-script-${s}`;
96
+ if (customElements.get(t) || document.getElementById(m))
97
+ return _;
98
+ const A = P(c), D = e.report ?? ((l) => B(i && U(i, s, c), l, n));
99
+ let h = !1, R = 0, g;
100
+ const f = () => {
101
+ g !== void 0 && clearTimeout(g);
102
+ }, E = (l, u, d) => {
103
+ if (h)
104
104
  return;
105
- const A = Math.round(performance.now() - _), y = {
105
+ const z = Math.round(performance.now() - R), C = {
106
106
  webComponentTag: t,
107
107
  appName: r,
108
108
  env: s,
109
- scriptUrl: p,
109
+ scriptUrl: u,
110
110
  reason: l,
111
- triedFallback: i,
112
- elapsedMs: A,
113
- claims: v
111
+ triedFallback: d,
112
+ elapsedMs: z,
113
+ claims: A
114
114
  };
115
- D(y);
116
- const w = i ? void 0 : T(a ?? {}, s, c);
117
- if (w && w !== p) {
115
+ D(C);
116
+ const w = d ? void 0 : N(a ?? {}, s, c);
117
+ if (w && w !== u) {
118
118
  b(w, !0);
119
119
  return;
120
120
  }
121
- u = !0, m(), document.getElementById(h)?.remove(), I?.(y);
122
- }, b = (l, p) => {
123
- m(), _ = performance.now();
124
- const i = document.createElement("script");
125
- i.id = h, i.src = l, i.type = "module", i.async = !0, i.onload = () => {
121
+ h = !0, f(), document.getElementById(m)?.remove(), I?.(C);
122
+ }, b = (l, u) => {
123
+ f(), R = performance.now();
124
+ const d = document.createElement("script");
125
+ d.id = m, d.src = l, d.type = "module", d.async = !0, d.onload = () => {
126
126
  setTimeout(() => {
127
- u || (customElements.get(t) ? (u = !0, m(), L?.()) : g("not-defined", l, p));
127
+ h || (customElements.get(t) ? (h = !0, f(), v?.()) : E("not-defined", l, u));
128
128
  }, 0);
129
- }, i.onerror = () => g("network", l, p), f = setTimeout(() => g("timeout", l, p), S), document.getElementById(h)?.remove(), document.head.appendChild(i);
130
- }, R = T(o, s, c);
131
- return R ? (b(R, !1), () => {
132
- u = !0, m();
133
- }) : E;
129
+ }, d.onerror = () => E("network", l, u), g = setTimeout(() => E("timeout", l, u), L), document.getElementById(m)?.remove(), document.head.appendChild(d);
130
+ }, y = N(o, s, c);
131
+ return y ? (b(y, !1), () => {
132
+ h = !0, f();
133
+ }) : _;
134
134
  };
135
- class B {
135
+ class j {
136
136
  config;
137
137
  state;
138
138
  scriptLoadingPromise;
139
139
  constructor(t) {
140
140
  if (!t.jwt || typeof t.jwt != "string")
141
- throw new Error(z);
141
+ throw new Error(W);
142
142
  this.config = {
143
143
  ...t,
144
- env: t.env || C,
144
+ env: t.env || T,
145
145
  theme: t.theme
146
146
  }, this.state = {
147
147
  initialized: !1,
@@ -202,7 +202,7 @@ class B {
202
202
  return { ...this.config };
203
203
  }
204
204
  getEnvironment() {
205
- return this.config.env || C;
205
+ return this.config.env || T;
206
206
  }
207
207
  getScriptId() {
208
208
  return `${this.webComponentTag}-script-${this.getEnvironment()}`;
@@ -221,11 +221,11 @@ class B {
221
221
  if (this.scriptLoadingPromise)
222
222
  return this.scriptLoadingPromise;
223
223
  this.scriptLoadingPromise = new Promise((t, r) => {
224
- U({
224
+ V({
225
225
  webComponentTag: this.webComponentTag,
226
226
  appName: this.webComponentTag,
227
227
  scriptUrls: this.getEffectiveScriptUrls(),
228
- collectorUrls: W,
228
+ collectorUrls: F,
229
229
  env: this.getEnvironment(),
230
230
  jwt: this.config.jwt,
231
231
  onLoad: t,
@@ -273,11 +273,27 @@ class B {
273
273
  }), t;
274
274
  }
275
275
  }
276
- var N;
276
+ const p = {
277
+ local: "http://localhost:5173",
278
+ dev: "https://sdk-cdn.dev.0hash.com",
279
+ cert: "https://sdk-cdn.cert.zerohash.com",
280
+ prod: "https://sdk-cdn.zerohash.com",
281
+ "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
282
+ "eu-prod": "https://sdk-cdn.zerohash.eu"
283
+ }, J = (e, t, r = {}) => {
284
+ const { eu: n = !1, legacyAliases: o = !1, local: a = p.local } = r, i = (c) => `${c}/${e}/${t}`, s = {
285
+ local: i(a),
286
+ dev: i(p.dev),
287
+ cert: i(p.cert),
288
+ prod: i(p.prod)
289
+ };
290
+ return o && (s.sandbox = i(p.cert), s.production = i(p.prod)), n && (s["eu-cert"] = i(p["eu-cert"]), s["eu-prod"] = i(p["eu-prod"])), s;
291
+ };
292
+ var S;
277
293
  (function(e) {
278
294
  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";
279
- })(N || (N = {}));
280
- class V extends B {
295
+ })(S || (S = {}));
296
+ class x extends j {
281
297
  errorMessages = {
282
298
  ALREADY_RENDERED: "FundWithdrawals widget is already rendered. Call destroy() before rendering again.",
283
299
  NOT_RENDERED: "FundWithdrawals widget is not rendered. Call render() first.",
@@ -285,18 +301,10 @@ class V extends B {
285
301
  SCRIPT_LOAD_FAILED: "Failed to load the Zerohash FundWithdrawals script.",
286
302
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
287
303
  };
288
- // US partners stay on connect.xyz; EU partners (JWT payload.region='eu') get
289
- // routed to sdk-cdn.zerohash.eu by BaseJsSdk.getScriptUrl via resolveEnvByRegion.
290
- scriptUrls = {
291
- local: "http://localhost:5173/fund-withdrawals-web/index.js",
292
- dev: "https://connect-sdk.dev.0hash.com/fund-withdrawals-web/index.js",
293
- cert: "https://sdk.sandbox.connect.xyz/fund-withdrawals-web/index.js",
294
- prod: "https://sdk.connect.xyz/fund-withdrawals-web/index.js",
295
- sandbox: "https://sdk.sandbox.connect.xyz/fund-withdrawals-web/index.js",
296
- production: "https://sdk.connect.xyz/fund-withdrawals-web/index.js",
297
- "eu-cert": "https://sdk-cdn.cert.zerohash.eu/fund-withdrawals-web/index.js",
298
- "eu-prod": "https://sdk-cdn.zerohash.eu/fund-withdrawals-web/index.js"
299
- };
304
+ scriptUrls = J("fund-withdrawals-web", "index.js", {
305
+ legacyAliases: !0,
306
+ eu: !0
307
+ });
300
308
  webComponentTag = "zerohash-fund-withdrawals";
301
309
  render(t) {
302
310
  return super.render(t);
@@ -315,7 +323,7 @@ class V extends B {
315
323
  }
316
324
  }
317
325
  export {
318
- N as ErrorCode,
319
- V as FundWithdrawals,
320
- V as default
326
+ S as ErrorCode,
327
+ x as FundWithdrawals,
328
+ x as default
321
329
  };
@@ -1 +1 @@
1
- (function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(i=typeof globalThis<"u"?globalThis:i||self,u(i.FundWithdrawals={}))})(this,(function(i){"use strict";const u="production",L="JWT token is required and must be a string.",v={dev:"https://grafana-faro-collector.dev.0hash.com/collect",cert:"https://grafana-faro-collector.cert.zerohash.com/collect",prod:"https://grafana-faro-collector.zerohash.com/collect","eu-cert":"https://grafana-faro-collector.cert.zerohash.eu/collect","eu-prod":"https://grafana-faro-collector.zerohash.eu/collect",sandbox:"https://grafana-faro-collector.cert.zerohash.com/collect",production:"https://grafana-faro-collector.zerohash.com/collect"},I=e=>{if(!e||typeof e!="string")return null;const t=e.split(".");if(t.length<2)return null;try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),n=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(n):Buffer.from(n,"base64").toString("utf-8"),c=JSON.parse(o)?.payload?.region;if(typeof c!="string")return null;const s=c.toLowerCase();return s==="us"||s==="eu"?s:null}catch{return null}},y=(e,t)=>I(t)!=="eu"?e:e==="cert"?"eu-cert":e==="prod"?"eu-prod":e,D=e=>{if(!e||typeof e!="string")return{};const t=e.split(".");if(t.length<2)return{};try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),n=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(n):Buffer.from(n,"base64").toString("utf-8"),d=JSON.parse(o),c=d?.payload??{},s=l=>typeof l=="string"&&l.length>0?l:void 0;return{participantCode:s(c.participant_code),platformName:s(c.platform_name),platformCode:s(d.platform_code),region:s(c.region)}}catch{return{}}},R=(e,t,r)=>{const n=y(t,r);return e[n]??e[t]??e.prod},A=(e,t,r)=>{const n=y(t,r);return e[n]??e[t]},w=()=>{},z=()=>{const e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")},W=(e,t)=>{const r=z(),n=globalThis.__ZH_WEB_SDK_VERSION__,o={};e.claims.participantCode&&(o.participant_code=e.claims.participantCode),e.claims.platformName&&(o.platform_name=e.claims.platformName),e.claims.platformCode&&(o.platform_code=e.claims.platformCode),e.claims.region&&(o.region=e.claims.region),n&&(o.zh_web_sdk_version=n);const d={meta:{app:{name:e.appName,version:t??"unknown",environment:e.env},session:{id:r,attributes:o},browser:typeof navigator<"u"?{userAgent:navigator.userAgent}:void 0,page:typeof window<"u"?{url:window.location.origin}:void 0},logs:[{message:`Failed to load the script for ${e.webComponentTag} from ${e.env} environment.`,level:"error",timestamp:new Date().toISOString(),context:{web_component:e.webComponentTag,script_url:e.scriptUrl,reason:e.reason,tried_fallback:String(e.triedFallback),elapsed_ms:String(e.elapsedMs)}}]};return{sessionId:r,payload:d}},F=(e,t,r)=>{if(!e||typeof fetch>"u")return;const{sessionId:n,payload:o}=W(t,r);try{fetch(e,{method:"POST",headers:{"Content-Type":"application/json","x-faro-session-id":n},body:JSON.stringify(o),keepalive:!0}).catch(()=>{})}catch{}},M=e=>{const{webComponentTag:t,appName:r,appVersion:n,scriptUrls:o,fallbackScriptUrls:d,collectorUrls:c,env:s,jwt:l,timeoutMs:x=15e3,onLoad:k,onError:P}=e;if(typeof document>"u")return w;const m=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(m))return w;const U=D(l),B=e.report??(p=>F(c&&A(c,s,l),p,n));let f=!1,C=0,E;const g=()=>{E!==void 0&&clearTimeout(E)},_=(p,h,a)=>{if(f)return;const V=Math.round(performance.now()-C),O={webComponentTag:t,appName:r,env:s,scriptUrl:h,reason:p,triedFallback:a,elapsedMs:V,claims:U};B(O);const b=a?void 0:R(d??{},s,l);if(b&&b!==h){N(b,!0);return}f=!0,g(),document.getElementById(m)?.remove(),P?.(O)},N=(p,h)=>{g(),C=performance.now();const a=document.createElement("script");a.id=m,a.src=p,a.type="module",a.async=!0,a.onload=()=>{setTimeout(()=>{f||(customElements.get(t)?(f=!0,g(),k?.()):_("not-defined",p,h))},0)},a.onerror=()=>_("network",p,h),E=setTimeout(()=>_("timeout",p,h),x),document.getElementById(m)?.remove(),document.head.appendChild(a)},S=R(o,s,l);return S?(N(S,!1),()=>{f=!0,g()}):w};class j{config;state;scriptLoadingPromise;constructor(t){if(!t.jwt||typeof t.jwt!="string")throw new Error(L);this.config={...t,env:t.env||u,theme:t.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(t){if(!t||!(t instanceof HTMLElement))throw new Error(this.errorMessages.INVALID_CONTAINER);if(this.state.initialized)throw new Error(this.errorMessages.ALREADY_RENDERED);try{await this.ensureScriptLoaded();const r=this.createWebComponent();t.innerHTML="",t.appendChild(r),this.state.container=t,this.state.element=r,this.state.initialized=!0}catch(r){throw console.error("Failed to render widget:",r),r}}updateConfig(t){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const r=this.state.element;Object.entries(t).forEach(([n,o])=>{o&&(this.config[n]=o,r[n]=o)})}destroy(){this.state.initialized&&(this.state.element&&this.state.element.parentNode&&this.state.element.parentNode.removeChild(this.state.element),this.state.container&&(this.state.container.innerHTML=""),this.state.container=null,this.state.element=null,this.state.initialized=!1)}isRendered(){return this.state.initialized}getConfig(){return{...this.config}}getEnvironment(){return this.config.env||u}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getEffectiveScriptUrls(){return this.scriptUrls}async loadScript(){if(!(this.getWebComponent()||this.isScriptLoaded())){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((t,r)=>{M({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:v,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:t,onError:n=>{r(new Error(n.reason==="not-defined"?this.errorMessages.WEB_COMPONENT_NOT_DEFINED:`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))}})});try{await this.scriptLoadingPromise}catch(t){throw this.scriptLoadingPromise=void 0,t}return this.scriptLoadingPromise}}async waitForWebComponent(t=5e3){if(!this.getWebComponent())return new Promise((r,n)=>{const o=setTimeout(()=>{n(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},t);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),r()}).catch(d=>{clearTimeout(o),n(d)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(t){throw console.error("Failed to load Connect script:",t),t}}createWebComponent(){const t=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([r,n])=>{n&&(t[r]=n)}),t}}i.ErrorCode=void 0,(function(e){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"})(i.ErrorCode||(i.ErrorCode={}));class T extends j{errorMessages={ALREADY_RENDERED:"FundWithdrawals widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"FundWithdrawals widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Zerohash FundWithdrawals script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={local:"http://localhost:5173/fund-withdrawals-web/index.js",dev:"https://connect-sdk.dev.0hash.com/fund-withdrawals-web/index.js",cert:"https://sdk.sandbox.connect.xyz/fund-withdrawals-web/index.js",prod:"https://sdk.connect.xyz/fund-withdrawals-web/index.js",sandbox:"https://sdk.sandbox.connect.xyz/fund-withdrawals-web/index.js",production:"https://sdk.connect.xyz/fund-withdrawals-web/index.js","eu-cert":"https://sdk-cdn.cert.zerohash.eu/fund-withdrawals-web/index.js","eu-prod":"https://sdk-cdn.zerohash.eu/fund-withdrawals-web/index.js"};webComponentTag="zerohash-fund-withdrawals";render(t){return super.render(t)}updateConfig(t){return super.updateConfig(t)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}i.FundWithdrawals=T,i.default=T,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.FundWithdrawals={}))})(this,(function(c){"use strict";const h="production",v="JWT token is required and must be a string.",I={dev:"https://grafana-faro-collector.dev.0hash.com/collect",cert:"https://grafana-faro-collector.cert.zerohash.com/collect",prod:"https://grafana-faro-collector.zerohash.com/collect","eu-cert":"https://grafana-faro-collector.cert.zerohash.eu/collect","eu-prod":"https://grafana-faro-collector.zerohash.eu/collect",sandbox:"https://grafana-faro-collector.cert.zerohash.com/collect",production:"https://grafana-faro-collector.zerohash.com/collect"},A=e=>{if(!e||typeof e!="string")return null;const t=e.split(".");if(t.length<2)return null;try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),n=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(n):Buffer.from(n,"base64").toString("utf-8"),i=JSON.parse(o)?.payload?.region;if(typeof i!="string")return null;const s=i.toLowerCase();return s==="us"||s==="eu"?s:null}catch{return null}},y=(e,t)=>A(t)!=="eu"?e:e==="cert"?"eu-cert":e==="prod"?"eu-prod":e,D=e=>{if(!e||typeof e!="string")return{};const t=e.split(".");if(t.length<2)return{};try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),n=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(n):Buffer.from(n,"base64").toString("utf-8"),a=JSON.parse(o),i=a?.payload??{},s=d=>typeof d=="string"&&d.length>0?d:void 0;return{participantCode:s(i.participant_code),platformName:s(i.platform_name),platformCode:s(a.platform_code),region:s(i.region)}}catch{return{}}},C=(e,t,r)=>{const n=y(t,r);return e[n]??e[t]??e.prod},W=(e,t,r)=>{const n=y(t,r);return e[n]??e[t]},w=()=>{},z=()=>{const e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")},F=(e,t)=>{const r=z(),n=globalThis.__ZH_WEB_SDK_VERSION__,o={};e.claims.participantCode&&(o.participant_code=e.claims.participantCode),e.claims.platformName&&(o.platform_name=e.claims.platformName),e.claims.platformCode&&(o.platform_code=e.claims.platformCode),e.claims.region&&(o.region=e.claims.region),n&&(o.zh_web_sdk_version=n);const a={meta:{app:{name:e.appName,version:t??"unknown",environment:e.env},session:{id:r,attributes:o},browser:typeof navigator<"u"?{userAgent:navigator.userAgent}:void 0,page:typeof window<"u"?{url:window.location.origin}:void 0},logs:[{message:`Failed to load the script for ${e.webComponentTag} from ${e.env} environment.`,level:"error",timestamp:new Date().toISOString(),context:{web_component:e.webComponentTag,script_url:e.scriptUrl,reason:e.reason,tried_fallback:String(e.triedFallback),elapsed_ms:String(e.elapsedMs)}}]};return{sessionId:r,payload:a}},M=(e,t,r)=>{if(!e||typeof fetch>"u")return;const{sessionId:n,payload:o}=F(t,r);try{fetch(e,{method:"POST",headers:{"Content-Type":"application/json","x-faro-session-id":n},body:JSON.stringify(o),keepalive:!0}).catch(()=>{})}catch{}},P=e=>{const{webComponentTag:t,appName:r,appVersion:n,scriptUrls:o,fallbackScriptUrls:a,collectorUrls:i,env:s,jwt:d,timeoutMs:$=15e3,onLoad:j,onError:B}=e;if(typeof document>"u")return w;const g=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(g))return w;const V=D(d),J=e.report??(u=>M(i&&W(i,s,d),u,n));let f=!1,N=0,_;const E=()=>{_!==void 0&&clearTimeout(_)},b=(u,m,l)=>{if(f)return;const H=Math.round(performance.now()-N),L={webComponentTag:t,appName:r,env:s,scriptUrl:m,reason:u,triedFallback:l,elapsedMs:H,claims:V};J(L);const R=l?void 0:C(a??{},s,d);if(R&&R!==m){S(R,!0);return}f=!0,E(),document.getElementById(g)?.remove(),B?.(L)},S=(u,m)=>{E(),N=performance.now();const l=document.createElement("script");l.id=g,l.src=u,l.type="module",l.async=!0,l.onload=()=>{setTimeout(()=>{f||(customElements.get(t)?(f=!0,E(),j?.()):b("not-defined",u,m))},0)},l.onerror=()=>b("network",u,m),_=setTimeout(()=>b("timeout",u,m),$),document.getElementById(g)?.remove(),document.head.appendChild(l)},O=C(o,s,d);return O?(S(O,!1),()=>{f=!0,E()}):w};class U{config;state;scriptLoadingPromise;constructor(t){if(!t.jwt||typeof t.jwt!="string")throw new Error(v);this.config={...t,env:t.env||h,theme:t.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(t){if(!t||!(t instanceof HTMLElement))throw new Error(this.errorMessages.INVALID_CONTAINER);if(this.state.initialized)throw new Error(this.errorMessages.ALREADY_RENDERED);try{await this.ensureScriptLoaded();const r=this.createWebComponent();t.innerHTML="",t.appendChild(r),this.state.container=t,this.state.element=r,this.state.initialized=!0}catch(r){throw console.error("Failed to render widget:",r),r}}updateConfig(t){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const r=this.state.element;Object.entries(t).forEach(([n,o])=>{o&&(this.config[n]=o,r[n]=o)})}destroy(){this.state.initialized&&(this.state.element&&this.state.element.parentNode&&this.state.element.parentNode.removeChild(this.state.element),this.state.container&&(this.state.container.innerHTML=""),this.state.container=null,this.state.element=null,this.state.initialized=!1)}isRendered(){return this.state.initialized}getConfig(){return{...this.config}}getEnvironment(){return this.config.env||h}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getEffectiveScriptUrls(){return this.scriptUrls}async loadScript(){if(!(this.getWebComponent()||this.isScriptLoaded())){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((t,r)=>{P({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:I,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:t,onError:n=>{r(new Error(n.reason==="not-defined"?this.errorMessages.WEB_COMPONENT_NOT_DEFINED:`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))}})});try{await this.scriptLoadingPromise}catch(t){throw this.scriptLoadingPromise=void 0,t}return this.scriptLoadingPromise}}async waitForWebComponent(t=5e3){if(!this.getWebComponent())return new Promise((r,n)=>{const o=setTimeout(()=>{n(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},t);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),r()}).catch(a=>{clearTimeout(o),n(a)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(t){throw console.error("Failed to load Connect script:",t),t}}createWebComponent(){const t=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([r,n])=>{n&&(t[r]=n)}),t}}const p={local:"http://localhost:5173",dev:"https://sdk-cdn.dev.0hash.com",cert:"https://sdk-cdn.cert.zerohash.com",prod:"https://sdk-cdn.zerohash.com","eu-cert":"https://sdk-cdn.cert.zerohash.eu","eu-prod":"https://sdk-cdn.zerohash.eu"},k=(e,t,r={})=>{const{eu:n=!1,legacyAliases:o=!1,local:a=p.local}=r,i=d=>`${d}/${e}/${t}`,s={local:i(a),dev:i(p.dev),cert:i(p.cert),prod:i(p.prod)};return o&&(s.sandbox=i(p.cert),s.production=i(p.prod)),n&&(s["eu-cert"]=i(p["eu-cert"]),s["eu-prod"]=i(p["eu-prod"])),s};c.ErrorCode=void 0,(function(e){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"})(c.ErrorCode||(c.ErrorCode={}));class T extends U{errorMessages={ALREADY_RENDERED:"FundWithdrawals widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"FundWithdrawals widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Zerohash FundWithdrawals script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls=k("fund-withdrawals-web","index.js",{legacyAliases:!0,eu:!0});webComponentTag="zerohash-fund-withdrawals";render(t){return super.render(t)}updateConfig(t){return super.updateConfig(t)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}c.FundWithdrawals=T,c.default=T,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/fund-withdrawals-js",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",