@zerohash-sdk/fund-withdrawals-js 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -391,6 +391,8 @@ declare class FundWithdrawals extends BaseJsSdk<FundWithdrawalsConfig> {
391
391
  prod: string;
392
392
  sandbox: string;
393
393
  production: string;
394
+ 'eu-cert': string;
395
+ 'eu-prod': string;
394
396
  };
395
397
  protected webComponentTag: string;
396
398
  render(container: HTMLElement): Promise<void>;
package/dist/index.js CHANGED
@@ -164,13 +164,17 @@ class m extends p {
164
164
  SCRIPT_LOAD_FAILED: "Failed to load the Zerohash FundWithdrawals script.",
165
165
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
166
166
  };
167
+ // US partners stay on connect.xyz; EU partners (JWT payload.region='eu') get
168
+ // routed to sdk-cdn.zerohash.eu by BaseJsSdk.getScriptUrl via resolveEnvByRegion.
167
169
  scriptUrls = {
168
170
  local: "http://localhost:5173/fund-withdrawals-web/index.js",
169
171
  dev: "https://connect-sdk.dev.0hash.com/fund-withdrawals-web/index.js",
170
172
  cert: "https://sdk.sandbox.connect.xyz/fund-withdrawals-web/index.js",
171
173
  prod: "https://sdk.connect.xyz/fund-withdrawals-web/index.js",
172
174
  sandbox: "https://sdk.sandbox.connect.xyz/fund-withdrawals-web/index.js",
173
- production: "https://sdk.connect.xyz/fund-withdrawals-web/index.js"
175
+ production: "https://sdk.connect.xyz/fund-withdrawals-web/index.js",
176
+ "eu-cert": "https://sdk-cdn.cert.zerohash.eu/fund-withdrawals-web/index.js",
177
+ "eu-prod": "https://sdk-cdn.zerohash.eu/fund-withdrawals-web/index.js"
174
178
  };
175
179
  webComponentTag = "zerohash-fund-withdrawals";
176
180
  render(e) {
@@ -1 +1 @@
1
- (function(i,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(i=typeof globalThis<"u"?globalThis:i||self,o(i.FundWithdrawals={}))})(this,(function(i){"use strict";const o="production",l="JWT token is required and must be a string.",u=r=>{if(!r||typeof r!="string")return null;const e=r.split(".");if(e.length<2)return null;try{const n=e[1].replace(/-/g,"+").replace(/_/g,"/"),t=n+"===".slice(0,(4-n.length%4)%4),s=typeof atob<"u"?atob(t):Buffer.from(t,"base64").toString("utf-8"),h=JSON.parse(s)?.payload?.region;if(typeof h!="string")return null;const d=h.toLowerCase();return d==="us"||d==="eu"?d:null}catch{return null}},p=(r,e)=>u(e)!=="eu"?r:r==="cert"?"eu-cert":r==="prod"?"eu-prod":r;class f{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(l);this.config={...e,env:e.env||o,theme:e.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(e){if(!e||!(e 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 n=this.createWebComponent();e.innerHTML="",e.appendChild(n),this.state.container=e,this.state.element=n,this.state.initialized=!0}catch(n){throw console.error("Failed to render widget:",n),n}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const n=this.state.element;Object.entries(e).forEach(([t,s])=>{s&&(this.config[t]=s,n[t]=s)})}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||o}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getScriptUrl(){const e=p(this.getEnvironment(),this.config.jwt);return this.scriptUrls[e]??this.scriptUrls[this.getEnvironment()]}async loadScript(){if(!this.isScriptLoaded()){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((e,n)=>{const t=document.createElement("script");t.id=this.getScriptId(),t.src=this.getScriptUrl(),t.type="module",t.async=!0,t.onload=()=>{setTimeout(()=>{this.getWebComponent()?e():n(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED))},0)},t.onerror=()=>{this.scriptLoadingPromise=void 0,n(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))},document.head.appendChild(t)});try{await this.scriptLoadingPromise}catch(e){throw this.scriptLoadingPromise=void 0,e}return this.scriptLoadingPromise}}async waitForWebComponent(e=5e3){if(!this.getWebComponent())return new Promise((n,t)=>{const s=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(s),n()}).catch(c=>{clearTimeout(s),t(c)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(e){throw console.error("Failed to load Connect script:",e),e}}createWebComponent(){const e=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([n,t])=>{t&&(e[n]=t)}),e}}i.ErrorCode=void 0,(function(r){r.NETWORK_ERROR="network_error",r.AUTH_ERROR="auth_error",r.NOT_FOUND_ERROR="not_found_error",r.VALIDATION_ERROR="validation_error",r.SERVER_ERROR="server_error",r.CLIENT_ERROR="client_error",r.UNKNOWN_ERROR="unknown_error"})(i.ErrorCode||(i.ErrorCode={}));class a extends f{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"};webComponentTag="zerohash-fund-withdrawals";render(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}i.FundWithdrawals=a,i.default=a,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(i,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(i=typeof globalThis<"u"?globalThis:i||self,o(i.FundWithdrawals={}))})(this,(function(i){"use strict";const o="production",l="JWT token is required and must be a string.",u=r=>{if(!r||typeof r!="string")return null;const e=r.split(".");if(e.length<2)return null;try{const n=e[1].replace(/-/g,"+").replace(/_/g,"/"),t=n+"===".slice(0,(4-n.length%4)%4),s=typeof atob<"u"?atob(t):Buffer.from(t,"base64").toString("utf-8"),h=JSON.parse(s)?.payload?.region;if(typeof h!="string")return null;const d=h.toLowerCase();return d==="us"||d==="eu"?d:null}catch{return null}},p=(r,e)=>u(e)!=="eu"?r:r==="cert"?"eu-cert":r==="prod"?"eu-prod":r;class f{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(l);this.config={...e,env:e.env||o,theme:e.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(e){if(!e||!(e 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 n=this.createWebComponent();e.innerHTML="",e.appendChild(n),this.state.container=e,this.state.element=n,this.state.initialized=!0}catch(n){throw console.error("Failed to render widget:",n),n}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const n=this.state.element;Object.entries(e).forEach(([t,s])=>{s&&(this.config[t]=s,n[t]=s)})}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||o}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getScriptUrl(){const e=p(this.getEnvironment(),this.config.jwt);return this.scriptUrls[e]??this.scriptUrls[this.getEnvironment()]}async loadScript(){if(!this.isScriptLoaded()){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((e,n)=>{const t=document.createElement("script");t.id=this.getScriptId(),t.src=this.getScriptUrl(),t.type="module",t.async=!0,t.onload=()=>{setTimeout(()=>{this.getWebComponent()?e():n(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED))},0)},t.onerror=()=>{this.scriptLoadingPromise=void 0,n(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))},document.head.appendChild(t)});try{await this.scriptLoadingPromise}catch(e){throw this.scriptLoadingPromise=void 0,e}return this.scriptLoadingPromise}}async waitForWebComponent(e=5e3){if(!this.getWebComponent())return new Promise((n,t)=>{const s=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(s),n()}).catch(c=>{clearTimeout(s),t(c)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(e){throw console.error("Failed to load Connect script:",e),e}}createWebComponent(){const e=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([n,t])=>{t&&(e[n]=t)}),e}}i.ErrorCode=void 0,(function(r){r.NETWORK_ERROR="network_error",r.AUTH_ERROR="auth_error",r.NOT_FOUND_ERROR="not_found_error",r.VALIDATION_ERROR="validation_error",r.SERVER_ERROR="server_error",r.CLIENT_ERROR="client_error",r.UNKNOWN_ERROR="unknown_error"})(i.ErrorCode||(i.ErrorCode={}));class a extends f{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(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}i.FundWithdrawals=a,i.default=a,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/fund-withdrawals-js",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",