@wf-financing/ui 4.7.0 → 4.7.2
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 +15 -0
- package/dist/index.es.js +36065 -1
- package/global.d.ts +2 -0
- package/index.ts +2 -1
- package/package.json +2 -1
- package/src/CtaWidget.tsx +6 -22
- 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/dist/ConsentModal-p-i_efvJ.mjs +0 -7186
- package/dist/Modal-P9Kk1lUG.mjs +0 -2561
- package/dist/embedded-journey-panel.es-CbWFRFL6.mjs +0 -3569
- package/dist/index-BN3wo8mJ.mjs +0 -24984
- 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/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.2",
|
|
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"
|
package/src/CtaWidget.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useState
|
|
1
|
+
import { useState } from 'react';
|
|
2
2
|
import type { CtaResponseType, ContinueHostedApplicationResponseType } from '@wf-financing/embedded-types';
|
|
3
3
|
import type { Copy } from '@wf-financing/ui-assets';
|
|
4
4
|
|
|
5
5
|
import { CtaBanner } from './components/banner/CtaBanner';
|
|
6
6
|
import { buildCtaUiProps } from './utils';
|
|
7
|
-
import { useContinueHostedApplication, useNotificationOnRender
|
|
8
|
-
import
|
|
7
|
+
import { useContinueHostedApplication, useNotificationOnRender } from './hooks';
|
|
8
|
+
import ConsentModal from './components/modal/ConsentModal.tsx';
|
|
9
9
|
|
|
10
10
|
type CtaWidgetProps = {
|
|
11
11
|
cta: Exclude<CtaResponseType, null>;
|
|
@@ -13,14 +13,10 @@ type CtaWidgetProps = {
|
|
|
13
13
|
skipAnimation: boolean;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const EmbeddedJourneyPanel = lazy(() => import('@wf-financing/embedded-journey/embedded-journey-panel'));
|
|
17
|
-
const ConsentModal = lazy(() => import('./components/modal/ConsentModal'));
|
|
18
|
-
|
|
19
16
|
export const CtaWidget = ({ cta, copy, skipAnimation }: CtaWidgetProps) => {
|
|
20
17
|
const [isWidgetOpen, setIsWidgetOpen] = useState(false);
|
|
21
18
|
const { mutate: continueHostedApplicationMutation } = useContinueHostedApplication();
|
|
22
19
|
const sendNotification = useNotificationOnRender();
|
|
23
|
-
const { portalContainer } = usePartnerContext();
|
|
24
20
|
|
|
25
21
|
const toggleIsWidgetOpen = () => setIsWidgetOpen((isOpen) => !isOpen);
|
|
26
22
|
const handleContinueHostedApplication = () => {
|
|
@@ -44,24 +40,12 @@ export const CtaWidget = ({ cta, copy, skipAnimation }: CtaWidgetProps) => {
|
|
|
44
40
|
|
|
45
41
|
sendNotification(cta, bannerProps);
|
|
46
42
|
|
|
47
|
-
const embeddedJourneyPanelProps: ComponentProps<typeof EmbeddedJourneyPanel> = {
|
|
48
|
-
portalContainer,
|
|
49
|
-
isOpen: isWidgetOpen,
|
|
50
|
-
closePanel: () => toggleIsWidgetOpen(),
|
|
51
|
-
};
|
|
52
|
-
|
|
53
43
|
return (
|
|
54
44
|
<>
|
|
55
45
|
<CtaBanner skipAnimation={skipAnimation} {...bannerProps} />
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
) : (
|
|
60
|
-
consentModalProps && (
|
|
61
|
-
<ConsentModal {...consentModalProps} {...partnerTemplateProps} isModalOpen={isWidgetOpen} />
|
|
62
|
-
)
|
|
63
|
-
)}
|
|
64
|
-
</Suspense>
|
|
46
|
+
{consentModalProps && (
|
|
47
|
+
<ConsentModal {...consentModalProps} {...partnerTemplateProps} isModalOpen={isWidgetOpen} />
|
|
48
|
+
)}
|
|
65
49
|
</>
|
|
66
50
|
);
|
|
67
51
|
};
|
|
@@ -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';
|