@zerohash-sdk/fiat-account-link-js 1.6.1 → 1.6.2

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/README.md CHANGED
@@ -21,14 +21,14 @@ import { FiatAccountLink } from '@zerohash-sdk/fiat-account-link-js';
21
21
  ```html
22
22
  <script
23
23
  type="module"
24
- src="https://sdk.connect.xyz/fiat-account-link-web/index.js"
24
+ src="https://sdk-cdn.zerohash.com/fiat-account-link-web/index.js"
25
25
  ></script>
26
26
  ```
27
27
 
28
28
  Or import directly in your JavaScript code:
29
29
 
30
30
  ```javascript
31
- import { FiatAccountLink } from 'https://sdk.connect.xyz/fiat-account-link-web/index.js';
31
+ import { FiatAccountLink } from 'https://sdk-cdn.zerohash.com/fiat-account-link-web/index.js';
32
32
  ```
33
33
 
34
34
  ## Getting Started
package/dist/index.d.ts CHANGED
@@ -408,14 +408,7 @@ declare class FiatAccountLink extends BaseJsSdk<FiatAccountLinkConfig> {
408
408
  SCRIPT_LOAD_FAILED: string;
409
409
  WEB_COMPONENT_NOT_DEFINED: string;
410
410
  };
411
- protected scriptUrls: {
412
- local: string;
413
- dev: string;
414
- cert: string;
415
- prod: string;
416
- sandbox: string;
417
- production: string;
418
- };
411
+ protected scriptUrls: Record<string, string>;
419
412
  protected webComponentTag: string;
420
413
  render(container: HTMLElement): Promise<void>;
421
414
  updateConfig(config: Partial<FiatAccountLinkConfig>): void;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const C = "production", k = "JWT token is required and must be a string.", z = {
1
+ const T = "production", k = "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",
@@ -6,55 +6,55 @@ const C = "production", k = "JWT token is required and must be a string.", z = {
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
- }, x = (t) => {
9
+ }, M = (t) => {
10
10
  if (!t || typeof t != "string")
11
11
  return null;
12
12
  const e = t.split(".");
13
13
  if (e.length < 2)
14
14
  return null;
15
15
  try {
16
- 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"), c = JSON.parse(o)?.payload?.region;
17
- if (typeof c != "string")
16
+ 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"), i = JSON.parse(o)?.payload?.region;
17
+ if (typeof i != "string")
18
18
  return null;
19
- const i = c.toLowerCase();
20
- return i === "us" || i === "eu" ? i : null;
19
+ const s = i.toLowerCase();
20
+ return s === "us" || s === "eu" ? s : null;
21
21
  } catch {
22
22
  return null;
23
23
  }
24
- }, L = (t, e) => x(e) !== "eu" ? t : t === "cert" ? "eu-cert" : t === "prod" ? "eu-prod" : t, F = (t) => {
24
+ }, S = (t, e) => M(e) !== "eu" ? t : t === "cert" ? "eu-cert" : t === "prod" ? "eu-prod" : t, W = (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 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"), a = JSON.parse(o), c = a?.payload ?? {}, i = (d) => typeof d == "string" && d.length > 0 ? d : 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"), a = JSON.parse(o), i = a?.payload ?? {}, s = (c) => typeof c == "string" && c.length > 0 ? c : void 0;
32
32
  return {
33
- participantCode: i(c.participant_code),
34
- platformName: i(c.platform_name),
35
- platformCode: i(a.platform_code),
36
- region: i(c.region)
33
+ participantCode: s(i.participant_code),
34
+ platformName: s(i.platform_name),
35
+ platformCode: s(a.platform_code),
36
+ region: s(i.region)
37
37
  };
38
38
  } catch {
39
39
  return {};
40
40
  }
41
- }, T = (t, e, n) => {
42
- const r = L(e, n);
43
- return t[r] ?? t[e] ?? t.prod;
44
- }, M = (t, e, n) => {
45
- const r = L(e, n);
46
- return t[r] ?? t[e];
47
- }, _ = () => {
48
- }, W = () => {
41
+ }, N = (t, e, r) => {
42
+ const n = S(e, r);
43
+ return t[n] ?? t[e] ?? t.prod;
44
+ }, P = (t, e, r) => {
45
+ const n = S(e, r);
46
+ return t[n] ?? t[e];
47
+ }, w = () => {
48
+ }, U = () => {
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
- }, P = (t, e) => {
52
- const n = W(), r = globalThis.__ZH_WEB_SDK_VERSION__, o = {};
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), r && (o.zh_web_sdk_version = r);
51
+ }, $ = (t, e) => {
52
+ const r = U(), n = globalThis.__ZH_WEB_SDK_VERSION__, o = {};
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
54
  const a = {
55
55
  meta: {
56
56
  app: { name: t.appName, version: e ?? "unknown", environment: t.env },
57
- session: { id: n, attributes: o },
57
+ session: { id: r, attributes: o },
58
58
  browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
59
59
  page: typeof window < "u" ? { url: window.location.origin } : void 0
60
60
  },
@@ -73,66 +73,66 @@ const C = "production", k = "JWT token is required and must be a string.", z = {
73
73
  }
74
74
  ]
75
75
  };
76
- return { sessionId: n, payload: a };
77
- }, U = (t, e, n) => {
76
+ return { sessionId: r, payload: a };
77
+ }, B = (t, e, r) => {
78
78
  if (!t || typeof fetch > "u")
79
79
  return;
80
- const { sessionId: r, payload: o } = P(e, n);
80
+ const { sessionId: n, payload: o } = $(e, r);
81
81
  try {
82
82
  fetch(t, {
83
83
  method: "POST",
84
- headers: { "Content-Type": "application/json", "x-faro-session-id": r },
84
+ headers: { "Content-Type": "application/json", "x-faro-session-id": n },
85
85
  body: JSON.stringify(o),
86
86
  keepalive: !0
87
87
  }).catch(() => {
88
88
  });
89
89
  } catch {
90
90
  }
91
- }, j = (t) => {
92
- const { webComponentTag: e, appName: n, appVersion: r, scriptUrls: o, fallbackScriptUrls: a, collectorUrls: c, env: i, jwt: d, timeoutMs: S = 15e3, onLoad: O, onError: v } = t;
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;
93
93
  if (typeof document > "u")
94
- return _;
95
- const m = `${e}-script-${i}`;
96
- if (customElements.get(e) || document.getElementById(m))
97
- return _;
98
- const I = F(d), A = t.report ?? ((l) => U(c && M(c, i, d), l, r));
99
- let u = !1, w = 0, h;
94
+ return w;
95
+ const h = `${e}-script-${s}`;
96
+ if (customElements.get(e) || document.getElementById(h))
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;
100
100
  const f = () => {
101
- h !== void 0 && clearTimeout(h);
102
- }, g = (l, p, s) => {
103
- if (u)
101
+ g !== void 0 && clearTimeout(g);
102
+ }, E = (l, u, d) => {
103
+ if (m)
104
104
  return;
105
- const D = Math.round(performance.now() - w), y = {
105
+ const z = Math.round(performance.now() - R), C = {
106
106
  webComponentTag: e,
107
- appName: n,
108
- env: i,
109
- scriptUrl: p,
107
+ appName: r,
108
+ env: s,
109
+ scriptUrl: u,
110
110
  reason: l,
111
- triedFallback: s,
112
- elapsedMs: D,
113
- claims: I
111
+ triedFallback: d,
112
+ elapsedMs: z,
113
+ claims: A
114
114
  };
115
- A(y);
116
- const E = s ? void 0 : T(a ?? {}, i, d);
117
- if (E && E !== p) {
118
- b(E, !0);
115
+ D(C);
116
+ const _ = d ? void 0 : N(a ?? {}, s, c);
117
+ if (_ && _ !== u) {
118
+ b(_, !0);
119
119
  return;
120
120
  }
121
- u = !0, f(), document.getElementById(m)?.remove(), v?.(y);
122
- }, b = (l, p) => {
123
- f(), w = performance.now();
124
- const s = document.createElement("script");
125
- s.id = m, s.src = l, s.type = "module", s.async = !0, s.onload = () => {
121
+ m = !0, f(), document.getElementById(h)?.remove(), I?.(C);
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 = () => {
126
126
  setTimeout(() => {
127
- u || (customElements.get(e) ? (u = !0, f(), O?.()) : g("not-defined", l, p));
127
+ m || (customElements.get(e) ? (m = !0, f(), v?.()) : E("not-defined", l, u));
128
128
  }, 0);
129
- }, s.onerror = () => g("network", l, p), h = setTimeout(() => g("timeout", l, p), S), document.getElementById(m)?.remove(), document.head.appendChild(s);
130
- }, R = T(o, i, d);
131
- return R ? (b(R, !1), () => {
132
- u = !0, f();
133
- }) : _;
134
- }, B = {};
135
- class V {
129
+ }, d.onerror = () => E("network", l, u), g = setTimeout(() => E("timeout", l, u), O), document.getElementById(h)?.remove(), document.head.appendChild(d);
130
+ }, y = N(o, s, c);
131
+ return y ? (b(y, !1), () => {
132
+ m = !0, f();
133
+ }) : w;
134
+ }, j = {};
135
+ class J {
136
136
  config;
137
137
  state;
138
138
  scriptLoadingPromise;
@@ -141,7 +141,7 @@ class V {
141
141
  throw new Error(k);
142
142
  this.config = {
143
143
  ...e,
144
- env: e.env || C,
144
+ env: e.env || T,
145
145
  theme: e.theme
146
146
  }, this.state = {
147
147
  initialized: !1,
@@ -162,10 +162,10 @@ class V {
162
162
  throw new Error(this.errorMessages.ALREADY_RENDERED);
163
163
  try {
164
164
  await this.ensureScriptLoaded();
165
- const n = this.createWebComponent();
166
- e.innerHTML = "", e.appendChild(n), this.state.container = e, this.state.element = n, this.state.initialized = !0;
167
- } catch (n) {
168
- throw console.error("Failed to render widget:", n), n;
165
+ const r = this.createWebComponent();
166
+ e.innerHTML = "", e.appendChild(r), this.state.container = e, this.state.element = r, this.state.initialized = !0;
167
+ } catch (r) {
168
+ throw console.error("Failed to render widget:", r), r;
169
169
  }
170
170
  }
171
171
  /**
@@ -176,9 +176,9 @@ class V {
176
176
  updateConfig(e) {
177
177
  if (!this.state.initialized || !this.state.element)
178
178
  throw new Error(this.errorMessages.NOT_RENDERED);
179
- const n = this.state.element;
180
- Object.entries(e).forEach(([r, o]) => {
181
- o && (this.config[r] = o, n[r] = o);
179
+ const r = this.state.element;
180
+ Object.entries(e).forEach(([n, o]) => {
181
+ o && (this.config[n] = o, r[n] = o);
182
182
  });
183
183
  }
184
184
  /**
@@ -202,7 +202,7 @@ class V {
202
202
  return { ...this.config };
203
203
  }
204
204
  getEnvironment() {
205
- return this.config.env || C;
205
+ return this.config.env || T;
206
206
  }
207
207
  getScriptId() {
208
208
  return `${this.webComponentTag}-script-${this.getEnvironment()}`;
@@ -215,7 +215,7 @@ class V {
215
215
  }
216
216
  getEffectiveScriptUrls() {
217
217
  if (typeof import.meta < "u") {
218
- const e = B.VITE_SCRIPT_URL;
218
+ const e = j.VITE_SCRIPT_URL;
219
219
  if (e)
220
220
  return { [this.getEnvironment()]: e };
221
221
  }
@@ -225,17 +225,17 @@ class V {
225
225
  if (!(this.getWebComponent() || this.isScriptLoaded())) {
226
226
  if (this.scriptLoadingPromise)
227
227
  return this.scriptLoadingPromise;
228
- this.scriptLoadingPromise = new Promise((e, n) => {
229
- j({
228
+ this.scriptLoadingPromise = new Promise((e, r) => {
229
+ V({
230
230
  webComponentTag: this.webComponentTag,
231
231
  appName: this.webComponentTag,
232
232
  scriptUrls: this.getEffectiveScriptUrls(),
233
- collectorUrls: z,
233
+ collectorUrls: F,
234
234
  env: this.getEnvironment(),
235
235
  jwt: this.config.jwt,
236
236
  onLoad: e,
237
- onError: (r) => {
238
- n(new Error(r.reason === "not-defined" ? this.errorMessages.WEB_COMPONENT_NOT_DEFINED : `${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
237
+ onError: (n) => {
238
+ r(new Error(n.reason === "not-defined" ? this.errorMessages.WEB_COMPONENT_NOT_DEFINED : `${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
239
239
  }
240
240
  });
241
241
  });
@@ -249,14 +249,14 @@ class V {
249
249
  }
250
250
  async waitForWebComponent(e = 5e3) {
251
251
  if (!this.getWebComponent())
252
- return new Promise((n, r) => {
252
+ return new Promise((r, n) => {
253
253
  const o = setTimeout(() => {
254
- r(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
254
+ n(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
255
255
  }, e);
256
256
  customElements.whenDefined(this.webComponentTag).then(() => {
257
- clearTimeout(o), n();
257
+ clearTimeout(o), r();
258
258
  }).catch((a) => {
259
- clearTimeout(o), r(a);
259
+ clearTimeout(o), n(a);
260
260
  });
261
261
  });
262
262
  }
@@ -273,16 +273,32 @@ class V {
273
273
  }
274
274
  createWebComponent() {
275
275
  const e = document.createElement(this.webComponentTag);
276
- return Object.entries(this.config).forEach(([n, r]) => {
277
- r && (e[n] = r);
276
+ return Object.entries(this.config).forEach(([r, n]) => {
277
+ n && (e[r] = n);
278
278
  }), e;
279
279
  }
280
280
  }
281
- var N;
281
+ const p = {
282
+ local: "http://localhost:5173",
283
+ dev: "https://sdk-cdn.dev.0hash.com",
284
+ cert: "https://sdk-cdn.cert.zerohash.com",
285
+ prod: "https://sdk-cdn.zerohash.com",
286
+ "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
287
+ "eu-prod": "https://sdk-cdn.zerohash.eu"
288
+ }, x = (t, e, r = {}) => {
289
+ const { eu: n = !1, legacyAliases: o = !1, local: a = p.local } = r, i = (c) => `${c}/${t}/${e}`, s = {
290
+ local: i(a),
291
+ dev: i(p.dev),
292
+ cert: i(p.cert),
293
+ prod: i(p.prod)
294
+ };
295
+ return o && (s.sandbox = i(p.cert), s.production = i(p.prod)), n && (s["eu-cert"] = i(p["eu-cert"]), s["eu-prod"] = i(p["eu-prod"])), s;
296
+ };
297
+ var L;
282
298
  (function(t) {
283
299
  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";
284
- })(N || (N = {}));
285
- class $ extends V {
300
+ })(L || (L = {}));
301
+ class H extends J {
286
302
  errorMessages = {
287
303
  ALREADY_RENDERED: "FiatAccountLink widget is already rendered. Call destroy() before rendering again.",
288
304
  NOT_RENDERED: "FiatAccountLink widget is not rendered. Call render() first.",
@@ -290,14 +306,11 @@ class $ extends V {
290
306
  SCRIPT_LOAD_FAILED: "Failed to load the Connect FiatAccountLink script.",
291
307
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
292
308
  };
293
- scriptUrls = {
294
- local: "http://localhost:4208/fiat-account-link-web/index.js",
295
- dev: "https://connect-sdk.dev.0hash.com/fiat-account-link-web/index.js",
296
- cert: "https://sdk.sandbox.connect.xyz/fiat-account-link-web/index.js",
297
- prod: "https://sdk.connect.xyz/fiat-account-link-web/index.js",
298
- sandbox: "https://sdk.sandbox.connect.xyz/fiat-account-link-web/index.js",
299
- production: "https://sdk.connect.xyz/fiat-account-link-web/index.js"
300
- };
309
+ // This SDK's vite dev server serves on port 4208.
310
+ scriptUrls = x("fiat-account-link-web", "index.js", {
311
+ legacyAliases: !0,
312
+ local: "http://localhost:4208"
313
+ });
301
314
  webComponentTag = "zerohash-fiat-account-link";
302
315
  render(e) {
303
316
  return super.render(e);
@@ -316,7 +329,7 @@ class $ extends V {
316
329
  }
317
330
  }
318
331
  export {
319
- N as ErrorCode,
320
- $ as FiatAccountLink,
321
- $ as default
332
+ L as ErrorCode,
333
+ H as FiatAccountLink,
334
+ H as default
322
335
  };
@@ -1 +1 @@
1
- (function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.FiatAccountLink={}))})(this,(function(s){"use strict";var u=typeof document<"u"?document.currentScript:null;const R="production",O="JWT token is required and must be a string.",I={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"},A=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"),d=JSON.parse(o)?.payload?.region;if(typeof d!="string")return null;const i=d.toLowerCase();return i==="us"||i==="eu"?i:null}catch{return null}},y=(t,e)=>A(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 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"),c=JSON.parse(o),d=c?.payload??{},i=l=>typeof l=="string"&&l.length>0?l:void 0;return{participantCode:i(d.participant_code),platformName:i(d.platform_name),platformCode:i(c.platform_code),region:i(d.region)}}catch{return{}}},C=(t,e,n)=>{const r=y(e,n);return t[r]??t[e]??t.prod},D=(t,e,n)=>{const r=y(e,n);return t[r]??t[e]},_=()=>{},z=()=>{const t=new Uint8Array(8);return globalThis.crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")},F=(t,e)=>{const n=z(),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 c={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:c}},M=(t,e,n)=>{if(!t||typeof fetch>"u")return;const{sessionId:r,payload:o}=F(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{}},U=t=>{const{webComponentTag:e,appName:n,appVersion:r,scriptUrls:o,fallbackScriptUrls:c,collectorUrls:d,env:i,jwt:l,timeoutMs:W=15e3,onLoad:x,onError:B}=t;if(typeof document>"u")return _;const h=`${e}-script-${i}`;if(customElements.get(e)||document.getElementById(h))return _;const V=k(l),$=t.report??(p=>M(d&&D(d,i,l),p,r));let m=!1,L=0,E;const g=()=>{E!==void 0&&clearTimeout(E)},w=(p,f,a)=>{if(m)return;const J=Math.round(performance.now()-L),v={webComponentTag:e,appName:n,env:i,scriptUrl:f,reason:p,triedFallback:a,elapsedMs:J,claims:V};$(v);const b=a?void 0:C(c??{},i,l);if(b&&b!==f){N(b,!0);return}m=!0,g(),document.getElementById(h)?.remove(),B?.(v)},N=(p,f)=>{g(),L=performance.now();const a=document.createElement("script");a.id=h,a.src=p,a.type="module",a.async=!0,a.onload=()=>{setTimeout(()=>{m||(customElements.get(e)?(m=!0,g(),x?.()):w("not-defined",p,f))},0)},a.onerror=()=>w("network",p,f),E=setTimeout(()=>w("timeout",p,f),W),document.getElementById(h)?.remove(),document.head.appendChild(a)},S=C(o,i,l);return S?(N(S,!1),()=>{m=!0,g()}):_},P={};class j{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(O);this.config={...e,env:e.env||R,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||R}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:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.umd.cjs",document.baseURI).href}<"u"){const e=P.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)=>{U({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:I,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(e=5e3){if(!this.getWebComponent())return new Promise((n,r)=>{const o=setTimeout(()=>{r(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),n()}).catch(c=>{clearTimeout(o),r(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(([n,r])=>{r&&(e[n]=r)}),e}}s.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"})(s.ErrorCode||(s.ErrorCode={}));class T 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={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()}}s.FiatAccountLink=T,s.default=T,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
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 b="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}},C=(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{}}},T=(t,e,r)=>{const n=C(e,r);return t[n]??t[e]??t.prod},z=(t,e,r)=>{const n=C(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:B=15e3,onLoad:V,onError:J}=t;if(typeof document>"u")return E;const g=`${e}-script-${i}`;if(customElements.get(e)||document.getElementById(g))return E;const H=k(d),x=t.report??(u=>M(s&&z(s,i,d),u,n));let h=!1,L=0,R;const _=()=>{R!==void 0&&clearTimeout(R)},w=(u,f,l)=>{if(h)return;const K=Math.round(performance.now()-L),O={webComponentTag:e,appName:r,env:i,scriptUrl:f,reason:u,triedFallback:l,elapsedMs:K,claims:H};x(O);const y=l?void 0:T(a??{},i,d);if(y&&y!==f){S(y,!0);return}h=!0,_(),document.getElementById(g)?.remove(),J?.(O)},S=(u,f)=>{_(),L=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,_(),V?.()):w("not-defined",u,f))},0)},l.onerror=()=>w("network",u,f),R=setTimeout(()=>w("timeout",u,f),B),document.getElementById(g)?.remove(),document.head.appendChild(l)},v=T(o,i,d);return v?(S(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||b,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||b}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"},$=(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),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=$("fiat-account-link-web","index.js",{legacyAliases:!0,local:"http://localhost:4208"});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"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/fiat-account-link-js",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",