@wf-financing/ui-sdk 3.4.0 → 3.4.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.cjs.js +1 -1
- package/dist/index.es.js +47 -43
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var
|
|
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",b=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},k={"Content-Type":"application/json"},u={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},g="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 s=t-e.lastActivity>E,n=t-e.createdAt>U;return s||n}mintNewSession(e){return{sessionId:crypto.randomUUID(),createdAt:e,lastActivity:e}}loadSession(){try{const e=sessionStorage.getItem(g);return e?JSON.parse(e):null}catch{return null}}saveSession(e){try{sessionStorage.setItem(g,JSON.stringify(e))}catch{console.warn("Failed to save session context")}}}const h=class a{constructor(e,t,s,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=s,this.headers={...k,...s?{"X-SDK-Version":s}:{}}}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,s,n){a.getGlobalInstance()&&console.warn("Logger re-initialized");const i=new a(e,t,s,n==null?void 0:n.isSandbox);a.setGlobalInstance(i)}static getMandatoryProperties(){const e=a.getInstance(),{sdkVersion:t,companyToken:s,entryPointVersion:n}=e,i=b(s),[d,y]=(i==null?void 0:i.sub.split("|"))||[],f=i==null?void 0:i.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 s=a.getInstance();try{const n={...a.getMandatoryProperties(),...t},i=await fetch(s.baseUrl+u.event,{method:"POST",headers:s.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:n})});if(i.status===200)return await i.json()}catch(n){console.error("Failed to log event",n)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const s=a.getInstance();try{const n={...a.getMandatoryProperties(),...t},i=await fetch(s.baseUrl+u.error,{method:"POST",headers:s.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:n})});if(i.status===200)return await i.json()}catch(n){console.warn("Failed to log error",n)}}};o(h,"isDevEnvironment",!1);let c=h;const S=(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.2",A="UI_SDK_READY_EVENT",O=async(r,e)=>window.WayflyerUiSdk?S(r,e):new Promise((s,n)=>{const i=document.createElement("script");i.src=_,i.type="module",i.id=D,i.async=!0,i.onerror=()=>{n(new Error(`Failed to load UI SDK script from ${i.src}`))};const d=()=>{const y=S(r,e);s(y)};window.addEventListener(A,d,{once:!0}),document.head.appendChild(i)}),z="ui";let l=null;class L{static async loadSdk(e,t){var n;l??(l=this.getLoadSdkPromise(e,t));const s=await l;return((n=s==null?void 0:s.options)==null?void 0:n.language)!==(t==null?void 0:t.language)?(l=this.getLoadSdkPromise(e,t),await l):s}static async getLoadSdkPromise(e,t){const s=Date.now();try{const n=await O(e,t),i=Date.now()-s;return c.initialize(e,w,n.sdkVersion,t),c.logEvent("ui_sdk_initialized",{entry_point_type:z,sdk_initialization_latency:i}),n}catch(n){const i=n instanceof Error?n:new Error(String(n));throw c.initialize(e,w,void 0,t),c.logError(i.message),n}}}exports.WayflyerUiSdk=L;
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
const
|
|
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", E = (r) => {
|
|
3
3
|
try {
|
|
4
4
|
return JSON.parse(atob(r.split(".")[1]));
|
|
5
5
|
} catch {
|
|
@@ -7,11 +7,11 @@ const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", E
|
|
|
7
7
|
}
|
|
8
8
|
}, b = {
|
|
9
9
|
"Content-Type": "application/json"
|
|
10
|
-
},
|
|
10
|
+
}, y = {
|
|
11
11
|
event: "/financing/v1/company/event/",
|
|
12
12
|
error: "/financing/v1/error/"
|
|
13
|
-
},
|
|
14
|
-
class
|
|
13
|
+
}, g = "wf_session_v1", k = 1800 * 1e3, U = 1440 * 60 * 1e3;
|
|
14
|
+
class D {
|
|
15
15
|
getSessionId() {
|
|
16
16
|
const e = Date.now();
|
|
17
17
|
let t = this.loadSession();
|
|
@@ -30,7 +30,7 @@ class _ {
|
|
|
30
30
|
}
|
|
31
31
|
loadSession() {
|
|
32
32
|
try {
|
|
33
|
-
const e = sessionStorage.getItem(
|
|
33
|
+
const e = sessionStorage.getItem(g);
|
|
34
34
|
return e ? JSON.parse(e) : null;
|
|
35
35
|
} catch {
|
|
36
36
|
return null;
|
|
@@ -38,17 +38,17 @@ class _ {
|
|
|
38
38
|
}
|
|
39
39
|
saveSession(e) {
|
|
40
40
|
try {
|
|
41
|
-
sessionStorage.setItem(
|
|
41
|
+
sessionStorage.setItem(g, JSON.stringify(e));
|
|
42
42
|
} catch {
|
|
43
43
|
console.warn("Failed to save session context");
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
constructor(e, t, s) {
|
|
49
|
-
|
|
47
|
+
const h = class a {
|
|
48
|
+
constructor(e, t, s, n) {
|
|
49
|
+
o(this, "baseUrl", null), o(this, "sessionManager"), o(this, "headers"), o(this, "entryPointVersion"), o(this, "sdkVersion"), this.companyToken = e, this.baseUrl = n ? I : m, this.sessionManager = new D(), this.entryPointVersion = t, this.sdkVersion = s, this.headers = {
|
|
50
50
|
...b,
|
|
51
|
-
...
|
|
51
|
+
...s ? { "X-SDK-Version": s } : {}
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
get requestHeaders() {
|
|
@@ -65,14 +65,20 @@ const p = class a {
|
|
|
65
65
|
static setGlobalInstance(e) {
|
|
66
66
|
window.WayflyerLogger = e;
|
|
67
67
|
}
|
|
68
|
-
static initialize(e, t, s) {
|
|
68
|
+
static initialize(e, t, s, n) {
|
|
69
69
|
a.getGlobalInstance() && console.warn("Logger re-initialized");
|
|
70
|
-
const
|
|
71
|
-
a.setGlobalInstance(
|
|
70
|
+
const i = new a(e, t, s, n == null ? void 0 : n.isSandbox);
|
|
71
|
+
a.setGlobalInstance(i);
|
|
72
72
|
}
|
|
73
|
-
static getMandatoryProperties(
|
|
74
|
-
const t = E(
|
|
75
|
-
return {
|
|
73
|
+
static getMandatoryProperties() {
|
|
74
|
+
const e = a.getInstance(), { sdkVersion: t, companyToken: s, entryPointVersion: n } = e, i = E(s), [d, u] = (i == null ? void 0 : i.sub.split("|")) || [], f = i == null ? void 0 : i.user_id;
|
|
75
|
+
return {
|
|
76
|
+
partner_id: d,
|
|
77
|
+
company_id: u,
|
|
78
|
+
user_id: f,
|
|
79
|
+
entry_point_version: n,
|
|
80
|
+
...t ? { sdk_version: t } : {}
|
|
81
|
+
};
|
|
76
82
|
}
|
|
77
83
|
static getInstance() {
|
|
78
84
|
const e = a.getGlobalInstance();
|
|
@@ -85,9 +91,9 @@ const p = class a {
|
|
|
85
91
|
const s = a.getInstance();
|
|
86
92
|
try {
|
|
87
93
|
const n = {
|
|
88
|
-
...a.getMandatoryProperties(
|
|
94
|
+
...a.getMandatoryProperties(),
|
|
89
95
|
...t
|
|
90
|
-
}, i = await fetch(s.baseUrl +
|
|
96
|
+
}, i = await fetch(s.baseUrl + y.event, {
|
|
91
97
|
method: "POST",
|
|
92
98
|
headers: s.requestHeaders,
|
|
93
99
|
body: JSON.stringify({
|
|
@@ -110,9 +116,9 @@ const p = class a {
|
|
|
110
116
|
const s = a.getInstance();
|
|
111
117
|
try {
|
|
112
118
|
const n = {
|
|
113
|
-
...a.getMandatoryProperties(
|
|
119
|
+
...a.getMandatoryProperties(),
|
|
114
120
|
...t
|
|
115
|
-
}, i = await fetch(s.baseUrl +
|
|
121
|
+
}, i = await fetch(s.baseUrl + y.error, {
|
|
116
122
|
method: "POST",
|
|
117
123
|
headers: s.requestHeaders,
|
|
118
124
|
body: JSON.stringify({
|
|
@@ -128,48 +134,46 @@ const p = class a {
|
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
136
|
};
|
|
131
|
-
|
|
132
|
-
let
|
|
137
|
+
o(h, "isDevEnvironment", !1);
|
|
138
|
+
let c = h;
|
|
133
139
|
const S = (r, e) => {
|
|
134
140
|
if (!window.WayflyerUiSdk)
|
|
135
141
|
throw new Error("SDK code was fetched successfully, but WayflyerUiSdk is unavailable on window");
|
|
136
142
|
const t = window.WayflyerUiSdk;
|
|
137
143
|
return new t(r, e);
|
|
138
|
-
},
|
|
144
|
+
}, P = "wayflyer-ui-package", _ = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", w = "3.4.2", A = "UI_SDK_READY_EVENT", z = async (r, e) => window.WayflyerUiSdk ? S(r, e) : new Promise((s, n) => {
|
|
139
145
|
const i = document.createElement("script");
|
|
140
|
-
i.src =
|
|
146
|
+
i.src = _, i.type = "module", i.id = P, i.async = !0, i.onerror = () => {
|
|
141
147
|
n(new Error(`Failed to load UI SDK script from ${i.src}`));
|
|
142
148
|
};
|
|
143
149
|
const d = () => {
|
|
144
|
-
const
|
|
145
|
-
s(
|
|
150
|
+
const u = S(r, e);
|
|
151
|
+
s(u);
|
|
146
152
|
};
|
|
147
|
-
window.addEventListener(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
window.addEventListener(A, d, { once: !0 }), document.head.appendChild(i);
|
|
154
|
+
}), L = "ui";
|
|
155
|
+
let l = null;
|
|
156
|
+
class O {
|
|
157
|
+
static async loadSdk(e, t) {
|
|
158
|
+
var n;
|
|
159
|
+
l ?? (l = this.getLoadSdkPromise(e, t));
|
|
160
|
+
const s = await l;
|
|
161
|
+
return ((n = s == null ? void 0 : s.options) == null ? void 0 : n.language) !== (t == null ? void 0 : t.language) ? (l = this.getLoadSdkPromise(e, t), await l) : s;
|
|
155
162
|
}
|
|
156
163
|
static async getLoadSdkPromise(e, t) {
|
|
157
164
|
const s = Date.now();
|
|
158
165
|
try {
|
|
159
|
-
const n = await
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
entry_point_type: z,
|
|
166
|
+
const n = await z(e, t), i = Date.now() - s;
|
|
167
|
+
return c.initialize(e, w, n.sdkVersion, t), c.logEvent("ui_sdk_initialized", {
|
|
168
|
+
entry_point_type: L,
|
|
163
169
|
sdk_initialization_latency: i
|
|
164
170
|
}), n;
|
|
165
171
|
} catch (n) {
|
|
166
172
|
const i = n instanceof Error ? n : new Error(String(n));
|
|
167
|
-
throw
|
|
168
|
-
entry_point_version: w
|
|
169
|
-
}), n;
|
|
173
|
+
throw c.initialize(e, w, void 0, t), c.logError(i.message), n;
|
|
170
174
|
}
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
export {
|
|
174
|
-
|
|
178
|
+
O as WayflyerUiSdk
|
|
175
179
|
};
|
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.2",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@wf-financing/embedded-types": "1.1.
|
|
19
|
-
"@wf-financing/logger": "2.2.
|
|
18
|
+
"@wf-financing/embedded-types": "1.1.1",
|
|
19
|
+
"@wf-financing/logger": "2.2.2"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vite": "^6.3.5",
|