@connect-xyz/auth-js 1.71.12 → 1.71.14

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
@@ -185,25 +185,20 @@ declare abstract class BaseJsSdk<Config extends BaseConfig<never> = BaseConfig>
185
185
  throw new Error(this.errorMessages.ALREADY_RENDERED);
186
186
  }
187
187
 
188
- try {
189
- // Ensure script is loaded
190
- await this.ensureScriptLoaded();
188
+ // Ensure script is loaded
189
+ await this.ensureScriptLoaded();
191
190
 
192
- // Create and append the web component
193
- const element = this.createWebComponent();
191
+ // Create and append the web component
192
+ const element = this.createWebComponent();
194
193
 
195
- // Clear the container and append the element
196
- container.innerHTML = '';
197
- container.appendChild(element);
194
+ // Clear the container and append the element
195
+ container.innerHTML = '';
196
+ container.appendChild(element);
198
197
 
199
- // Update state
200
- this.state.container = container;
201
- this.state.element = element;
202
- this.state.initialized = true;
203
- } catch (error) {
204
- console.error('Failed to render widget:', error);
205
- throw error;
206
- }
198
+ // Update state
199
+ this.state.container = container;
200
+ this.state.element = element;
201
+ this.state.initialized = true;
207
202
  }
208
203
 
209
204
  /**
@@ -220,14 +215,12 @@ declare abstract class BaseJsSdk<Config extends BaseConfig<never> = BaseConfig>
220
215
  throw new Error(this.errorMessages.NOT_RENDERED);
221
216
  }
222
217
 
223
- const element = this.state.element as SdkElement<Config>;
218
+ const element = this.state.element;
219
+ const updates = Object.fromEntries(Object.entries(config).filter(([, value]) => value));
224
220
 
225
- Object.entries(config).forEach(([key, value]) => {
226
- if (value) {
227
- this.config[key as keyof Config] = value;
228
- element[key as keyof Config] = value;
229
- }
230
- });
221
+ Object.assign(this.config, updates);
222
+ // The web component reads its config from same-named properties.
223
+ Object.assign(element, updates);
231
224
  }
232
225
 
233
226
  /**
@@ -381,24 +374,15 @@ declare abstract class BaseJsSdk<Config extends BaseConfig<never> = BaseConfig>
381
374
  return;
382
375
  }
383
376
 
384
- try {
385
- await this.loadScript();
386
- await this.waitForWebComponent();
387
- this.state.scriptLoaded = true;
388
- } catch (error) {
389
- console.error('Failed to load Connect script:', error);
390
- throw error;
391
- }
377
+ await this.loadScript();
378
+ await this.waitForWebComponent();
379
+ this.state.scriptLoaded = true;
392
380
  }
393
381
 
394
382
  private createWebComponent() {
395
- const element = document.createElement(this.webComponentTag) as SdkElement<Config>;
396
-
397
- Object.entries(this.config).forEach(([key, value]) => {
398
- if (value) {
399
- element[key as keyof Config] = value;
400
- }
401
- });
383
+ const element = document.createElement(this.webComponentTag);
384
+ // The web component reads its config from same-named properties.
385
+ Object.assign(element, Object.fromEntries(Object.entries(this.config).filter(([, value]) => value)));
402
386
 
403
387
  return element;
404
388
  }
package/dist/index.js CHANGED
@@ -6,39 +6,41 @@ var e = {
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
- }, t = (e) => {
9
+ }, t = (e) => typeof e == "object" && !!e && !Array.isArray(e), n = (e) => {
10
10
  if (!e || typeof e != "string") return null;
11
- let t = e.split(".");
12
- if (t.length < 2) return null;
11
+ let n = e.split(".");
12
+ if (n.length < 2) return null;
13
13
  try {
14
- let e = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = e + "===".slice(0, (4 - e.length % 4) % 4), r = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), i = JSON.parse(r)?.payload?.region;
15
- if (typeof i != "string") return null;
16
- let a = i.toLowerCase();
17
- return a === "us" || a === "eu" ? a : null;
14
+ let e = n[1].replace(/-/g, "+").replace(/_/g, "/"), r = e + "===".slice(0, (4 - e.length % 4) % 4), i = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), a = JSON.parse(i), o = t(a) ? a.payload : void 0, s = t(o) ? o.region : void 0;
15
+ if (typeof s != "string") return null;
16
+ let c = s.toLowerCase();
17
+ return c === "us" || c === "eu" ? c : null;
18
18
  } catch {
19
19
  return null;
20
20
  }
21
- }, n = (e, n) => t(n) === "eu" ? e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e : e, r = (e) => {
21
+ }, r = (e, t) => n(t) === "eu" ? e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e : e, i = (e) => {
22
22
  if (!e || typeof e != "string") return {};
23
- let t = e.split(".");
24
- if (t.length < 2) return {};
23
+ let n = e.split(".");
24
+ if (n.length < 2) return {};
25
25
  try {
26
- let e = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = e + "===".slice(0, (4 - e.length % 4) % 4), r = typeof atob < "u" ? atob(n) : Buffer.from(n, "base64").toString("utf-8"), i = JSON.parse(r), a = i?.payload ?? {}, o = (e) => typeof e == "string" && e.length > 0 ? e : void 0;
26
+ let e = n[1].replace(/-/g, "+").replace(/_/g, "/"), r = e + "===".slice(0, (4 - e.length % 4) % 4), i = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), a = JSON.parse(i);
27
+ if (!t(a)) return {};
28
+ let o = t(a.payload) ? a.payload : {}, s = (e) => typeof e == "string" && e.length > 0 ? e : void 0;
27
29
  return {
28
- participantCode: o(a.participant_code),
29
- platformName: o(a.platform_name),
30
- platformCode: o(i.platform_code),
31
- region: o(a.region)
30
+ participantCode: s(o.participant_code),
31
+ platformName: s(o.platform_name),
32
+ platformCode: s(a.platform_code),
33
+ region: s(o.region)
32
34
  };
33
35
  } catch {
34
36
  return {};
35
37
  }
36
- }, i = (e, t, r) => e[n(t, r)] ?? e[t] ?? e.prod, a = (e, t, r) => e[n(t, r)] ?? e[t], o = () => void 0, s = () => {
38
+ }, a = (e, t, n) => e[r(t, n)] ?? e[t] ?? e.prod, o = (e, t, n) => e[r(t, n)] ?? e[t], s = () => void 0, c = () => {
37
39
  let e = /* @__PURE__ */ new Uint8Array(8);
38
40
  return globalThis.crypto.getRandomValues(e), Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
39
- }, c = (e, t) => {
40
- let n = s(), r = globalThis.__ZH_WEB_SDK_VERSION__, i = {};
41
- return e.claims.participantCode && (i.participant_code = e.claims.participantCode), e.claims.platformName && (i.platform_name = e.claims.platformName), e.claims.platformCode && (i.platform_code = e.claims.platformCode), e.claims.region && (i.region = e.claims.region), r && (i.zh_web_sdk_version = r), {
41
+ }, l = (e, t) => {
42
+ let n = c(), r = Reflect.get(globalThis, "__ZH_WEB_SDK_VERSION__"), i = typeof r == "string" ? r : void 0, a = {};
43
+ return e.claims.participantCode && (a.participant_code = e.claims.participantCode), e.claims.platformName && (a.platform_name = e.claims.platformName), e.claims.platformCode && (a.platform_code = e.claims.platformCode), e.claims.region && (a.region = e.claims.region), i && (a.zh_web_sdk_version = i), {
42
44
  sessionId: n,
43
45
  payload: {
44
46
  meta: {
@@ -49,7 +51,7 @@ var e = {
49
51
  },
50
52
  session: {
51
53
  id: n,
52
- attributes: i
54
+ attributes: a
53
55
  },
54
56
  browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
55
57
  page: typeof window < "u" ? { url: window.location.origin } : void 0
@@ -68,9 +70,9 @@ var e = {
68
70
  }]
69
71
  }
70
72
  };
71
- }, l = (e, t, n) => {
73
+ }, u = (e, t, n) => {
72
74
  if (!e || typeof fetch > "u") return;
73
- let { sessionId: r, payload: i } = c(t, n);
75
+ let { sessionId: r, payload: i } = l(t, n);
74
76
  try {
75
77
  fetch(e, {
76
78
  method: "POST",
@@ -82,14 +84,14 @@ var e = {
82
84
  keepalive: !0
83
85
  }).catch(() => void 0);
84
86
  } catch {}
85
- }, u = (e) => {
86
- let { webComponentTag: t, appName: n, appVersion: s, scriptUrls: c, fallbackScriptUrls: u, collectorUrls: d, env: f, jwt: p, timeoutMs: m = 15e3, onLoad: h, onError: g } = e;
87
- if (typeof document > "u") return o;
87
+ }, d = (e) => {
88
+ let { webComponentTag: t, appName: n, appVersion: r, scriptUrls: c, fallbackScriptUrls: l, collectorUrls: d, env: f, jwt: p, timeoutMs: m = 15e3, onLoad: h, onError: g } = e;
89
+ if (typeof document > "u") return s;
88
90
  let _ = `${t}-script-${f}`;
89
- if (customElements.get(t) || document.getElementById(_)) return o;
90
- let v = r(p), y = e.report ?? ((e) => l(d && a(d, f, p), e, s)), b = !1, x = 0, S, C = () => {
91
+ if (customElements.get(t) || document.getElementById(_)) return s;
92
+ let v = i(p), y = e.report ?? ((e) => u(d && o(d, f, p), e, r)), b = !1, x = 0, S, C = () => {
91
93
  S !== void 0 && clearTimeout(S);
92
- }, w = (e, r, a) => {
94
+ }, w = (e, r, i) => {
93
95
  if (b) return;
94
96
  let o = Math.round(performance.now() - x), s = {
95
97
  webComponentTag: t,
@@ -97,12 +99,12 @@ var e = {
97
99
  env: f,
98
100
  scriptUrl: r,
99
101
  reason: e,
100
- triedFallback: a,
102
+ triedFallback: i,
101
103
  elapsedMs: o,
102
104
  claims: v
103
105
  };
104
106
  y(s);
105
- let c = a ? void 0 : i(u ?? {}, f, p);
107
+ let c = i ? void 0 : a(l ?? {}, f, p);
106
108
  if (c && c !== r) {
107
109
  T(c, !0);
108
110
  return;
@@ -111,16 +113,16 @@ var e = {
111
113
  }, T = (e, n) => {
112
114
  C(), x = performance.now();
113
115
  let r = document.createElement("script");
114
- r.id = _, r.src = e, r.type = "module", r.async = !0, r.onload = () => {
116
+ r.id = _, r.src = e, r.type = "module", r.async = !0, r.addEventListener("load", () => {
115
117
  setTimeout(() => {
116
118
  b || (customElements.get(t) ? (b = !0, C(), h?.()) : w("not-defined", e, n));
117
119
  }, 0);
118
- }, r.onerror = () => w("network", e, n), S = setTimeout(() => w("timeout", e, n), m), document.getElementById(_)?.remove(), document.head.appendChild(r);
119
- }, E = i(c, f, p);
120
+ }), r.addEventListener("error", () => w("network", e, n)), S = setTimeout(() => w("timeout", e, n), m), document.getElementById(_)?.remove(), document.head.appendChild(r);
121
+ }, E = a(c, f, p);
120
122
  return E ? (T(E, !1), () => {
121
123
  b = !0, C();
122
- }) : o;
123
- }, d = 1e4, f = class {
124
+ }) : s;
125
+ }, f = 1e4, p = class {
124
126
  config;
125
127
  state;
126
128
  scriptLoadingPromise;
@@ -140,20 +142,14 @@ var e = {
140
142
  async render(e) {
141
143
  if (!e || !(e instanceof HTMLElement)) throw Error(this.errorMessages.INVALID_CONTAINER);
142
144
  if (this.state.initialized) throw Error(this.errorMessages.ALREADY_RENDERED);
143
- try {
144
- await this.ensureScriptLoaded();
145
- let t = this.createWebComponent();
146
- e.innerHTML = "", e.appendChild(t), this.state.container = e, this.state.element = t, this.state.initialized = !0;
147
- } catch (e) {
148
- throw console.error("Failed to render widget:", e), e;
149
- }
145
+ await this.ensureScriptLoaded();
146
+ let t = this.createWebComponent();
147
+ e.innerHTML = "", e.appendChild(t), this.state.container = e, this.state.element = t, this.state.initialized = !0;
150
148
  }
151
149
  updateConfig(e) {
152
150
  if (!this.state.initialized || !this.state.element) throw Error(this.errorMessages.NOT_RENDERED);
153
- let t = this.state.element;
154
- Object.entries(e).forEach(([e, n]) => {
155
- n && (this.config[e] = n, t[e] = n);
156
- });
151
+ let t = this.state.element, n = Object.fromEntries(Object.entries(e).filter(([, e]) => e));
152
+ Object.assign(this.config, n), Object.assign(t, n);
157
153
  }
158
154
  destroy() {
159
155
  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);
@@ -183,7 +179,7 @@ var e = {
183
179
  if (!(this.getWebComponent() || this.isScriptLoaded())) {
184
180
  if (this.scriptLoadingPromise) return this.scriptLoadingPromise;
185
181
  this.scriptLoadingPromise = new Promise((t, n) => {
186
- u({
182
+ d({
187
183
  webComponentTag: this.webComponentTag,
188
184
  appName: this.webComponentTag,
189
185
  scriptUrls: this.getEffectiveScriptUrls(),
@@ -208,7 +204,7 @@ var e = {
208
204
  if (!this.getWebComponent()) return new Promise((e, t) => {
209
205
  let n = setTimeout(() => {
210
206
  t(/* @__PURE__ */ Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
211
- }, d);
207
+ }, f);
212
208
  customElements.whenDefined(this.webComponentTag).then(() => {
213
209
  clearTimeout(n), e();
214
210
  }).catch((e) => {
@@ -217,19 +213,13 @@ var e = {
217
213
  });
218
214
  }
219
215
  async ensureScriptLoaded() {
220
- if (!this.state.scriptLoaded) try {
221
- await this.loadScript(), await this.waitForWebComponent(), this.state.scriptLoaded = !0;
222
- } catch (e) {
223
- throw console.error("Failed to load Connect script:", e), e;
224
- }
216
+ this.state.scriptLoaded || (await this.loadScript(), await this.waitForWebComponent(), this.state.scriptLoaded = !0);
225
217
  }
226
218
  createWebComponent() {
227
219
  let e = document.createElement(this.webComponentTag);
228
- return Object.entries(this.config).forEach(([t, n]) => {
229
- n && (e[t] = n);
230
- }), e;
220
+ return Object.assign(e, Object.fromEntries(Object.entries(this.config).filter(([, e]) => e))), e;
231
221
  }
232
- }, p = {
222
+ }, m = {
233
223
  local: {
234
224
  BASE_URL: "/",
235
225
  DEV: !1,
@@ -257,22 +247,22 @@ var e = {
257
247
  "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
258
248
  "eu-prod": "https://sdk-cdn.zerohash.eu"
259
249
  };
260
- [...Object.entries(p).filter(([e]) => e !== "local").map(([, e]) => e)], {
250
+ [...Object.entries(m).filter(([e]) => e !== "local").map(([, e]) => e)], {
261
251
  LOADED: "travel_rule_loaded",
262
252
  COMPLETED: "travel_rule_completed"
263
253
  }.LOADED;
264
254
  //#endregion
265
255
  //#region ../../../common/callbacks/dist/shared/models.js
266
- var m;
256
+ var h;
267
257
  (function(e) {
268
258
  e.NETWORK_ERROR = "network_error", e.AUTH_ERROR = "auth_error", e.NOT_FOUND_ERROR = "not_found_error", e.VALIDATION_ERROR = "validation_error", e.SERVER_ERROR = "server_error", e.CLIENT_ERROR = "client_error", e.UNKNOWN_ERROR = "unknown_error";
269
- })(m ||= {});
259
+ })(h ||= {});
270
260
  //#endregion
271
261
  //#region src/lib/auth.ts
272
- var h = {
262
+ var g = {
273
263
  sandbox: "https://sdk.sandbox.connect.xyz/auth-web/index.js",
274
264
  production: "https://sdk.connect.xyz/auth-web/index.js"
275
- }, g = class extends f {
265
+ }, _ = class extends p {
276
266
  errorMessages = {
277
267
  ALREADY_RENDERED: "Auth widget is already rendered. Call destroy() before rendering again.",
278
268
  NOT_RENDERED: "Auth widget is not rendered. Call render() first.",
@@ -280,7 +270,7 @@ var h = {
280
270
  SCRIPT_LOAD_FAILED: "Failed to load the Connect Auth script.",
281
271
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
282
272
  };
283
- scriptUrls = h;
273
+ scriptUrls = g;
284
274
  webComponentTag = "connect-auth";
285
275
  render(e) {
286
276
  return super.render(e);
@@ -299,4 +289,4 @@ var h = {
299
289
  }
300
290
  };
301
291
  //#endregion
302
- export { g as Auth, g as default, m as ErrorCode };
292
+ export { _ as Auth, _ as default, h as ErrorCode };
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Auth={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=`JWT token is required and must be a string.`,n={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`},r=e=>{if(!e||typeof e!=`string`)return null;let t=e.split(`.`);if(t.length<2)return null;try{let e=t[1].replace(/-/g,`+`).replace(/_/g,`/`),n=e+`===`.slice(0,(4-e.length%4)%4),r=typeof atob<`u`?atob(n):Buffer.from(n,`base64`).toString(`utf-8`),i=JSON.parse(r)?.payload?.region;if(typeof i!=`string`)return null;let a=i.toLowerCase();return a===`us`||a===`eu`?a:null}catch{return null}},i=(e,t)=>r(t)===`eu`?e===`cert`?`eu-cert`:e===`prod`?`eu-prod`:e:e,a=e=>{if(!e||typeof e!=`string`)return{};let t=e.split(`.`);if(t.length<2)return{};try{let e=t[1].replace(/-/g,`+`).replace(/_/g,`/`),n=e+`===`.slice(0,(4-e.length%4)%4),r=typeof atob<`u`?atob(n):Buffer.from(n,`base64`).toString(`utf-8`),i=JSON.parse(r),a=i?.payload??{},o=e=>typeof e==`string`&&e.length>0?e:void 0;return{participantCode:o(a.participant_code),platformName:o(a.platform_name),platformCode:o(i.platform_code),region:o(a.region)}}catch{return{}}},o=(e,t,n)=>e[i(t,n)]??e[t]??e.prod,s=(e,t,n)=>e[i(t,n)]??e[t],c=()=>void 0,l=()=>{let e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)},u=(e,t)=>{let n=l(),r=globalThis.__ZH_WEB_SDK_VERSION__,i={};return e.claims.participantCode&&(i.participant_code=e.claims.participantCode),e.claims.platformName&&(i.platform_name=e.claims.platformName),e.claims.platformCode&&(i.platform_code=e.claims.platformCode),e.claims.region&&(i.region=e.claims.region),r&&(i.zh_web_sdk_version=r),{sessionId:n,payload:{meta:{app:{name:e.appName,version:t??`unknown`,environment:e.env},session:{id:n,attributes:i},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 ${e.webComponentTag} from ${e.env} environment.`,level:`error`,timestamp:new Date().toISOString(),context:{web_component:e.webComponentTag,script_url:e.scriptUrl,reason:e.reason,tried_fallback:String(e.triedFallback),elapsed_ms:String(e.elapsedMs)}}]}}},d=(e,t,n)=>{if(!e||typeof fetch>`u`)return;let{sessionId:r,payload:i}=u(t,n);try{fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`,"x-faro-session-id":r},body:JSON.stringify(i),keepalive:!0}).catch(()=>void 0)}catch{}},f=e=>{let{webComponentTag:t,appName:n,appVersion:r,scriptUrls:i,fallbackScriptUrls:l,collectorUrls:u,env:f,jwt:p,timeoutMs:m=15e3,onLoad:h,onError:g}=e;if(typeof document>`u`)return c;let _=`${t}-script-${f}`;if(customElements.get(t)||document.getElementById(_))return c;let v=a(p),y=e.report??(e=>d(u&&s(u,f,p),e,r)),b=!1,x=0,S,C=()=>{S!==void 0&&clearTimeout(S)},w=(e,r,i)=>{if(b)return;let a=Math.round(performance.now()-x),s={webComponentTag:t,appName:n,env:f,scriptUrl:r,reason:e,triedFallback:i,elapsedMs:a,claims:v};y(s);let c=i?void 0:o(l??{},f,p);if(c&&c!==r){T(c,!0);return}b=!0,C(),document.getElementById(_)?.remove(),g?.(s)},T=(e,n)=>{C(),x=performance.now();let r=document.createElement(`script`);r.id=_,r.src=e,r.type=`module`,r.async=!0,r.onload=()=>{setTimeout(()=>{b||(customElements.get(t)?(b=!0,C(),h?.()):w(`not-defined`,e,n))},0)},r.onerror=()=>w(`network`,e,n),S=setTimeout(()=>w(`timeout`,e,n),m),document.getElementById(_)?.remove(),document.head.appendChild(r)},E=o(i,f,p);return E?(T(E,!1),()=>{b=!0,C()}):c},p=1e4,m=class{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!=`string`)throw Error(t);this.config={...e,env:e.env||`production`,theme:e.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(e){if(!e||!(e instanceof HTMLElement))throw Error(this.errorMessages.INVALID_CONTAINER);if(this.state.initialized)throw Error(this.errorMessages.ALREADY_RENDERED);try{await this.ensureScriptLoaded();let t=this.createWebComponent();e.innerHTML=``,e.appendChild(t),this.state.container=e,this.state.element=t,this.state.initialized=!0}catch(e){throw console.error(`Failed to render widget:`,e),e}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw Error(this.errorMessages.NOT_RENDERED);let t=this.state.element;Object.entries(e).forEach(([e,n])=>{n&&(this.config[e]=n,t[e]=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||`production`}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getEffectiveScriptUrls(){return this.scriptUrls}async loadScript(){if(!(this.getWebComponent()||this.isScriptLoaded())){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((e,t)=>{f({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:n,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:e,onError:e=>{t(Error(e.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,t)=>{let n=setTimeout(()=>{t(Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},p);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(n),e()}).catch(e=>{clearTimeout(n),t(e)})})}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(){let e=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([t,n])=>{n&&(e[t]=n)}),e}},h={local:{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ASSETS_SERVICE_URL:`http://localhost:5173/assets`,VITE_CONNECT_API_BASE_URL:`/api/v1`,VITE_CONNECT_ENV:`local`,VITE_CONNECT_SDK_API_BASE_URL:`/sdk/v1`,VITE_DYNAMIC_ENVIRONMENT_ID:`38ce0330-c85e-414a-80b4-6129c548018f`,VITE_FARO_COLLECTOR_URL:`https://grafana-faro-collector.dev.0hash.com/collect`,VITE_FEATURE_SERVER_PROXY_URL:`https://ff-edge.dev.0hash.com/api/frontend`,VITE_INTERNAL_BUILD:`false`,VITE_ONBOARDING_API_BASE_URL:`/onboarding`,VITE_POST_MESSAGE_COMMUNICATION_PLATFORMS:`UW6VWU`,VITE_REDIRECT_HANDLER_URL:`http://localhost:4202/redirect-handler/index.html`,VITE_SCRAPER_EXTENSION_ID_CHROMIUM:`kofibejdfkmnbobmbogndbiimkflcllf`,VITE_TRADE_API_BASE_URL:`/trade`,VITE_UNLEASH_APIKEY:`zerohash-sdk:dev.b0d8aa594e9b94564f885167881bcb9dc69332f935fcb253e656ff34`}.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`};[...Object.entries(h).filter(([e])=>e!==`local`).map(([,e])=>e)],{LOADED:`travel_rule_loaded`,COMPLETED:`travel_rule_completed`}.LOADED;var g;(function(e){e.NETWORK_ERROR=`network_error`,e.AUTH_ERROR=`auth_error`,e.NOT_FOUND_ERROR=`not_found_error`,e.VALIDATION_ERROR=`validation_error`,e.SERVER_ERROR=`server_error`,e.CLIENT_ERROR=`client_error`,e.UNKNOWN_ERROR=`unknown_error`})(g||={});var _={sandbox:`https://sdk.sandbox.connect.xyz/auth-web/index.js`,production:`https://sdk.connect.xyz/auth-web/index.js`},v=class extends m{errorMessages={ALREADY_RENDERED:`Auth widget is already rendered. Call destroy() before rendering again.`,NOT_RENDERED:`Auth widget is not rendered. Call render() first.`,INVALID_CONTAINER:`Invalid container element provided.`,SCRIPT_LOAD_FAILED:`Failed to load the Connect Auth script.`,WEB_COMPONENT_NOT_DEFINED:`Web component is not defined. Script may not be loaded.`};scriptUrls=_;webComponentTag=`connect-auth`;render(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}};e.Auth=v,e.default=v,Object.defineProperty(e,"ErrorCode",{enumerable:!0,get:function(){return g}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Auth={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=`JWT token is required and must be a string.`,n={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`},r=e=>typeof e==`object`&&!!e&&!Array.isArray(e),i=e=>{if(!e||typeof e!=`string`)return null;let t=e.split(`.`);if(t.length<2)return null;try{let e=t[1].replace(/-/g,`+`).replace(/_/g,`/`),n=e+`===`.slice(0,(4-e.length%4)%4),i=typeof atob<`u`?atob(n):Buffer.from(n,`base64`).toString(`utf-8`),a=JSON.parse(i),o=r(a)?a.payload:void 0,s=r(o)?o.region:void 0;if(typeof s!=`string`)return null;let c=s.toLowerCase();return c===`us`||c===`eu`?c:null}catch{return null}},a=(e,t)=>i(t)===`eu`?e===`cert`?`eu-cert`:e===`prod`?`eu-prod`:e:e,o=e=>{if(!e||typeof e!=`string`)return{};let t=e.split(`.`);if(t.length<2)return{};try{let e=t[1].replace(/-/g,`+`).replace(/_/g,`/`),n=e+`===`.slice(0,(4-e.length%4)%4),i=typeof atob<`u`?atob(n):Buffer.from(n,`base64`).toString(`utf-8`),a=JSON.parse(i);if(!r(a))return{};let o=r(a.payload)?a.payload:{},s=e=>typeof e==`string`&&e.length>0?e:void 0;return{participantCode:s(o.participant_code),platformName:s(o.platform_name),platformCode:s(a.platform_code),region:s(o.region)}}catch{return{}}},s=(e,t,n)=>e[a(t,n)]??e[t]??e.prod,c=(e,t,n)=>e[a(t,n)]??e[t],l=()=>void 0,u=()=>{let e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)},d=(e,t)=>{let n=u(),r=Reflect.get(globalThis,`__ZH_WEB_SDK_VERSION__`),i=typeof r==`string`?r:void 0,a={};return e.claims.participantCode&&(a.participant_code=e.claims.participantCode),e.claims.platformName&&(a.platform_name=e.claims.platformName),e.claims.platformCode&&(a.platform_code=e.claims.platformCode),e.claims.region&&(a.region=e.claims.region),i&&(a.zh_web_sdk_version=i),{sessionId:n,payload:{meta:{app:{name:e.appName,version:t??`unknown`,environment:e.env},session:{id:n,attributes:a},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 ${e.webComponentTag} from ${e.env} environment.`,level:`error`,timestamp:new Date().toISOString(),context:{web_component:e.webComponentTag,script_url:e.scriptUrl,reason:e.reason,tried_fallback:String(e.triedFallback),elapsed_ms:String(e.elapsedMs)}}]}}},f=(e,t,n)=>{if(!e||typeof fetch>`u`)return;let{sessionId:r,payload:i}=d(t,n);try{fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`,"x-faro-session-id":r},body:JSON.stringify(i),keepalive:!0}).catch(()=>void 0)}catch{}},p=e=>{let{webComponentTag:t,appName:n,appVersion:r,scriptUrls:i,fallbackScriptUrls:a,collectorUrls:u,env:d,jwt:p,timeoutMs:m=15e3,onLoad:h,onError:g}=e;if(typeof document>`u`)return l;let _=`${t}-script-${d}`;if(customElements.get(t)||document.getElementById(_))return l;let v=o(p),y=e.report??(e=>f(u&&c(u,d,p),e,r)),b=!1,x=0,S,C=()=>{S!==void 0&&clearTimeout(S)},w=(e,r,i)=>{if(b)return;let o=Math.round(performance.now()-x),c={webComponentTag:t,appName:n,env:d,scriptUrl:r,reason:e,triedFallback:i,elapsedMs:o,claims:v};y(c);let l=i?void 0:s(a??{},d,p);if(l&&l!==r){T(l,!0);return}b=!0,C(),document.getElementById(_)?.remove(),g?.(c)},T=(e,n)=>{C(),x=performance.now();let r=document.createElement(`script`);r.id=_,r.src=e,r.type=`module`,r.async=!0,r.addEventListener(`load`,()=>{setTimeout(()=>{b||(customElements.get(t)?(b=!0,C(),h?.()):w(`not-defined`,e,n))},0)}),r.addEventListener(`error`,()=>w(`network`,e,n)),S=setTimeout(()=>w(`timeout`,e,n),m),document.getElementById(_)?.remove(),document.head.appendChild(r)},E=s(i,d,p);return E?(T(E,!1),()=>{b=!0,C()}):l},m=1e4,h=class{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!=`string`)throw Error(t);this.config={...e,env:e.env||`production`,theme:e.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(e){if(!e||!(e instanceof HTMLElement))throw Error(this.errorMessages.INVALID_CONTAINER);if(this.state.initialized)throw Error(this.errorMessages.ALREADY_RENDERED);await this.ensureScriptLoaded();let t=this.createWebComponent();e.innerHTML=``,e.appendChild(t),this.state.container=e,this.state.element=t,this.state.initialized=!0}updateConfig(e){if(!this.state.initialized||!this.state.element)throw Error(this.errorMessages.NOT_RENDERED);let t=this.state.element,n=Object.fromEntries(Object.entries(e).filter(([,e])=>e));Object.assign(this.config,n),Object.assign(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||`production`}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getEffectiveScriptUrls(){return this.scriptUrls}async loadScript(){if(!(this.getWebComponent()||this.isScriptLoaded())){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((e,t)=>{p({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:n,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:e,onError:e=>{t(Error(e.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,t)=>{let n=setTimeout(()=>{t(Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},m);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(n),e()}).catch(e=>{clearTimeout(n),t(e)})})}async ensureScriptLoaded(){this.state.scriptLoaded||(await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0)}createWebComponent(){let e=document.createElement(this.webComponentTag);return Object.assign(e,Object.fromEntries(Object.entries(this.config).filter(([,e])=>e))),e}},g={local:{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ASSETS_SERVICE_URL:`http://localhost:5173/assets`,VITE_CONNECT_API_BASE_URL:`/api/v1`,VITE_CONNECT_ENV:`local`,VITE_CONNECT_SDK_API_BASE_URL:`/sdk/v1`,VITE_DYNAMIC_ENVIRONMENT_ID:`38ce0330-c85e-414a-80b4-6129c548018f`,VITE_FARO_COLLECTOR_URL:`https://grafana-faro-collector.dev.0hash.com/collect`,VITE_FEATURE_SERVER_PROXY_URL:`https://ff-edge.dev.0hash.com/api/frontend`,VITE_INTERNAL_BUILD:`false`,VITE_ONBOARDING_API_BASE_URL:`/onboarding`,VITE_POST_MESSAGE_COMMUNICATION_PLATFORMS:`UW6VWU`,VITE_REDIRECT_HANDLER_URL:`http://localhost:4202/redirect-handler/index.html`,VITE_SCRAPER_EXTENSION_ID_CHROMIUM:`kofibejdfkmnbobmbogndbiimkflcllf`,VITE_TRADE_API_BASE_URL:`/trade`,VITE_UNLEASH_APIKEY:`zerohash-sdk:dev.b0d8aa594e9b94564f885167881bcb9dc69332f935fcb253e656ff34`}.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`};[...Object.entries(g).filter(([e])=>e!==`local`).map(([,e])=>e)],{LOADED:`travel_rule_loaded`,COMPLETED:`travel_rule_completed`}.LOADED;var _;(function(e){e.NETWORK_ERROR=`network_error`,e.AUTH_ERROR=`auth_error`,e.NOT_FOUND_ERROR=`not_found_error`,e.VALIDATION_ERROR=`validation_error`,e.SERVER_ERROR=`server_error`,e.CLIENT_ERROR=`client_error`,e.UNKNOWN_ERROR=`unknown_error`})(_||={});var v={sandbox:`https://sdk.sandbox.connect.xyz/auth-web/index.js`,production:`https://sdk.connect.xyz/auth-web/index.js`},y=class extends h{errorMessages={ALREADY_RENDERED:`Auth widget is already rendered. Call destroy() before rendering again.`,NOT_RENDERED:`Auth widget is not rendered. Call render() first.`,INVALID_CONTAINER:`Invalid container element provided.`,SCRIPT_LOAD_FAILED:`Failed to load the Connect Auth script.`,WEB_COMPONENT_NOT_DEFINED:`Web component is not defined. Script may not be loaded.`};scriptUrls=v;webComponentTag=`connect-auth`;render(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}};e.Auth=y,e.default=y,Object.defineProperty(e,"ErrorCode",{enumerable:!0,get:function(){return _}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connect-xyz/auth-js",
3
- "version": "1.71.12",
3
+ "version": "1.71.14",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",