@wf-financing/ui-sdk 3.4.3 → 3.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +4 -4
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v=Object.defineProperty,m=(r,e,t)=>e in r?v(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,o=(r,e,t)=>m(r,typeof e!="symbol"?e+"":e,t);const p="https://api.wayflyer.com",I="https://sandbox-api.wayflyer.com",k=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},b={"Content-Type":"application/json"},u={event:"/
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v=Object.defineProperty,m=(r,e,t)=>e in r?v(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,o=(r,e,t)=>m(r,typeof e!="symbol"?e+"":e,t);const p="https://api.wayflyer.com/financing",I="https://sandbox-api.wayflyer.com/financing",k=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},b={"Content-Type":"application/json"},u={event:"/v1/company/event/",error:"/v1/error/"},S="wf_session_v1",E=1800*1e3,U=1440*60*1e3;class P{getSessionId(){const e=Date.now();let t=this.loadSession();return(!t||this.isSessionExpired(t,e))&&(t=this.mintNewSession(e)),t.lastActivity=e,this.saveSession(t),t.sessionId}isSessionExpired(e,t){const i=t-e.lastActivity>E,n=t-e.createdAt>U;return i||n}mintNewSession(e){return{sessionId:crypto.randomUUID(),createdAt:e,lastActivity:e}}loadSession(){try{const e=sessionStorage.getItem(S);return e?JSON.parse(e):null}catch{return null}}saveSession(e){try{sessionStorage.setItem(S,JSON.stringify(e))}catch{console.warn("Failed to save session context")}}}const h=class a{constructor(e,t,i,n){o(this,"baseUrl",null),o(this,"sessionManager"),o(this,"headers"),o(this,"entryPointVersion"),o(this,"sdkVersion"),this.companyToken=e,this.baseUrl=n?I:p,this.sessionManager=new P,this.entryPointVersion=t,this.sdkVersion=i,this.headers={...b,...i?{"X-SDK-Version":i}:{}}}get requestHeaders(){const e=a.getInstance(),t=e.sessionManager.getSessionId();return{Authorization:`Bearer ${e.companyToken}`,"X-Session-ID":t,...e.headers}}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,t,i,n){a.getGlobalInstance()&&console.warn("Logger re-initialized");const s=new a(e,t,i,n==null?void 0:n.isSandbox);a.setGlobalInstance(s)}static getMandatoryProperties(){const e=a.getInstance(),{sdkVersion:t,companyToken:i,entryPointVersion:n}=e,s=k(i),[d,y]=(s==null?void 0:s.sub.split("|"))||[],f=s==null?void 0:s.user_id;return{partner_id:d,company_id:y,user_id:f,entry_point_version:n,...t?{sdk_version:t}:{}}}static getInstance(){const e=a.getGlobalInstance();if(!e)throw new Error("Logger not initialized. Call initialize() first.");return e}static async logEvent(e,t){if(this.isDevEnvironment)return;const i=a.getInstance();try{const n={...a.getMandatoryProperties(),...t},s=await fetch(i.baseUrl+u.event,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:n})});if(s.status===200)return await s.json()}catch(n){console.error("Failed to log event",n)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const i=a.getInstance();try{const n={...a.getMandatoryProperties(),...t},s=await fetch(i.baseUrl+u.error,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:n})});if(s.status===200)return await s.json()}catch(n){console.warn("Failed to log error",n)}}};o(h,"isDevEnvironment",!1);let l=h;const g=(r,e)=>{if(!window.WayflyerUiSdk)throw new Error("SDK code was fetched successfully, but WayflyerUiSdk is unavailable on window");const t=window.WayflyerUiSdk;return new t(r,e)},D="wayflyer-ui-package",_="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4",w="3.4.4",A="UI_SDK_READY_EVENT",z=async(r,e)=>window.WayflyerUiSdk?g(r,e):new Promise((i,n)=>{const s=document.createElement("script");s.src=_,s.type="module",s.id=D,s.async=!0,s.onerror=()=>{n(new Error(`Failed to load UI SDK script from ${s.src}`))};const d=()=>{const y=g(r,e);i(y)};window.addEventListener(A,d,{once:!0}),document.head.appendChild(s)}),N="ui";let c=null;class O{static async loadSdk(e,t){var i;c??(c=this.getLoadSdkPromise(e,t));try{const n=await c;return((i=n==null?void 0:n.options)==null?void 0:i.language)!==(t==null?void 0:t.language)||n.companyToken!==e?(c=this.getLoadSdkPromise(e,t),await c):n}catch(n){throw c=null,n}}static async getLoadSdkPromise(e,t){const i=Date.now();try{const n=await z(e,t),s=Date.now()-i;return l.initialize(e,w,n.sdkVersion,t),l.logEvent("ui_sdk_initialized",{entry_point_type:N,sdk_initialization_latency:s}),n}catch(n){const s=n instanceof Error?n:new Error(String(n));throw l.initialize(e,w,void 0,t),l.logError(s.message),n}}}exports.WayflyerUiSdk=O;
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var p = Object.defineProperty, v = (r, e, t) => e in r ? p(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, o = (r, e, t) => v(r, typeof e != "symbol" ? e + "" : e, t);
|
|
2
|
-
const m = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", k = (r) => {
|
|
2
|
+
const m = "https://api.wayflyer.com/financing", I = "https://sandbox-api.wayflyer.com/financing", k = (r) => {
|
|
3
3
|
try {
|
|
4
4
|
return JSON.parse(atob(r.split(".")[1]));
|
|
5
5
|
} catch {
|
|
@@ -8,8 +8,8 @@ const m = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", k
|
|
|
8
8
|
}, E = {
|
|
9
9
|
"Content-Type": "application/json"
|
|
10
10
|
}, y = {
|
|
11
|
-
event: "/
|
|
12
|
-
error: "/
|
|
11
|
+
event: "/v1/company/event/",
|
|
12
|
+
error: "/v1/error/"
|
|
13
13
|
}, g = "wf_session_v1", b = 1800 * 1e3, U = 1440 * 60 * 1e3;
|
|
14
14
|
class D {
|
|
15
15
|
getSessionId() {
|
|
@@ -141,7 +141,7 @@ const S = (r, e) => {
|
|
|
141
141
|
throw new Error("SDK code was fetched successfully, but WayflyerUiSdk is unavailable on window");
|
|
142
142
|
const t = window.WayflyerUiSdk;
|
|
143
143
|
return new t(r, e);
|
|
144
|
-
}, P = "wayflyer-ui-package", _ = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", w = "3.4.
|
|
144
|
+
}, P = "wayflyer-ui-package", _ = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", w = "3.4.4", A = "UI_SDK_READY_EVENT", z = async (r, e) => window.WayflyerUiSdk ? S(r, e) : new Promise((i, n) => {
|
|
145
145
|
const s = document.createElement("script");
|
|
146
146
|
s.src = _, s.type = "module", s.id = P, s.async = !0, s.onerror = () => {
|
|
147
147
|
n(new Error(`Failed to load UI SDK script from ${s.src}`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wf-financing/ui-sdk",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.4",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@wf-financing/embedded-types": "1.1.1",
|
|
19
|
-
"@wf-financing/logger": "2.2.
|
|
19
|
+
"@wf-financing/logger": "2.2.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vite": "^6.3.5",
|