@wf-financing/ui-sdk 2.1.6 → 2.1.7
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 +50 -43
- package/package.json +2 -2
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 h=Object.defineProperty,m=(r,e,t)=>e in r?h(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,c=(r,e,t)=>m(r,typeof e!="symbol"?e+"":e,t);const v="https://api.wayflyer.com",I="https://sandbox-api.wayflyer.com",b=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},y={"Content-Type":"application/json"},u={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},g="wf_session_v1",U=1800*1e3,k=1440*60*1e3;class E{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 n=t-e.lastActivity>U,s=t-e.createdAt>k;return n||s}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 p=class i{constructor(e,t){c(this,"baseUrl",null),c(this,"sessionManager"),this.companyToken=e,this.baseUrl=t?I:v,this.sessionManager=new E}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,t){i.getGlobalInstance()&&console.warn("Logger re-initialized");const n=new i(e,t==null?void 0:t.isSandbox);i.setGlobalInstance(n)}static getMandatoryProperties(e){const t=b(e),[n,s]=(t==null?void 0:t.sub.split("|"))||[],a=t==null?void 0:t.user_id;return{partnerId:n,companyId:s,userId:a}}static getInstance(){const e=i.getGlobalInstance();if(!e)throw new Error("Logger not initialized. Call initialize() first.");return e}static async logEvent(e,t){if(this.isDevEnvironment)return;const n=i.getInstance(),s=n.sessionManager.getSessionId(),a={...y,Authorization:`Bearer ${n.companyToken}`,"X-Session-ID":s};try{const o={...i.getMandatoryProperties(n.companyToken),...t},l=await fetch(n.baseUrl+u.event,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:o})});if(l.status===200)return await l.json()}catch(o){console.error("Failed to log event",o)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const n=i.getInstance(),s=n.sessionManager.getSessionId(),a={...y,"X-Session-ID":s};try{const o={...i.getMandatoryProperties(n.companyToken),...t},l=await fetch(n.baseUrl+u.error,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:o})});if(l.status===200)return await l.json()}catch(o){console.warn("Failed to log error",o)}}};c(p,"isDevEnvironment",!1);let d=p;const S="wayflyer-ui-package",A="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@3",w=(r,e)=>{if(!window.WayflyerUiSdk)throw new Error("Failed to load WayflyerUiSdk from the script.");const t=window.WayflyerUiSdk;return new t(r,e)},f=(r,e,t)=>new Promise((n,s)=>{r.onload=()=>{try{n(w(e,t))}catch(a){s(a)}}}),D=async(r,e)=>{try{const t=document.getElementById(S);if(window.WayflyerUiSdk)return w(r,e);if(t)return f(t,r,e);const n=document.createElement("script");return n.src=A,n.type="module",n.id=S,n.async=!0,n.onerror=()=>d.logError("Failed to load ui SDK script"),document.head.appendChild(n),f(n,r,e)}catch{throw new Error("Failed to load script")}};class O{static async loadSdk(e,t){d.initialize(e,t);const n=await D(e,t);return d.logEvent("ui_sdk_initialized"),n}}exports.WayflyerUiSdk=O;
|
package/dist/index.es.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
const
|
|
1
|
+
var h = Object.defineProperty, m = (r, e, t) => e in r ? h(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, l = (r, e, t) => m(r, typeof e != "symbol" ? e + "" : e, t);
|
|
2
|
+
const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", b = (r) => {
|
|
3
3
|
try {
|
|
4
|
-
return JSON.parse(atob(
|
|
4
|
+
return JSON.parse(atob(r.split(".")[1]));
|
|
5
5
|
} catch {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
|
-
}, d = {
|
|
9
|
-
"Content-Type": "application/json"
|
|
10
8
|
}, y = {
|
|
9
|
+
"Content-Type": "application/json"
|
|
10
|
+
}, u = {
|
|
11
11
|
event: "/financing/v1/company/event/",
|
|
12
12
|
error: "/financing/v1/error/"
|
|
13
|
-
},
|
|
14
|
-
class
|
|
13
|
+
}, g = "wf_session_v1", U = 1800 * 1e3, E = 1440 * 60 * 1e3;
|
|
14
|
+
class k {
|
|
15
15
|
getSessionId() {
|
|
16
16
|
const e = Date.now();
|
|
17
17
|
let t = this.loadSession();
|
|
18
18
|
return (!t || this.isSessionExpired(t, e)) && (t = this.mintNewSession(e)), t.lastActivity = e, this.saveSession(t), t.sessionId;
|
|
19
19
|
}
|
|
20
20
|
isSessionExpired(e, t) {
|
|
21
|
-
const
|
|
22
|
-
return
|
|
21
|
+
const n = t - e.lastActivity > U, s = t - e.createdAt > E;
|
|
22
|
+
return n || s;
|
|
23
23
|
}
|
|
24
24
|
mintNewSession(e) {
|
|
25
25
|
return {
|
|
@@ -30,7 +30,7 @@ class U {
|
|
|
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,15 +38,15 @@ class U {
|
|
|
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
|
-
class i {
|
|
47
|
+
const w = class i {
|
|
48
48
|
constructor(e, t) {
|
|
49
|
-
l(this, "baseUrl", null), l(this, "sessionManager"), this.companyToken = e, this.baseUrl = t ?
|
|
49
|
+
l(this, "baseUrl", null), l(this, "sessionManager"), this.companyToken = e, this.baseUrl = t ? I : v, this.sessionManager = new k();
|
|
50
50
|
}
|
|
51
51
|
static getGlobalInstance() {
|
|
52
52
|
return window.WayflyerLogger || null;
|
|
@@ -56,12 +56,12 @@ class i {
|
|
|
56
56
|
}
|
|
57
57
|
static initialize(e, t) {
|
|
58
58
|
i.getGlobalInstance() && console.warn("Logger re-initialized");
|
|
59
|
-
const
|
|
60
|
-
i.setGlobalInstance(
|
|
59
|
+
const n = new i(e, t == null ? void 0 : t.isSandbox);
|
|
60
|
+
i.setGlobalInstance(n);
|
|
61
61
|
}
|
|
62
62
|
static getMandatoryProperties(e) {
|
|
63
|
-
const t =
|
|
64
|
-
return { partnerId:
|
|
63
|
+
const t = b(e), [n, s] = (t == null ? void 0 : t.sub.split("|")) || [], a = t == null ? void 0 : t.user_id;
|
|
64
|
+
return { partnerId: n, companyId: s, userId: a };
|
|
65
65
|
}
|
|
66
66
|
static getInstance() {
|
|
67
67
|
const e = i.getGlobalInstance();
|
|
@@ -70,16 +70,17 @@ class i {
|
|
|
70
70
|
return e;
|
|
71
71
|
}
|
|
72
72
|
static async logEvent(e, t) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
if (this.isDevEnvironment) return;
|
|
74
|
+
const n = i.getInstance(), s = n.sessionManager.getSessionId(), a = {
|
|
75
|
+
...y,
|
|
76
|
+
Authorization: `Bearer ${n.companyToken}`,
|
|
76
77
|
"X-Session-ID": s
|
|
77
78
|
};
|
|
78
79
|
try {
|
|
79
80
|
const o = {
|
|
80
|
-
...i.getMandatoryProperties(
|
|
81
|
+
...i.getMandatoryProperties(n.companyToken),
|
|
81
82
|
...t
|
|
82
|
-
}, c = await fetch(
|
|
83
|
+
}, c = await fetch(n.baseUrl + u.event, {
|
|
83
84
|
method: "POST",
|
|
84
85
|
headers: a,
|
|
85
86
|
body: JSON.stringify({
|
|
@@ -95,15 +96,19 @@ class i {
|
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
static async logError(e, t) {
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
if (this.isDevEnvironment) {
|
|
100
|
+
console.error(e);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const n = i.getInstance(), s = n.sessionManager.getSessionId(), a = {
|
|
104
|
+
...y,
|
|
100
105
|
"X-Session-ID": s
|
|
101
106
|
};
|
|
102
107
|
try {
|
|
103
108
|
const o = {
|
|
104
|
-
...i.getMandatoryProperties(
|
|
109
|
+
...i.getMandatoryProperties(n.companyToken),
|
|
105
110
|
...t
|
|
106
|
-
}, c = await fetch(
|
|
111
|
+
}, c = await fetch(n.baseUrl + u.error, {
|
|
107
112
|
method: "POST",
|
|
108
113
|
headers: a,
|
|
109
114
|
body: JSON.stringify({
|
|
@@ -118,40 +123,42 @@ class i {
|
|
|
118
123
|
console.warn("Failed to log error", o);
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
126
|
+
};
|
|
127
|
+
l(w, "isDevEnvironment", !1);
|
|
128
|
+
let d = w;
|
|
129
|
+
const S = "wayflyer-ui-package", A = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@3", f = (r, e) => {
|
|
123
130
|
if (!window.WayflyerUiSdk)
|
|
124
131
|
throw new Error("Failed to load WayflyerUiSdk from the script.");
|
|
125
132
|
const t = window.WayflyerUiSdk;
|
|
126
|
-
return new t(
|
|
127
|
-
},
|
|
128
|
-
|
|
133
|
+
return new t(r, e);
|
|
134
|
+
}, p = (r, e, t) => new Promise((n, s) => {
|
|
135
|
+
r.onload = () => {
|
|
129
136
|
try {
|
|
130
|
-
|
|
137
|
+
n(f(e, t));
|
|
131
138
|
} catch (a) {
|
|
132
139
|
s(a);
|
|
133
140
|
}
|
|
134
141
|
};
|
|
135
|
-
}),
|
|
142
|
+
}), D = async (r, e) => {
|
|
136
143
|
try {
|
|
137
|
-
const t = document.getElementById(
|
|
144
|
+
const t = document.getElementById(S);
|
|
138
145
|
if (window.WayflyerUiSdk)
|
|
139
|
-
return
|
|
146
|
+
return f(r, e);
|
|
140
147
|
if (t)
|
|
141
|
-
return
|
|
142
|
-
const
|
|
143
|
-
return
|
|
148
|
+
return p(t, r, e);
|
|
149
|
+
const n = document.createElement("script");
|
|
150
|
+
return n.src = A, n.type = "module", n.id = S, n.async = !0, n.onerror = () => d.logError("Failed to load ui SDK script"), document.head.appendChild(n), p(n, r, e);
|
|
144
151
|
} catch {
|
|
145
152
|
throw new Error("Failed to load script");
|
|
146
153
|
}
|
|
147
154
|
};
|
|
148
|
-
class
|
|
155
|
+
class O {
|
|
149
156
|
static async loadSdk(e, t) {
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
return
|
|
157
|
+
d.initialize(e, t);
|
|
158
|
+
const n = await D(e, t);
|
|
159
|
+
return d.logEvent("ui_sdk_initialized"), n;
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
export {
|
|
156
|
-
|
|
163
|
+
O as WayflyerUiSdk
|
|
157
164
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wf-financing/ui-sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
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": "0.7.1",
|
|
19
|
-
"@wf-financing/logger": "1.1.
|
|
19
|
+
"@wf-financing/logger": "1.1.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vite": "^6.3.5",
|