@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 +7 -3
- package/dist/index.js +71 -53
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
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 '
|
|
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
|
-
|
|
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: '
|
|
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
|
|
2
|
-
|
|
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(
|
|
7
|
-
if (!
|
|
8
|
-
throw new Error(
|
|
21
|
+
constructor(e) {
|
|
22
|
+
if (!e.jwt || typeof e.jwt != "string")
|
|
23
|
+
throw new Error(h);
|
|
9
24
|
this.config = {
|
|
10
|
-
...
|
|
11
|
-
env:
|
|
12
|
-
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(
|
|
26
|
-
if (!
|
|
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
|
|
33
|
-
|
|
34
|
-
} catch (
|
|
35
|
-
throw console.error("Failed to render widget:",
|
|
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(
|
|
58
|
+
updateConfig(e) {
|
|
44
59
|
if (!this.state.initialized || !this.state.element)
|
|
45
60
|
throw new Error(this.errorMessages.NOT_RENDERED);
|
|
46
|
-
const
|
|
47
|
-
Object.entries(
|
|
48
|
-
|
|
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 ||
|
|
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
|
-
|
|
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((
|
|
91
|
-
const
|
|
92
|
-
|
|
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() ?
|
|
112
|
+
this.getWebComponent() ? e() : r(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED));
|
|
95
113
|
}, 0);
|
|
96
|
-
},
|
|
97
|
-
this.scriptLoadingPromise = void 0,
|
|
98
|
-
}, document.head.appendChild(
|
|
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 (
|
|
103
|
-
throw this.scriptLoadingPromise = void 0,
|
|
120
|
+
} catch (e) {
|
|
121
|
+
throw this.scriptLoadingPromise = void 0, e;
|
|
104
122
|
}
|
|
105
123
|
return this.scriptLoadingPromise;
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
|
-
async waitForWebComponent(
|
|
126
|
+
async waitForWebComponent(e = 5e3) {
|
|
109
127
|
if (!this.getWebComponent())
|
|
110
|
-
return new Promise((
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
},
|
|
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(
|
|
116
|
-
}).catch((
|
|
117
|
-
clearTimeout(
|
|
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 (
|
|
129
|
-
throw console.error("Failed to load Connect script:",
|
|
146
|
+
} catch (e) {
|
|
147
|
+
throw console.error("Failed to load Connect script:", e), e;
|
|
130
148
|
}
|
|
131
149
|
}
|
|
132
150
|
createWebComponent() {
|
|
133
|
-
const
|
|
134
|
-
return Object.entries(this.config).forEach(([
|
|
135
|
-
|
|
136
|
-
}),
|
|
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
|
|
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
|
-
})(
|
|
143
|
-
class
|
|
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(
|
|
161
|
-
return super.render(
|
|
178
|
+
render(e) {
|
|
179
|
+
return super.render(e);
|
|
162
180
|
}
|
|
163
|
-
updateConfig(
|
|
164
|
-
return super.updateConfig(
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
195
|
+
d as ErrorCode,
|
|
196
|
+
g as FiatAccountLink,
|
|
197
|
+
g as default
|
|
180
198
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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"}})}));
|