@wf-financing/headless-sdk 2.0.0 → 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
|
@@ -4,15 +4,20 @@ Wayflyer provides a `@wf-financing/headless-sdk` package that can be used as a c
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
Install the package directly from NPM with `npm install @wf-financing/headless-sdk`.
|
|
7
|
-
To minimize bundle size and reduce the impact on partners' page load times, the SDK uses dynamic imports to load main
|
|
7
|
+
To minimize bundle size and reduce the impact on partners' page load times, the SDK uses dynamic imports to load the main functionality.
|
|
8
8
|
|
|
9
9
|
## Instantiation
|
|
10
|
-
Initialize the Wayflyer headless SDK by passing the `companyToken` and a
|
|
10
|
+
Initialize the Wayflyer headless SDK by passing the `companyToken` and an optional `options` object with a type of `SdkOptionsType` that specifies additional functionality of SDK instance - e.g. consuming sandbox API instead of the production.
|
|
11
11
|
|
|
12
12
|
```jsx
|
|
13
|
-
import {
|
|
13
|
+
import { WayflyerHeadlessSdk, SdkOptionsType } from '@wf-financing/headless-sdk';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// instantiation in production mode
|
|
16
|
+
const wayflyerHeadlessSdk = await WayflyerHeadlessSdk.loadSdk(companyToken);
|
|
17
|
+
|
|
18
|
+
// instantiation in sandbox mode, `options` type of SdkOptionsType
|
|
19
|
+
const options: SdkOptionsType = { isSandbox: true };
|
|
20
|
+
const wayflyerHeadlessSdk = await WayflyerHeadlessSdk.loadSdk(companyToken, options);
|
|
16
21
|
```
|
|
17
22
|
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.
|
|
18
23
|
|
|
@@ -47,71 +52,19 @@ Returns a URL to the Wayflyer landing page after the submission of the merchant
|
|
|
47
52
|
```jsx
|
|
48
53
|
import type { ContinueHostedApplicationResponseType } from '@wf-financing/headless-sdk';
|
|
49
54
|
|
|
50
|
-
const startHostedApplication: ContinueHostedApplicationResponseType = await wayflyerSdk.
|
|
55
|
+
const startHostedApplication: ContinueHostedApplicationResponseType = await wayflyerSdk.continueHostedApplication();
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
##
|
|
54
|
-
To simplify the testing process, the SDK can be initialized in mock mode. To do so, pass a second argument with the value `true`.
|
|
55
|
-
|
|
56
|
-
```jsx
|
|
57
|
-
import { WayflyerHeadlessCtaSdk } from '@wf-financing/headless-sdk';
|
|
58
|
-
|
|
59
|
-
const wayflyerSdk = (await WayflyerHeadlessCtaSdk.loadSdk('token', true)) as IHeadlessWayflyerSdk;
|
|
60
|
-
```
|
|
61
|
-
In mock mode, partner can manually set responses for SDK methods via additional methods:
|
|
62
|
-
1. `setCtaResponse(responseType: CtaResponseTypes)`
|
|
63
|
-
2. `setStartHostedApplicationResponse(responseType: StartHostedApplicationResponseTypes)`
|
|
64
|
-
3. `setContinueHostedApplicationResponse(responseType: ContinueHostedApplicationResponseTypes)`
|
|
65
|
-
4. `setSdkScenario(sdkScenario: SdkScenarios)`
|
|
58
|
+
## Sandbox
|
|
66
59
|
|
|
67
|
-
|
|
68
|
-
Sets a mocked response for the `getCta()` method.
|
|
60
|
+
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 additional package `@wf-financing/sandbox-ui`.
|
|
69
61
|
|
|
70
62
|
```jsx
|
|
71
|
-
import {
|
|
63
|
+
import { WayflyerHeadlessSdk, SdkOptionsType } from '@wf-financing/headless-sdk';
|
|
72
64
|
|
|
73
|
-
|
|
74
|
-
wayflyerSdk.
|
|
75
|
-
wayflyerSdk.setCtaResponse(CtaResponseTypes.CONTINUE_HOSTED_APPLICATION);
|
|
76
|
-
wayflyerSdk.setCtaResponse(CtaResponseTypes.NO_CTA);
|
|
77
|
-
wayflyerSdk.setCtaResponse(CtaResponseTypes.INVALID_TOKEN);
|
|
65
|
+
const options: SdkOptionsType = { isSandbox: true };
|
|
66
|
+
const wayflyerSdk = await WayflyerHeadlessSdk.loadSdk(companyToken, options);
|
|
78
67
|
```
|
|
79
68
|
|
|
80
|
-
### `setCtaResponse(responseType: CtaResponseTypes)`
|
|
81
|
-
Sets a mocked response for the `startHostedApplication(applicationRequest: StartHostedApplicationRequestType)` method.
|
|
82
|
-
|
|
83
|
-
```jsx
|
|
84
|
-
import { StartHostedApplicationResponseTypes } from '@wf-financing/headless-sdk';
|
|
85
|
-
|
|
86
|
-
wayflyerSdk.setStartHostedApplicationResponse(StartHostedApplicationResponseTypes.REDIRECT_URL);
|
|
87
|
-
wayflyerSdk.setStartHostedApplicationResponse(StartHostedApplicationResponseTypes.BAD_REQUEST);
|
|
88
|
-
wayflyerSdk.setStartHostedApplicationResponse(StartHostedApplicationResponseTypes.INVALID_TOKEN);
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### `setContinueHostedApplicationResponse(responseType: ContinueHostedApplicationResponseTypes)`
|
|
92
|
-
Sets a mocked response for the `continueHostedApplication()` method.
|
|
93
|
-
|
|
94
|
-
```jsx
|
|
95
|
-
import { ContinueHostedApplicationResponseTypes } from '@wf-financing/headless-sdk';
|
|
96
|
-
|
|
97
|
-
wayflyerSdk.setContinueHostedApplicationResponse(ContinueHostedApplicationResponseTypes.REDIRECT_URL);
|
|
98
|
-
wayflyerSdk.setContinueHostedApplicationResponse(ContinueHostedApplicationResponseTypes.BAD_REQUEST);
|
|
99
|
-
wayflyerSdk.setContinueHostedApplicationResponse(ContinueHostedApplicationResponseTypes.INVALID_TOKEN);
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### `setSdkScenario(sdkScenario: SdkScenarios)`
|
|
103
|
-
Provides complex mocked scenarios for complete E2E testing. This ensures that partners do not encounter incompatible responses for different methods, such as `startHostedApplication(applicationRequest: StartHostedApplicationRequestType)` and `continueHostedApplication()`, which cannot return valid responses at the same time.
|
|
104
|
-
|
|
105
|
-
```jsx
|
|
106
|
-
import { SdkScenarios } from '@wf-financing/headless-sdk';
|
|
107
|
-
|
|
108
|
-
wayflyerSdk.setSdkScenario(SdkScenarios.INDICATIVE_NEW_APPLICATION);
|
|
109
|
-
wayflyerSdk.setSdkScenario(SdkScenarios.GENERIC_NEW_APPLICATION);
|
|
110
|
-
wayflyerSdk.setSdkScenario(SdkScenarios.CONTINUE_APPLICATION);
|
|
111
|
-
wayflyerSdk.setSdkScenario(SdkScenarios.NO_CTA);
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Note: After calling `setSdkScenario(sdkScenario: SdkScenarios)`, other methods for setting manual responses will no longer have any effect.
|
|
115
|
-
|
|
116
69
|
## Next Steps
|
|
117
70
|
For further details on using the SDK, troubleshooting, or expanding on these examples, check out our [full documentation](https://docs.wayflyer.com/).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ContinueHostedApplicationResponseTypes, CtaResponseTypes, CtaStateType, StartHostedApplicationResponseTypes, } from '@wf-financing/embedded-types';
|
|
2
|
-
export type { CanadianProvinceCode, CompanyDataType, ContinueHostedApplicationResponseType, CountryCode, CtaContinueFundingType, CtaGenericOfferType, CtaIndicativeOfferType, CtaResponseType,
|
|
2
|
+
export type { CanadianProvinceCode, CompanyDataType, ContinueHostedApplicationResponseType, CountryCode, CtaContinueFundingType, CtaGenericOfferType, CtaIndicativeOfferType, CtaResponseType, IWayflyerHeadlessSdk, StartHostedApplicationRequestType, StartHostedApplicationResponseType, UserDataType, USStateCode, SdkOptionsType, } from '@wf-financing/embedded-types';
|
|
3
3
|
export { WayflyerHeadlessSdk } from './sdk';
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SdkOptionsType } from '@wf-financing/embedded-types';
|
|
1
|
+
import { SdkOptionsType, IWayflyerHeadlessSdk } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
3
|
export declare class WayflyerHeadlessSdk {
|
|
4
|
-
static loadSdk(companyToken: string, options?: SdkOptionsType): Promise<
|
|
4
|
+
static loadSdk(companyToken: string, options?: SdkOptionsType): Promise<IWayflyerHeadlessSdk>;
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IWayflyerHeadlessSdk, SdkOptionsType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
type LoadHeadlessSdkModeType = (companyToken: string, options?: SdkOptionsType) => Promise<
|
|
3
|
+
type LoadHeadlessSdkModeType = (companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerHeadlessSdk | void>;
|
|
4
4
|
export declare const loadHeadlessSdkMode: LoadHeadlessSdkModeType;
|
|
5
5
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IWayflyerHeadlessSdk, SdkOptionsType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
export declare const initializeHeadlessSdk: (companyToken: string, options?: SdkOptionsType) =>
|
|
3
|
+
export declare const initializeHeadlessSdk: (companyToken: string, options?: SdkOptionsType) => IWayflyerHeadlessSdk;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IWayflyerHeadlessSdk, SdkOptionsType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, companyToken: string, options?: SdkOptionsType) => Promise<
|
|
3
|
+
export declare const loadScriptAndInitializeSdk: (script: HTMLScriptElement, companyToken: string, options?: SdkOptionsType) => Promise<IWayflyerHeadlessSdk>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wf-financing/headless-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,7 +15,7 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@wf-financing/embedded-types": "0.4.
|
|
18
|
+
"@wf-financing/embedded-types": "0.4.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"vite": "^6.3.5",
|