@zerohash-sdk/crypto-buy-js 1.16.1 → 1.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,8 +7,6 @@
7
7
  * @packageDocumentation
8
8
  */
9
9
 
10
- import { CryptoBuyFilters } from '@zerohash-sdk/crypto-buy';
11
-
12
10
  /**
13
11
  * Generic app event structure
14
12
  * @template TType - Event type string
@@ -411,7 +409,12 @@ declare type CryptoBuyEvent = AppEvent<CryptoBuyEventType>;
411
409
 
412
410
  declare type CryptoBuyEventType = string;
413
411
 
414
- export { CryptoBuyFilters }
412
+ export declare type CryptoBuyFilters = {
413
+ getAssets?: {
414
+ stablecoin?: boolean;
415
+ deposit_address_creation?: string;
416
+ };
417
+ };
415
418
 
416
419
  /**
417
420
  * Deposit completed payload — emitted by SDKs that drive a deposit through
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ const T = "production", M = "JWT token is required and must be a string.", W = {
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
- }, B = (e) => {
9
+ }, k = (e) => {
10
10
  if (!e || typeof e != "string")
11
11
  return null;
12
12
  const t = e.split(".");
@@ -21,7 +21,7 @@ const T = "production", M = "JWT token is required and must be a string.", W = {
21
21
  } catch {
22
22
  return null;
23
23
  }
24
- }, O = (e, t) => B(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, P = (e) => {
24
+ }, O = (e, t) => k(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, B = (e) => {
25
25
  if (!e || typeof e != "string")
26
26
  return {};
27
27
  const t = e.split(".");
@@ -41,15 +41,15 @@ const T = "production", M = "JWT token is required and must be a string.", W = {
41
41
  }, N = (e, t, r) => {
42
42
  const o = O(t, r);
43
43
  return e[o] ?? e[t] ?? e.prod;
44
- }, U = (e, t, r) => {
44
+ }, P = (e, t, r) => {
45
45
  const o = O(t, r);
46
46
  return e[o] ?? e[t];
47
47
  }, y = () => {
48
- }, k = () => {
48
+ }, U = () => {
49
49
  const e = new Uint8Array(8);
50
50
  return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
51
51
  }, F = (e, t) => {
52
- const r = k(), o = globalThis.__ZH_WEB_SDK_VERSION__, n = {};
52
+ const r = U(), o = globalThis.__ZH_WEB_SDK_VERSION__, n = {};
53
53
  e.claims.participantCode && (n.participant_code = e.claims.participantCode), e.claims.platformName && (n.platform_name = e.claims.platformName), e.claims.platformCode && (n.platform_code = e.claims.platformCode), e.claims.region && (n.region = e.claims.region), o && (n.zh_web_sdk_version = o);
54
54
  const a = {
55
55
  meta: {
@@ -95,14 +95,14 @@ const T = "production", M = "JWT token is required and must be a string.", W = {
95
95
  const h = `${t}-script-${s}`;
96
96
  if (customElements.get(t) || document.getElementById(h))
97
97
  return y;
98
- const A = P(c), D = e.report ?? ((l) => $(i && U(i, s, c), l, o));
98
+ const A = B(c), D = e.report ?? ((l) => $(i && P(i, s, c), l, o));
99
99
  let m = !1, w = 0, g;
100
100
  const f = () => {
101
101
  g !== void 0 && clearTimeout(g);
102
102
  }, E = (l, u, d) => {
103
103
  if (m)
104
104
  return;
105
- const z = Math.round(performance.now() - w), C = {
105
+ const z = Math.round(performance.now() - w), b = {
106
106
  webComponentTag: t,
107
107
  appName: r,
108
108
  env: s,
@@ -112,14 +112,14 @@ const T = "production", M = "JWT token is required and must be a string.", W = {
112
112
  elapsedMs: z,
113
113
  claims: A
114
114
  };
115
- D(C);
115
+ D(b);
116
116
  const _ = d ? void 0 : N(a ?? {}, s, c);
117
117
  if (_ && _ !== u) {
118
- R(_, !0);
118
+ C(_, !0);
119
119
  return;
120
120
  }
121
- m = !0, f(), document.getElementById(h)?.remove(), I?.(C);
122
- }, R = (l, u) => {
121
+ m = !0, f(), document.getElementById(h)?.remove(), I?.(b);
122
+ }, C = (l, u) => {
123
123
  f(), w = performance.now();
124
124
  const d = document.createElement("script");
125
125
  d.id = h, d.src = l, d.type = "module", d.async = !0, d.onload = () => {
@@ -127,8 +127,8 @@ const T = "production", M = "JWT token is required and must be a string.", W = {
127
127
  m || (customElements.get(t) ? (m = !0, f(), v?.()) : E("not-defined", l, u));
128
128
  }, 0);
129
129
  }, d.onerror = () => E("network", l, u), g = setTimeout(() => E("timeout", l, u), L), document.getElementById(h)?.remove(), document.head.appendChild(d);
130
- }, b = N(n, s, c);
131
- return b ? (R(b, !1), () => {
130
+ }, R = N(n, s, c);
131
+ return R ? (C(R, !1), () => {
132
132
  m = !0, f();
133
133
  }) : y;
134
134
  };
@@ -280,10 +280,11 @@ const p = {
280
280
  prod: "https://sdk-cdn.zerohash.com",
281
281
  "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
282
282
  "eu-prod": "https://sdk-cdn.zerohash.eu"
283
- }, J = (e, t, r = {}) => {
283
+ }, J = "https://sdk-cdn.gating.0hash.com", x = (e, t, r = {}) => {
284
284
  const { eu: o = !1, legacyAliases: n = !1, local: a = p.local } = r, i = (c) => `${c}/${e}/${t}`, s = {
285
285
  local: i(a),
286
286
  dev: i(p.dev),
287
+ gating: i(J),
287
288
  cert: i(p.cert),
288
289
  prod: i(p.prod)
289
290
  };
@@ -293,7 +294,7 @@ var S;
293
294
  (function(e) {
294
295
  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";
295
296
  })(S || (S = {}));
296
- class x extends j {
297
+ class H extends j {
297
298
  errorMessages = {
298
299
  ALREADY_RENDERED: "CryptoBuy widget is already rendered. Call destroy() before rendering again.",
299
300
  NOT_RENDERED: "CryptoBuy widget is not rendered. Call render() first.",
@@ -301,7 +302,7 @@ class x extends j {
301
302
  SCRIPT_LOAD_FAILED: "Failed to load the Connect CryptoBuy script.",
302
303
  WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
303
304
  };
304
- scriptUrls = J("crypto-buy-web", "index.js", { legacyAliases: !0 });
305
+ scriptUrls = x("crypto-buy-web", "index.js", { legacyAliases: !0 });
305
306
  webComponentTag = "zerohash-crypto-buy";
306
307
  /**
307
308
  * Render the CryptoBuy widget to a container element
@@ -340,7 +341,7 @@ class x extends j {
340
341
  }
341
342
  }
342
343
  export {
343
- x as CryptoBuy,
344
+ H as CryptoBuy,
344
345
  S as ErrorCode,
345
- x as default
346
+ H as default
346
347
  };
@@ -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.CryptoBuy={}))})(this,(function(c){"use strict";const m="production",v="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=e=>{if(!e||typeof e!="string")return null;const t=e.split(".");if(t.length<2)return null;try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),o=r+"===".slice(0,(4-r.length%4)%4),n=typeof atob<"u"?atob(o):Buffer.from(o,"base64").toString("utf-8"),i=JSON.parse(n)?.payload?.region;if(typeof i!="string")return null;const s=i.toLowerCase();return s==="us"||s==="eu"?s:null}catch{return null}},b=(e,t)=>A(t)!=="eu"?e:e==="cert"?"eu-cert":e==="prod"?"eu-prod":e,D=e=>{if(!e||typeof e!="string")return{};const t=e.split(".");if(t.length<2)return{};try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),o=r+"===".slice(0,(4-r.length%4)%4),n=typeof atob<"u"?atob(o):Buffer.from(o,"base64").toString("utf-8"),a=JSON.parse(n),i=a?.payload??{},s=d=>typeof d=="string"&&d.length>0?d:void 0;return{participantCode:s(i.participant_code),platformName:s(i.platform_name),platformCode:s(a.platform_code),region:s(i.region)}}catch{return{}}},R=(e,t,r)=>{const o=b(t,r);return e[o]??e[t]??e.prod},z=(e,t,r)=>{const o=b(t,r);return e[o]??e[t]},y=()=>{},M=()=>{const e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")},B=(e,t)=>{const r=M(),o=globalThis.__ZH_WEB_SDK_VERSION__,n={};e.claims.participantCode&&(n.participant_code=e.claims.participantCode),e.claims.platformName&&(n.platform_name=e.claims.platformName),e.claims.platformCode&&(n.platform_code=e.claims.platformCode),e.claims.region&&(n.region=e.claims.region),o&&(n.zh_web_sdk_version=o);const a={meta:{app:{name:e.appName,version:t??"unknown",environment:e.env},session:{id:r,attributes:n},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)}}]};return{sessionId:r,payload:a}},W=(e,t,r)=>{if(!e||typeof fetch>"u")return;const{sessionId:o,payload:n}=B(t,r);try{fetch(e,{method:"POST",headers:{"Content-Type":"application/json","x-faro-session-id":o},body:JSON.stringify(n),keepalive:!0}).catch(()=>{})}catch{}},P=e=>{const{webComponentTag:t,appName:r,appVersion:o,scriptUrls:n,fallbackScriptUrls:a,collectorUrls:i,env:s,jwt:d,timeoutMs:F=15e3,onLoad:$,onError:j}=e;if(typeof document>"u")return y;const g=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(g))return y;const V=D(d),J=e.report??(u=>W(i&&z(i,s,d),u,o));let f=!1,N=0,_;const E=()=>{_!==void 0&&clearTimeout(_)},w=(u,h,l)=>{if(f)return;const H=Math.round(performance.now()-N),L={webComponentTag:t,appName:r,env:s,scriptUrl:h,reason:u,triedFallback:l,elapsedMs:H,claims:V};J(L);const C=l?void 0:R(a??{},s,d);if(C&&C!==h){S(C,!0);return}f=!0,E(),document.getElementById(g)?.remove(),j?.(L)},S=(u,h)=>{E(),N=performance.now();const l=document.createElement("script");l.id=g,l.src=u,l.type="module",l.async=!0,l.onload=()=>{setTimeout(()=>{f||(customElements.get(t)?(f=!0,E(),$?.()):w("not-defined",u,h))},0)},l.onerror=()=>w("network",u,h),_=setTimeout(()=>w("timeout",u,h),F),document.getElementById(g)?.remove(),document.head.appendChild(l)},O=R(n,s,d);return O?(S(O,!1),()=>{f=!0,E()}):y};class U{config;state;scriptLoadingPromise;constructor(t){if(!t.jwt||typeof t.jwt!="string")throw new Error(v);this.config={...t,env:t.env||m,theme:t.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(t){if(!t||!(t 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();t.innerHTML="",t.appendChild(r),this.state.container=t,this.state.element=r,this.state.initialized=!0}catch(r){throw console.error("Failed to render widget:",r),r}}updateConfig(t){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const r=this.state.element;Object.entries(t).forEach(([o,n])=>{n&&(this.config[o]=n,r[o]=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||m}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((t,r)=>{P({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:I,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:t,onError:o=>{r(new Error(o.reason==="not-defined"?this.errorMessages.WEB_COMPONENT_NOT_DEFINED:`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))}})});try{await this.scriptLoadingPromise}catch(t){throw this.scriptLoadingPromise=void 0,t}return this.scriptLoadingPromise}}async waitForWebComponent(t=5e3){if(!this.getWebComponent())return new Promise((r,o)=>{const n=setTimeout(()=>{o(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},t);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(n),r()}).catch(a=>{clearTimeout(n),o(a)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(t){throw console.error("Failed to load Connect script:",t),t}}createWebComponent(){const t=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([r,o])=>{o&&(t[r]=o)}),t}}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"},k=(e,t,r={})=>{const{eu:o=!1,legacyAliases:n=!1,local:a=p.local}=r,i=d=>`${d}/${e}/${t}`,s={local:i(a),dev:i(p.dev),cert:i(p.cert),prod:i(p.prod)};return n&&(s.sandbox=i(p.cert),s.production=i(p.prod)),o&&(s["eu-cert"]=i(p["eu-cert"]),s["eu-prod"]=i(p["eu-prod"])),s};c.ErrorCode=void 0,(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"})(c.ErrorCode||(c.ErrorCode={}));class T extends U{errorMessages={ALREADY_RENDERED:"CryptoBuy widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"CryptoBuy widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect CryptoBuy script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls=k("crypto-buy-web","index.js",{legacyAliases:!0});webComponentTag="zerohash-crypto-buy";render(t){return super.render(t)}updateConfig(t){return super.updateConfig(t)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}c.CryptoBuy=T,c.default=T,Object.defineProperties(c,{__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.CryptoBuy={}))})(this,(function(c){"use strict";const m="production",v="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=e=>{if(!e||typeof e!="string")return null;const t=e.split(".");if(t.length<2)return null;try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),o=r+"===".slice(0,(4-r.length%4)%4),n=typeof atob<"u"?atob(o):Buffer.from(o,"base64").toString("utf-8"),i=JSON.parse(n)?.payload?.region;if(typeof i!="string")return null;const s=i.toLowerCase();return s==="us"||s==="eu"?s:null}catch{return null}},b=(e,t)=>A(t)!=="eu"?e:e==="cert"?"eu-cert":e==="prod"?"eu-prod":e,D=e=>{if(!e||typeof e!="string")return{};const t=e.split(".");if(t.length<2)return{};try{const r=t[1].replace(/-/g,"+").replace(/_/g,"/"),o=r+"===".slice(0,(4-r.length%4)%4),n=typeof atob<"u"?atob(o):Buffer.from(o,"base64").toString("utf-8"),a=JSON.parse(n),i=a?.payload??{},s=d=>typeof d=="string"&&d.length>0?d:void 0;return{participantCode:s(i.participant_code),platformName:s(i.platform_name),platformCode:s(a.platform_code),region:s(i.region)}}catch{return{}}},R=(e,t,r)=>{const o=b(t,r);return e[o]??e[t]??e.prod},z=(e,t,r)=>{const o=b(t,r);return e[o]??e[t]},y=()=>{},M=()=>{const e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")},B=(e,t)=>{const r=M(),o=globalThis.__ZH_WEB_SDK_VERSION__,n={};e.claims.participantCode&&(n.participant_code=e.claims.participantCode),e.claims.platformName&&(n.platform_name=e.claims.platformName),e.claims.platformCode&&(n.platform_code=e.claims.platformCode),e.claims.region&&(n.region=e.claims.region),o&&(n.zh_web_sdk_version=o);const a={meta:{app:{name:e.appName,version:t??"unknown",environment:e.env},session:{id:r,attributes:n},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)}}]};return{sessionId:r,payload:a}},W=(e,t,r)=>{if(!e||typeof fetch>"u")return;const{sessionId:o,payload:n}=B(t,r);try{fetch(e,{method:"POST",headers:{"Content-Type":"application/json","x-faro-session-id":o},body:JSON.stringify(n),keepalive:!0}).catch(()=>{})}catch{}},P=e=>{const{webComponentTag:t,appName:r,appVersion:o,scriptUrls:n,fallbackScriptUrls:a,collectorUrls:i,env:s,jwt:d,timeoutMs:$=15e3,onLoad:j,onError:V}=e;if(typeof document>"u")return y;const g=`${t}-script-${s}`;if(customElements.get(t)||document.getElementById(g))return y;const J=D(d),H=e.report??(u=>W(i&&z(i,s,d),u,o));let f=!1,N=0,_;const E=()=>{_!==void 0&&clearTimeout(_)},w=(u,h,l)=>{if(f)return;const x=Math.round(performance.now()-N),L={webComponentTag:t,appName:r,env:s,scriptUrl:h,reason:u,triedFallback:l,elapsedMs:x,claims:J};H(L);const C=l?void 0:R(a??{},s,d);if(C&&C!==h){S(C,!0);return}f=!0,E(),document.getElementById(g)?.remove(),V?.(L)},S=(u,h)=>{E(),N=performance.now();const l=document.createElement("script");l.id=g,l.src=u,l.type="module",l.async=!0,l.onload=()=>{setTimeout(()=>{f||(customElements.get(t)?(f=!0,E(),j?.()):w("not-defined",u,h))},0)},l.onerror=()=>w("network",u,h),_=setTimeout(()=>w("timeout",u,h),$),document.getElementById(g)?.remove(),document.head.appendChild(l)},O=R(n,s,d);return O?(S(O,!1),()=>{f=!0,E()}):y};class k{config;state;scriptLoadingPromise;constructor(t){if(!t.jwt||typeof t.jwt!="string")throw new Error(v);this.config={...t,env:t.env||m,theme:t.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(t){if(!t||!(t 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();t.innerHTML="",t.appendChild(r),this.state.container=t,this.state.element=r,this.state.initialized=!0}catch(r){throw console.error("Failed to render widget:",r),r}}updateConfig(t){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const r=this.state.element;Object.entries(t).forEach(([o,n])=>{n&&(this.config[o]=n,r[o]=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||m}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((t,r)=>{P({webComponentTag:this.webComponentTag,appName:this.webComponentTag,scriptUrls:this.getEffectiveScriptUrls(),collectorUrls:I,env:this.getEnvironment(),jwt:this.config.jwt,onLoad:t,onError:o=>{r(new Error(o.reason==="not-defined"?this.errorMessages.WEB_COMPONENT_NOT_DEFINED:`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))}})});try{await this.scriptLoadingPromise}catch(t){throw this.scriptLoadingPromise=void 0,t}return this.scriptLoadingPromise}}async waitForWebComponent(t=5e3){if(!this.getWebComponent())return new Promise((r,o)=>{const n=setTimeout(()=>{o(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},t);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(n),r()}).catch(a=>{clearTimeout(n),o(a)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(t){throw console.error("Failed to load Connect script:",t),t}}createWebComponent(){const t=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([r,o])=>{o&&(t[r]=o)}),t}}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"},U="https://sdk-cdn.gating.0hash.com",F=(e,t,r={})=>{const{eu:o=!1,legacyAliases:n=!1,local:a=p.local}=r,i=d=>`${d}/${e}/${t}`,s={local:i(a),dev:i(p.dev),gating:i(U),cert:i(p.cert),prod:i(p.prod)};return n&&(s.sandbox=i(p.cert),s.production=i(p.prod)),o&&(s["eu-cert"]=i(p["eu-cert"]),s["eu-prod"]=i(p["eu-prod"])),s};c.ErrorCode=void 0,(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"})(c.ErrorCode||(c.ErrorCode={}));class T extends k{errorMessages={ALREADY_RENDERED:"CryptoBuy widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"CryptoBuy widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect CryptoBuy script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls=F("crypto-buy-web","index.js",{legacyAliases:!0});webComponentTag="zerohash-crypto-buy";render(t){return super.render(t)}updateConfig(t){return super.updateConfig(t)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}c.CryptoBuy=T,c.default=T,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/crypto-buy-js",
3
- "version": "1.16.1",
3
+ "version": "1.17.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",