@zerohash-sdk/fiat-account-link-js 1.3.0 → 1.3.3

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
@@ -27,7 +27,7 @@ declare interface BaseConfig<TEvent = AppEvent> extends CommonCallbacks<TEvent>
27
27
 
28
28
  /**
29
29
  * Theme mode
30
- * @default 'auto'
30
+ * @default 'light'
31
31
  *
32
32
  * Available themes:
33
33
  * - `'auto'` - Automatically detect system preference (light/dark mode)
@@ -191,7 +191,11 @@ declare abstract class BaseJsSdk<Config extends BaseConfig<never> = BaseConfig>
191
191
  return import.meta.env['VITE_SCRIPT_URL'] || this.scriptUrls[this.getEnvironment()];
192
192
  }
193
193
 
194
- return this.scriptUrls[this.getEnvironment()];
194
+ // Route EU partners (region claim in JWT) to EU-hosted assets without
195
+ // changing the public `env` contract — falls back to the configured env
196
+ // when no EU URL is registered for that environment.
197
+ const effectiveEnv = resolveEnvByRegion(this.getEnvironment(), this.config.jwt);
198
+ return this.scriptUrls[effectiveEnv] ?? this.scriptUrls[this.getEnvironment()];
195
199
  }
196
200
 
197
201
  private async loadScript() {
@@ -353,7 +357,7 @@ declare type ErrorPayload = {
353
357
  * const fiatAccountLink = new FiatAccountLink({
354
358
  * jwt: 'your-jwt-token',
355
359
  * env: 'prod',
356
- * theme: 'auto',
360
+ * theme: 'light',
357
361
  * onCompleted: ({ externalAccountId, institutionName }) => console.log('Linked', institutionName),
358
362
  * onClose: () => console.log('Closed'),
359
363
  * onError: ({ errorCode, reason }) => console.error(errorCode, reason),
package/dist/index.js CHANGED
@@ -1,15 +1,30 @@
1
- const s = "production", c = "JWT token is required and must be a string.", d = {};
2
- class h {
1
+ const c = "production", h = "JWT token is required and must be a string.", l = (n) => {
2
+ if (!n || typeof n != "string")
3
+ return null;
4
+ const e = n.split(".");
5
+ if (e.length < 2)
6
+ return null;
7
+ try {
8
+ const r = e[1].replace(/-/g, "+").replace(/_/g, "/"), t = r + "===".slice(0, (4 - r.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 = (n, e) => l(e) !== "eu" ? n : n === "cert" ? "eu-cert" : n === "prod" ? "eu-prod" : n, p = {};
17
+ class m {
3
18
  config;
4
19
  state;
5
20
  scriptLoadingPromise;
6
- constructor(t) {
7
- if (!t.jwt || typeof t.jwt != "string")
8
- throw new Error(c);
21
+ constructor(e) {
22
+ if (!e.jwt || typeof e.jwt != "string")
23
+ throw new Error(h);
9
24
  this.config = {
10
- ...t,
11
- env: t.env || s,
12
- theme: t.theme
25
+ ...e,
26
+ env: e.env || c,
27
+ theme: e.theme
13
28
  }, this.state = {
14
29
  initialized: !1,
15
30
  scriptLoaded: !1,
@@ -22,17 +37,17 @@ class h {
22
37
  * @param container - The container element to render the widget into
23
38
  * @returns Promise that resolves when the widget is rendered
24
39
  */
25
- async render(t) {
26
- if (!t || !(t instanceof HTMLElement))
40
+ async render(e) {
41
+ if (!e || !(e instanceof HTMLElement))
27
42
  throw new Error(this.errorMessages.INVALID_CONTAINER);
28
43
  if (this.state.initialized)
29
44
  throw new Error(this.errorMessages.ALREADY_RENDERED);
30
45
  try {
31
46
  await this.ensureScriptLoaded();
32
- const i = this.createWebComponent();
33
- t.innerHTML = "", t.appendChild(i), this.state.container = t, this.state.element = i, this.state.initialized = !0;
34
- } catch (i) {
35
- throw console.error("Failed to render widget:", i), i;
47
+ const r = this.createWebComponent();
48
+ e.innerHTML = "", e.appendChild(r), this.state.container = e, this.state.element = r, this.state.initialized = !0;
49
+ } catch (r) {
50
+ throw console.error("Failed to render widget:", r), r;
36
51
  }
37
52
  }
38
53
  /**
@@ -40,12 +55,12 @@ class h {
40
55
  * @param config - Partial configuration to update
41
56
  * @returns void
42
57
  */
43
- updateConfig(t) {
58
+ updateConfig(e) {
44
59
  if (!this.state.initialized || !this.state.element)
45
60
  throw new Error(this.errorMessages.NOT_RENDERED);
46
- const i = this.state.element;
47
- Object.entries(t).forEach(([e, r]) => {
48
- r && (this.config[e] = r, i[e] = r);
61
+ const r = this.state.element;
62
+ Object.entries(e).forEach(([t, i]) => {
63
+ i && (this.config[t] = i, r[t] = i);
49
64
  });
50
65
  }
51
66
  /**
@@ -69,7 +84,7 @@ class h {
69
84
  return { ...this.config };
70
85
  }
71
86
  getEnvironment() {
72
- return this.config.env || s;
87
+ return this.config.env || c;
73
88
  }
74
89
  getScriptId() {
75
90
  return `${this.webComponentTag}-script-${this.getEnvironment()}`;
@@ -81,40 +96,43 @@ class h {
81
96
  return customElements.get(this.webComponentTag);
82
97
  }
83
98
  getScriptUrl() {
84
- return typeof import.meta < "u" ? d.VITE_SCRIPT_URL || this.scriptUrls[this.getEnvironment()] : this.scriptUrls[this.getEnvironment()];
99
+ if (typeof import.meta < "u")
100
+ return p.VITE_SCRIPT_URL || this.scriptUrls[this.getEnvironment()];
101
+ const e = u(this.getEnvironment(), this.config.jwt);
102
+ return this.scriptUrls[e] ?? this.scriptUrls[this.getEnvironment()];
85
103
  }
86
104
  async loadScript() {
87
105
  if (!this.isScriptLoaded()) {
88
106
  if (this.scriptLoadingPromise)
89
107
  return this.scriptLoadingPromise;
90
- this.scriptLoadingPromise = new Promise((t, i) => {
91
- const e = document.createElement("script");
92
- e.id = this.getScriptId(), e.src = this.getScriptUrl(), e.type = "module", e.async = !0, e.onload = () => {
108
+ this.scriptLoadingPromise = new Promise((e, r) => {
109
+ const t = document.createElement("script");
110
+ t.id = this.getScriptId(), t.src = this.getScriptUrl(), t.type = "module", t.async = !0, t.onload = () => {
93
111
  setTimeout(() => {
94
- this.getWebComponent() ? t() : i(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED));
112
+ this.getWebComponent() ? e() : r(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED));
95
113
  }, 0);
96
- }, e.onerror = () => {
97
- this.scriptLoadingPromise = void 0, i(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
98
- }, document.head.appendChild(e);
114
+ }, t.onerror = () => {
115
+ this.scriptLoadingPromise = void 0, r(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
116
+ }, document.head.appendChild(t);
99
117
  });
100
118
  try {
101
119
  await this.scriptLoadingPromise;
102
- } catch (t) {
103
- throw this.scriptLoadingPromise = void 0, t;
120
+ } catch (e) {
121
+ throw this.scriptLoadingPromise = void 0, e;
104
122
  }
105
123
  return this.scriptLoadingPromise;
106
124
  }
107
125
  }
108
- async waitForWebComponent(t = 5e3) {
126
+ async waitForWebComponent(e = 5e3) {
109
127
  if (!this.getWebComponent())
110
- return new Promise((i, e) => {
111
- const r = setTimeout(() => {
112
- e(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
113
- }, t);
128
+ return new Promise((r, t) => {
129
+ const i = setTimeout(() => {
130
+ t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
131
+ }, e);
114
132
  customElements.whenDefined(this.webComponentTag).then(() => {
115
- clearTimeout(r), i();
116
- }).catch((a) => {
117
- clearTimeout(r), e(a);
133
+ clearTimeout(i), r();
134
+ }).catch((o) => {
135
+ clearTimeout(i), t(o);
118
136
  });
119
137
  });
120
138
  }
@@ -125,22 +143,22 @@ class h {
125
143
  if (!this.state.scriptLoaded)
126
144
  try {
127
145
  await this.loadScript(), await this.waitForWebComponent(), this.state.scriptLoaded = !0;
128
- } catch (t) {
129
- throw console.error("Failed to load Connect script:", t), t;
146
+ } catch (e) {
147
+ throw console.error("Failed to load Connect script:", e), e;
130
148
  }
131
149
  }
132
150
  createWebComponent() {
133
- const t = document.createElement(this.webComponentTag);
134
- return Object.entries(this.config).forEach(([i, e]) => {
135
- e && (t[i] = e);
136
- }), t;
151
+ const e = document.createElement(this.webComponentTag);
152
+ return Object.entries(this.config).forEach(([r, t]) => {
153
+ t && (e[r] = t);
154
+ }), e;
137
155
  }
138
156
  }
139
- var o;
157
+ var d;
140
158
  (function(n) {
141
159
  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";
142
- })(o || (o = {}));
143
- class l extends h {
160
+ })(d || (d = {}));
161
+ class g extends m {
144
162
  errorMessages = {
145
163
  ALREADY_RENDERED: "FiatAccountLink widget is already rendered. Call destroy() before rendering again.",
146
164
  NOT_RENDERED: "FiatAccountLink widget is not rendered. Call render() first.",
@@ -157,11 +175,11 @@ class l extends h {
157
175
  production: "https://sdk.connect.xyz/fiat-account-link-web/index.js"
158
176
  };
159
177
  webComponentTag = "zerohash-fiat-account-link";
160
- render(t) {
161
- return super.render(t);
178
+ render(e) {
179
+ return super.render(e);
162
180
  }
163
- updateConfig(t) {
164
- return super.updateConfig(t);
181
+ updateConfig(e) {
182
+ return super.updateConfig(e);
165
183
  }
166
184
  getConfig() {
167
185
  return super.getConfig();
@@ -174,7 +192,7 @@ class l extends h {
174
192
  }
175
193
  }
176
194
  export {
177
- o as ErrorCode,
178
- l as FiatAccountLink,
179
- l as default
195
+ d as ErrorCode,
196
+ g as FiatAccountLink,
197
+ g as default
180
198
  };
@@ -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.FiatAccountLink={}))})(this,(function(i){"use strict";var s=typeof document<"u"?document.currentScript:null;const a="production",c="JWT token is required and must be a string.",u={};class h{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(c);this.config={...e,env:e.env||a,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,o])=>{o&&(this.config[t]=o,n[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||a}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getScriptUrl(){return typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:s&&s.tagName.toUpperCase()==="SCRIPT"&&s.src||new URL("index.umd.cjs",document.baseURI).href}<"u"?u.VITE_SCRIPT_URL||this.scriptUrls[this.getEnvironment()]: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 o=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),n()}).catch(l=>{clearTimeout(o),t(l)})})}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 d extends h{errorMessages={ALREADY_RENDERED:"FiatAccountLink widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"FiatAccountLink widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect FiatAccountLink script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={local:"http://localhost:4208/fiat-account-link-web/index.js",dev:"https://connect-sdk.dev.0hash.com/fiat-account-link-web/index.js",cert:"https://sdk.sandbox.connect.xyz/fiat-account-link-web/index.js",prod:"https://sdk.connect.xyz/fiat-account-link-web/index.js",sandbox:"https://sdk.sandbox.connect.xyz/fiat-account-link-web/index.js",production:"https://sdk.connect.xyz/fiat-account-link-web/index.js"};webComponentTag="zerohash-fiat-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.FiatAccountLink=d,i.default=d,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
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.FiatAccountLink={}))})(this,(function(r){"use strict";var s=typeof document<"u"?document.currentScript:null;const c="production",h="JWT token is required and must be a string.",p=n=>{if(!n||typeof n!="string")return null;const e=n.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),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 a=l.toLowerCase();return a==="us"||a==="eu"?a:null}catch{return null}},f=(n,e)=>p(e)!=="eu"?n:n==="cert"?"eu-cert":n==="prod"?"eu-prod":n,m={};class g{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(h);this.config={...e,env:e.env||c,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||c}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getScriptUrl(){if(typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:s&&s.tagName.toUpperCase()==="SCRIPT"&&s.src||new URL("index.umd.cjs",document.baseURI).href}<"u")return m.VITE_SCRIPT_URL||this.scriptUrls[this.getEnvironment()];const e=f(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 o=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),i()}).catch(u=>{clearTimeout(o),t(u)})})}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 d extends g{errorMessages={ALREADY_RENDERED:"FiatAccountLink widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"FiatAccountLink widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect FiatAccountLink script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={local:"http://localhost:4208/fiat-account-link-web/index.js",dev:"https://connect-sdk.dev.0hash.com/fiat-account-link-web/index.js",cert:"https://sdk.sandbox.connect.xyz/fiat-account-link-web/index.js",prod:"https://sdk.connect.xyz/fiat-account-link-web/index.js",sandbox:"https://sdk.sandbox.connect.xyz/fiat-account-link-web/index.js",production:"https://sdk.connect.xyz/fiat-account-link-web/index.js"};webComponentTag="zerohash-fiat-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()}}r.FiatAccountLink=d,r.default=d,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/fiat-account-link-js",
3
- "version": "1.3.0",
3
+ "version": "1.3.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",