@wf-financing/ui-sdk 2.1.7 → 3.1.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/README.md +9 -6
- package/dist/config/applicationVersion.d.ts +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/url.d.ts +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +49 -44
- package/dist/sdk/index.d.ts +2 -2
- package/dist/sdk-mode/loadSdkUiMode.d.ts +2 -2
- package/dist/utils/initializeUiSdk.d.ts +2 -2
- package/dist/utils/loadScriptAndInitializeSdk.d.ts +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ To initialize `WayflyerUiSdk`, call the static method `loadSdk` with the followi
|
|
|
12
12
|
|
|
13
13
|
1. `companyToken` - The merchant identifier.
|
|
14
14
|
- **Note**: The `companyToken` should be minted using the Company Token endpoint on the partner's backend. See the Authentication section [here](https://docs.wayflyer.com/embedded-finance/authentication) for more details.
|
|
15
|
-
2. `options` (optional) – an object of type `
|
|
15
|
+
2. `options` (optional) – an object of type `UiSdkOptions` that provides an ability to configure SDK behaviour.
|
|
16
16
|
|
|
17
17
|
```jsx
|
|
18
18
|
import { WayflyerUiSdk } from '@wf-financing/ui-sdk';
|
|
@@ -26,8 +26,11 @@ const wayflyerUiSdk = await WayflyerUiSdk.loadSdk(companyToken);
|
|
|
26
26
|
|
|
27
27
|
This function mounts the CTA banner once it's called.
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
## `options` parameter
|
|
30
|
+
When initializing the SDK, the options parameter allows you to configure its behavior:
|
|
31
|
+
1) `options.skipAnimations` - by default, animations are enabled for the CTA banner. Set this to true to disable animations.
|
|
32
|
+
2) `options.isSandbox` - enables sandbox (non-production) mode for the SDK.
|
|
33
|
+
3) `options.language` - sets the preferred language for the UI. If not provided, English will be used as the default.
|
|
31
34
|
|
|
32
35
|
```jsx
|
|
33
36
|
import { type PartnerCallbackType, type StartHostedApplicationRequestType } from '@wf-financing/ui-sdk';
|
|
@@ -48,12 +51,12 @@ The callback may also be used to execute partner-related logic in response to th
|
|
|
48
51
|
|
|
49
52
|
## Sandbox
|
|
50
53
|
|
|
51
|
-
To simplify the testing process, the SDK can be initialized in sandbox mode. To do so, pass the second argument of type `
|
|
54
|
+
To simplify the testing process, the SDK can be initialized in sandbox mode. To do so, pass the second argument of type `UiSdkOptions` with `isSandbox` flag set to `true`. In sandbox mode, the partner can simulate responses for SDK methods with the help of the additional package `@wf-financing/sandbox-ui`.
|
|
52
55
|
|
|
53
56
|
```jsx
|
|
54
|
-
import { WayflyerUiSdk, type
|
|
57
|
+
import { WayflyerUiSdk, type UiSdkOptions, type PartnerCallbackType, type StartHostedApplicationRequestType } from '@wf-financing/ui-sdk';
|
|
55
58
|
|
|
56
|
-
const options:
|
|
59
|
+
const options: UiSdkOptions = { isSandbox: true };
|
|
57
60
|
const wayflyerUiSdk = await WayflyerUiSdk.loadSdk(companyToken, options);
|
|
58
61
|
|
|
59
62
|
const partnerCallback: PartnerCallbackType = await () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const APPLICATION_VERSION: string;
|
package/dist/config/index.d.ts
CHANGED
package/dist/config/url.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const UI_PACKAGE_URL = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@
|
|
1
|
+
export declare const UI_PACKAGE_URL = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4";
|
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 m=Object.defineProperty,h=(i,e,t)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,l=(i,e,t)=>h(i,typeof e!="symbol"?e+"":e,t);const v="https://api.wayflyer.com",I="https://sandbox-api.wayflyer.com",b=i=>{try{return JSON.parse(atob(i.split(".")[1]))}catch{return null}},y={"Content-Type":"application/json"},u={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},g="wf_session_v1",k=1800*1e3,U=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>k,s=t-e.createdAt>U;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 w=class a{constructor(e,t){l(this,"baseUrl",null),l(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){a.getGlobalInstance()&&console.warn("Logger re-initialized");const n=new a(e,t==null?void 0:t.isSandbox);a.setGlobalInstance(n)}static getMandatoryProperties(e){const t=b(e),[n,s]=(t==null?void 0:t.sub.split("|"))||[],o=t==null?void 0:t.user_id;return{partner_id:n,company_id:s,user_id:o}}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(),s=n.sessionManager.getSessionId(),o={...y,Authorization:`Bearer ${n.companyToken}`,"X-Session-ID":s};try{const r={...a.getMandatoryProperties(n.companyToken),...t},c=await fetch(n.baseUrl+u.event,{method:"POST",headers:o,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:r})});if(c.status===200)return await c.json()}catch(r){console.error("Failed to log event",r)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const n=a.getInstance(),s=n.sessionManager.getSessionId(),o={...y,"X-Session-ID":s};try{const r={...a.getMandatoryProperties(n.companyToken),...t},c=await fetch(n.baseUrl+u.error,{method:"POST",headers:o,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:r})});if(c.status===200)return await c.json()}catch(r){console.warn("Failed to log error",r)}}};l(w,"isDevEnvironment",!1);let d=w;const p="wayflyer-ui-package",A="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4",z="3.1.0",f=(i,e)=>{if(!window.WayflyerUiSdk)throw new Error("Failed to load WayflyerUiSdk from the script.");const t=window.WayflyerUiSdk;return new t(i,e)},S=(i,e,t)=>new Promise((n,s)=>{i.onload=()=>{try{n(f(e,t))}catch(o){s(o)}}}),D=async(i,e)=>{try{const t=document.getElementById(p);if(window.WayflyerUiSdk)return f(i,e);if(t)return S(t,i,e);const n=document.createElement("script");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),S(n,i,e)}catch{throw new Error("Failed to load script")}};class O{static async loadSdk(e,t){const n=Date.now();d.initialize(e,t);const s=await D(e,t),r=Date.now()-n;return d.logEvent("ui_sdk_initialized",{entry_point_version:z,sdk_version:(s==null?void 0:s.sdkVersion)??"unknown version",sdk_initialization_latency:r}),s}}exports.WayflyerUiSdk=O;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { IWayflyerUiSdk, PartnerCallbackType, SdkOptionsType, StartHostedApplicationRequestType, } from '@wf-financing/embedded-types';
|
|
1
|
+
export type { IWayflyerUiSdk, PartnerCallbackType, SdkOptionsType, UiSdkOptions, StartHostedApplicationRequestType, } from '@wf-financing/embedded-types';
|
|
2
2
|
export { WayflyerUiSdk } from './sdk';
|
package/dist/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com",
|
|
1
|
+
var f = Object.defineProperty, h = (i, e, t) => e in i ? f(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, l = (i, e, t) => h(i, typeof e != "symbol" ? e + "" : e, t);
|
|
2
|
+
const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", k = (i) => {
|
|
3
3
|
try {
|
|
4
|
-
return JSON.parse(atob(
|
|
4
|
+
return JSON.parse(atob(i.split(".")[1]));
|
|
5
5
|
} catch {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
@@ -10,15 +10,15 @@ const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", b
|
|
|
10
10
|
}, u = {
|
|
11
11
|
event: "/financing/v1/company/event/",
|
|
12
12
|
error: "/financing/v1/error/"
|
|
13
|
-
}, g = "wf_session_v1",
|
|
14
|
-
class
|
|
13
|
+
}, g = "wf_session_v1", b = 1800 * 1e3, E = 1440 * 60 * 1e3;
|
|
14
|
+
class U {
|
|
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 > b, s = t - e.createdAt > E;
|
|
22
22
|
return n || s;
|
|
23
23
|
}
|
|
24
24
|
mintNewSession(e) {
|
|
@@ -44,9 +44,9 @@ class k {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
const
|
|
47
|
+
const S = class a {
|
|
48
48
|
constructor(e, t) {
|
|
49
|
-
l(this, "baseUrl", null), l(this, "sessionManager"), this.companyToken = e, this.baseUrl = t ? I : v, this.sessionManager = new
|
|
49
|
+
l(this, "baseUrl", null), l(this, "sessionManager"), this.companyToken = e, this.baseUrl = t ? I : v, this.sessionManager = new U();
|
|
50
50
|
}
|
|
51
51
|
static getGlobalInstance() {
|
|
52
52
|
return window.WayflyerLogger || null;
|
|
@@ -55,44 +55,44 @@ const w = class i {
|
|
|
55
55
|
window.WayflyerLogger = e;
|
|
56
56
|
}
|
|
57
57
|
static initialize(e, t) {
|
|
58
|
-
|
|
59
|
-
const n = new
|
|
60
|
-
|
|
58
|
+
a.getGlobalInstance() && console.warn("Logger re-initialized");
|
|
59
|
+
const n = new a(e, t == null ? void 0 : t.isSandbox);
|
|
60
|
+
a.setGlobalInstance(n);
|
|
61
61
|
}
|
|
62
62
|
static getMandatoryProperties(e) {
|
|
63
|
-
const t =
|
|
64
|
-
return {
|
|
63
|
+
const t = k(e), [n, s] = (t == null ? void 0 : t.sub.split("|")) || [], o = t == null ? void 0 : t.user_id;
|
|
64
|
+
return { partner_id: n, company_id: s, user_id: o };
|
|
65
65
|
}
|
|
66
66
|
static getInstance() {
|
|
67
|
-
const e =
|
|
67
|
+
const e = a.getGlobalInstance();
|
|
68
68
|
if (!e)
|
|
69
69
|
throw new Error("Logger not initialized. Call initialize() first.");
|
|
70
70
|
return e;
|
|
71
71
|
}
|
|
72
72
|
static async logEvent(e, t) {
|
|
73
73
|
if (this.isDevEnvironment) return;
|
|
74
|
-
const n =
|
|
74
|
+
const n = a.getInstance(), s = n.sessionManager.getSessionId(), o = {
|
|
75
75
|
...y,
|
|
76
76
|
Authorization: `Bearer ${n.companyToken}`,
|
|
77
77
|
"X-Session-ID": s
|
|
78
78
|
};
|
|
79
79
|
try {
|
|
80
|
-
const
|
|
81
|
-
...
|
|
80
|
+
const r = {
|
|
81
|
+
...a.getMandatoryProperties(n.companyToken),
|
|
82
82
|
...t
|
|
83
83
|
}, c = await fetch(n.baseUrl + u.event, {
|
|
84
84
|
method: "POST",
|
|
85
|
-
headers:
|
|
85
|
+
headers: o,
|
|
86
86
|
body: JSON.stringify({
|
|
87
87
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
88
88
|
event_name: e,
|
|
89
|
-
properties:
|
|
89
|
+
properties: r
|
|
90
90
|
})
|
|
91
91
|
});
|
|
92
92
|
if (c.status === 200)
|
|
93
93
|
return await c.json();
|
|
94
|
-
} catch (
|
|
95
|
-
console.error("Failed to log event",
|
|
94
|
+
} catch (r) {
|
|
95
|
+
console.error("Failed to log event", r);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
static async logError(e, t) {
|
|
@@ -100,63 +100,68 @@ const w = class i {
|
|
|
100
100
|
console.error(e);
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
|
-
const n =
|
|
103
|
+
const n = a.getInstance(), s = n.sessionManager.getSessionId(), o = {
|
|
104
104
|
...y,
|
|
105
105
|
"X-Session-ID": s
|
|
106
106
|
};
|
|
107
107
|
try {
|
|
108
|
-
const
|
|
109
|
-
...
|
|
108
|
+
const r = {
|
|
109
|
+
...a.getMandatoryProperties(n.companyToken),
|
|
110
110
|
...t
|
|
111
111
|
}, c = await fetch(n.baseUrl + u.error, {
|
|
112
112
|
method: "POST",
|
|
113
|
-
headers:
|
|
113
|
+
headers: o,
|
|
114
114
|
body: JSON.stringify({
|
|
115
115
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
116
116
|
message: e,
|
|
117
|
-
properties:
|
|
117
|
+
properties: r
|
|
118
118
|
})
|
|
119
119
|
});
|
|
120
120
|
if (c.status === 200)
|
|
121
121
|
return await c.json();
|
|
122
|
-
} catch (
|
|
123
|
-
console.warn("Failed to log error",
|
|
122
|
+
} catch (r) {
|
|
123
|
+
console.warn("Failed to log error", r);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
l(
|
|
128
|
-
let d =
|
|
129
|
-
const
|
|
127
|
+
l(S, "isDevEnvironment", !1);
|
|
128
|
+
let d = S;
|
|
129
|
+
const p = "wayflyer-ui-package", A = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", z = "3.1.0", m = (i, e) => {
|
|
130
130
|
if (!window.WayflyerUiSdk)
|
|
131
131
|
throw new Error("Failed to load WayflyerUiSdk from the script.");
|
|
132
132
|
const t = window.WayflyerUiSdk;
|
|
133
|
-
return new t(
|
|
134
|
-
},
|
|
135
|
-
|
|
133
|
+
return new t(i, e);
|
|
134
|
+
}, w = (i, e, t) => new Promise((n, s) => {
|
|
135
|
+
i.onload = () => {
|
|
136
136
|
try {
|
|
137
|
-
n(
|
|
138
|
-
} catch (
|
|
139
|
-
s(
|
|
137
|
+
n(m(e, t));
|
|
138
|
+
} catch (o) {
|
|
139
|
+
s(o);
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
-
}), D = async (
|
|
142
|
+
}), D = async (i, e) => {
|
|
143
143
|
try {
|
|
144
|
-
const t = document.getElementById(
|
|
144
|
+
const t = document.getElementById(p);
|
|
145
145
|
if (window.WayflyerUiSdk)
|
|
146
|
-
return
|
|
146
|
+
return m(i, e);
|
|
147
147
|
if (t)
|
|
148
|
-
return
|
|
148
|
+
return w(t, i, e);
|
|
149
149
|
const n = document.createElement("script");
|
|
150
|
-
return n.src = A, n.type = "module", n.id =
|
|
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
151
|
} catch {
|
|
152
152
|
throw new Error("Failed to load script");
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
155
|
class O {
|
|
156
156
|
static async loadSdk(e, t) {
|
|
157
|
+
const n = Date.now();
|
|
157
158
|
d.initialize(e, t);
|
|
158
|
-
const
|
|
159
|
-
return d.logEvent("ui_sdk_initialized"
|
|
159
|
+
const s = await D(e, t), r = Date.now() - n;
|
|
160
|
+
return d.logEvent("ui_sdk_initialized", {
|
|
161
|
+
entry_point_version: z,
|
|
162
|
+
sdk_version: (s == null ? void 0 : s.sdkVersion) ?? "unknown version",
|
|
163
|
+
sdk_initialization_latency: r
|
|
164
|
+
}), s;
|
|
160
165
|
}
|
|
161
166
|
}
|
|
162
167
|
export {
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IWayflyerUiSdk,
|
|
1
|
+
import { IWayflyerUiSdk, UiSdkOptions } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
3
|
export declare class WayflyerUiSdk {
|
|
4
|
-
static loadSdk(companyToken: string, options?:
|
|
4
|
+
static loadSdk(companyToken: string, options?: UiSdkOptions): Promise<IWayflyerUiSdk>;
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IWayflyerUiSdk,
|
|
1
|
+
import { IWayflyerUiSdk, UiSdkOptions } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
type LoadUiSdkModeType = (companyToken: string, options?:
|
|
3
|
+
type LoadUiSdkModeType = (companyToken: string, options?: UiSdkOptions) => Promise<IWayflyerUiSdk | void>;
|
|
4
4
|
export declare const loadUiSdkMode: LoadUiSdkModeType;
|
|
5
5
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IWayflyerUiSdk,
|
|
1
|
+
import { IWayflyerUiSdk, UiSdkOptions } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
export declare const initializeUiSdk: (companyToken: string, options?:
|
|
3
|
+
export declare const initializeUiSdk: (companyToken: string, options?: UiSdkOptions) => IWayflyerUiSdk;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IWayflyerUiSdk,
|
|
1
|
+
import { IWayflyerUiSdk, UiSdkOptions } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, companyToken: string, options?:
|
|
3
|
+
export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, companyToken: string, options?: UiSdkOptions) => Promise<IWayflyerUiSdk>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wf-financing/ui-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
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": "
|
|
19
|
-
"@wf-financing/logger": "
|
|
18
|
+
"@wf-financing/embedded-types": "1.1.0",
|
|
19
|
+
"@wf-financing/logger": "2.1.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vite": "^6.3.5",
|