@connect-xyz/withdraw-js 0.52.0 → 0.52.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/dist/index.d.ts +2 -2
- package/dist/index.js +15 -13
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -460,8 +460,8 @@ declare class Withdraw extends BaseJsSdk<WithdrawConfig> {
|
|
|
460
460
|
INVALID_JWT: string;
|
|
461
461
|
};
|
|
462
462
|
protected scriptUrls: {
|
|
463
|
-
sandbox:
|
|
464
|
-
production:
|
|
463
|
+
readonly sandbox: "https://sdk.sandbox.connect.xyz/withdraw-web/index.js";
|
|
464
|
+
readonly production: "https://sdk.connect.xyz/withdraw-web/index.js";
|
|
465
465
|
};
|
|
466
466
|
protected webComponentTag: string;
|
|
467
467
|
/**
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ const T = "production", W = "JWT token is required and must be a string.", z = {
|
|
|
21
21
|
} catch {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
|
-
},
|
|
24
|
+
}, S = (e, t) => M(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, P = (e) => {
|
|
25
25
|
if (!e || typeof e != "string")
|
|
26
26
|
return {};
|
|
27
27
|
const t = e.split(".");
|
|
@@ -39,10 +39,10 @@ const T = "production", W = "JWT token is required and must be a string.", z = {
|
|
|
39
39
|
return {};
|
|
40
40
|
}
|
|
41
41
|
}, C = (e, t, r) => {
|
|
42
|
-
const n =
|
|
42
|
+
const n = S(t, r);
|
|
43
43
|
return e[n] ?? e[t] ?? e.prod;
|
|
44
44
|
}, U = (e, t, r) => {
|
|
45
|
-
const n =
|
|
45
|
+
const n = S(t, r);
|
|
46
46
|
return e[n] ?? e[t];
|
|
47
47
|
}, E = () => {
|
|
48
48
|
}, F = () => {
|
|
@@ -89,7 +89,7 @@ const T = "production", W = "JWT token is required and must be a string.", z = {
|
|
|
89
89
|
} catch {
|
|
90
90
|
}
|
|
91
91
|
}, B = (e) => {
|
|
92
|
-
const { webComponentTag: t, appName: r, appVersion: n, scriptUrls: o, fallbackScriptUrls: a, collectorUrls: c, env: s, jwt: d, timeoutMs:
|
|
92
|
+
const { webComponentTag: t, appName: r, appVersion: n, scriptUrls: o, fallbackScriptUrls: a, collectorUrls: c, env: s, jwt: d, timeoutMs: L = 15e3, onLoad: O, onError: I } = e;
|
|
93
93
|
if (typeof document > "u")
|
|
94
94
|
return E;
|
|
95
95
|
const u = `${t}-script-${s}`;
|
|
@@ -124,9 +124,9 @@ const T = "production", W = "JWT token is required and must be a string.", z = {
|
|
|
124
124
|
const i = document.createElement("script");
|
|
125
125
|
i.id = u, i.src = l, i.type = "module", i.async = !0, i.onload = () => {
|
|
126
126
|
setTimeout(() => {
|
|
127
|
-
m || (customElements.get(t) ? (m = !0, h(),
|
|
127
|
+
m || (customElements.get(t) ? (m = !0, h(), O?.()) : g("not-defined", l, p));
|
|
128
128
|
}, 0);
|
|
129
|
-
}, i.onerror = () => g("network", l, p), f = setTimeout(() => g("timeout", l, p),
|
|
129
|
+
}, i.onerror = () => g("network", l, p), f = setTimeout(() => g("timeout", l, p), L), document.getElementById(u)?.remove(), document.head.appendChild(i);
|
|
130
130
|
}, b = C(o, s, d);
|
|
131
131
|
return b ? (R(b, !1), () => {
|
|
132
132
|
m = !0, h();
|
|
@@ -281,7 +281,11 @@ var N;
|
|
|
281
281
|
(function(e) {
|
|
282
282
|
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";
|
|
283
283
|
})(N || (N = {}));
|
|
284
|
-
|
|
284
|
+
const j = {
|
|
285
|
+
sandbox: "https://sdk.sandbox.connect.xyz/withdraw-web/index.js",
|
|
286
|
+
production: "https://sdk.connect.xyz/withdraw-web/index.js"
|
|
287
|
+
};
|
|
288
|
+
class J extends V {
|
|
285
289
|
errorMessages = {
|
|
286
290
|
ALREADY_RENDERED: "Withdraw widget is already rendered. Call destroy() before rendering again.",
|
|
287
291
|
NOT_RENDERED: "Withdraw widget is not rendered. Call render() first.",
|
|
@@ -290,10 +294,8 @@ class j extends V {
|
|
|
290
294
|
WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded.",
|
|
291
295
|
INVALID_JWT: "JWT token is required and must be a string."
|
|
292
296
|
};
|
|
293
|
-
scriptUrls =
|
|
294
|
-
|
|
295
|
-
production: "https://sdk.connect.xyz/withdraw-web/index.js"
|
|
296
|
-
};
|
|
297
|
+
// protected override scriptUrls = EFFECTIVE_SCRIPT_URLS;
|
|
298
|
+
scriptUrls = j;
|
|
297
299
|
webComponentTag = "connect-withdraw";
|
|
298
300
|
/**
|
|
299
301
|
* Render the Withdraw widget to a container element
|
|
@@ -333,6 +335,6 @@ class j extends V {
|
|
|
333
335
|
}
|
|
334
336
|
export {
|
|
335
337
|
N as ErrorCode,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
+
J as Withdraw,
|
|
339
|
+
J as default
|
|
338
340
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -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.Withdraw={}))})(this,(function(s){"use strict";const u="production",
|
|
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.Withdraw={}))})(this,(function(s){"use strict";const u="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"},v=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,"/"),n=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(n):Buffer.from(n,"base64").toString("utf-8"),d=JSON.parse(o)?.payload?.region;if(typeof d!="string")return null;const i=d.toLowerCase();return i==="us"||i==="eu"?i:null}catch{return null}},R=(e,t)=>v(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,"/"),n=r+"===".slice(0,(4-r.length%4)%4),o=typeof atob<"u"?atob(n):Buffer.from(n,"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{}}},y=(e,t,r)=>{const n=R(t,r);return e[n]??e[t]??e.prod},A=(e,t,r)=>{const n=R(t,r);return e[n]??e[t]},w=()=>{},W=()=>{const e=new Uint8Array(8);return globalThis.crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")},M=(e,t)=>{const r=W(),n=globalThis.__ZH_WEB_SDK_VERSION__,o={};e.claims.participantCode&&(o.participant_code=e.claims.participantCode),e.claims.platformName&&(o.platform_name=e.claims.platformName),e.claims.platformCode&&(o.platform_code=e.claims.platformCode),e.claims.region&&(o.region=e.claims.region),n&&(o.zh_web_sdk_version=n);const c={meta:{app:{name:e.appName,version:t??"unknown",environment:e.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 ${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:c}},z=(e,t,r)=>{if(!e||typeof fetch>"u")return;const{sessionId:n,payload:o}=M(t,r);try{fetch(e,{method:"POST",headers:{"Content-Type":"application/json","x-faro-session-id":n},body:JSON.stringify(o),keepalive:!0}).catch(()=>{})}catch{}},P=e=>{const{webComponentTag:t,appName:r,appVersion:n,scriptUrls:o,fallbackScriptUrls:c,collectorUrls:d,env:i,jwt:l,timeoutMs:j=15e3,onLoad:k,onError:B}=e;if(typeof document>"u")return w;const h=`${t}-script-${i}`;if(customElements.get(t)||document.getElementById(h))return w;const V=D(l),J=e.report??(p=>z(d&&A(d,i,l),p,n));let f=!1,C=0,E;const g=()=>{E!==void 0&&clearTimeout(E)},_=(p,m,a)=>{if(f)return;const $=Math.round(performance.now()-C),L={webComponentTag:t,appName:r,env:i,scriptUrl:m,reason:p,triedFallback:a,elapsedMs:$,claims:V};J(L);const b=a?void 0:y(c??{},i,l);if(b&&b!==m){N(b,!0);return}f=!0,g(),document.getElementById(h)?.remove(),B?.(L)},N=(p,m)=>{g(),C=performance.now();const a=document.createElement("script");a.id=h,a.src=p,a.type="module",a.async=!0,a.onload=()=>{setTimeout(()=>{f||(customElements.get(t)?(f=!0,g(),k?.()):_("not-defined",p,m))},0)},a.onerror=()=>_("network",p,m),E=setTimeout(()=>_("timeout",p,m),j),document.getElementById(h)?.remove(),document.head.appendChild(a)},S=y(o,i,l);return S?(N(S,!1),()=>{f=!0,g()}):w};class U{config;state;scriptLoadingPromise;constructor(t){if(!t.jwt||typeof t.jwt!="string")throw new Error(O);this.config={...t,env:t.env||u,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(([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||u}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: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(t){throw this.scriptLoadingPromise=void 0,t}return this.scriptLoadingPromise}}async waitForWebComponent(t=5e3){if(!this.getWebComponent())return new Promise((r,n)=>{const o=setTimeout(()=>{n(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},t);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),r()}).catch(c=>{clearTimeout(o),n(c)})})}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,n])=>{n&&(t[r]=n)}),t}}s.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"})(s.ErrorCode||(s.ErrorCode={}));const F={sandbox:"https://sdk.sandbox.connect.xyz/withdraw-web/index.js",production:"https://sdk.connect.xyz/withdraw-web/index.js"};class T extends U{errorMessages={ALREADY_RENDERED:"Withdraw widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"Withdraw widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect Withdraw script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded.",INVALID_JWT:"JWT token is required and must be a string."};scriptUrls=F;webComponentTag="connect-withdraw";render(t){return super.render(t)}updateConfig(t){return super.updateConfig(t)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}s.Withdraw=T,s.default=T,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|