@zerohash-sdk/csp-crypto-withdrawals-js 1.6.0 → 1.6.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
@@ -83,16 +83,16 @@ await cspCryptoWithdrawals.render(document.getElementById('container')!);
83
83
 
84
84
  ### Configuration
85
85
 
86
- | Prop | Type | Required | Default | Description |
87
- | ------------- | ----------------------------------------------------------------------------------- | -------- | -------- | -------------------------------------------------------- |
88
- | `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
89
- | `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
90
- | `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
91
- | `onCompleted` | `({ withdrawalRequestId, assetSymbol, amount, networkFee, withdrawalFee }) => void` | No | - | Callback when the withdrawal flow completes successfully |
92
- | `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
93
- | `onClose` | `() => void` | No | - | Callback when the widget is closed |
94
- | `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
95
- | `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
86
+ | Prop | Type | Required | Default | Description |
87
+ | ------------- | ----------------------------------------------------------------------------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
88
+ | `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
89
+ | `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment. EU partners (JWT `payload.region='eu'`) are routed automatically to the EU CDN (`sdk-cdn.cert.zerohash.eu` / `sdk-cdn.zerohash.eu`). |
90
+ | `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
91
+ | `onCompleted` | `({ withdrawalRequestId, assetSymbol, amount, networkFee, withdrawalFee }) => void` | No | - | Callback when the withdrawal flow completes successfully |
92
+ | `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
93
+ | `onClose` | `() => void` | No | - | Callback when the widget is closed |
94
+ | `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
95
+ | `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
96
96
 
97
97
  ### Methods
98
98
 
package/dist/index.d.ts CHANGED
@@ -318,6 +318,11 @@ 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;
321
326
  };
322
327
 
323
328
  /**
@@ -362,6 +367,8 @@ declare class CspCryptoWithdrawals extends BaseJsSdk<CspCryptoWithdrawalsConfig>
362
367
  prod: string;
363
368
  sandbox: string;
364
369
  production: string;
370
+ 'eu-cert': string;
371
+ 'eu-prod': string;
365
372
  };
366
373
  protected webComponentTag: string;
367
374
  render(container: HTMLElement): Promise<void>;
@@ -404,6 +411,35 @@ declare type CspCryptoWithdrawalsEvent = AppEvent<CspCryptoWithdrawalsEventType>
404
411
  */
405
412
  declare type CspCryptoWithdrawalsEventType = string;
406
413
 
414
+ /**
415
+ * Deposit completed payload — emitted by SDKs that drive a deposit through
416
+ * the integrations flow. Lives on `CommonCallbacks` because both Auth and
417
+ * any SDK embedding `@zerohash/integrations-flow` (e.g. fund with `useAuth`)
418
+ * resolve through the same deposit-status hook.
419
+ */
420
+ declare type DepositCompletedPayload = {
421
+ data: {
422
+ depositId: string;
423
+ status: DepositStatus;
424
+ assetId: string;
425
+ networkId: string;
426
+ amount?: string;
427
+ accountMatchingValidation?: {
428
+ status: 'PENDING' | 'VALID' | 'INVALID' | 'ERROR';
429
+ reason?: string;
430
+ };
431
+ };
432
+ };
433
+
434
+ /**
435
+ * Deposit status object — shared across SDKs that surface deposit completion.
436
+ */
437
+ declare type DepositStatus = {
438
+ value: string;
439
+ details: string;
440
+ occurredAt: string;
441
+ };
442
+
407
443
  /**
408
444
  * Environment configuration for the SDK
409
445
  */
package/dist/index.js CHANGED
@@ -41,15 +41,15 @@ const R = "production", z = "JWT token is required and must be a string.", W = {
41
41
  }, T = (e, t, r) => {
42
42
  const n = O(t, r);
43
43
  return e[n] ?? e[t] ?? e.prod;
44
- }, P = (e, t, r) => {
44
+ }, j = (e, t, r) => {
45
45
  const n = O(t, r);
46
46
  return e[n] ?? e[t];
47
47
  }, E = () => {
48
- }, j = () => {
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
+ }, P = (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: {
@@ -77,7 +77,7 @@ const R = "production", z = "JWT token is required and must be a string.", W = {
77
77
  }, U = (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 } = P(t, r);
81
81
  try {
82
82
  fetch(e, {
83
83
  method: "POST",
@@ -92,15 +92,15 @@ const R = "production", z = "JWT token is required and must be a string.", W = {
92
92
  const { webComponentTag: t, appName: r, appVersion: n, scriptUrls: o, fallbackScriptUrls: a, collectorUrls: c, env: s, jwt: d, timeoutMs: S = 15e3, onLoad: L, onError: I } = e;
93
93
  if (typeof document > "u")
94
94
  return E;
95
- const h = `${t}-script-${s}`;
96
- if (customElements.get(t) || document.getElementById(h))
95
+ const m = `${t}-script-${s}`;
96
+ if (customElements.get(t) || document.getElementById(m))
97
97
  return E;
98
- const v = M(d), D = e.report ?? ((l) => U(c && P(c, s, d), l, n));
99
- let m = !1, y = 0, f;
98
+ const v = M(d), D = e.report ?? ((l) => U(c && j(c, s, d), l, n));
99
+ let h = !1, y = 0, f;
100
100
  const u = () => {
101
101
  f !== void 0 && clearTimeout(f);
102
102
  }, g = (l, p, i) => {
103
- if (m)
103
+ if (h)
104
104
  return;
105
105
  const A = Math.round(performance.now() - y), C = {
106
106
  webComponentTag: t,
@@ -118,18 +118,18 @@ const R = "production", z = "JWT token is required and must be a string.", W = {
118
118
  _(w, !0);
119
119
  return;
120
120
  }
121
- m = !0, u(), document.getElementById(h)?.remove(), I?.(C);
121
+ h = !0, u(), document.getElementById(m)?.remove(), I?.(C);
122
122
  }, _ = (l, p) => {
123
123
  u(), y = performance.now();
124
124
  const i = document.createElement("script");
125
- i.id = h, i.src = l, i.type = "module", i.async = !0, i.onload = () => {
125
+ i.id = m, i.src = l, i.type = "module", i.async = !0, i.onload = () => {
126
126
  setTimeout(() => {
127
- m || (customElements.get(t) ? (m = !0, u(), L?.()) : g("not-defined", l, p));
127
+ h || (customElements.get(t) ? (h = !0, u(), L?.()) : g("not-defined", l, p));
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);
129
+ }, i.onerror = () => g("network", l, p), f = setTimeout(() => g("timeout", l, p), S), document.getElementById(m)?.remove(), document.head.appendChild(i);
130
130
  }, b = T(o, s, d);
131
131
  return b ? (_(b, !1), () => {
132
- m = !0, u();
132
+ h = !0, u();
133
133
  }) : E;
134
134
  };
135
135
  class B {
@@ -285,13 +285,17 @@ class V extends B {
285
285
  SCRIPT_LOAD_FAILED: "Failed to load the Connect CspCryptoWithdrawals script.",
286
286
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
287
287
  };
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.
288
290
  scriptUrls = {
289
291
  local: "http://localhost:5173/csp-crypto-withdrawals-web/index.js",
290
292
  dev: "https://connect-sdk.dev.0hash.com/csp-crypto-withdrawals-web/index.js",
291
293
  cert: "https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",
292
294
  prod: "https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js",
293
295
  sandbox: "https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",
294
- production: "https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js"
296
+ production: "https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js",
297
+ "eu-cert": "https://sdk-cdn.cert.zerohash.eu/csp-crypto-withdrawals-web/index.js",
298
+ "eu-prod": "https://sdk-cdn.zerohash.eu/csp-crypto-withdrawals-web/index.js"
295
299
  };
296
300
  webComponentTag = "zerohash-csp-crypto-withdrawals";
297
301
  render(t) {
@@ -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.CspCryptoWithdrawals={}))})(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"),d=JSON.parse(o)?.payload?.region;if(typeof d!="string")return null;const s=d.toLowerCase();return s==="us"||s==="eu"?s:null}catch{return null}},C=(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"),c=JSON.parse(o),d=c?.payload??{},s=l=>typeof l=="string"&&l.length>0?l:void 0;return{participantCode:s(d.participant_code),platformName:s(d.platform_name),platformCode:s(c.platform_code),region:s(d.region)}}catch{return{}}},b=(e,t,r)=>{const n=C(t,r);return e[n]??e[t]??e.prod},A=(e,t,r)=>{const n=C(t,r);return e[n]??e[t]},w=()=>{},W=()=>{const e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")},z=(e,t)=>{const r=W(),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 c={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:c}},M=(e,t,r)=>{if(!e||typeof fetch>"u")return;const{sessionId:n,payload:o}=z(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{}},j=e=>{const{webComponentTag:t,appName:r,appVersion:n,scriptUrls:o,fallbackScriptUrls:c,collectorUrls:d,env:s,jwt:l,timeoutMs:x=15e3,onLoad:k,onError:U}=e;if(typeof document>"u")return w;const f=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(f))return w;const F=D(l),B=e.report??(p=>M(d&&A(d,s,l),p,n));let m=!1,T=0,E;const g=()=>{E!==void 0&&clearTimeout(E)},y=(p,h,a)=>{if(m)return;const V=Math.round(performance.now()-T),O={webComponentTag:t,appName:r,env:s,scriptUrl:h,reason:p,triedFallback:a,elapsedMs:V,claims:F};B(O);const _=a?void 0:b(c??{},s,l);if(_&&_!==h){N(_,!0);return}m=!0,g(),document.getElementById(f)?.remove(),U?.(O)},N=(p,h)=>{g(),T=performance.now();const a=document.createElement("script");a.id=f,a.src=p,a.type="module",a.async=!0,a.onload=()=>{setTimeout(()=>{m||(customElements.get(t)?(m=!0,g(),k?.()):y("not-defined",p,h))},0)},a.onerror=()=>y("network",p,h),E=setTimeout(()=>y("timeout",p,h),x),document.getElementById(f)?.remove(),document.head.appendChild(a)},S=b(o,s,l);return S?(N(S,!1),()=>{m=!0,g()}):w};class P{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)=>{j({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(c=>{clearTimeout(o),n(c)})})}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 R extends P{errorMessages={ALREADY_RENDERED:"CspCryptoWithdrawals widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"CspCryptoWithdrawals widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect CspCryptoWithdrawals script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={local:"http://localhost:5173/csp-crypto-withdrawals-web/index.js",dev:"https://connect-sdk.dev.0hash.com/csp-crypto-withdrawals-web/index.js",cert:"https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",prod:"https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js",sandbox:"https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",production:"https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js"};webComponentTag="zerohash-csp-crypto-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.CspCryptoWithdrawals=R,i.default=R,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(i,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(i=typeof globalThis<"u"?globalThis:i||self,h(i.CspCryptoWithdrawals={}))})(this,(function(i){"use strict";const h="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"),d=JSON.parse(o)?.payload?.region;if(typeof d!="string")return null;const s=d.toLowerCase();return s==="us"||s==="eu"?s:null}catch{return null}},b=(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"),c=JSON.parse(o),d=c?.payload??{},s=l=>typeof l=="string"&&l.length>0?l:void 0;return{participantCode:s(d.participant_code),platformName:s(d.platform_name),platformCode:s(c.platform_code),region:s(d.region)}}catch{return{}}},C=(e,t,r)=>{const n=b(t,r);return e[n]??e[t]??e.prod},A=(e,t,r)=>{const n=b(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 c={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:c}},M=(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{}},j=e=>{const{webComponentTag:t,appName:r,appVersion:n,scriptUrls:o,fallbackScriptUrls:c,collectorUrls:d,env:s,jwt:l,timeoutMs:k=15e3,onLoad:P,onError:U}=e;if(typeof document>"u")return w;const f=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(f))return w;const F=D(l),B=e.report??(p=>M(d&&A(d,s,l),p,n));let m=!1,T=0,E;const g=()=>{E!==void 0&&clearTimeout(E)},y=(p,u,a)=>{if(m)return;const V=Math.round(performance.now()-T),O={webComponentTag:t,appName:r,env:s,scriptUrl:u,reason:p,triedFallback:a,elapsedMs:V,claims:F};B(O);const _=a?void 0:C(c??{},s,l);if(_&&_!==u){N(_,!0);return}m=!0,g(),document.getElementById(f)?.remove(),U?.(O)},N=(p,u)=>{g(),T=performance.now();const a=document.createElement("script");a.id=f,a.src=p,a.type="module",a.async=!0,a.onload=()=>{setTimeout(()=>{m||(customElements.get(t)?(m=!0,g(),P?.()):y("not-defined",p,u))},0)},a.onerror=()=>y("network",p,u),E=setTimeout(()=>y("timeout",p,u),k),document.getElementById(f)?.remove(),document.head.appendChild(a)},S=C(o,s,l);return S?(N(S,!1),()=>{m=!0,g()}):w};class x{config;state;scriptLoadingPromise;constructor(t){if(!t.jwt||typeof t.jwt!="string")throw new Error(L);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)=>{j({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(c=>{clearTimeout(o),n(c)})})}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 R extends x{errorMessages={ALREADY_RENDERED:"CspCryptoWithdrawals widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"CspCryptoWithdrawals widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect CspCryptoWithdrawals script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={local:"http://localhost:5173/csp-crypto-withdrawals-web/index.js",dev:"https://connect-sdk.dev.0hash.com/csp-crypto-withdrawals-web/index.js",cert:"https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",prod:"https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js",sandbox:"https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",production:"https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js","eu-cert":"https://sdk-cdn.cert.zerohash.eu/csp-crypto-withdrawals-web/index.js","eu-prod":"https://sdk-cdn.zerohash.eu/csp-crypto-withdrawals-web/index.js"};webComponentTag="zerohash-csp-crypto-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.CspCryptoWithdrawals=R,i.default=R,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/csp-crypto-withdrawals-js",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",