@zerohash-sdk/fiat-account-link-js 1.15.3 → 1.15.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
@@ -247,15 +247,20 @@ declare abstract class BaseJsSdk<Config extends BaseConfig<never> = BaseConfig>
247
247
  return this.scriptLoadingPromise;
248
248
  }
249
249
 
250
- private async waitForWebComponent(timeout = 5000) {
250
+ private async waitForWebComponent() {
251
251
  if (this.getWebComponent()) {
252
252
  return;
253
253
  }
254
254
 
255
+ // The script has already loaded (loadScript awaited its onLoad); this only
256
+ // covers the window until the custom element registers. Under load (CI, slow
257
+ // devices) that can take longer than a few seconds, so the grace period is
258
+ // generous — a genuine load failure still fails fast via loadScript's
259
+ // onError, not this timer.
255
260
  return new Promise<void>((resolve, reject) => {
256
261
  const timeoutId = setTimeout(() => {
257
262
  reject(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
258
- }, timeout);
263
+ }, DEFAULT_WEB_COMPONENT_TIMEOUT_MS);
259
264
 
260
265
  customElements
261
266
  .whenDefined(this.webComponentTag)
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const y = "production", z = "JWT token is required and must be a string.", F = {
1
+ const y = "production", z = "JWT token is required and must be a string.", M = {
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",
@@ -6,7 +6,7 @@ const y = "production", z = "JWT token is required and must be a string.", F = {
6
6
  "eu-prod": "https://grafana-faro-collector.zerohash.eu/collect",
7
7
  sandbox: "https://grafana-faro-collector.cert.zerohash.com/collect",
8
8
  production: "https://grafana-faro-collector.zerohash.com/collect"
9
- }, M = (t) => {
9
+ }, F = (t) => {
10
10
  if (!t || typeof t != "string")
11
11
  return null;
12
12
  const e = t.split(".");
@@ -21,37 +21,37 @@ const y = "production", z = "JWT token is required and must be a string.", F = {
21
21
  } catch {
22
22
  return null;
23
23
  }
24
- }, S = (t, e) => M(e) !== "eu" ? t : t === "cert" ? "eu-cert" : t === "prod" ? "eu-prod" : t, W = (t) => {
24
+ }, O = (t, e) => F(e) !== "eu" ? t : t === "cert" ? "eu-cert" : t === "prod" ? "eu-prod" : t, U = (t) => {
25
25
  if (!t || typeof t != "string")
26
26
  return {};
27
27
  const e = t.split(".");
28
28
  if (e.length < 2)
29
29
  return {};
30
30
  try {
31
- 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), i = a?.payload ?? {}, s = (c) => typeof c == "string" && c.length > 0 ? c : void 0;
31
+ 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"), d = JSON.parse(o), i = d?.payload ?? {}, s = (a) => typeof a == "string" && a.length > 0 ? a : void 0;
32
32
  return {
33
33
  participantCode: s(i.participant_code),
34
34
  platformName: s(i.platform_name),
35
- platformCode: s(a.platform_code),
35
+ platformCode: s(d.platform_code),
36
36
  region: s(i.region)
37
37
  };
38
38
  } catch {
39
39
  return {};
40
40
  }
41
41
  }, N = (t, e, r) => {
42
- const n = S(e, r);
42
+ const n = O(e, r);
43
43
  return t[n] ?? t[e] ?? t.prod;
44
- }, P = (t, e, r) => {
45
- const n = S(e, r);
44
+ }, W = (t, e, r) => {
45
+ const n = O(e, r);
46
46
  return t[n] ?? t[e];
47
47
  }, w = () => {
48
- }, U = () => {
48
+ }, P = () => {
49
49
  const t = new Uint8Array(8);
50
50
  return globalThis.crypto.getRandomValues(t), Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
51
51
  }, $ = (t, e) => {
52
- const r = U(), n = globalThis.__ZH_WEB_SDK_VERSION__, o = {};
52
+ const r = P(), n = globalThis.__ZH_WEB_SDK_VERSION__, o = {};
53
53
  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);
54
- const a = {
54
+ const d = {
55
55
  meta: {
56
56
  app: { name: t.appName, version: e ?? "unknown", environment: t.env },
57
57
  session: { id: r, attributes: o },
@@ -73,7 +73,7 @@ const y = "production", z = "JWT token is required and must be a string.", F = {
73
73
  }
74
74
  ]
75
75
  };
76
- return { sessionId: r, payload: a };
76
+ return { sessionId: r, payload: d };
77
77
  }, B = (t, e, r) => {
78
78
  if (!t || typeof fetch > "u")
79
79
  return;
@@ -89,49 +89,49 @@ const y = "production", z = "JWT token is required and must be a string.", F = {
89
89
  } catch {
90
90
  }
91
91
  }, V = (t) => {
92
- const { webComponentTag: e, appName: r, appVersion: n, scriptUrls: o, fallbackScriptUrls: a, collectorUrls: i, env: s, jwt: c, timeoutMs: O = 15e3, onLoad: v, onError: I } = t;
92
+ const { webComponentTag: e, appName: r, appVersion: n, scriptUrls: o, fallbackScriptUrls: d, collectorUrls: i, env: s, jwt: a, timeoutMs: S = 15e3, onLoad: v, onError: I } = t;
93
93
  if (typeof document > "u")
94
94
  return w;
95
95
  const h = `${e}-script-${s}`;
96
96
  if (customElements.get(e) || document.getElementById(h))
97
97
  return w;
98
- const A = W(c), D = t.report ?? ((l) => B(i && P(i, s, c), l, n));
99
- let m = !1, R = 0, g;
98
+ const A = U(a), D = t.report ?? ((l) => B(i && W(i, s, a), l, n));
99
+ let m = !1, T = 0, g;
100
100
  const f = () => {
101
101
  g !== void 0 && clearTimeout(g);
102
- }, _ = (l, u, d) => {
102
+ }, _ = (l, u, c) => {
103
103
  if (m)
104
104
  return;
105
- const k = Math.round(performance.now() - R), T = {
105
+ const k = Math.round(performance.now() - T), b = {
106
106
  webComponentTag: e,
107
107
  appName: r,
108
108
  env: s,
109
109
  scriptUrl: u,
110
110
  reason: l,
111
- triedFallback: d,
111
+ triedFallback: c,
112
112
  elapsedMs: k,
113
113
  claims: A
114
114
  };
115
- D(T);
116
- const E = d ? void 0 : N(a ?? {}, s, c);
115
+ D(b);
116
+ const E = c ? void 0 : N(d ?? {}, s, a);
117
117
  if (E && E !== u) {
118
- b(E, !0);
118
+ C(E, !0);
119
119
  return;
120
120
  }
121
- m = !0, f(), document.getElementById(h)?.remove(), I?.(T);
122
- }, b = (l, u) => {
123
- f(), R = performance.now();
124
- const d = document.createElement("script");
125
- d.id = h, d.src = l, d.type = "module", d.async = !0, d.onload = () => {
121
+ m = !0, f(), document.getElementById(h)?.remove(), I?.(b);
122
+ }, C = (l, u) => {
123
+ f(), T = performance.now();
124
+ const c = document.createElement("script");
125
+ c.id = h, c.src = l, c.type = "module", c.async = !0, c.onload = () => {
126
126
  setTimeout(() => {
127
127
  m || (customElements.get(e) ? (m = !0, f(), v?.()) : _("not-defined", l, u));
128
128
  }, 0);
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), () => {
129
+ }, c.onerror = () => _("network", l, u), g = setTimeout(() => _("timeout", l, u), S), document.getElementById(h)?.remove(), document.head.appendChild(c);
130
+ }, R = N(o, s, a);
131
+ return R ? (C(R, !1), () => {
132
132
  m = !0, f();
133
133
  }) : w;
134
- }, j = {};
134
+ }, j = {}, H = 1e4;
135
135
  class J {
136
136
  config;
137
137
  state;
@@ -234,7 +234,7 @@ class J {
234
234
  webComponentTag: this.webComponentTag,
235
235
  appName: this.webComponentTag,
236
236
  scriptUrls: this.getEffectiveScriptUrls(),
237
- collectorUrls: F,
237
+ collectorUrls: M,
238
238
  env: this.getEnvironment(),
239
239
  jwt: this.config.jwt,
240
240
  onLoad: e,
@@ -251,16 +251,16 @@ class J {
251
251
  return this.scriptLoadingPromise;
252
252
  }
253
253
  }
254
- async waitForWebComponent(e = 5e3) {
254
+ async waitForWebComponent() {
255
255
  if (!this.getWebComponent())
256
- return new Promise((r, n) => {
257
- const o = setTimeout(() => {
258
- n(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
259
- }, e);
256
+ return new Promise((e, r) => {
257
+ const n = setTimeout(() => {
258
+ r(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
259
+ }, H);
260
260
  customElements.whenDefined(this.webComponentTag).then(() => {
261
- clearTimeout(o), r();
262
- }).catch((a) => {
263
- clearTimeout(o), n(a);
261
+ clearTimeout(n), e();
262
+ }).catch((o) => {
263
+ clearTimeout(n), r(o);
264
264
  });
265
265
  });
266
266
  }
@@ -282,18 +282,18 @@ class J {
282
282
  }), e;
283
283
  }
284
284
  }
285
- const p = {
286
- local: "http://localhost:5173",
285
+ const x = {}, G = typeof import.meta < "u" && x?.VITE_LOCAL_CDN_HOST || "http://localhost:5173", p = {
286
+ local: G,
287
287
  dev: "https://sdk-cdn.dev.0hash.com",
288
288
  cert: "https://sdk-cdn.cert.zerohash.com",
289
289
  prod: "https://sdk-cdn.zerohash.com",
290
290
  "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
291
291
  "eu-prod": "https://sdk-cdn.zerohash.eu"
292
- }, x = "https://sdk-cdn.gating.0hash.com", H = (t, e, r = {}) => {
293
- const { eu: n = !1, legacyAliases: o = !1, local: a = p.local } = r, i = (c) => `${c}/${t}/${e}`, s = {
294
- local: i(a),
292
+ }, K = "https://sdk-cdn.gating.0hash.com", Y = (t, e, r = {}) => {
293
+ const { eu: n = !1, legacyAliases: o = !1, local: d = p.local } = r, i = (a) => `${a}/${t}/${e}`, s = {
294
+ local: i(d),
295
295
  dev: i(p.dev),
296
- gating: i(x),
296
+ gating: i(K),
297
297
  cert: i(p.cert),
298
298
  prod: i(p.prod)
299
299
  };
@@ -303,7 +303,7 @@ var L;
303
303
  (function(t) {
304
304
  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";
305
305
  })(L || (L = {}));
306
- class G extends J {
306
+ class q extends J {
307
307
  errorMessages = {
308
308
  ALREADY_RENDERED: "FiatAccountLink widget is already rendered. Call destroy() before rendering again.",
309
309
  NOT_RENDERED: "FiatAccountLink widget is not rendered. Call render() first.",
@@ -311,7 +311,7 @@ class G extends J {
311
311
  SCRIPT_LOAD_FAILED: "Failed to load the Connect FiatAccountLink script.",
312
312
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
313
313
  };
314
- scriptUrls = H("fiat-account-link-web", "index.js", {
314
+ scriptUrls = Y("fiat-account-link-web", "index.js", {
315
315
  legacyAliases: !0,
316
316
  eu: !0
317
317
  });
@@ -334,6 +334,6 @@ class G extends J {
334
334
  }
335
335
  export {
336
336
  L as ErrorCode,
337
- G as FiatAccountLink,
338
- G as default
337
+ q as FiatAccountLink,
338
+ q as default
339
339
  };
@@ -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 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??(p=>M(s&&z(s,i,d),p,n));let h=!1,S=0,R;const _=()=>{R!==void 0&&clearTimeout(R)},w=(p,f,l)=>{if(h)return;const K=Math.round(performance.now()-S),O={webComponentTag:e,appName:r,env:i,scriptUrl:f,reason:p,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=(p,f)=>{_(),S=performance.now();const l=document.createElement("script");l.id=g,l.src=p,l.type="module",l.async=!0,l.onload=()=>{setTimeout(()=>{h||(customElements.get(e)?(h=!0,_(),J?.()):w("not-defined",p,f))},0)},l.onerror=()=>w("network",p,f),R=setTimeout(()=>w("timeout",p,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 u={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=u.local}=r,s=d=>`${d}/${t}/${e}`,i={local:s(a),dev:s(u.dev),gating:s($),cert:s(u.cert),prod:s(u.prod)};return o&&(i.sandbox=s(u.cert),i.production=s(u.prod)),n&&(i["eu-cert"]=s(u["eu-cert"]),i["eu-prod"]=s(u["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,eu:!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"}})}));
1
+ (function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a.FiatAccountLink={}))})(this,(function(a){"use strict";var c=typeof document<"u"?document.currentScript:null;const y="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 n=e[1].replace(/-/g,"+").replace(/_/g,"/"),r=n+"===".slice(0,(4-n.length%4)%4),o=typeof atob<"u"?atob(r):Buffer.from(r,"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}},w=(t,e)=>D(e)!=="eu"?t:t==="cert"?"eu-cert":t==="prod"?"eu-prod":t,U=t=>{if(!t||typeof t!="string")return{};const e=t.split(".");if(e.length<2)return{};try{const n=e[1].replace(/-/g,"+").replace(/_/g,"/"),r=n+"===".slice(0,(4-n.length%4)%4),o=typeof atob<"u"?atob(r):Buffer.from(r,"base64").toString("utf-8"),u=JSON.parse(o),s=u?.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(u.platform_code),region:i(s.region)}}catch{return{}}},b=(t,e,n)=>{const r=w(e,n);return t[r]??t[e]??t.prod},k=(t,e,n)=>{const r=w(e,n);return t[r]??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("")},M=(t,e)=>{const n=F(),r=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),r&&(o.zh_web_sdk_version=r);const u={meta:{app:{name:t.appName,version:e??"unknown",environment:t.env},session:{id:n,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:n,payload:u}},z=(t,e,n)=>{if(!t||typeof fetch>"u")return;const{sessionId:r,payload:o}=M(e,n);try{fetch(t,{method:"POST",headers:{"Content-Type":"application/json","x-faro-session-id":r},body:JSON.stringify(o),keepalive:!0}).catch(()=>{})}catch{}},P=t=>{const{webComponentTag:e,appName:n,appVersion:r,scriptUrls:o,fallbackScriptUrls:u,collectorUrls:s,env:i,jwt:d,timeoutMs:J=15e3,onLoad:x,onError:q}=t;if(typeof document>"u")return E;const g=`${e}-script-${i}`;if(customElements.get(e)||document.getElementById(g))return E;const G=U(d),K=t.report??(f=>z(s&&k(s,i,d),f,r));let h=!1,N=0,T;const _=()=>{T!==void 0&&clearTimeout(T)},C=(f,m,l)=>{if(h)return;const Y=Math.round(performance.now()-N),v={webComponentTag:e,appName:n,env:i,scriptUrl:m,reason:f,triedFallback:l,elapsedMs:Y,claims:G};K(v);const R=l?void 0:b(u??{},i,d);if(R&&R!==m){S(R,!0);return}h=!0,_(),document.getElementById(g)?.remove(),q?.(v)},S=(f,m)=>{_(),N=performance.now();const l=document.createElement("script");l.id=g,l.src=f,l.type="module",l.async=!0,l.onload=()=>{setTimeout(()=>{h||(customElements.get(e)?(h=!0,_(),x?.()):C("not-defined",f,m))},0)},l.onerror=()=>C("network",f,m),T=setTimeout(()=>C("timeout",f,m),J),document.getElementById(g)?.remove(),document.head.appendChild(l)},O=b(o,i,d);return O?(S(O,!1),()=>{h=!0,_()}):E},W={},j=1e4;class ${config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(I);this.config={...e,env:e.env||y,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(([r,o])=>{o&&(this.config[r]=o,n[r]=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||y}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:c&&c.tagName.toUpperCase()==="SCRIPT"&&c.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,n)=>{P({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:A,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:e,onError:r=>{n(new Error(r.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(){if(!this.getWebComponent())return new Promise((e,n)=>{const r=setTimeout(()=>{n(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},j);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(r),e()}).catch(o=>{clearTimeout(r),n(o)})})}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,r])=>{r&&(e[n]=r)}),e}}const B={},p={local:typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:c&&c.tagName.toUpperCase()==="SCRIPT"&&c.src||new URL("index.umd.cjs",document.baseURI).href}<"u"&&B?.VITE_LOCAL_CDN_HOST||"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"},V="https://sdk-cdn.gating.0hash.com",H=(t,e,n={})=>{const{eu:r=!1,legacyAliases:o=!1,local:u=p.local}=n,s=d=>`${d}/${t}/${e}`,i={local:s(u),dev:s(p.dev),gating:s(V),cert:s(p.cert),prod:s(p.prod)};return o&&(i.sandbox=s(p.cert),i.production=s(p.prod)),r&&(i["eu-cert"]=s(p["eu-cert"]),i["eu-prod"]=s(p["eu-prod"])),i};a.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"})(a.ErrorCode||(a.ErrorCode={}));class L extends ${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=H("fiat-account-link-web","index.js",{legacyAliases:!0,eu:!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()}}a.FiatAccountLink=L,a.default=L,Object.defineProperties(a,{__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.15.3",
3
+ "version": "1.15.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",