@zerohash-sdk/fiat-withdrawals-js 1.11.3 → 1.11.4

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.js CHANGED
@@ -96,17 +96,17 @@ const T = "production", W = "JWT token is required and must be a string.", F = {
96
96
  if (customElements.get(t) || document.getElementById(m))
97
97
  return _;
98
98
  const A = k(c), D = e.report ?? ((l) => B(i && P(i, s, c), l, o));
99
- let u = !1, R = 0, g;
99
+ let h = !1, R = 0, g;
100
100
  const f = () => {
101
101
  g !== void 0 && clearTimeout(g);
102
- }, E = (l, h, d) => {
103
- if (u)
102
+ }, E = (l, u, d) => {
103
+ if (h)
104
104
  return;
105
105
  const z = Math.round(performance.now() - R), y = {
106
106
  webComponentTag: t,
107
107
  appName: r,
108
108
  env: s,
109
- scriptUrl: h,
109
+ scriptUrl: u,
110
110
  reason: l,
111
111
  triedFallback: d,
112
112
  elapsedMs: z,
@@ -114,22 +114,22 @@ const T = "production", W = "JWT token is required and must be a string.", F = {
114
114
  };
115
115
  D(y);
116
116
  const w = d ? void 0 : N(a ?? {}, s, c);
117
- if (w && w !== h) {
117
+ if (w && w !== u) {
118
118
  b(w, !0);
119
119
  return;
120
120
  }
121
- u = !0, f(), document.getElementById(m)?.remove(), I?.(y);
122
- }, b = (l, h) => {
121
+ h = !0, f(), document.getElementById(m)?.remove(), I?.(y);
122
+ }, b = (l, u) => {
123
123
  f(), R = performance.now();
124
124
  const d = document.createElement("script");
125
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, f(), v?.()) : E("not-defined", l, h));
127
+ h || (customElements.get(t) ? (h = !0, f(), v?.()) : E("not-defined", l, u));
128
128
  }, 0);
129
- }, d.onerror = () => E("network", l, h), g = setTimeout(() => E("timeout", l, h), L), document.getElementById(m)?.remove(), document.head.appendChild(d);
129
+ }, d.onerror = () => E("network", l, u), g = setTimeout(() => E("timeout", l, u), L), document.getElementById(m)?.remove(), document.head.appendChild(d);
130
130
  }, C = N(n, s, c);
131
131
  return C ? (b(C, !1), () => {
132
- u = !0, f();
132
+ h = !0, f();
133
133
  }) : _;
134
134
  };
135
135
  class j {
@@ -302,7 +302,7 @@ class H extends j {
302
302
  SCRIPT_LOAD_FAILED: "Failed to load the Connect FiatWithdrawals script.",
303
303
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
304
304
  };
305
- scriptUrls = x("fiat-withdrawals-web", "index.js", { legacyAliases: !0 });
305
+ scriptUrls = x("fiat-withdrawals-web", "index.js", { legacyAliases: !0, eu: !0 });
306
306
  webComponentTag = "zerohash-fiat-withdrawals";
307
307
  render(t) {
308
308
  return super.render(t);
@@ -1 +1 @@
1
- (function(u,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(u=typeof globalThis<"u"?globalThis:u||self,h(u.FiatWithdrawals={}))})(this,(function(u){"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=c=>typeof c=="string"&&c.length>0?c:void 0;return{participantCode:s(i.participant_code),platformName:s(i.platform_name),platformCode:s(a.platform_code),region:s(i.region)}}catch{return{}}},T=(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:c,timeoutMs:B=15e3,onLoad:V,onError:x}=e;if(typeof document>"u")return w;const g=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(g))return w;const J=D(c),H=e.report??(p=>M(i&&W(i,s,c),p,n));let f=!1,N=0,_;const E=()=>{_!==void 0&&clearTimeout(_)},b=(p,m,d)=>{if(f)return;const G=Math.round(performance.now()-N),L={webComponentTag:t,appName:r,env:s,scriptUrl:m,reason:p,triedFallback:d,elapsedMs:G,claims:J};H(L);const R=d?void 0:T(a??{},s,c);if(R&&R!==m){S(R,!0);return}f=!0,E(),document.getElementById(g)?.remove(),x?.(L)},S=(p,m)=>{E(),N=performance.now();const d=document.createElement("script");d.id=g,d.src=p,d.type="module",d.async=!0,d.onload=()=>{setTimeout(()=>{f||(customElements.get(t)?(f=!0,E(),V?.()):b("not-defined",p,m))},0)},d.onerror=()=>b("network",p,m),_=setTimeout(()=>b("timeout",p,m),B),document.getElementById(g)?.remove(),document.head.appendChild(d)},O=T(o,s,c);return O?(S(O,!1),()=>{f=!0,E()}):w};class k{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 l={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"},U="https://sdk-cdn.gating.0hash.com",$=(e,t,r={})=>{const{eu:n=!1,legacyAliases:o=!1,local:a=l.local}=r,i=c=>`${c}/${e}/${t}`,s={local:i(a),dev:i(l.dev),gating:i(U),cert:i(l.cert),prod:i(l.prod)};return o&&(s.sandbox=i(l.cert),s.production=i(l.prod)),n&&(s["eu-cert"]=i(l["eu-cert"]),s["eu-prod"]=i(l["eu-prod"])),s};var C;(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||(C={}));class j extends k{errorMessages={ALREADY_RENDERED:"FiatWithdrawals widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"FiatWithdrawals widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect FiatWithdrawals script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls=$("fiat-withdrawals-web","index.js",{legacyAliases:!0});webComponentTag="zerohash-fiat-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()}}u.FiatWithdrawals=j,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(u,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(u=typeof globalThis<"u"?globalThis:u||self,h(u.FiatWithdrawals={}))})(this,(function(u){"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=c=>typeof c=="string"&&c.length>0?c:void 0;return{participantCode:s(i.participant_code),platformName:s(i.platform_name),platformCode:s(a.platform_code),region:s(i.region)}}catch{return{}}},T=(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:c,timeoutMs:B=15e3,onLoad:V,onError:x}=e;if(typeof document>"u")return w;const g=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(g))return w;const J=D(c),H=e.report??(p=>M(i&&W(i,s,c),p,n));let f=!1,N=0,_;const E=()=>{_!==void 0&&clearTimeout(_)},b=(p,m,d)=>{if(f)return;const G=Math.round(performance.now()-N),L={webComponentTag:t,appName:r,env:s,scriptUrl:m,reason:p,triedFallback:d,elapsedMs:G,claims:J};H(L);const R=d?void 0:T(a??{},s,c);if(R&&R!==m){S(R,!0);return}f=!0,E(),document.getElementById(g)?.remove(),x?.(L)},S=(p,m)=>{E(),N=performance.now();const d=document.createElement("script");d.id=g,d.src=p,d.type="module",d.async=!0,d.onload=()=>{setTimeout(()=>{f||(customElements.get(t)?(f=!0,E(),V?.()):b("not-defined",p,m))},0)},d.onerror=()=>b("network",p,m),_=setTimeout(()=>b("timeout",p,m),B),document.getElementById(g)?.remove(),document.head.appendChild(d)},O=T(o,s,c);return O?(S(O,!1),()=>{f=!0,E()}):w};class k{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 l={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"},U="https://sdk-cdn.gating.0hash.com",$=(e,t,r={})=>{const{eu:n=!1,legacyAliases:o=!1,local:a=l.local}=r,i=c=>`${c}/${e}/${t}`,s={local:i(a),dev:i(l.dev),gating:i(U),cert:i(l.cert),prod:i(l.prod)};return o&&(s.sandbox=i(l.cert),s.production=i(l.prod)),n&&(s["eu-cert"]=i(l["eu-cert"]),s["eu-prod"]=i(l["eu-prod"])),s};var C;(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||(C={}));class j extends k{errorMessages={ALREADY_RENDERED:"FiatWithdrawals widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"FiatWithdrawals widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect FiatWithdrawals script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls=$("fiat-withdrawals-web","index.js",{legacyAliases:!0,eu:!0});webComponentTag="zerohash-fiat-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()}}u.FiatWithdrawals=j,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/fiat-withdrawals-js",
3
- "version": "1.11.3",
3
+ "version": "1.11.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",