@zerohash-sdk/fiat-deposits-js 1.3.1 → 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 +32 -16
- 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() {
|
|
@@ -355,7 +359,7 @@ declare type ErrorPayload = {
|
|
|
355
359
|
* const fiatDeposits = new FiatDeposits({
|
|
356
360
|
* jwt: 'your-jwt-token',
|
|
357
361
|
* env: 'prod',
|
|
358
|
-
* theme: '
|
|
362
|
+
* theme: 'light',
|
|
359
363
|
* onCompleted: ({ amountDeposited }) => console.log('Deposited', amountDeposited),
|
|
360
364
|
* onClose: () => console.log('Closed'),
|
|
361
365
|
* onError: ({ errorCode, reason }) => console.error(errorCode, reason),
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const d = "production", h = "JWT token is required and must be a string.", p = (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 i = e[1].replace(/-/g, "+").replace(/_/g, "/"), t = i + "===".slice(0, (4 - i.length % 4) % 4), n = typeof atob < "u" ? atob(t) : Buffer.from(t, "base64").toString("utf-8"), a = JSON.parse(n)?.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
|
+
}, l = (r, e) => p(e) !== "eu" ? r : r === "cert" ? "eu-cert" : r === "prod" ? "eu-prod" : r;
|
|
17
|
+
class u {
|
|
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(
|
|
23
|
+
throw new Error(h);
|
|
9
24
|
this.config = {
|
|
10
25
|
...e,
|
|
11
|
-
env: e.env ||
|
|
26
|
+
env: e.env || d,
|
|
12
27
|
theme: e.theme
|
|
13
28
|
}, this.state = {
|
|
14
29
|
initialized: !1,
|
|
@@ -44,8 +59,8 @@ class c {
|
|
|
44
59
|
if (!this.state.initialized || !this.state.element)
|
|
45
60
|
throw new Error(this.errorMessages.NOT_RENDERED);
|
|
46
61
|
const i = this.state.element;
|
|
47
|
-
Object.entries(e).forEach(([t,
|
|
48
|
-
|
|
62
|
+
Object.entries(e).forEach(([t, n]) => {
|
|
63
|
+
n && (this.config[t] = n, i[t] = n);
|
|
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 ||
|
|
87
|
+
return this.config.env || d;
|
|
73
88
|
}
|
|
74
89
|
getScriptId() {
|
|
75
90
|
return `${this.webComponentTag}-script-${this.getEnvironment()}`;
|
|
@@ -81,7 +96,8 @@ class c {
|
|
|
81
96
|
return customElements.get(this.webComponentTag);
|
|
82
97
|
}
|
|
83
98
|
getScriptUrl() {
|
|
84
|
-
|
|
99
|
+
const e = l(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()) {
|
|
@@ -108,13 +124,13 @@ class c {
|
|
|
108
124
|
async waitForWebComponent(e = 5e3) {
|
|
109
125
|
if (!this.getWebComponent())
|
|
110
126
|
return new Promise((i, t) => {
|
|
111
|
-
const
|
|
127
|
+
const n = 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(
|
|
116
|
-
}).catch((
|
|
117
|
-
clearTimeout(
|
|
131
|
+
clearTimeout(n), i();
|
|
132
|
+
}).catch((o) => {
|
|
133
|
+
clearTimeout(n), t(o);
|
|
118
134
|
});
|
|
119
135
|
});
|
|
120
136
|
}
|
|
@@ -136,11 +152,11 @@ class c {
|
|
|
136
152
|
}), e;
|
|
137
153
|
}
|
|
138
154
|
}
|
|
139
|
-
var
|
|
155
|
+
var c;
|
|
140
156
|
(function(r) {
|
|
141
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";
|
|
142
|
-
})(
|
|
143
|
-
class
|
|
158
|
+
})(c || (c = {}));
|
|
159
|
+
class m extends u {
|
|
144
160
|
errorMessages = {
|
|
145
161
|
ALREADY_RENDERED: "FiatDeposits widget is already rendered. Call destroy() before rendering again.",
|
|
146
162
|
NOT_RENDERED: "FiatDeposits widget is not rendered. Call render() first.",
|
|
@@ -194,5 +210,5 @@ class h extends c {
|
|
|
194
210
|
}
|
|
195
211
|
}
|
|
196
212
|
export {
|
|
197
|
-
|
|
213
|
+
m as FiatDeposits
|
|
198
214
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s.FiatDeposits={}))})(this,(function(s){"use strict";const o="production",h="JWT token is required and must be a string.",l=i=>{if(!i||typeof i!="string")return null;const e=i.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),n=typeof atob<"u"?atob(t):Buffer.from(t,"base64").toString("utf-8"),p=JSON.parse(n)?.payload?.region;if(typeof p!="string")return null;const a=p.toLowerCase();return a==="us"||a==="eu"?a:null}catch{return null}},u=(i,e)=>l(e)!=="eu"?i:i==="cert"?"eu-cert":i==="prod"?"eu-prod":i;class f{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(h);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 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,n])=>{n&&(this.config[t]=n,r[t]=n)})}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=u(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 n=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(n),r()}).catch(c=>{clearTimeout(n),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(([r,t])=>{t&&(e[r]=t)}),e}}var d;(function(i){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"})(d||(d={}));class m extends f{errorMessages={ALREADY_RENDERED:"FiatDeposits widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"FiatDeposits widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect FiatDeposits script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={local:"http://localhost:5173/fiat-deposits-web/index.js",dev:"https://connect-sdk.dev.0hash.com/fiat-deposits-web/index.js",cert:"https://sdk.sandbox.connect.xyz/fiat-deposits-web/index.js",prod:"https://sdk.connect.xyz/fiat-deposits-web/index.js",sandbox:"https://sdk.sandbox.connect.xyz/fiat-deposits-web/index.js",production:"https://sdk.connect.xyz/fiat-deposits-web/index.js"};webComponentTag="zerohash-fiat-deposits";render(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}s.FiatDeposits=m,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|