@wf-financing/ui-sdk 2.1.6 → 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 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 `SdkOptionsType` that provides an ability for SDK to run in different modes (e.g. sandbox mode).
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
- 1. `targetId` - the `id` of the DOM element where the CTA banner should be mounted.
30
- 2. `partnerCallback` a callback function that should return data of type `StartHostedApplicationRequestType`.
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 `SdkOptionsType` 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`.
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 SdkOptionsType, type PartnerCallbackType, type StartHostedApplicationRequestType } from '@wf-financing/ui-sdk';
57
+ import { WayflyerUiSdk, type UiSdkOptions, type PartnerCallbackType, type StartHostedApplicationRequestType } from '@wf-financing/ui-sdk';
55
58
 
56
- const options: SdkOptionsType = { isSandbox: true };
59
+ const options: UiSdkOptions = { isSandbox: true };
57
60
  const wayflyerUiSdk = await WayflyerUiSdk.loadSdk(companyToken, options);
58
61
 
59
62
  const partnerCallback: PartnerCallbackType = await () => {
@@ -1 +1 @@
1
- export declare const UI_PACKAGE_URL = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@3";
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 w=Object.defineProperty,f=(n,e,t)=>e in n?w(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,l=(n,e,t)=>f(n,typeof e!="symbol"?e+"":e,t);const h="https://api.wayflyer.com",m="https://sandbox-api.wayflyer.com",I=n=>{try{return JSON.parse(atob(n.split(".")[1]))}catch{return null}},d={"Content-Type":"application/json"},y={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},u="wf_session_v1",v=1800*1e3,b=1440*60*1e3;class U{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 r=t-e.lastActivity>v,s=t-e.createdAt>b;return r||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")}}}class i{constructor(e,t){l(this,"baseUrl",null),l(this,"sessionManager"),this.companyToken=e,this.baseUrl=t?m:h,this.sessionManager=new U}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,t){i.getGlobalInstance()&&console.warn("Logger re-initialized");const r=new i(e,t==null?void 0:t.isSandbox);i.setGlobalInstance(r)}static getMandatoryProperties(e){const t=I(e),[r,s]=(t==null?void 0:t.sub.split("|"))||[],a=t==null?void 0:t.user_id;return{partnerId:r,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){const r=i.getInstance(),s=r.sessionManager.getSessionId(),a={...d,Authorization:`Bearer ${r.companyToken}`,"X-Session-ID":s};try{const o={...i.getMandatoryProperties(r.companyToken),...t},c=await fetch(r.baseUrl+y.event,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:o})});if(c.status===200)return await c.json()}catch(o){console.error("Failed to log event",o)}}static async logError(e,t){const r=i.getInstance(),s=r.sessionManager.getSessionId(),a={...d,"X-Session-ID":s};try{const o={...i.getMandatoryProperties(r.companyToken),...t},c=await fetch(r.baseUrl+y.error,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:o})});if(c.status===200)return await c.json()}catch(o){console.warn("Failed to log error",o)}}}const g="wayflyer-ui-package",k="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@3",p=(n,e)=>{if(!window.WayflyerUiSdk)throw new Error("Failed to load WayflyerUiSdk from the script.");const t=window.WayflyerUiSdk;return new t(n,e)},S=(n,e,t)=>new Promise((r,s)=>{n.onload=()=>{try{r(p(e,t))}catch(a){s(a)}}}),E=async(n,e)=>{try{const t=document.getElementById(g);if(window.WayflyerUiSdk)return p(n,e);if(t)return S(t,n,e);const r=document.createElement("script");return r.src=k,r.type="module",r.id=g,r.async=!0,r.onerror=()=>i.logError("Failed to load ui SDK script"),document.head.appendChild(r),S(r,n,e)}catch{throw new Error("Failed to load script")}};class A{static async loadSdk(e,t){i.initialize(e,t);const r=await E(e,t);return i.logEvent("ui_sdk_initialized"),r}}exports.WayflyerUiSdk=A;
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
@@ -1,25 +1,25 @@
1
- var w = Object.defineProperty, f = (n, e, t) => e in n ? w(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, l = (n, e, t) => f(n, typeof e != "symbol" ? e + "" : e, t);
2
- const h = "https://api.wayflyer.com", m = "https://sandbox-api.wayflyer.com", I = (n) => {
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(n.split(".")[1]));
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
- }, u = "wf_session_v1", v = 1800 * 1e3, b = 1440 * 60 * 1e3;
14
- class U {
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 r = t - e.lastActivity > v, s = t - e.createdAt > b;
22
- return r || s;
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(u);
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(u, JSON.stringify(e));
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 ? m : h, this.sessionManager = new U();
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 r = new i(e, t == null ? void 0 : t.isSandbox);
60
- i.setGlobalInstance(r);
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 = I(e), [r, s] = (t == null ? void 0 : t.sub.split("|")) || [], a = t == null ? void 0 : t.user_id;
64
- return { partnerId: r, companyId: s, userId: a };
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
- const r = i.getInstance(), s = r.sessionManager.getSessionId(), a = {
74
- ...d,
75
- Authorization: `Bearer ${r.companyToken}`,
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(r.companyToken),
81
+ ...i.getMandatoryProperties(n.companyToken),
81
82
  ...t
82
- }, c = await fetch(r.baseUrl + y.event, {
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
- const r = i.getInstance(), s = r.sessionManager.getSessionId(), a = {
99
- ...d,
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(r.companyToken),
109
+ ...i.getMandatoryProperties(n.companyToken),
105
110
  ...t
106
- }, c = await fetch(r.baseUrl + y.error, {
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
- const g = "wayflyer-ui-package", k = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@3", p = (n, e) => {
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@4", 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(n, e);
127
- }, S = (n, e, t) => new Promise((r, s) => {
128
- n.onload = () => {
133
+ return new t(r, e);
134
+ }, p = (r, e, t) => new Promise((n, s) => {
135
+ r.onload = () => {
129
136
  try {
130
- r(p(e, t));
137
+ n(f(e, t));
131
138
  } catch (a) {
132
139
  s(a);
133
140
  }
134
141
  };
135
- }), E = async (n, e) => {
142
+ }), D = async (r, e) => {
136
143
  try {
137
- const t = document.getElementById(g);
144
+ const t = document.getElementById(S);
138
145
  if (window.WayflyerUiSdk)
139
- return p(n, e);
146
+ return f(r, e);
140
147
  if (t)
141
- return S(t, n, e);
142
- const r = document.createElement("script");
143
- return r.src = k, r.type = "module", r.id = g, r.async = !0, r.onerror = () => i.logError("Failed to load ui SDK script"), document.head.appendChild(r), S(r, n, e);
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 A {
155
+ class O {
149
156
  static async loadSdk(e, t) {
150
- i.initialize(e, t);
151
- const r = await E(e, t);
152
- return i.logEvent("ui_sdk_initialized"), r;
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
- A as WayflyerUiSdk
163
+ O as WayflyerUiSdk
157
164
  };
@@ -1,5 +1,5 @@
1
- import { IWayflyerUiSdk, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerUiSdk, UiSdkOptions } from '@wf-financing/embedded-types';
2
2
 
3
3
  export declare class WayflyerUiSdk {
4
- static loadSdk(companyToken: string, options?: SdkOptionsType): Promise<IWayflyerUiSdk>;
4
+ static loadSdk(companyToken: string, options?: UiSdkOptions): Promise<IWayflyerUiSdk>;
5
5
  }
@@ -1,5 +1,5 @@
1
- import { IWayflyerUiSdk, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerUiSdk, UiSdkOptions } from '@wf-financing/embedded-types';
2
2
 
3
- type LoadUiSdkModeType = (companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerUiSdk | void>;
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, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerUiSdk, UiSdkOptions } from '@wf-financing/embedded-types';
2
2
 
3
- export declare const initializeUiSdk: (companyToken: string, options?: SdkOptionsType) => IWayflyerUiSdk;
3
+ export declare const initializeUiSdk: (companyToken: string, options?: UiSdkOptions) => IWayflyerUiSdk;
@@ -1,3 +1,3 @@
1
- import { IWayflyerUiSdk, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerUiSdk, UiSdkOptions } from '@wf-financing/embedded-types';
2
2
 
3
- export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerUiSdk>;
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": "2.1.6",
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.7.1",
19
- "@wf-financing/logger": "1.1.2"
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",