@wf-financing/ui-sdk 1.0.0 → 2.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
@@ -1,6 +1,6 @@
1
1
  # Wayflyer Financing UI SDK
2
2
 
3
- Wayflyer provides a `@wf-financing/ui-sdk` package that can be used as a client-side UI SDK to interact with the Embedded Finance API. It provides a single method to mount the CTA banner in the partner UI.
3
+ Wayflyer provides a `@wf-financing/ui-sdk` - a client-side UI SDK to interact with the Embedded Finance API. Its primary method mounts the CTA banner in the partner UI.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,55 +10,46 @@ Install the package directly from NPM with `npm install @wf-financing/ui-sdk`. T
10
10
 
11
11
  To initialize `WayflyerUiSdk`, call the static method `loadSdk` with the following parameters:
12
12
 
13
- 1. `targetId` - The DOM element's ID where the CTA is supposed to be mounted.
14
- 2. `partnerCallback` - A function of type `PartnerCallbackType`, which is also provided by the `@wf-financing/ui-sdk` package.
15
- 3. `companyToken` - The merchant identifier.
13
+ 1. `companyToken` - The merchant identifier.
16
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).
17
16
 
18
17
  ```jsx
19
- import { type IWayflyerUiCtaSdk, WayflyerUiSdk } from '@wf-financing/ui-sdk';
18
+ import { WayflyerUiSdk } from '@wf-financing/ui-sdk';
20
19
 
21
- const wayflyerSdk = (await WayflyerUiSdk.loadSdk(targetId, partnerCallback, companyToken)) as IWayflyerUiCtaSdk;
20
+ const wayflyerUiSdk = await WayflyerUiSdk.loadSdk(companyToken);
22
21
  ```
23
22
 
24
23
  ## SDK methods
25
24
 
26
- ### `mountCta()`
25
+ ### `mountCta(targetId, partnerCallback)`
27
26
 
28
27
  This function mounts the CTA banner once it's called.
29
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 `PartnerCallbackType`.
31
+
30
32
  ```jsx
31
- wayflyerSdk.mountCta();
32
- ```
33
+ import { type PartnerCallbackType } from '@wf-financing/ui-sdk';
33
34
 
34
- ## Mocked mode
35
+ const partnerCallback: PartnerCallbackType = await () => {};
35
36
 
36
- To simplify the testing process, the SDK can be initialized in mock mode. To do so, pass the fourth argument of type `MockedModeType`. In mock mode, the partner can manually set responses for SDK methods via the `sdkScenario` field in the optional `mockedMode` argument.
37
+ wayflyerUiSdk.mountCta(targetId, partnerCallback);
38
+ ```
37
39
 
38
- ```jsx
39
- import { WayflyerUiSdk, type MockedModeType, SdkScenarios } from '@wf-financing/ui-sdk';
40
+ ## Sandbox
40
41
 
41
- const mockedModeNewApplication: MockedModeType = {
42
- isMockedMode: true,
43
- sdkScenario: SdkScenarios.INDICATIVE_NEW_APPLICATION,
44
- };
42
+ 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`.
45
43
 
46
- const mockedModeNewApplication: MockedModeType = {
47
- isMockedMode: true,
48
- sdkScenario: SdkScenarios.GENERIC_NEW_APPLICATION,
49
- };
44
+ ```jsx
45
+ import { WayflyerUiSdk, type SdkOptionsType, type PartnerCallbackType } from '@wf-financing/ui-sdk';
50
46
 
51
- const mockedModeContinueApplication: MockedModeType = {
52
- isMockedMode: true,
53
- sdkScenario: SdkScenarios.CONTINUE_APPLICATION,
54
- };
47
+ const options: SdkOptionsType = { isSandbox: true };
48
+ const wayflyerUiSdk = await WayflyerUiSdk.loadSdk(companyToken, options);
55
49
 
56
- const mockedModeNoCta: MockedModeType = {
57
- isMockedMode: true,
58
- sdkScenario: SdkScenarios.NO_CTA,
59
- };
50
+ const partnerCallback: PartnerCallbackType = await () => {};
60
51
 
61
- const wayflyerSdk = (await WayflyerUiSdk.loadSdk(targetId, partnerCallback, companyToken, mockedMode)) as IWayflyerUiCtaSdk;
52
+ wayflyerUiSdk.mountCta(targetId, partnerCallback);
62
53
  ```
63
54
 
64
- After instantiation with the mockedMode parameter, the CTA banner will behave according to the specified scenario.
55
+ After instantiation in sandbox mode, the SDK will call the sandbox environment API.
@@ -1 +1 @@
1
- export declare const UI_PACKAGE_URL = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@2";
1
+ export declare const UI_PACKAGE_URL = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@3";
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n="wayflyer-ui-package",s="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@2",c=(a,t,i,d)=>{if(!window.WayflyerUiCtaSdk)throw new Error("Failed to load WayflyerUiCtaSdk from the script.");const e=window.WayflyerUiCtaSdk;return new e(a,t,i,d)},o=(a,t,i,d,e)=>new Promise((r,y)=>{a.onload=()=>{try{r(c(t,i,d,e))}catch(l){y(l)}}}),f=async(a,t,i,d)=>{try{const e=document.getElementById(n);if(window.WayflyerUiCtaSdk)return c(a,t,i,d);if(e)return o(e,a,t,i,d);const r=document.createElement("script");return r.src=s,r.type="module",r.id=n,r.async=!0,document.head.appendChild(r),o(r,a,t,i,d)}catch(e){throw console.error("Error in loading headless SDK:",e),new Error("Failed to load script")}};class S{static async loadSdk(t,i,d,e){return await f(t,i,d,e)}}exports.WayflyerUiSdk=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d="wayflyer-ui-package",l="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@3",a=(i,t)=>{if(!window.WayflyerUiSdk)throw new Error("Failed to load WayflyerUiSdk from the script.");const e=window.WayflyerUiSdk;return new e(i,t)},n=(i,t,e)=>new Promise((r,o)=>{i.onload=()=>{try{r(a(t,e))}catch(c){o(c)}}}),y=async(i,t)=>{try{const e=document.getElementById(d);if(window.WayflyerUiSdk)return a(i,t);if(e)return n(e,i,t);const r=document.createElement("script");return r.src=l,r.type="module",r.id=d,r.async=!0,document.head.appendChild(r),n(r,i,t)}catch(e){throw console.error("Error in loading headless SDK:",e),new Error("Failed to load script")}};class s{static async loadSdk(t,e){return await y(t,e)}}exports.WayflyerUiSdk=s;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type { IWayflyerUiCtaSdk, PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ export type { IWayflyerUiSdk, PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
2
2
  export { WayflyerUiSdk } from './sdk';
package/dist/index.es.js CHANGED
@@ -1,34 +1,34 @@
1
- const a = "wayflyer-ui-package", s = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@2", c = (n, t, i, d) => {
2
- if (!window.WayflyerUiCtaSdk)
3
- throw new Error("Failed to load WayflyerUiCtaSdk from the script.");
4
- const e = window.WayflyerUiCtaSdk;
5
- return new e(n, t, i, d);
6
- }, o = (n, t, i, d, e) => new Promise((r, y) => {
7
- n.onload = () => {
1
+ const d = "wayflyer-ui-package", l = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@3", a = (i, t) => {
2
+ if (!window.WayflyerUiSdk)
3
+ throw new Error("Failed to load WayflyerUiSdk from the script.");
4
+ const r = window.WayflyerUiSdk;
5
+ return new r(i, t);
6
+ }, n = (i, t, r) => new Promise((e, o) => {
7
+ i.onload = () => {
8
8
  try {
9
- r(c(t, i, d, e));
10
- } catch (l) {
11
- y(l);
9
+ e(a(t, r));
10
+ } catch (c) {
11
+ o(c);
12
12
  }
13
13
  };
14
- }), f = async (n, t, i, d) => {
14
+ }), y = async (i, t) => {
15
15
  try {
16
- const e = document.getElementById(a);
17
- if (window.WayflyerUiCtaSdk)
18
- return c(n, t, i, d);
19
- if (e)
20
- return o(e, n, t, i, d);
21
- const r = document.createElement("script");
22
- return r.src = s, r.type = "module", r.id = a, r.async = !0, document.head.appendChild(r), o(r, n, t, i, d);
23
- } catch (e) {
24
- throw console.error("Error in loading headless SDK:", e), new Error("Failed to load script");
16
+ const r = document.getElementById(d);
17
+ if (window.WayflyerUiSdk)
18
+ return a(i, t);
19
+ if (r)
20
+ return n(r, i, t);
21
+ const e = document.createElement("script");
22
+ return e.src = l, e.type = "module", e.id = d, e.async = !0, document.head.appendChild(e), n(e, i, t);
23
+ } catch (r) {
24
+ throw console.error("Error in loading headless SDK:", r), new Error("Failed to load script");
25
25
  }
26
26
  };
27
- class w {
28
- static async loadSdk(t, i, d, e) {
29
- return await f(t, i, d, e);
27
+ class s {
28
+ static async loadSdk(t, r) {
29
+ return await y(t, r);
30
30
  }
31
31
  }
32
32
  export {
33
- w as WayflyerUiSdk
33
+ s as WayflyerUiSdk
34
34
  };
@@ -1,5 +1,5 @@
1
- import { PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { SdkOptionsType, IWayflyerUiSdk } from '@wf-financing/embedded-types';
2
2
 
3
3
  export declare class WayflyerUiSdk {
4
- static loadSdk(targetId: string, partnerCallback: PartnerCallbackType, companyToken: string, options?: SdkOptionsType): Promise<void | import('@wf-financing/embedded-types').IWayflyerUiCtaSdk>;
4
+ static loadSdk(companyToken: string, options?: SdkOptionsType): Promise<IWayflyerUiSdk>;
5
5
  }
@@ -1,5 +1,5 @@
1
- import { IWayflyerUiCtaSdk, PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerUiSdk, SdkOptionsType } from '@wf-financing/embedded-types';
2
2
 
3
- type LoadUiSdkModeType = (targetId: string, partnerCallback: PartnerCallbackType, companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerUiCtaSdk | void>;
3
+ type LoadUiSdkModeType = (companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerUiSdk | void>;
4
4
  export declare const loadUiSdkMode: LoadUiSdkModeType;
5
5
  export {};
@@ -1,3 +1,3 @@
1
- import { IWayflyerUiCtaSdk, SdkOptionsType, PartnerCallbackType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerUiSdk, SdkOptionsType } from '@wf-financing/embedded-types';
2
2
 
3
- export declare const initializeUiSdk: (targetId: string, partnerCallback: PartnerCallbackType, companyToken: string, options?: SdkOptionsType) => IWayflyerUiCtaSdk;
3
+ export declare const initializeUiSdk: (companyToken: string, options?: SdkOptionsType) => IWayflyerUiSdk;
@@ -1,3 +1,3 @@
1
- import { IWayflyerUiCtaSdk, PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerUiSdk, SdkOptionsType } from '@wf-financing/embedded-types';
2
2
 
3
- export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, targetId: string, partnerCallback: PartnerCallbackType, companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerUiCtaSdk>;
3
+ export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerUiSdk>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/ui-sdk",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@wf-financing/embedded-types": "0.4.0"
18
+ "@wf-financing/embedded-types": "0.4.1"
19
19
  },
20
20
  "devDependencies": {
21
21
  "vite": "^6.3.5",