@wf-financing/ui-sdk 3.2.0 → 3.3.0
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 +75 -73
- package/dist/sdk/index.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/loadUiSdkScript.d.ts +5 -0
- package/package.json +3 -3
- package/dist/sdk-mode/index.d.ts +0 -1
- package/dist/sdk-mode/loadSdkUiMode.d.ts +0 -5
- package/dist/utils/loadScriptAndInitializeSdk.d.ts +0 -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 h=Object.defineProperty,v=(r,e,t)=>e in r?h(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,d=(r,e,t)=>v(r,typeof e!="symbol"?e+"":e,t);const I="https://api.wayflyer.com",b="https://sandbox-api.wayflyer.com",k=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},E={"Content-Type":"application/json"},y={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},u="wf_session_v1",U=1800*1e3,A=1440*60*1e3;class D{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>A;return n||s}mintNewSession(e){return{sessionId:crypto.randomUUID(),createdAt:e,lastActivity:e}}loadSession(){try{const e=sessionStorage.getItem(u);return e?JSON.parse(e):null}catch{return null}}saveSession(e){try{sessionStorage.setItem(u,JSON.stringify(e))}catch{console.warn("Failed to save session context")}}}const w=class a{constructor(e,t,n){d(this,"baseUrl",null),d(this,"sessionManager"),d(this,"headers"),this.companyToken=e,this.baseUrl=n?b:I,this.sessionManager=new D,this.headers={...E,...t?{"X-SDK-Version":t}:{}}}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,n){a.getGlobalInstance()&&console.warn("Logger re-initialized");const s=new a(e,t,n==null?void 0:n.isSandbox);a.setGlobalInstance(s)}static getMandatoryProperties(e){const t=k(e),[n,s]=(t==null?void 0:t.sub.split("|"))||[],i=t==null?void 0:t.user_id;return{partner_id:n,company_id:s,user_id:i}}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 n=a.getInstance();try{const s={...a.getMandatoryProperties(n.companyToken),...t},i=await fetch(n.baseUrl+y.event,{method:"POST",headers:n.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:s})});if(i.status===200)return await i.json()}catch(s){console.error("Failed to log event",s)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const n=a.getInstance();try{const s={...a.getMandatoryProperties(n.companyToken),...t},i=await fetch(n.baseUrl+y.error,{method:"POST",headers:n.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:s})});if(i.status===200)return await i.json()}catch(s){console.warn("Failed to log error",s)}}};d(w,"isDevEnvironment",!1);let l=w;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)},p="wayflyer-ui-package",_="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4",S="3.3.0",z=async(r,e)=>document.getElementById(p)?g(r,e):new Promise((n,s)=>{const i=document.createElement("script");i.src=_,i.type="module",i.id=p,i.async=!0,i.onload=()=>{try{const o=g(r,e);n(o)}catch(o){s(o)}},i.onerror=()=>{s(new Error(`Failed to load UI SDK script from ${i.src}`))},document.head.appendChild(i)}),O="ui";class P{static async loadSdk(e,t){const n=Date.now();let s;try{s=await z(e,t)}catch(c){const m=c instanceof Error?c:new Error(String(c));throw l.initialize(e,void 0,t),l.logError(m.message,{entry_point_version:S}),c}const o=Date.now()-n,f=s.sdkVersion;return l.initialize(e,f,t),l.logEvent("ui_sdk_initialized",{entry_point_version:S,entry_point_type:O,sdk_initialization_latency:o}),s}}exports.WayflyerUiSdk=P;
|
package/dist/index.es.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
var f = Object.defineProperty,
|
|
2
|
-
const
|
|
1
|
+
var f = Object.defineProperty, v = (r, e, t) => e in r ? f(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, d = (r, e, t) => v(r, typeof e != "symbol" ? e + "" : e, t);
|
|
2
|
+
const I = "https://api.wayflyer.com", b = "https://sandbox-api.wayflyer.com", E = (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
|
-
},
|
|
8
|
+
}, k = {
|
|
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
|
+
}, u = "wf_session_v1", U = 1800 * 1e3, A = 1440 * 60 * 1e3;
|
|
14
|
+
class D {
|
|
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 n = t - e.lastActivity >
|
|
21
|
+
const n = t - e.lastActivity > U, s = t - e.createdAt > A;
|
|
22
22
|
return n || s;
|
|
23
23
|
}
|
|
24
24
|
mintNewSession(e) {
|
|
@@ -30,7 +30,7 @@ class U {
|
|
|
30
30
|
}
|
|
31
31
|
loadSession() {
|
|
32
32
|
try {
|
|
33
|
-
const e = sessionStorage.getItem(
|
|
33
|
+
const e = sessionStorage.getItem(u);
|
|
34
34
|
return e ? JSON.parse(e) : null;
|
|
35
35
|
} catch {
|
|
36
36
|
return null;
|
|
@@ -38,15 +38,26 @@ class U {
|
|
|
38
38
|
}
|
|
39
39
|
saveSession(e) {
|
|
40
40
|
try {
|
|
41
|
-
sessionStorage.setItem(
|
|
41
|
+
sessionStorage.setItem(u, 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) {
|
|
49
|
-
|
|
47
|
+
const w = class a {
|
|
48
|
+
constructor(e, t, n) {
|
|
49
|
+
d(this, "baseUrl", null), d(this, "sessionManager"), d(this, "headers"), this.companyToken = e, this.baseUrl = n ? b : I, this.sessionManager = new D(), this.headers = {
|
|
50
|
+
...k,
|
|
51
|
+
...t ? { "X-SDK-Version": t } : {}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
get requestHeaders() {
|
|
55
|
+
const e = a.getInstance(), t = e.sessionManager.getSessionId();
|
|
56
|
+
return {
|
|
57
|
+
Authorization: `Bearer ${e.companyToken}`,
|
|
58
|
+
"X-Session-ID": t,
|
|
59
|
+
...e.headers
|
|
60
|
+
};
|
|
50
61
|
}
|
|
51
62
|
static getGlobalInstance() {
|
|
52
63
|
return window.WayflyerLogger || null;
|
|
@@ -54,14 +65,14 @@ const S = class a {
|
|
|
54
65
|
static setGlobalInstance(e) {
|
|
55
66
|
window.WayflyerLogger = e;
|
|
56
67
|
}
|
|
57
|
-
static initialize(e, t) {
|
|
68
|
+
static initialize(e, t, n) {
|
|
58
69
|
a.getGlobalInstance() && console.warn("Logger re-initialized");
|
|
59
|
-
const
|
|
60
|
-
a.setGlobalInstance(
|
|
70
|
+
const s = new a(e, t, n == null ? void 0 : n.isSandbox);
|
|
71
|
+
a.setGlobalInstance(s);
|
|
61
72
|
}
|
|
62
73
|
static getMandatoryProperties(e) {
|
|
63
|
-
const t =
|
|
64
|
-
return { partner_id: n, company_id: s, user_id:
|
|
74
|
+
const t = E(e), [n, s] = (t == null ? void 0 : t.sub.split("|")) || [], i = t == null ? void 0 : t.user_id;
|
|
75
|
+
return { partner_id: n, company_id: s, user_id: i };
|
|
65
76
|
}
|
|
66
77
|
static getInstance() {
|
|
67
78
|
const e = a.getGlobalInstance();
|
|
@@ -71,28 +82,24 @@ const S = class a {
|
|
|
71
82
|
}
|
|
72
83
|
static async logEvent(e, t) {
|
|
73
84
|
if (this.isDevEnvironment) return;
|
|
74
|
-
const n = a.getInstance()
|
|
75
|
-
...y,
|
|
76
|
-
Authorization: `Bearer ${n.companyToken}`,
|
|
77
|
-
"X-Session-ID": s
|
|
78
|
-
};
|
|
85
|
+
const n = a.getInstance();
|
|
79
86
|
try {
|
|
80
|
-
const
|
|
87
|
+
const s = {
|
|
81
88
|
...a.getMandatoryProperties(n.companyToken),
|
|
82
89
|
...t
|
|
83
|
-
},
|
|
90
|
+
}, i = await fetch(n.baseUrl + y.event, {
|
|
84
91
|
method: "POST",
|
|
85
|
-
headers:
|
|
92
|
+
headers: n.requestHeaders,
|
|
86
93
|
body: JSON.stringify({
|
|
87
94
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
88
95
|
event_name: e,
|
|
89
|
-
properties:
|
|
96
|
+
properties: s
|
|
90
97
|
})
|
|
91
98
|
});
|
|
92
|
-
if (
|
|
93
|
-
return await
|
|
94
|
-
} catch (
|
|
95
|
-
console.error("Failed to log event",
|
|
99
|
+
if (i.status === 200)
|
|
100
|
+
return await i.json();
|
|
101
|
+
} catch (s) {
|
|
102
|
+
console.error("Failed to log event", s);
|
|
96
103
|
}
|
|
97
104
|
}
|
|
98
105
|
static async logError(e, t) {
|
|
@@ -100,70 +107,65 @@ const S = class a {
|
|
|
100
107
|
console.error(e);
|
|
101
108
|
return;
|
|
102
109
|
}
|
|
103
|
-
const n = a.getInstance()
|
|
104
|
-
...y,
|
|
105
|
-
"X-Session-ID": s
|
|
106
|
-
};
|
|
110
|
+
const n = a.getInstance();
|
|
107
111
|
try {
|
|
108
|
-
const
|
|
112
|
+
const s = {
|
|
109
113
|
...a.getMandatoryProperties(n.companyToken),
|
|
110
114
|
...t
|
|
111
|
-
},
|
|
115
|
+
}, i = await fetch(n.baseUrl + y.error, {
|
|
112
116
|
method: "POST",
|
|
113
|
-
headers:
|
|
117
|
+
headers: n.requestHeaders,
|
|
114
118
|
body: JSON.stringify({
|
|
115
119
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
116
120
|
message: e,
|
|
117
|
-
properties:
|
|
121
|
+
properties: s
|
|
118
122
|
})
|
|
119
123
|
});
|
|
120
|
-
if (
|
|
121
|
-
return await
|
|
122
|
-
} catch (
|
|
123
|
-
console.warn("Failed to log error",
|
|
124
|
+
if (i.status === 200)
|
|
125
|
+
return await i.json();
|
|
126
|
+
} catch (s) {
|
|
127
|
+
console.warn("Failed to log error", s);
|
|
124
128
|
}
|
|
125
129
|
}
|
|
126
130
|
};
|
|
127
|
-
|
|
128
|
-
let
|
|
129
|
-
const
|
|
131
|
+
d(w, "isDevEnvironment", !1);
|
|
132
|
+
let l = w;
|
|
133
|
+
const g = (r, e) => {
|
|
130
134
|
if (!window.WayflyerUiSdk)
|
|
131
|
-
throw new Error("
|
|
135
|
+
throw new Error("SDK code was fetched successfully, but WayflyerUiSdk is unavailable on window");
|
|
132
136
|
const t = window.WayflyerUiSdk;
|
|
133
|
-
return new t(
|
|
134
|
-
},
|
|
135
|
-
i
|
|
137
|
+
return new t(r, e);
|
|
138
|
+
}, p = "wayflyer-ui-package", _ = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", S = "3.3.0", z = async (r, e) => document.getElementById(p) ? g(r, e) : new Promise((n, s) => {
|
|
139
|
+
const i = document.createElement("script");
|
|
140
|
+
i.src = _, i.type = "module", i.id = p, i.async = !0, i.onload = () => {
|
|
136
141
|
try {
|
|
137
|
-
|
|
142
|
+
const o = g(r, e);
|
|
143
|
+
n(o);
|
|
138
144
|
} catch (o) {
|
|
139
145
|
s(o);
|
|
140
146
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return m(i, e);
|
|
147
|
-
if (t)
|
|
148
|
-
return w(t, i, e);
|
|
149
|
-
const n = document.createElement("script");
|
|
150
|
-
return n.src = A, n.type = "module", n.id = p, n.async = !0, n.onerror = () => d.logError("Failed to load ui SDK script"), document.head.appendChild(n), w(n, i, e);
|
|
151
|
-
} catch {
|
|
152
|
-
throw new Error("Failed to load script");
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
class O {
|
|
147
|
+
}, i.onerror = () => {
|
|
148
|
+
s(new Error(`Failed to load UI SDK script from ${i.src}`));
|
|
149
|
+
}, document.head.appendChild(i);
|
|
150
|
+
}), O = "ui";
|
|
151
|
+
class P {
|
|
156
152
|
static async loadSdk(e, t) {
|
|
157
153
|
const n = Date.now();
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
154
|
+
let s;
|
|
155
|
+
try {
|
|
156
|
+
s = await z(e, t);
|
|
157
|
+
} catch (c) {
|
|
158
|
+
const m = c instanceof Error ? c : new Error(String(c));
|
|
159
|
+
throw l.initialize(e, void 0, t), l.logError(m.message, { entry_point_version: S }), c;
|
|
160
|
+
}
|
|
161
|
+
const o = Date.now() - n, h = s.sdkVersion;
|
|
162
|
+
return l.initialize(e, h, t), l.logEvent("ui_sdk_initialized", {
|
|
163
|
+
entry_point_version: S,
|
|
164
|
+
entry_point_type: O,
|
|
165
|
+
sdk_initialization_latency: o
|
|
164
166
|
}), s;
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
export {
|
|
168
|
-
|
|
170
|
+
P as WayflyerUiSdk
|
|
169
171
|
};
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UiSdkOptions, IWayflyerUiSdk } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
3
|
export declare class WayflyerUiSdk {
|
|
4
4
|
static loadSdk(companyToken: string, options?: UiSdkOptions): Promise<IWayflyerUiSdk>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { initializeUiSdk } from './initializeUiSdk';
|
|
2
|
-
export {
|
|
2
|
+
export { loadUiSdkScript } from './loadUiSdkScript';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wf-financing/ui-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
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.0",
|
|
19
|
-
"@wf-financing/logger": "2.
|
|
19
|
+
"@wf-financing/logger": "2.2.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vite": "^6.3.5",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build": "vite build",
|
|
32
32
|
"link": "node ../../tools/scripts/link-local.mjs",
|
|
33
33
|
"unlink": "node ../../tools/scripts/unlink-local.mjs",
|
|
34
|
-
"prepare-sdk-cta": "pnpm clean && pnpm build && pnpm pack",
|
|
34
|
+
"prepare-sdk-cta": "pnpm clean && NODE_ENV=development pnpm build --mode development && pnpm pack",
|
|
35
35
|
"publish-sdk-cta": "pnpm clean && pnpm build && pnpm publish --access public --no-git-checks",
|
|
36
36
|
"test": "vitest",
|
|
37
37
|
"test:coverage": "vitest --coverage"
|
package/dist/sdk-mode/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { loadUiSdkMode } from './loadSdkUiMode';
|