@zerohash-sdk/fiat-account-link-js 1.10.2 → 1.11.1
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.js +22 -21
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const y = "production", z = "JWT token is required and must be a string.", F = {
|
|
2
2
|
dev: "https://grafana-faro-collector.dev.0hash.com/collect",
|
|
3
3
|
cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
4
4
|
prod: "https://grafana-faro-collector.zerohash.com/collect",
|
|
@@ -99,36 +99,36 @@ const T = "production", k = "JWT token is required and must be a string.", F = {
|
|
|
99
99
|
let m = !1, R = 0, g;
|
|
100
100
|
const f = () => {
|
|
101
101
|
g !== void 0 && clearTimeout(g);
|
|
102
|
-
},
|
|
102
|
+
}, _ = (l, u, d) => {
|
|
103
103
|
if (m)
|
|
104
104
|
return;
|
|
105
|
-
const
|
|
105
|
+
const k = Math.round(performance.now() - R), T = {
|
|
106
106
|
webComponentTag: e,
|
|
107
107
|
appName: r,
|
|
108
108
|
env: s,
|
|
109
109
|
scriptUrl: u,
|
|
110
110
|
reason: l,
|
|
111
111
|
triedFallback: d,
|
|
112
|
-
elapsedMs:
|
|
112
|
+
elapsedMs: k,
|
|
113
113
|
claims: A
|
|
114
114
|
};
|
|
115
|
-
D(
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
118
|
-
b(
|
|
115
|
+
D(T);
|
|
116
|
+
const E = d ? void 0 : N(a ?? {}, s, c);
|
|
117
|
+
if (E && E !== u) {
|
|
118
|
+
b(E, !0);
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
m = !0, f(), document.getElementById(h)?.remove(), I?.(
|
|
121
|
+
m = !0, f(), document.getElementById(h)?.remove(), I?.(T);
|
|
122
122
|
}, b = (l, u) => {
|
|
123
123
|
f(), R = performance.now();
|
|
124
124
|
const d = document.createElement("script");
|
|
125
125
|
d.id = h, d.src = l, d.type = "module", d.async = !0, d.onload = () => {
|
|
126
126
|
setTimeout(() => {
|
|
127
|
-
m || (customElements.get(e) ? (m = !0, f(), v?.()) :
|
|
127
|
+
m || (customElements.get(e) ? (m = !0, f(), v?.()) : _("not-defined", l, u));
|
|
128
128
|
}, 0);
|
|
129
|
-
}, d.onerror = () =>
|
|
130
|
-
},
|
|
131
|
-
return
|
|
129
|
+
}, d.onerror = () => _("network", l, u), g = setTimeout(() => _("timeout", l, u), O), document.getElementById(h)?.remove(), document.head.appendChild(d);
|
|
130
|
+
}, C = N(o, s, c);
|
|
131
|
+
return C ? (b(C, !1), () => {
|
|
132
132
|
m = !0, f();
|
|
133
133
|
}) : w;
|
|
134
134
|
}, j = {};
|
|
@@ -138,10 +138,10 @@ class J {
|
|
|
138
138
|
scriptLoadingPromise;
|
|
139
139
|
constructor(e) {
|
|
140
140
|
if (!e.jwt || typeof e.jwt != "string")
|
|
141
|
-
throw new Error(
|
|
141
|
+
throw new Error(z);
|
|
142
142
|
this.config = {
|
|
143
143
|
...e,
|
|
144
|
-
env: e.env ||
|
|
144
|
+
env: e.env || y,
|
|
145
145
|
theme: e.theme
|
|
146
146
|
}, this.state = {
|
|
147
147
|
initialized: !1,
|
|
@@ -202,7 +202,7 @@ class J {
|
|
|
202
202
|
return { ...this.config };
|
|
203
203
|
}
|
|
204
204
|
getEnvironment() {
|
|
205
|
-
return this.config.env ||
|
|
205
|
+
return this.config.env || y;
|
|
206
206
|
}
|
|
207
207
|
getScriptId() {
|
|
208
208
|
return `${this.webComponentTag}-script-${this.getEnvironment()}`;
|
|
@@ -285,10 +285,11 @@ const p = {
|
|
|
285
285
|
prod: "https://sdk-cdn.zerohash.com",
|
|
286
286
|
"eu-cert": "https://sdk-cdn.cert.zerohash.eu",
|
|
287
287
|
"eu-prod": "https://sdk-cdn.zerohash.eu"
|
|
288
|
-
}, x = (t, e, r = {}) => {
|
|
288
|
+
}, x = "https://sdk-cdn.gating.0hash.com", H = (t, e, r = {}) => {
|
|
289
289
|
const { eu: n = !1, legacyAliases: o = !1, local: a = p.local } = r, i = (c) => `${c}/${t}/${e}`, s = {
|
|
290
290
|
local: i(a),
|
|
291
291
|
dev: i(p.dev),
|
|
292
|
+
gating: i(x),
|
|
292
293
|
cert: i(p.cert),
|
|
293
294
|
prod: i(p.prod)
|
|
294
295
|
};
|
|
@@ -298,7 +299,7 @@ var L;
|
|
|
298
299
|
(function(t) {
|
|
299
300
|
t.NETWORK_ERROR = "network_error", t.AUTH_ERROR = "auth_error", t.NOT_FOUND_ERROR = "not_found_error", t.VALIDATION_ERROR = "validation_error", t.SERVER_ERROR = "server_error", t.CLIENT_ERROR = "client_error", t.UNKNOWN_ERROR = "unknown_error";
|
|
300
301
|
})(L || (L = {}));
|
|
301
|
-
class
|
|
302
|
+
class G extends J {
|
|
302
303
|
errorMessages = {
|
|
303
304
|
ALREADY_RENDERED: "FiatAccountLink widget is already rendered. Call destroy() before rendering again.",
|
|
304
305
|
NOT_RENDERED: "FiatAccountLink widget is not rendered. Call render() first.",
|
|
@@ -306,7 +307,7 @@ class H extends J {
|
|
|
306
307
|
SCRIPT_LOAD_FAILED: "Failed to load the Connect FiatAccountLink script.",
|
|
307
308
|
WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
|
|
308
309
|
};
|
|
309
|
-
scriptUrls =
|
|
310
|
+
scriptUrls = H("fiat-account-link-web", "index.js", {
|
|
310
311
|
legacyAliases: !0
|
|
311
312
|
});
|
|
312
313
|
webComponentTag = "zerohash-fiat-account-link";
|
|
@@ -328,6 +329,6 @@ class H extends J {
|
|
|
328
329
|
}
|
|
329
330
|
export {
|
|
330
331
|
L as ErrorCode,
|
|
331
|
-
|
|
332
|
-
|
|
332
|
+
G as FiatAccountLink,
|
|
333
|
+
G as default
|
|
333
334
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(c=typeof globalThis<"u"?globalThis:c||self,m(c.FiatAccountLink={}))})(this,(function(c){"use strict";var m=typeof document<"u"?document.currentScript:null;const
|
|
1
|
+
(function(c,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(c=typeof globalThis<"u"?globalThis:c||self,m(c.FiatAccountLink={}))})(this,(function(c){"use strict";var m=typeof document<"u"?document.currentScript:null;const C="production",I="JWT token is required and must be a string.",A={dev:"https://grafana-faro-collector.dev.0hash.com/collect",cert:"https://grafana-faro-collector.cert.zerohash.com/collect",prod:"https://grafana-faro-collector.zerohash.com/collect","eu-cert":"https://grafana-faro-collector.cert.zerohash.eu/collect","eu-prod":"https://grafana-faro-collector.zerohash.eu/collect",sandbox:"https://grafana-faro-collector.cert.zerohash.com/collect",production:"https://grafana-faro-collector.zerohash.com/collect"},D=t=>{if(!t||typeof t!="string")return null;const e=t.split(".");if(e.length<2)return null;try{const r=e[1].replace(/-/g,"+").replace(/_/g,"/"),n=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(n):Buffer.from(n,"base64").toString("utf-8"),s=JSON.parse(o)?.payload?.region;if(typeof s!="string")return null;const i=s.toLowerCase();return i==="us"||i==="eu"?i:null}catch{return null}},T=(t,e)=>D(e)!=="eu"?t:t==="cert"?"eu-cert":t==="prod"?"eu-prod":t,k=t=>{if(!t||typeof t!="string")return{};const e=t.split(".");if(e.length<2)return{};try{const r=e[1].replace(/-/g,"+").replace(/_/g,"/"),n=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(n):Buffer.from(n,"base64").toString("utf-8"),a=JSON.parse(o),s=a?.payload??{},i=d=>typeof d=="string"&&d.length>0?d:void 0;return{participantCode:i(s.participant_code),platformName:i(s.platform_name),platformCode:i(a.platform_code),region:i(s.region)}}catch{return{}}},b=(t,e,r)=>{const n=T(e,r);return t[n]??t[e]??t.prod},z=(t,e,r)=>{const n=T(e,r);return t[n]??t[e]},E=()=>{},F=()=>{const t=new Uint8Array(8);return globalThis.crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")},U=(t,e)=>{const r=F(),n=globalThis.__ZH_WEB_SDK_VERSION__,o={};t.claims.participantCode&&(o.participant_code=t.claims.participantCode),t.claims.platformName&&(o.platform_name=t.claims.platformName),t.claims.platformCode&&(o.platform_code=t.claims.platformCode),t.claims.region&&(o.region=t.claims.region),n&&(o.zh_web_sdk_version=n);const a={meta:{app:{name:t.appName,version:e??"unknown",environment:t.env},session:{id:r,attributes:o},browser:typeof navigator<"u"?{userAgent:navigator.userAgent}:void 0,page:typeof window<"u"?{url:window.location.origin}:void 0},logs:[{message:`Failed to load the script for ${t.webComponentTag} from ${t.env} environment.`,level:"error",timestamp:new Date().toISOString(),context:{web_component:t.webComponentTag,script_url:t.scriptUrl,reason:t.reason,tried_fallback:String(t.triedFallback),elapsed_ms:String(t.elapsedMs)}}]};return{sessionId:r,payload:a}},M=(t,e,r)=>{if(!t||typeof fetch>"u")return;const{sessionId:n,payload:o}=U(e,r);try{fetch(t,{method:"POST",headers:{"Content-Type":"application/json","x-faro-session-id":n},body:JSON.stringify(o),keepalive:!0}).catch(()=>{})}catch{}},P=t=>{const{webComponentTag:e,appName:r,appVersion:n,scriptUrls:o,fallbackScriptUrls:a,collectorUrls:s,env:i,jwt:d,timeoutMs:V=15e3,onLoad:J,onError:H}=t;if(typeof document>"u")return E;const g=`${e}-script-${i}`;if(customElements.get(e)||document.getElementById(g))return E;const x=k(d),G=t.report??(u=>M(s&&z(s,i,d),u,n));let h=!1,S=0,R;const _=()=>{R!==void 0&&clearTimeout(R)},w=(u,f,l)=>{if(h)return;const K=Math.round(performance.now()-S),O={webComponentTag:e,appName:r,env:i,scriptUrl:f,reason:u,triedFallback:l,elapsedMs:K,claims:x};G(O);const y=l?void 0:b(a??{},i,d);if(y&&y!==f){L(y,!0);return}h=!0,_(),document.getElementById(g)?.remove(),H?.(O)},L=(u,f)=>{_(),S=performance.now();const l=document.createElement("script");l.id=g,l.src=u,l.type="module",l.async=!0,l.onload=()=>{setTimeout(()=>{h||(customElements.get(e)?(h=!0,_(),J?.()):w("not-defined",u,f))},0)},l.onerror=()=>w("network",u,f),R=setTimeout(()=>w("timeout",u,f),V),document.getElementById(g)?.remove(),document.head.appendChild(l)},v=b(o,i,d);return v?(L(v,!1),()=>{h=!0,_()}):E},W={};class j{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(I);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 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(([n,o])=>{o&&(this.config[n]=o,r[n]=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)}getEffectiveScriptUrls(){if(typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:m&&m.tagName.toUpperCase()==="SCRIPT"&&m.src||new URL("index.umd.cjs",document.baseURI).href}<"u"){const e=W.VITE_SCRIPT_URL;if(e)return{[this.getEnvironment()]:e}}return this.scriptUrls}async loadScript(){if(!(this.getWebComponent()||this.isScriptLoaded())){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((e,r)=>{P({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:A,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:e,onError:n=>{r(new Error(n.reason==="not-defined"?this.errorMessages.WEB_COMPONENT_NOT_DEFINED:`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))}})});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,n)=>{const o=setTimeout(()=>{n(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),r()}).catch(a=>{clearTimeout(o),n(a)})})}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,n])=>{n&&(e[r]=n)}),e}}const p={local:"http://localhost:5173",dev:"https://sdk-cdn.dev.0hash.com",cert:"https://sdk-cdn.cert.zerohash.com",prod:"https://sdk-cdn.zerohash.com","eu-cert":"https://sdk-cdn.cert.zerohash.eu","eu-prod":"https://sdk-cdn.zerohash.eu"},$="https://sdk-cdn.gating.0hash.com",B=(t,e,r={})=>{const{eu:n=!1,legacyAliases:o=!1,local:a=p.local}=r,s=d=>`${d}/${t}/${e}`,i={local:s(a),dev:s(p.dev),gating:s($),cert:s(p.cert),prod:s(p.prod)};return o&&(i.sandbox=s(p.cert),i.production=s(p.prod)),n&&(i["eu-cert"]=s(p["eu-cert"]),i["eu-prod"]=s(p["eu-prod"])),i};c.ErrorCode=void 0,(function(t){t.NETWORK_ERROR="network_error",t.AUTH_ERROR="auth_error",t.NOT_FOUND_ERROR="not_found_error",t.VALIDATION_ERROR="validation_error",t.SERVER_ERROR="server_error",t.CLIENT_ERROR="client_error",t.UNKNOWN_ERROR="unknown_error"})(c.ErrorCode||(c.ErrorCode={}));class N extends j{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=B("fiat-account-link-web","index.js",{legacyAliases:!0});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()}}c.FiatAccountLink=N,c.default=N,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|