@wf-financing/ui 4.7.0 → 4.7.1
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/.env.development +3 -1
- package/.env.production +2 -0
- package/CHANGELOG.md +9 -0
- package/dist/{ConsentModal-p-i_efvJ.mjs → ConsentModal-BpdP3szE.mjs} +2 -2
- package/dist/{Modal-P9Kk1lUG.mjs → Modal-BJQKZH91.mjs} +1 -1
- package/dist/{embedded-journey-panel.es-CbWFRFL6.mjs → embedded-journey-panel.es-1JDaJ255.mjs} +2 -2
- package/dist/{index-BN3wo8mJ.mjs → index-B6i2pWgP.mjs} +10880 -9319
- package/dist/index.es.js +1 -1
- package/global.d.ts +2 -0
- package/index.ts +2 -1
- package/package.json +2 -1
- package/src/api/getHeadlessSdkInstance.test.ts +31 -36
- package/src/api/getHeadlessSdkInstance.ts +12 -38
- package/src/config/index.ts +0 -2
- package/src/utils/index.ts +0 -2
- package/src/config/scriptId.ts +0 -1
- package/src/config/url.ts +0 -1
- package/src/utils/initializeHeadlessSdk.ts +0 -17
- package/src/utils/loadScriptAndInitializeSdk.ts +0 -19
package/dist/index.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import "./index-
|
|
1
|
+
import "./index-B6i2pWgP.mjs";
|
package/global.d.ts
CHANGED
package/index.ts
CHANGED
|
@@ -5,7 +5,8 @@ const addUiSdkToWindow = () => {
|
|
|
5
5
|
|
|
6
6
|
window.WayflyerUiSdk = WayflyerUiSdk;
|
|
7
7
|
/**
|
|
8
|
-
* Trigger event handler in entry point that notifies it that the SDK is ready to use.
|
|
8
|
+
* Trigger event handler in entry point that notifies it that the SDK is ready to use.
|
|
9
|
+
* See packages/ui-sdk-entry/utils/loadUiSdkScript.ts
|
|
9
10
|
*/
|
|
10
11
|
window.dispatchEvent(new CustomEvent(UI_SDK_READY_EVENT));
|
|
11
12
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wf-financing/ui",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./dist/index.es.js",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"react-markdown": "^10.1.0",
|
|
39
39
|
"styled-components": "^6.1.19",
|
|
40
40
|
"@wf-financing/embedded-types": "1.1.1",
|
|
41
|
+
"@wf-financing/headless": "3.3.3",
|
|
41
42
|
"@wf-financing/logger": "2.2.2",
|
|
42
43
|
"@wf-financing/ui-assets": "1.1.3",
|
|
43
44
|
"@wf-financing/embedded-journey": "0.2.0"
|
|
@@ -1,52 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
vi.
|
|
4
|
-
|
|
3
|
+
const mockSetCompanyToken = vi.fn();
|
|
4
|
+
const MockHeadlessSdk = vi.fn(() => ({
|
|
5
|
+
setCompanyToken: mockSetCompanyToken,
|
|
5
6
|
}));
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const fakeSdk = {
|
|
11
|
-
getCta: vi.fn(),
|
|
12
|
-
startHostedApplication: vi.fn(),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const options = {
|
|
16
|
-
isSandbox: true,
|
|
17
|
-
};
|
|
8
|
+
vi.mock('@wf-financing/headless/sdk', () => ({
|
|
9
|
+
HeadlessSdk: MockHeadlessSdk,
|
|
10
|
+
}));
|
|
18
11
|
|
|
19
|
-
describe('
|
|
20
|
-
|
|
12
|
+
describe('getHeadlessSdkInstance', () => {
|
|
13
|
+
beforeEach(() => {
|
|
21
14
|
vi.clearAllMocks();
|
|
15
|
+
vi.resetModules();
|
|
22
16
|
});
|
|
23
17
|
|
|
24
|
-
test('
|
|
25
|
-
const
|
|
26
|
-
const fakeNextUrl = '/next-url';
|
|
27
|
-
const partnerCallback = vi.fn().mockResolvedValue(fakePartnerData);
|
|
28
|
-
|
|
29
|
-
(getHeadlessSdkInstance as unknown as Mock).mockResolvedValueOnce(fakeSdk);
|
|
30
|
-
fakeSdk.startHostedApplication.mockResolvedValueOnce(fakeNextUrl);
|
|
18
|
+
test('creates a new HeadlessSdk instance on first call', async () => {
|
|
19
|
+
const { getHeadlessSdkInstance } = await import('./getHeadlessSdkInstance');
|
|
31
20
|
|
|
32
|
-
const
|
|
21
|
+
const sdk = await getHeadlessSdkInstance('TOKEN_1');
|
|
33
22
|
|
|
34
|
-
expect(
|
|
35
|
-
expect(
|
|
36
|
-
expect(fakeSdk.startHostedApplication).toHaveBeenCalledWith(fakePartnerData);
|
|
37
|
-
expect(result).toBe(fakeNextUrl);
|
|
23
|
+
expect(MockHeadlessSdk).toHaveBeenCalledWith('TOKEN_1', undefined);
|
|
24
|
+
expect(sdk).toEqual(expect.objectContaining({ setCompanyToken: expect.any(Function) }));
|
|
38
25
|
});
|
|
39
26
|
|
|
40
|
-
test('
|
|
41
|
-
const
|
|
42
|
-
const
|
|
27
|
+
test('creates a new HeadlessSdk instance with options', async () => {
|
|
28
|
+
const { getHeadlessSdkInstance } = await import('./getHeadlessSdkInstance');
|
|
29
|
+
const options = { isSandbox: true };
|
|
30
|
+
|
|
31
|
+
const sdk = await getHeadlessSdkInstance('TOKEN_1', options);
|
|
32
|
+
|
|
33
|
+
expect(MockHeadlessSdk).toHaveBeenCalledWith('TOKEN_1', options);
|
|
34
|
+
expect(sdk).toEqual(expect.objectContaining({ setCompanyToken: expect.any(Function) }));
|
|
35
|
+
});
|
|
43
36
|
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
test('returns cached instance and calls setCompanyToken on subsequent calls', async () => {
|
|
38
|
+
const { getHeadlessSdkInstance } = await import('./getHeadlessSdkInstance');
|
|
46
39
|
|
|
47
|
-
const
|
|
40
|
+
const firstSdk = await getHeadlessSdkInstance('TOKEN_1');
|
|
41
|
+
const secondSdk = await getHeadlessSdkInstance('TOKEN_2');
|
|
48
42
|
|
|
49
|
-
expect(
|
|
50
|
-
expect(
|
|
43
|
+
expect(MockHeadlessSdk).toHaveBeenCalledTimes(1);
|
|
44
|
+
expect(firstSdk).toBe(secondSdk);
|
|
45
|
+
expect(mockSetCompanyToken).toHaveBeenCalledWith('TOKEN_2');
|
|
51
46
|
});
|
|
52
47
|
});
|
|
@@ -1,43 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { Logger } from '@wf-financing/logger';
|
|
4
|
-
import { HEADLESS_SDK_URL, WAYFLYER_HEADLESS_SDK_ID } from '../config';
|
|
5
|
-
import { initializeHeadlessSdk, loadScriptAndInitializeSdk } from '../utils';
|
|
1
|
+
import { HeadlessSdk } from '@wf-financing/headless/sdk';
|
|
2
|
+
import type { IWayflyerHeadlessSdk, HeadlessSdkOptions } from '@wf-financing/embedded-types';
|
|
6
3
|
|
|
7
4
|
let cachedSdkInstance: IWayflyerHeadlessSdk | null = null;
|
|
8
5
|
|
|
9
|
-
export const getHeadlessSdkInstance = async (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const existingScript = document.getElementById(WAYFLYER_HEADLESS_SDK_ID) as HTMLScriptElement;
|
|
18
|
-
|
|
19
|
-
if (window.WayflyerHeadlessSdk) {
|
|
20
|
-
return initializeHeadlessSdk(companyToken, options);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (existingScript) {
|
|
24
|
-
return loadScriptAndInitializeSdk(existingScript, companyToken, options);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const script = document.createElement('script');
|
|
28
|
-
script.src = HEADLESS_SDK_URL;
|
|
29
|
-
script.type = 'module';
|
|
30
|
-
script.id = WAYFLYER_HEADLESS_SDK_ID;
|
|
31
|
-
script.async = true;
|
|
32
|
-
script.onerror = () => Logger.logError('Error in loading headless SDK script');
|
|
33
|
-
|
|
34
|
-
document.head.appendChild(script);
|
|
35
|
-
const headlessSdk: IWayflyerHeadlessSdk = await loadScriptAndInitializeSdk(script, companyToken, options);
|
|
36
|
-
cachedSdkInstance = headlessSdk;
|
|
37
|
-
|
|
38
|
-
return headlessSdk;
|
|
39
|
-
} catch {
|
|
40
|
-
Logger.logError('Error in loading headless SDK');
|
|
41
|
-
throw new Error('Failed to load script');
|
|
6
|
+
export const getHeadlessSdkInstance = async (
|
|
7
|
+
companyToken: string,
|
|
8
|
+
options?: HeadlessSdkOptions,
|
|
9
|
+
): Promise<IWayflyerHeadlessSdk> => {
|
|
10
|
+
if (cachedSdkInstance) {
|
|
11
|
+
cachedSdkInstance.setCompanyToken(companyToken);
|
|
12
|
+
return cachedSdkInstance;
|
|
42
13
|
}
|
|
14
|
+
|
|
15
|
+
cachedSdkInstance = new HeadlessSdk(companyToken, options);
|
|
16
|
+
return cachedSdkInstance;
|
|
43
17
|
};
|
package/src/config/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export { ROOTS_CONFIG } from './rootsParameters';
|
|
2
|
-
export { WAYFLYER_HEADLESS_SDK_ID } from './scriptId';
|
|
3
|
-
export { HEADLESS_SDK_URL } from './url';
|
|
4
2
|
export { APPLICATION_VERSION } from './applicationVersion';
|
|
5
3
|
export { IS_EMBEDDED_JOURNEY } from './isEmbeddedJourney';
|
package/src/utils/index.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export { applyStyles } from './applyStyles';
|
|
2
2
|
export { createRoots } from './createRoots';
|
|
3
3
|
export { getPartnerIdFromToken } from './getPartnerIdFromToken';
|
|
4
|
-
export { initializeHeadlessSdk } from './initializeHeadlessSdk';
|
|
5
|
-
export { loadScriptAndInitializeSdk } from './loadScriptAndInitializeSdk';
|
|
6
4
|
export { PartnerContext, type PartnerContextType } from './partnerContext';
|
|
7
5
|
export { replacePlaceholdersForMainText } from './replacePlaceholdersForMainText.ts';
|
|
8
6
|
export { getModalItems } from './getModalItems';
|
package/src/config/scriptId.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const WAYFLYER_HEADLESS_SDK_ID = 'wayflyer-headless-sdk';
|
package/src/config/url.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const HEADLESS_SDK_URL = 'https://embedded-finance-frontend.vercel.app/npm/@wf-financing/headless@3';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IWayflyerHeadlessSdk, HeadlessSdkOptions } from '@wf-financing/embedded-types';
|
|
2
|
-
|
|
3
|
-
export const initializeHeadlessSdk = (companyToken: string, options?: HeadlessSdkOptions): IWayflyerHeadlessSdk => {
|
|
4
|
-
if (!window.WayflyerHeadlessSdk) {
|
|
5
|
-
throw new Error('Failed to load WayflyerHeadlessSdk from the script.');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const WayflyerHeadlessSdk = window.WayflyerHeadlessSdk;
|
|
9
|
-
|
|
10
|
-
if (options) {
|
|
11
|
-
const wayflyerSdk = new WayflyerHeadlessSdk(companyToken, options);
|
|
12
|
-
|
|
13
|
-
return wayflyerSdk;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return new WayflyerHeadlessSdk(companyToken);
|
|
17
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { IWayflyerHeadlessSdk, HeadlessSdkOptions } from '@wf-financing/embedded-types';
|
|
2
|
-
|
|
3
|
-
import { initializeHeadlessSdk } from './initializeHeadlessSdk';
|
|
4
|
-
|
|
5
|
-
export const loadScriptAndInitializeSdk = (
|
|
6
|
-
script: HTMLScriptElement,
|
|
7
|
-
companyToken: string,
|
|
8
|
-
options?: HeadlessSdkOptions,
|
|
9
|
-
): Promise<IWayflyerHeadlessSdk> => {
|
|
10
|
-
return new Promise<IWayflyerHeadlessSdk>((resolve, reject) => {
|
|
11
|
-
script.onload = () => {
|
|
12
|
-
try {
|
|
13
|
-
resolve(initializeHeadlessSdk(companyToken, options));
|
|
14
|
-
} catch (error) {
|
|
15
|
-
reject(error);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
};
|