@connect-xyz/withdraw-js 0.42.1 → 0.42.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.d.ts CHANGED
@@ -41,7 +41,7 @@ declare interface BaseConfig<TEvent = AppEvent> extends CommonCallbacks<TEvent>
41
41
 
42
42
  /**
43
43
  * Theme mode
44
- * @default 'auto'
44
+ * @default 'light'
45
45
  *
46
46
  * Available themes:
47
47
  * - `'auto'` - Automatically detect system preference (light/dark mode)
@@ -205,7 +205,11 @@ declare abstract class BaseJsSdk<Config extends BaseConfig<never> = BaseConfig>
205
205
  return import.meta.env['VITE_SCRIPT_URL'] || this.scriptUrls[this.getEnvironment()];
206
206
  }
207
207
 
208
- return this.scriptUrls[this.getEnvironment()];
208
+ // Route EU partners (region claim in JWT) to EU-hosted assets without
209
+ // changing the public `env` contract — falls back to the configured env
210
+ // when no EU URL is registered for that environment.
211
+ const effectiveEnv = resolveEnvByRegion(this.getEnvironment(), this.config.jwt);
212
+ return this.scriptUrls[effectiveEnv] ?? this.scriptUrls[this.getEnvironment()];
209
213
  }
210
214
 
211
215
  private async loadScript() {
package/dist/index.js CHANGED
@@ -1,14 +1,29 @@
1
- const s = "production", d = "JWT token is required and must be a string.";
2
- class c {
1
+ const d = "production", h = "JWT token is required and must be a string.", l = (r) => {
2
+ if (!r || typeof r != "string")
3
+ return null;
4
+ const e = r.split(".");
5
+ if (e.length < 2)
6
+ return null;
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")
10
+ return null;
11
+ const s = a.toLowerCase();
12
+ return s === "us" || s === "eu" ? s : null;
13
+ } catch {
14
+ return null;
15
+ }
16
+ }, u = (r, e) => l(e) !== "eu" ? r : r === "cert" ? "eu-cert" : r === "prod" ? "eu-prod" : r;
17
+ class p {
3
18
  config;
4
19
  state;
5
20
  scriptLoadingPromise;
6
21
  constructor(e) {
7
22
  if (!e.jwt || typeof e.jwt != "string")
8
- throw new Error(d);
23
+ throw new Error(h);
9
24
  this.config = {
10
25
  ...e,
11
- env: e.env || s,
26
+ env: e.env || d,
12
27
  theme: e.theme
13
28
  }, this.state = {
14
29
  initialized: !1,
@@ -29,10 +44,10 @@ class c {
29
44
  throw new Error(this.errorMessages.ALREADY_RENDERED);
30
45
  try {
31
46
  await this.ensureScriptLoaded();
32
- const r = this.createWebComponent();
33
- e.innerHTML = "", e.appendChild(r), this.state.container = e, this.state.element = r, this.state.initialized = !0;
34
- } catch (r) {
35
- throw console.error("Failed to render widget:", r), r;
47
+ const n = this.createWebComponent();
48
+ e.innerHTML = "", e.appendChild(n), this.state.container = e, this.state.element = n, this.state.initialized = !0;
49
+ } catch (n) {
50
+ throw console.error("Failed to render widget:", n), n;
36
51
  }
37
52
  }
38
53
  /**
@@ -43,9 +58,9 @@ class c {
43
58
  updateConfig(e) {
44
59
  if (!this.state.initialized || !this.state.element)
45
60
  throw new Error(this.errorMessages.NOT_RENDERED);
46
- const r = this.state.element;
47
- Object.entries(e).forEach(([t, n]) => {
48
- n && (this.config[t] = n, r[t] = n);
61
+ const n = this.state.element;
62
+ Object.entries(e).forEach(([t, i]) => {
63
+ i && (this.config[t] = i, n[t] = i);
49
64
  });
50
65
  }
51
66
  /**
@@ -69,7 +84,7 @@ class c {
69
84
  return { ...this.config };
70
85
  }
71
86
  getEnvironment() {
72
- return this.config.env || s;
87
+ return this.config.env || d;
73
88
  }
74
89
  getScriptId() {
75
90
  return `${this.webComponentTag}-script-${this.getEnvironment()}`;
@@ -81,20 +96,21 @@ class c {
81
96
  return customElements.get(this.webComponentTag);
82
97
  }
83
98
  getScriptUrl() {
84
- return this.scriptUrls[this.getEnvironment()];
99
+ const e = u(this.getEnvironment(), this.config.jwt);
100
+ return this.scriptUrls[e] ?? this.scriptUrls[this.getEnvironment()];
85
101
  }
86
102
  async loadScript() {
87
103
  if (!this.isScriptLoaded()) {
88
104
  if (this.scriptLoadingPromise)
89
105
  return this.scriptLoadingPromise;
90
- this.scriptLoadingPromise = new Promise((e, r) => {
106
+ this.scriptLoadingPromise = new Promise((e, n) => {
91
107
  const t = document.createElement("script");
92
108
  t.id = this.getScriptId(), t.src = this.getScriptUrl(), t.type = "module", t.async = !0, t.onload = () => {
93
109
  setTimeout(() => {
94
- this.getWebComponent() ? e() : r(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED));
110
+ this.getWebComponent() ? e() : n(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED));
95
111
  }, 0);
96
112
  }, t.onerror = () => {
97
- this.scriptLoadingPromise = void 0, r(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
113
+ this.scriptLoadingPromise = void 0, n(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
98
114
  }, document.head.appendChild(t);
99
115
  });
100
116
  try {
@@ -107,14 +123,14 @@ class c {
107
123
  }
108
124
  async waitForWebComponent(e = 5e3) {
109
125
  if (!this.getWebComponent())
110
- return new Promise((r, t) => {
111
- const n = setTimeout(() => {
126
+ return new Promise((n, t) => {
127
+ const i = setTimeout(() => {
112
128
  t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
113
129
  }, e);
114
130
  customElements.whenDefined(this.webComponentTag).then(() => {
115
- clearTimeout(n), r();
116
- }).catch((a) => {
117
- clearTimeout(n), t(a);
131
+ clearTimeout(i), n();
132
+ }).catch((o) => {
133
+ clearTimeout(i), t(o);
118
134
  });
119
135
  });
120
136
  }
@@ -131,16 +147,16 @@ class c {
131
147
  }
132
148
  createWebComponent() {
133
149
  const e = document.createElement(this.webComponentTag);
134
- return Object.entries(this.config).forEach(([r, t]) => {
135
- t && (e[r] = t);
150
+ return Object.entries(this.config).forEach(([n, t]) => {
151
+ t && (e[n] = t);
136
152
  }), e;
137
153
  }
138
154
  }
139
- var o;
140
- (function(i) {
141
- i.NETWORK_ERROR = "network_error", i.AUTH_ERROR = "auth_error", i.NOT_FOUND_ERROR = "not_found_error", i.VALIDATION_ERROR = "validation_error", i.SERVER_ERROR = "server_error", i.CLIENT_ERROR = "client_error", i.UNKNOWN_ERROR = "unknown_error";
142
- })(o || (o = {}));
143
- class h extends c {
155
+ var c;
156
+ (function(r) {
157
+ 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";
158
+ })(c || (c = {}));
159
+ class g extends p {
144
160
  errorMessages = {
145
161
  ALREADY_RENDERED: "Withdraw widget is already rendered. Call destroy() before rendering again.",
146
162
  NOT_RENDERED: "Withdraw widget is not rendered. Call render() first.",
@@ -191,7 +207,7 @@ class h extends c {
191
207
  }
192
208
  }
193
209
  export {
194
- o as ErrorCode,
195
- h as Withdraw,
196
- h as default
210
+ c as ErrorCode,
211
+ g as Withdraw,
212
+ g as default
197
213
  };
@@ -1 +1 @@
1
- (function(r,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(r=typeof globalThis<"u"?globalThis:r||self,s(r.Withdraw={}))})(this,(function(r){"use strict";const s="production",d="JWT token is required and must be a string.";class h{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(d);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 i=this.createWebComponent();e.innerHTML="",e.appendChild(i),this.state.container=e,this.state.element=i,this.state.initialized=!0}catch(i){throw console.error("Failed to render widget:",i),i}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const i=this.state.element;Object.entries(e).forEach(([t,o])=>{o&&(this.config[t]=o,i[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(){return this.scriptUrls[this.getEnvironment()]}async loadScript(){if(!this.isScriptLoaded()){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((e,i)=>{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():i(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED))},0)},t.onerror=()=>{this.scriptLoadingPromise=void 0,i(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((i,t)=>{const o=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),i()}).catch(c=>{clearTimeout(o),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(([i,t])=>{t&&(e[i]=t)}),e}}r.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"})(r.ErrorCode||(r.ErrorCode={}));class a extends h{errorMessages={ALREADY_RENDERED:"Withdraw widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"Withdraw widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect Withdraw script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded.",INVALID_JWT:"JWT token is required and must be a string."};scriptUrls={sandbox:"https://sdk.sandbox.connect.xyz/withdraw-web/index.js",production:"https://sdk.connect.xyz/withdraw-web/index.js"};webComponentTag="connect-withdraw";render(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}r.Withdraw=a,r.default=a,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(n,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(n=typeof globalThis<"u"?globalThis:n||self,o(n.Withdraw={}))})(this,(function(n){"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 i=e[1].replace(/-/g,"+").replace(/_/g,"/"),t=i+"===".slice(0,(4-i.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 a=h.toLowerCase();return a==="us"||a==="eu"?a:null}catch{return null}},p=(r,e)=>u(e)!=="eu"?r:r==="cert"?"eu-cert":r==="prod"?"eu-prod":r;class m{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 i=this.createWebComponent();e.innerHTML="",e.appendChild(i),this.state.container=e,this.state.element=i,this.state.initialized=!0}catch(i){throw console.error("Failed to render widget:",i),i}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const i=this.state.element;Object.entries(e).forEach(([t,s])=>{s&&(this.config[t]=s,i[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,i)=>{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():i(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED))},0)},t.onerror=()=>{this.scriptLoadingPromise=void 0,i(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((i,t)=>{const s=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(s),i()}).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(([i,t])=>{t&&(e[i]=t)}),e}}n.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"})(n.ErrorCode||(n.ErrorCode={}));class d extends m{errorMessages={ALREADY_RENDERED:"Withdraw widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"Withdraw widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect Withdraw script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded.",INVALID_JWT:"JWT token is required and must be a string."};scriptUrls={sandbox:"https://sdk.sandbox.connect.xyz/withdraw-web/index.js",production:"https://sdk.connect.xyz/withdraw-web/index.js"};webComponentTag="connect-withdraw";render(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}n.Withdraw=d,n.default=d,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connect-xyz/withdraw-js",
3
- "version": "0.42.1",
3
+ "version": "0.42.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",