@zerohash-sdk/crypto-account-link-js 1.3.5 → 1.4.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
@@ -364,6 +364,8 @@ declare class CryptoAccountLink extends BaseJsSdk<CryptoAccountLinkConfig> {
364
364
  prod: string;
365
365
  sandbox: string;
366
366
  production: string;
367
+ 'eu-cert': string;
368
+ 'eu-prod': string;
367
369
  };
368
370
  protected webComponentTag: string;
369
371
  /**
package/dist/index.js CHANGED
@@ -1,29 +1,29 @@
1
- const c = "production", l = "JWT token is required and must be a string.", h = (r) => {
1
+ const a = "production", h = "JWT token is required and must be a string.", l = (r) => {
2
2
  if (!r || typeof r != "string")
3
3
  return null;
4
4
  const e = r.split(".");
5
5
  if (e.length < 2)
6
6
  return null;
7
7
  try {
8
- const n = e[1].replace(/-/g, "+").replace(/_/g, "/"), t = n + "===".slice(0, (4 - n.length % 4) % 4), i = typeof atob < "u" ? atob(t) : Buffer.from(t, "base64").toString("utf-8"), a = JSON.parse(i)?.payload?.region;
9
- if (typeof a != "string")
8
+ const n = e[1].replace(/-/g, "+").replace(/_/g, "/"), t = n + "===".slice(0, (4 - n.length % 4) % 4), i = typeof atob < "u" ? atob(t) : Buffer.from(t, "base64").toString("utf-8"), c = JSON.parse(i)?.payload?.region;
9
+ if (typeof c != "string")
10
10
  return null;
11
- const s = a.toLowerCase();
11
+ const s = c.toLowerCase();
12
12
  return s === "us" || s === "eu" ? s : null;
13
13
  } catch {
14
14
  return null;
15
15
  }
16
- }, p = (r, e) => h(e) !== "eu" ? r : r === "cert" ? "eu-cert" : r === "prod" ? "eu-prod" : r;
16
+ }, p = (r, e) => l(e) !== "eu" ? r : r === "cert" ? "eu-cert" : r === "prod" ? "eu-prod" : r;
17
17
  class u {
18
18
  config;
19
19
  state;
20
20
  scriptLoadingPromise;
21
21
  constructor(e) {
22
22
  if (!e.jwt || typeof e.jwt != "string")
23
- throw new Error(l);
23
+ throw new Error(h);
24
24
  this.config = {
25
25
  ...e,
26
- env: e.env || c,
26
+ env: e.env || a,
27
27
  theme: e.theme
28
28
  }, this.state = {
29
29
  initialized: !1,
@@ -84,7 +84,7 @@ class u {
84
84
  return { ...this.config };
85
85
  }
86
86
  getEnvironment() {
87
- return this.config.env || c;
87
+ return this.config.env || a;
88
88
  }
89
89
  getScriptId() {
90
90
  return `${this.webComponentTag}-script-${this.getEnvironment()}`;
@@ -164,13 +164,17 @@ class m extends u {
164
164
  SCRIPT_LOAD_FAILED: "Failed to load the Connect CryptoAccountLink 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/crypto-account-link-web/index.js",
169
171
  dev: "https://connect-sdk.dev.0hash.com/crypto-account-link-web/index.js",
170
172
  cert: "https://sdk.sandbox.connect.xyz/crypto-account-link-web/index.js",
171
173
  prod: "https://sdk.connect.xyz/crypto-account-link-web/index.js",
172
174
  sandbox: "https://sdk.sandbox.connect.xyz/crypto-account-link-web/index.js",
173
- production: "https://sdk.connect.xyz/crypto-account-link-web/index.js"
175
+ production: "https://sdk.connect.xyz/crypto-account-link-web/index.js",
176
+ "eu-cert": "https://sdk-cdn.cert.zerohash.eu/crypto-account-link-web/index.js",
177
+ "eu-prod": "https://sdk-cdn.zerohash.eu/crypto-account-link-web/index.js"
174
178
  };
175
179
  webComponentTag = "zerohash-crypto-account-link";
176
180
  /**
@@ -1 +1 @@
1
- (function(i,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(i=typeof globalThis<"u"?globalThis:i||self,s(i.CryptoAccountLink={}))})(this,(function(i){"use strict";const s="production",u="JWT token is required and must be a string.",h=n=>{if(!n||typeof n!="string")return null;const e=n.split(".");if(e.length<2)return null;try{const r=e[1].replace(/-/g,"+").replace(/_/g,"/"),t=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(t):Buffer.from(t,"base64").toString("utf-8"),l=JSON.parse(o)?.payload?.region;if(typeof l!="string")return null;const c=l.toLowerCase();return c==="us"||c==="eu"?c:null}catch{return null}},p=(n,e)=>h(e)!=="eu"?n:n==="cert"?"eu-cert":n==="prod"?"eu-prod":n;class m{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(u);this.config={...e,env:e.env||s,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 r=this.createWebComponent();e.innerHTML="",e.appendChild(r),this.state.container=e,this.state.element=r,this.state.initialized=!0}catch(r){throw console.error("Failed to render widget:",r),r}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const r=this.state.element;Object.entries(e).forEach(([t,o])=>{o&&(this.config[t]=o,r[t]=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||s}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,r)=>{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():r(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED))},0)},t.onerror=()=>{this.scriptLoadingPromise=void 0,r(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((r,t)=>{const o=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),r()}).catch(d=>{clearTimeout(o),t(d)})})}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(([r,t])=>{t&&(e[r]=t)}),e}}i.ErrorCode=void 0,(function(n){n.NETWORK_ERROR="network_error",n.AUTH_ERROR="auth_error",n.NOT_FOUND_ERROR="not_found_error",n.VALIDATION_ERROR="validation_error",n.SERVER_ERROR="server_error",n.CLIENT_ERROR="client_error",n.UNKNOWN_ERROR="unknown_error"})(i.ErrorCode||(i.ErrorCode={}));class a extends m{errorMessages={ALREADY_RENDERED:"CryptoAccountLink widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"CryptoAccountLink widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect CryptoAccountLink script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={local:"http://localhost:5173/crypto-account-link-web/index.js",dev:"https://connect-sdk.dev.0hash.com/crypto-account-link-web/index.js",cert:"https://sdk.sandbox.connect.xyz/crypto-account-link-web/index.js",prod:"https://sdk.connect.xyz/crypto-account-link-web/index.js",sandbox:"https://sdk.sandbox.connect.xyz/crypto-account-link-web/index.js",production:"https://sdk.connect.xyz/crypto-account-link-web/index.js"};webComponentTag="zerohash-crypto-account-link";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.CryptoAccountLink=a,i.default=a,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(i,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(i=typeof globalThis<"u"?globalThis:i||self,s(i.CryptoAccountLink={}))})(this,(function(i){"use strict";const s="production",l="JWT token is required and must be a string.",h=n=>{if(!n||typeof n!="string")return null;const e=n.split(".");if(e.length<2)return null;try{const r=e[1].replace(/-/g,"+").replace(/_/g,"/"),t=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(t):Buffer.from(t,"base64").toString("utf-8"),u=JSON.parse(o)?.payload?.region;if(typeof u!="string")return null;const c=u.toLowerCase();return c==="us"||c==="eu"?c:null}catch{return null}},p=(n,e)=>h(e)!=="eu"?n:n==="cert"?"eu-cert":n==="prod"?"eu-prod":n;class m{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(l);this.config={...e,env:e.env||s,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 r=this.createWebComponent();e.innerHTML="",e.appendChild(r),this.state.container=e,this.state.element=r,this.state.initialized=!0}catch(r){throw console.error("Failed to render widget:",r),r}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const r=this.state.element;Object.entries(e).forEach(([t,o])=>{o&&(this.config[t]=o,r[t]=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||s}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,r)=>{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():r(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED))},0)},t.onerror=()=>{this.scriptLoadingPromise=void 0,r(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((r,t)=>{const o=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),r()}).catch(d=>{clearTimeout(o),t(d)})})}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(([r,t])=>{t&&(e[r]=t)}),e}}i.ErrorCode=void 0,(function(n){n.NETWORK_ERROR="network_error",n.AUTH_ERROR="auth_error",n.NOT_FOUND_ERROR="not_found_error",n.VALIDATION_ERROR="validation_error",n.SERVER_ERROR="server_error",n.CLIENT_ERROR="client_error",n.UNKNOWN_ERROR="unknown_error"})(i.ErrorCode||(i.ErrorCode={}));class a extends m{errorMessages={ALREADY_RENDERED:"CryptoAccountLink widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"CryptoAccountLink widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect CryptoAccountLink script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={local:"http://localhost:5173/crypto-account-link-web/index.js",dev:"https://connect-sdk.dev.0hash.com/crypto-account-link-web/index.js",cert:"https://sdk.sandbox.connect.xyz/crypto-account-link-web/index.js",prod:"https://sdk.connect.xyz/crypto-account-link-web/index.js",sandbox:"https://sdk.sandbox.connect.xyz/crypto-account-link-web/index.js",production:"https://sdk.connect.xyz/crypto-account-link-web/index.js","eu-cert":"https://sdk-cdn.cert.zerohash.eu/crypto-account-link-web/index.js","eu-prod":"https://sdk-cdn.zerohash.eu/crypto-account-link-web/index.js"};webComponentTag="zerohash-crypto-account-link";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.CryptoAccountLink=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/crypto-account-link-js",
3
- "version": "1.3.5",
3
+ "version": "1.4.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",