@wf-financing/ui-sdk 2.1.7 → 3.0.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/url.d.ts +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +1 -1
- 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 () => {
|
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 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@
|
|
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@4",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.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
|
@@ -126,7 +126,7 @@ const w = class i {
|
|
|
126
126
|
};
|
|
127
127
|
l(w, "isDevEnvironment", !1);
|
|
128
128
|
let d = w;
|
|
129
|
-
const S = "wayflyer-ui-package", A = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@
|
|
129
|
+
const S = "wayflyer-ui-package", A = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", f = (r, e) => {
|
|
130
130
|
if (!window.WayflyerUiSdk)
|
|
131
131
|
throw new Error("Failed to load WayflyerUiSdk from the script.");
|
|
132
132
|
const t = window.WayflyerUiSdk;
|
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.0.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": "0.
|
|
19
|
-
"@wf-financing/logger": "
|
|
18
|
+
"@wf-financing/embedded-types": "1.0.0",
|
|
19
|
+
"@wf-financing/logger": "2.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vite": "^6.3.5",
|