@wf-financing/ui-sdk 0.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 +64 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/scriptId.d.ts +1 -0
- package/dist/config/url.d.ts +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +43 -0
- package/dist/sdk/index.d.ts +5 -0
- package/dist/sdk-mode/index.d.ts +1 -0
- package/dist/sdk-mode/loadSdkUiMode.d.ts +5 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/initializeUiSdk.d.ts +3 -0
- package/dist/utils/loadScriptAndInitializeSdk.d.ts +3 -0
- package/dist/vite.config.d.ts +2 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Wayflyer Financing UI SDK
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package directly from NPM with `npm install @wf-financing/ui-sdk`.
|
|
8
|
+
To minimize the bundle size and reduce the impact on partners' page load times, the SDK uses dynamic imports to load the main part of the functionality.
|
|
9
|
+
|
|
10
|
+
## Instantiation
|
|
11
|
+
|
|
12
|
+
To initialize `WayflyerUiSdk`, call the static method `loadSdk` with the following parameters:
|
|
13
|
+
|
|
14
|
+
1. `targetId` - The DOM element's ID where the CTA is supposed to be mounted.
|
|
15
|
+
2. `partnerDesignId` - The ID of the partner theme that needs to be applied to the CTA.
|
|
16
|
+
- **Note**: The partner must request Wayflyer to generate a special theme ID.
|
|
17
|
+
3. `partnerCallback` - A function of type `PartnerCallbackType`, which is also provided by the `@wf-financing/ui-sdk` package.
|
|
18
|
+
4. `companyToken` - The merchant identifier.
|
|
19
|
+
- **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.
|
|
20
|
+
|
|
21
|
+
```jsx
|
|
22
|
+
import { type IWayflyerUiCtaSdk, WayflyerUiSdk } from '@wf-financing/ui-sdk';
|
|
23
|
+
|
|
24
|
+
const wayflyerSdk = (await WayflyerUiSdk.loadSdk(targetId, partnerDesignId, partnerCallback, companyToken)) as IWayflyerUiCtaSdk;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## SDK methods
|
|
28
|
+
### `mountCta()`
|
|
29
|
+
This function mounts the CTA banner once it's called.
|
|
30
|
+
|
|
31
|
+
```jsx
|
|
32
|
+
wayflyerSdk.mountCta();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Mocked mode
|
|
36
|
+
To simplify the testing process, the SDK can be initialized in mock mode. To do so, pass a fifth argument of type `MockedModeType`.
|
|
37
|
+
In mock mode, the partner can manually set responses for SDK methods via the `sdkScenario` field in the optional `mockedMode` argument.
|
|
38
|
+
|
|
39
|
+
```jsx
|
|
40
|
+
import { WayflyerUiSdk, type MockedModeType, SdkScenarios } from '@wf-financing/ui-sdk';
|
|
41
|
+
|
|
42
|
+
const mockedModeNewApplication: MockedModeType = {
|
|
43
|
+
isMockedMode: true,
|
|
44
|
+
sdkScenario: SdkScenarios.INDICATIVE_NEW_APPLICATION,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const mockedModeNewApplication: MockedModeType = {
|
|
48
|
+
isMockedMode: true,
|
|
49
|
+
sdkScenario: SdkScenarios.GENERIC_NEW_APPLICATION,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const mockedModeContinueApplication: MockedModeType = {
|
|
53
|
+
isMockedMode: true,
|
|
54
|
+
sdkScenario: SdkScenarios.CONTINUE_APPLICATION,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const mockedModeNoCta: MockedModeType = {
|
|
58
|
+
isMockedMode: true,
|
|
59
|
+
sdkScenario: SdkScenarios.NO_CTA,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const wayflyerSdk = (await WayflyerUiSdk.loadSdk(targetId, partnerDesignId, partnerCallback, companyToken, mockedMode)) as IWayflyerUiCtaSdk;
|
|
63
|
+
```
|
|
64
|
+
After instantiation with the mockedMode parameter, the CTA banner will behave according to the specified scenario.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const WAYFLYER_UI_PACKAGE_ID = "wayflyer-ui-package";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UI_PACKAGE_URL = "https://unpkg.com/@wf-financing/ui@1/dist/index.es.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var l=(i=>(i.NO_CTA="no_cta",i.CONTINUE_APPLICATION="continue_application",i.GENERIC_NEW_APPLICATION="generic_new_application",i.INDICATIVE_NEW_APPLICATION="indicative_new_application",i))(l||{});const c="wayflyer-ui-package",w="https://unpkg.com/@wf-financing/ui@1/dist/index.es.js",s=(i,e,a,n,o)=>{if(!window.WayflyerUiCtaSdk)throw new Error("Failed to load WayflyerUiCtaSdk from the script.");const t=window.WayflyerUiCtaSdk;return new t(i,e,a,n,o)},d=(i,e,a,n,o,t)=>new Promise((r,y)=>{i.onload=()=>{try{r(s(e,a,n,o,t))}catch(S){y(S)}}}),f=async(i,e,a,n,o)=>{try{const t=document.getElementById(c);if(window.WayflyerUiCtaSdk)return s(i,e,a,n,o);if(t)return d(t,i,e,a,n,o);const r=document.createElement("script");return r.src=w,r.type="module",r.id=c,r.async=!0,document.head.appendChild(r),d(r,i,e,a,n,o)}catch(t){throw console.error("Error in loading headless SDK:",t),new Error("Failed to load script")}};class u{static async loadSdk(e,a,n,o,t){return await f(e,a,n,o,t)}}exports.SdkScenarios=l;exports.WayflyerUiSdk=u;
|
package/dist/index.d.ts
ADDED
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var w = /* @__PURE__ */ ((i) => (i.NO_CTA = "no_cta", i.CONTINUE_APPLICATION = "continue_application", i.GENERIC_NEW_APPLICATION = "generic_new_application", i.INDICATIVE_NEW_APPLICATION = "indicative_new_application", i))(w || {});
|
|
2
|
+
const c = "wayflyer-ui-package", S = "https://unpkg.com/@wf-financing/ui@1/dist/index.es.js", s = (i, e, a, n, o) => {
|
|
3
|
+
if (!window.WayflyerUiCtaSdk)
|
|
4
|
+
throw new Error("Failed to load WayflyerUiCtaSdk from the script.");
|
|
5
|
+
const t = window.WayflyerUiCtaSdk;
|
|
6
|
+
return new t(i, e, a, n, o);
|
|
7
|
+
}, d = (i, e, a, n, o, t) => new Promise((r, l) => {
|
|
8
|
+
i.onload = () => {
|
|
9
|
+
try {
|
|
10
|
+
r(s(e, a, n, o, t));
|
|
11
|
+
} catch (y) {
|
|
12
|
+
l(y);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}), f = async (i, e, a, n, o) => {
|
|
16
|
+
try {
|
|
17
|
+
const t = document.getElementById(c);
|
|
18
|
+
if (window.WayflyerUiCtaSdk)
|
|
19
|
+
return s(i, e, a, n, o);
|
|
20
|
+
if (t)
|
|
21
|
+
return d(
|
|
22
|
+
t,
|
|
23
|
+
i,
|
|
24
|
+
e,
|
|
25
|
+
a,
|
|
26
|
+
n,
|
|
27
|
+
o
|
|
28
|
+
);
|
|
29
|
+
const r = document.createElement("script");
|
|
30
|
+
return r.src = S, r.type = "module", r.id = c, r.async = !0, document.head.appendChild(r), d(r, i, e, a, n, o);
|
|
31
|
+
} catch (t) {
|
|
32
|
+
throw console.error("Error in loading headless SDK:", t), new Error("Failed to load script");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
class C {
|
|
36
|
+
static async loadSdk(e, a, n, o, t) {
|
|
37
|
+
return await f(e, a, n, o, t);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
w as SdkScenarios,
|
|
42
|
+
C as WayflyerUiSdk
|
|
43
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PartnerCallbackType, MockedModeType } from '@wf-financing/embedded-types';
|
|
2
|
+
|
|
3
|
+
export declare class WayflyerUiSdk {
|
|
4
|
+
static loadSdk(targetId: string, partnerDesignId: string, partnerCallback: PartnerCallbackType, companyToken: string, mockedMode?: MockedModeType): Promise<void | import('@wf-financing/embedded-types').IWayflyerUiCtaSdk>;
|
|
5
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loadUiSdkMode } from './loadSdkUiMode';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IWayflyerUiCtaSdk, PartnerCallbackType, MockedModeType } from '@wf-financing/embedded-types';
|
|
2
|
+
|
|
3
|
+
type LoadUiSdkModeType = (targetId: string, partnerDesignId: string, partnerCallback: PartnerCallbackType, companyToken: string, mockedMode?: MockedModeType) => Promise<IWayflyerUiCtaSdk | void>;
|
|
4
|
+
export declare const loadUiSdkMode: LoadUiSdkModeType;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IWayflyerUiCtaSdk, PartnerCallbackType, MockedModeType } from '@wf-financing/embedded-types';
|
|
2
|
+
|
|
3
|
+
export declare const initializeUiSdk: (targetId: string, partnerDesignId: string, partnerCallback: PartnerCallbackType, companyToken: string, mockedMode?: MockedModeType) => IWayflyerUiCtaSdk;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IWayflyerUiCtaSdk, PartnerCallbackType, MockedModeType } from '@wf-financing/embedded-types';
|
|
2
|
+
|
|
3
|
+
export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, targetId: string, partnerDesignId: string, partnerCallback: PartnerCallbackType, companyToken: string, isMockedMode?: MockedModeType) => Promise<IWayflyerUiCtaSdk>;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wf-financing/ui-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.cjs.js",
|
|
5
|
+
"module": "dist/index.es.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.es.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.cjs.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@wf-financing/embedded-types": "0.2.6"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"vite": "^6.3.5",
|
|
22
|
+
"vite-plugin-dts": "^3.4.0",
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"clean": "rm -rf dist",
|
|
30
|
+
"build": "vite build",
|
|
31
|
+
"prepare-sdk-cta": "pnpm clean && pnpm build && pnpm pack",
|
|
32
|
+
"publish-sdk-cta": "pnpm clean && pnpm build && pnpm publish --access public --no-git-checks",
|
|
33
|
+
"test": "vitest",
|
|
34
|
+
"test:coverage": "vitest --coverage"
|
|
35
|
+
}
|
|
36
|
+
}
|