@wf-financing/ui-sdk 0.1.2 → 1.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 +10 -10
- package/dist/config/url.d.ts +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.es.js +20 -29
- 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 +2 -2
package/README.md
CHANGED
|
@@ -4,28 +4,27 @@ Wayflyer provides a `@wf-financing/ui-sdk` package that can be used as a client-
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
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.
|
|
7
|
+
Install the package directly from NPM with `npm install @wf-financing/ui-sdk`. 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
8
|
|
|
10
9
|
## Instantiation
|
|
11
10
|
|
|
12
11
|
To initialize `WayflyerUiSdk`, call the static method `loadSdk` with the following parameters:
|
|
13
12
|
|
|
14
13
|
1. `targetId` - The DOM element's ID where the CTA is supposed to be mounted.
|
|
15
|
-
2. `
|
|
16
|
-
|
|
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.
|
|
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.
|
|
19
16
|
- **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
17
|
|
|
21
18
|
```jsx
|
|
22
19
|
import { type IWayflyerUiCtaSdk, WayflyerUiSdk } from '@wf-financing/ui-sdk';
|
|
23
20
|
|
|
24
|
-
const wayflyerSdk = (await WayflyerUiSdk.loadSdk(targetId,
|
|
21
|
+
const wayflyerSdk = (await WayflyerUiSdk.loadSdk(targetId, partnerCallback, companyToken)) as IWayflyerUiCtaSdk;
|
|
25
22
|
```
|
|
26
23
|
|
|
27
24
|
## SDK methods
|
|
25
|
+
|
|
28
26
|
### `mountCta()`
|
|
27
|
+
|
|
29
28
|
This function mounts the CTA banner once it's called.
|
|
30
29
|
|
|
31
30
|
```jsx
|
|
@@ -33,8 +32,8 @@ wayflyerSdk.mountCta();
|
|
|
33
32
|
```
|
|
34
33
|
|
|
35
34
|
## Mocked mode
|
|
36
|
-
|
|
37
|
-
In mock mode, the partner can manually set responses for SDK methods via the `sdkScenario` field in the optional `mockedMode` argument.
|
|
35
|
+
|
|
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.
|
|
38
37
|
|
|
39
38
|
```jsx
|
|
40
39
|
import { WayflyerUiSdk, type MockedModeType, SdkScenarios } from '@wf-financing/ui-sdk';
|
|
@@ -59,6 +58,7 @@ const mockedModeNoCta: MockedModeType = {
|
|
|
59
58
|
sdkScenario: SdkScenarios.NO_CTA,
|
|
60
59
|
};
|
|
61
60
|
|
|
62
|
-
const wayflyerSdk = (await WayflyerUiSdk.loadSdk(targetId,
|
|
61
|
+
const wayflyerSdk = (await WayflyerUiSdk.loadSdk(targetId, partnerCallback, companyToken, mockedMode)) as IWayflyerUiCtaSdk;
|
|
63
62
|
```
|
|
63
|
+
|
|
64
64
|
After instantiation with the mockedMode parameter, the CTA banner will behave according to the specified scenario.
|
package/dist/config/url.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const UI_PACKAGE_URL = "https://
|
|
1
|
+
export declare const UI_PACKAGE_URL = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@2";
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
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;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export type { IWayflyerUiCtaSdk, PartnerCallbackType,
|
|
2
|
-
export { SdkScenarios } from '@wf-financing/embedded-types';
|
|
1
|
+
export type { IWayflyerUiCtaSdk, PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
|
|
3
2
|
export { WayflyerUiSdk } from './sdk';
|
package/dist/index.es.js
CHANGED
|
@@ -1,43 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
const c = "wayflyer-ui-package", S = "https://unpkg.com/@wf-financing/ui@1/dist/index.es.js", s = (i, e, a, n, o) => {
|
|
1
|
+
const a = "wayflyer-ui-package", s = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@2", c = (n, t, i, d) => {
|
|
3
2
|
if (!window.WayflyerUiCtaSdk)
|
|
4
3
|
throw new Error("Failed to load WayflyerUiCtaSdk from the script.");
|
|
5
|
-
const
|
|
6
|
-
return new
|
|
7
|
-
},
|
|
8
|
-
|
|
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 = () => {
|
|
9
8
|
try {
|
|
10
|
-
r(
|
|
11
|
-
} catch (
|
|
12
|
-
l
|
|
9
|
+
r(c(t, i, d, e));
|
|
10
|
+
} catch (l) {
|
|
11
|
+
y(l);
|
|
13
12
|
}
|
|
14
13
|
};
|
|
15
|
-
}), f = async (
|
|
14
|
+
}), f = async (n, t, i, d) => {
|
|
16
15
|
try {
|
|
17
|
-
const
|
|
16
|
+
const e = document.getElementById(a);
|
|
18
17
|
if (window.WayflyerUiCtaSdk)
|
|
19
|
-
return
|
|
20
|
-
if (
|
|
21
|
-
return d
|
|
22
|
-
t,
|
|
23
|
-
i,
|
|
24
|
-
e,
|
|
25
|
-
a,
|
|
26
|
-
n,
|
|
27
|
-
o
|
|
28
|
-
);
|
|
18
|
+
return c(n, t, i, d);
|
|
19
|
+
if (e)
|
|
20
|
+
return o(e, n, t, i, d);
|
|
29
21
|
const r = document.createElement("script");
|
|
30
|
-
return r.src =
|
|
31
|
-
} catch (
|
|
32
|
-
throw console.error("Error in loading headless SDK:",
|
|
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");
|
|
33
25
|
}
|
|
34
26
|
};
|
|
35
|
-
class
|
|
36
|
-
static async loadSdk(
|
|
37
|
-
return await f(
|
|
27
|
+
class w {
|
|
28
|
+
static async loadSdk(t, i, d, e) {
|
|
29
|
+
return await f(t, i, d, e);
|
|
38
30
|
}
|
|
39
31
|
}
|
|
40
32
|
export {
|
|
41
|
-
w as
|
|
42
|
-
C as WayflyerUiSdk
|
|
33
|
+
w as WayflyerUiSdk
|
|
43
34
|
};
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PartnerCallbackType,
|
|
1
|
+
import { PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
3
|
export declare class WayflyerUiSdk {
|
|
4
|
-
static loadSdk(targetId: string,
|
|
4
|
+
static loadSdk(targetId: string, partnerCallback: PartnerCallbackType, companyToken: string, options?: SdkOptionsType): Promise<void | import('@wf-financing/embedded-types').IWayflyerUiCtaSdk>;
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IWayflyerUiCtaSdk, PartnerCallbackType,
|
|
1
|
+
import { IWayflyerUiCtaSdk, PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
type LoadUiSdkModeType = (targetId: string,
|
|
3
|
+
type LoadUiSdkModeType = (targetId: string, partnerCallback: PartnerCallbackType, companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerUiCtaSdk | void>;
|
|
4
4
|
export declare const loadUiSdkMode: LoadUiSdkModeType;
|
|
5
5
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IWayflyerUiCtaSdk,
|
|
1
|
+
import { IWayflyerUiCtaSdk, SdkOptionsType, PartnerCallbackType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
export declare const initializeUiSdk: (targetId: string,
|
|
3
|
+
export declare const initializeUiSdk: (targetId: string, partnerCallback: PartnerCallbackType, companyToken: string, options?: SdkOptionsType) => IWayflyerUiCtaSdk;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IWayflyerUiCtaSdk, PartnerCallbackType,
|
|
1
|
+
import { IWayflyerUiCtaSdk, PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, targetId: string,
|
|
3
|
+
export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, targetId: string, partnerCallback: PartnerCallbackType, companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerUiCtaSdk>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wf-financing/ui-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.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.
|
|
18
|
+
"@wf-financing/embedded-types": "0.4.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"vite": "^6.3.5",
|