@incodetech/web 2.0.0-alpha.2 → 2.0.0-alpha.4
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/dist/{styles/core.css → base.css} +53 -57
- package/dist/email/email.es.js +1 -1
- package/dist/email/styles.css +11 -11
- package/dist/flow/styles.css +688 -1
- package/dist/{incodeModule-BF5MX9GT.js → incodeModule-Ct9jp5k6.js} +22 -19
- package/dist/index.es.js +18 -18
- package/dist/phone/phone.es.js +1 -1
- package/dist/phone/styles.css +31 -31
- package/dist/selfie/selfie.es.js +16 -16
- package/dist/selfie/styles.css +0 -51
- package/dist/themes/dark.css +652 -0
- package/dist/types/dark.d.ts +1 -0
- package/dist/types/light.d.ts +1 -0
- package/dist/types/themes/light.d.ts +1 -0
- package/package.json +12 -6
- package/.turbo/turbo-build.log +0 -58
- package/.turbo/turbo-coverage.log +0 -23
- package/.turbo/turbo-format.log +0 -6
- package/.turbo/turbo-lint$colon$fix.log +0 -6
- package/.turbo/turbo-lint.log +0 -6
- package/.turbo/turbo-test.log +0 -1033
- package/.turbo/turbo-typecheck.log +0 -5
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/email/email.tsx.html +0 -850
- package/coverage/email/emailInput.tsx.html +0 -340
- package/coverage/email/index.html +0 -131
- package/coverage/favicon.png +0 -0
- package/coverage/flow/flow.tsx.html +0 -961
- package/coverage/flow/flowCompleted.tsx.html +0 -448
- package/coverage/flow/flowInit.ts.html +0 -367
- package/coverage/flow/flowStart.tsx.html +0 -208
- package/coverage/flow/index.html +0 -221
- package/coverage/flow/preloadFlow.ts.html +0 -598
- package/coverage/flow/unsupportedModule.tsx.html +0 -202
- package/coverage/flow/useFlowInitialization.ts.html +0 -469
- package/coverage/flow/useModuleLoader.ts.html +0 -361
- package/coverage/hooks/index.html +0 -116
- package/coverage/hooks/useManager.ts.html +0 -205
- package/coverage/index.html +0 -401
- package/coverage/permissions/boldWithArrow.tsx.html +0 -208
- package/coverage/permissions/denied.tsx.html +0 -172
- package/coverage/permissions/deniedAndroid.tsx.html +0 -253
- package/coverage/permissions/deniedDesktop.tsx.html +0 -277
- package/coverage/permissions/deniedIOS.tsx.html +0 -304
- package/coverage/permissions/deniedInstructions.tsx.html +0 -142
- package/coverage/permissions/iconWrapper.tsx.html +0 -130
- package/coverage/permissions/index.html +0 -251
- package/coverage/permissions/learnMore.tsx.html +0 -340
- package/coverage/permissions/numberedStep.tsx.html +0 -127
- package/coverage/permissions/permissions.tsx.html +0 -289
- package/coverage/phone/index.html +0 -116
- package/coverage/phone/phoneInput.tsx.html +0 -832
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/selfie/index.html +0 -131
- package/coverage/selfie/selfie.tsx.html +0 -334
- package/coverage/selfie/tutorial.tsx.html +0 -214
- package/coverage/shared/baseTutorial/baseTutorial.tsx.html +0 -250
- package/coverage/shared/baseTutorial/index.html +0 -131
- package/coverage/shared/baseTutorial/replaceBaseTutorial.ts.html +0 -289
- package/coverage/shared/button/button.tsx.html +0 -226
- package/coverage/shared/button/index.html +0 -116
- package/coverage/shared/componentRoot/incodeComponent.tsx.html +0 -121
- package/coverage/shared/componentRoot/index.html +0 -116
- package/coverage/shared/countries/countries.ts.html +0 -502
- package/coverage/shared/countries/index.html +0 -116
- package/coverage/shared/icons/chevronDown.tsx.html +0 -151
- package/coverage/shared/icons/index.html +0 -131
- package/coverage/shared/icons/successIcon.tsx.html +0 -163
- package/coverage/shared/loader/index.html +0 -116
- package/coverage/shared/loader/loadingIcon.tsx.html +0 -286
- package/coverage/shared/otpInput/index.html +0 -116
- package/coverage/shared/otpInput/otpInput.tsx.html +0 -808
- package/coverage/shared/page/index.html +0 -146
- package/coverage/shared/page/page.tsx.html +0 -358
- package/coverage/shared/page/pageUiConfig.ts.html +0 -277
- package/coverage/shared/page/verifiedByIncode.tsx.html +0 -310
- package/coverage/shared/spacer/index.html +0 -116
- package/coverage/shared/spacer/spacer.tsx.html +0 -349
- package/coverage/shared/spinner/index.html +0 -116
- package/coverage/shared/spinner/spinner.tsx.html +0 -280
- package/coverage/shared/title/index.html +0 -116
- package/coverage/shared/title/title.tsx.html +0 -121
- package/coverage/shared/uiConfig/index.html +0 -116
- package/coverage/shared/uiConfig/uiConfig.ts.html +0 -193
- package/coverage/shared/webComponent/incodeModule.ts.html +0 -172
- package/coverage/shared/webComponent/index.html +0 -131
- package/coverage/shared/webComponent/registerIncodeElement.ts.html +0 -130
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/coverage/styles/cn.tsx.html +0 -148
- package/coverage/styles/fetchTheme.ts.html +0 -349
- package/coverage/styles/index.html +0 -131
- package/dev/README.md +0 -163
- package/dev/getToken.ts +0 -36
- package/dev/headless.html +0 -875
- package/dev/index.html +0 -366
- package/dev/main-headless.tsx +0 -1332
- package/dev/main-orchestrated-flow.tsx +0 -1158
- package/dev/main-preact.tsx +0 -323
- package/dev/main-simplified.tsx +0 -123
- package/dev/main-web-component.tsx +0 -256
- package/dev/main.tsx +0 -332
- package/dev/manual.html +0 -27
- package/dev/orchestrated-flow.html +0 -64
- package/dev/simplified.html +0 -64
- package/dev/tiktok-logo.svg +0 -7
- package/dist/asset-manifest.json +0 -18
- package/src/defineCustomElement.tsx +0 -30
- package/src/email/email.test.tsx +0 -368
- package/src/email/email.tsx +0 -255
- package/src/email/emailInput.test.tsx +0 -264
- package/src/email/emailInput.tsx +0 -85
- package/src/email/styles.css +0 -59
- package/src/flow/flow.test.tsx +0 -796
- package/src/flow/flow.tsx +0 -292
- package/src/flow/flowCompleted.css +0 -30
- package/src/flow/flowCompleted.test.tsx +0 -331
- package/src/flow/flowCompleted.tsx +0 -121
- package/src/flow/flowInit.test.ts +0 -264
- package/src/flow/flowInit.ts +0 -94
- package/src/flow/flowStart.css +0 -58
- package/src/flow/flowStart.test.tsx +0 -49
- package/src/flow/flowStart.tsx +0 -41
- package/src/flow/incode-logo.svg +0 -8
- package/src/flow/index.ts +0 -7
- package/src/flow/preloadFlow.test.ts +0 -421
- package/src/flow/preloadFlow.ts +0 -171
- package/src/flow/styles.css +0 -9
- package/src/flow/unsupportedModule.css +0 -21
- package/src/flow/unsupportedModule.tsx +0 -39
- package/src/flow/useFlowInitialization.test.tsx +0 -292
- package/src/flow/useFlowInitialization.ts +0 -128
- package/src/flow/useModuleLoader.test.tsx +0 -212
- package/src/flow/useModuleLoader.ts +0 -92
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useManager.test.ts +0 -91
- package/src/hooks/useManager.ts +0 -40
- package/src/i18n/index.ts +0 -3
- package/src/i18n/instance.ts +0 -16
- package/src/i18n/setup.ts +0 -184
- package/src/i18n/useTranslation.ts +0 -42
- package/src/index.ts +0 -27
- package/src/permissions/assets/android-dots-icon.svg +0 -7
- package/src/permissions/assets/android-settings-icon.svg +0 -16
- package/src/permissions/assets/android-toggle-icon.svg +0 -20
- package/src/permissions/assets/bank-card-icon.svg +0 -14
- package/src/permissions/assets/camera-icon.svg +0 -12
- package/src/permissions/assets/camera-ios.svg +0 -53
- package/src/permissions/assets/check-icon.svg +0 -8
- package/src/permissions/assets/chrome-icon.svg +0 -43
- package/src/permissions/assets/password-icon.svg +0 -11
- package/src/permissions/assets/permissions-img.svg +0 -51
- package/src/permissions/assets/safari-icon.svg +0 -37
- package/src/permissions/assets/settings-icon.svg +0 -33
- package/src/permissions/assets/toggle-icon.svg +0 -19
- package/src/permissions/assets/warning-icon.svg +0 -6
- package/src/permissions/boldWithArrow.css +0 -9
- package/src/permissions/boldWithArrow.tsx +0 -41
- package/src/permissions/denied.css +0 -37
- package/src/permissions/denied.tsx +0 -29
- package/src/permissions/deniedAndroid.tsx +0 -56
- package/src/permissions/deniedDesktop.css +0 -9
- package/src/permissions/deniedDesktop.tsx +0 -64
- package/src/permissions/deniedIOS.tsx +0 -73
- package/src/permissions/deniedInstructions.tsx +0 -19
- package/src/permissions/iconWrapper.css +0 -9
- package/src/permissions/iconWrapper.tsx +0 -15
- package/src/permissions/learnMore.css +0 -37
- package/src/permissions/learnMore.tsx +0 -85
- package/src/permissions/numberedStep.css +0 -13
- package/src/permissions/numberedStep.tsx +0 -14
- package/src/permissions/permissions.css +0 -13
- package/src/permissions/permissions.tsx +0 -68
- package/src/phone/phone.tsx +0 -246
- package/src/phone/phoneInput.test.tsx +0 -275
- package/src/phone/phoneInput.tsx +0 -249
- package/src/phone/styles.css +0 -158
- package/src/selfie/cameraButton.css +0 -13
- package/src/selfie/cameraButton.tsx +0 -35
- package/src/selfie/capture.css +0 -57
- package/src/selfie/capture.tsx +0 -232
- package/src/selfie/errorModal.tsx +0 -218
- package/src/selfie/errorModalContent.css +0 -33
- package/src/selfie/errorModalContent.tsx +0 -44
- package/src/selfie/faceOutline.css +0 -5
- package/src/selfie/faceOutline.tsx +0 -22
- package/src/selfie/loadingBorder.css +0 -12
- package/src/selfie/loadingBorder.tsx +0 -77
- package/src/selfie/manualCaptureButton.css +0 -13
- package/src/selfie/manualCaptureButton.tsx +0 -35
- package/src/selfie/noMoreAttemptsModal.tsx +0 -44
- package/src/selfie/notification.css +0 -9
- package/src/selfie/notification.tsx +0 -36
- package/src/selfie/retryErrorModal.tsx +0 -56
- package/src/selfie/selfie.test.tsx +0 -458
- package/src/selfie/selfie.tsx +0 -83
- package/src/selfie/selfieTutorial.json +0 -2626
- package/src/selfie/styles.css +0 -1
- package/src/selfie/tutorial.test.tsx +0 -200
- package/src/selfie/tutorial.tsx +0 -43
- package/src/setup.ts +0 -33
- package/src/shared/baseTutorial/baseTutorial.css +0 -21
- package/src/shared/baseTutorial/baseTutorial.test.tsx +0 -184
- package/src/shared/baseTutorial/baseTutorial.tsx +0 -55
- package/src/shared/baseTutorial/replaceBaseTutorial.test.ts +0 -267
- package/src/shared/baseTutorial/replaceBaseTutorial.ts +0 -68
- package/src/shared/button/button.css +0 -55
- package/src/shared/button/button.test.tsx +0 -101
- package/src/shared/button/button.tsx +0 -47
- package/src/shared/componentRoot/incodeComponent.tsx +0 -12
- package/src/shared/countries/countries.test.ts +0 -75
- package/src/shared/countries/countries.ts +0 -139
- package/src/shared/countries/index.ts +0 -6
- package/src/shared/icons/chevronDown.tsx +0 -22
- package/src/shared/icons/index.ts +0 -2
- package/src/shared/icons/successIcon.css +0 -5
- package/src/shared/icons/successIcon.test.tsx +0 -40
- package/src/shared/icons/successIcon.tsx +0 -26
- package/src/shared/loader/loadingIcon.css +0 -28
- package/src/shared/loader/loadingIcon.tsx +0 -67
- package/src/shared/lottie/lottie.tsx +0 -108
- package/src/shared/otpInput/otpInput.css +0 -85
- package/src/shared/otpInput/otpInput.test.tsx +0 -356
- package/src/shared/otpInput/otpInput.tsx +0 -241
- package/src/shared/page/incode-logo.svg +0 -3
- package/src/shared/page/page.css +0 -47
- package/src/shared/page/page.test.tsx +0 -97
- package/src/shared/page/page.tsx +0 -91
- package/src/shared/page/pageUiConfig.test.ts +0 -112
- package/src/shared/page/pageUiConfig.ts +0 -64
- package/src/shared/page/verifiedByIncode.css +0 -5
- package/src/shared/page/verifiedByIncode.tsx +0 -75
- package/src/shared/spacer/spacer.css +0 -149
- package/src/shared/spacer/spacer.test.tsx +0 -143
- package/src/shared/spacer/spacer.tsx +0 -88
- package/src/shared/spinner/index.ts +0 -2
- package/src/shared/spinner/spinner.css +0 -28
- package/src/shared/spinner/spinner.test.tsx +0 -82
- package/src/shared/spinner/spinner.tsx +0 -65
- package/src/shared/title/title.css +0 -7
- package/src/shared/title/title.tsx +0 -12
- package/src/shared/uiConfig/uiConfig.ts +0 -36
- package/src/shared/webComponent/incodeModule.ts +0 -29
- package/src/shared/webComponent/registerIncodeElement.ts +0 -15
- package/src/styles/__mocks__/fetchTheme.ts +0 -19
- package/src/styles/applyTheme.ts +0 -37
- package/src/styles/cn.test.tsx +0 -57
- package/src/styles/cn.tsx +0 -21
- package/src/styles/core.css +0 -12
- package/src/styles/fetchTheme.test.ts +0 -390
- package/src/styles/fetchTheme.ts +0 -88
- package/src/styles/generatePalette.ts +0 -111
- package/src/styles/reset.css +0 -65
- package/src/styles/resolveCssVariableToHex.ts +0 -28
- package/src/styles/tailwind.css +0 -291
- package/src/styles/themeTypes.ts +0 -18
- package/src/styles/tokens/colors.css +0 -190
- package/src/styles/tokens/components.css +0 -174
- package/src/styles/tokens/index.css +0 -4
- package/src/styles/tokens/primitives.css +0 -129
- package/src/styles/tokens/semantic.css +0 -51
- package/src/svg.d.ts +0 -4
- package/src/types/assets.d.ts +0 -1
- package/src/types/custom-elements.d.ts +0 -104
- package/tsconfig.json +0 -22
- package/vite.config.ts +0 -260
- package/vitest.config.ts +0 -40
- package/vitest.setup.ts +0 -16
- /package/dist/{styles/tokens.css → themes/light.css} +0 -0
- /package/dist/types/{core.d.ts → base.d.ts} +0 -0
- /package/dist/types/{styles/core.d.ts → themes/dark.d.ts} +0 -0
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
import type { Mock } from 'vitest';
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
type SubscribeCallback = (state: {
|
|
5
|
-
status: string;
|
|
6
|
-
currentStep?: string;
|
|
7
|
-
flow?: { flowModules: { key: string }[] };
|
|
8
|
-
error?: string;
|
|
9
|
-
}) => void;
|
|
10
|
-
|
|
11
|
-
const mockFlowManager = {
|
|
12
|
-
load: vi.fn(),
|
|
13
|
-
getState: vi.fn(() => ({ status: 'idle' })),
|
|
14
|
-
subscribe: vi.fn() as Mock<(cb: SubscribeCallback) => () => void>,
|
|
15
|
-
stop: vi.fn(),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const mockSetupSDK = vi.fn().mockResolvedValue(undefined);
|
|
19
|
-
const mockFetchTheme = vi.fn().mockResolvedValue({
|
|
20
|
-
theme: { logo: 'logo.png' },
|
|
21
|
-
uiConfig: { logoSrc: 'logo.png' },
|
|
22
|
-
});
|
|
23
|
-
const mockWarmupWasmIfNeeded = vi.fn();
|
|
24
|
-
const mockPreloadFirstModule = vi.fn();
|
|
25
|
-
|
|
26
|
-
vi.mock('./flowInit', () => ({
|
|
27
|
-
createFlowManager: vi.fn(() => mockFlowManager),
|
|
28
|
-
setupSDK: (...args: unknown[]) => mockSetupSDK(...args),
|
|
29
|
-
fetchTheme: () => mockFetchTheme(),
|
|
30
|
-
warmupWasmIfNeeded: (...args: unknown[]) => mockWarmupWasmIfNeeded(...args),
|
|
31
|
-
preloadFirstModule: (...args: unknown[]) => mockPreloadFirstModule(...args),
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
import {
|
|
35
|
-
consumePreloadedData,
|
|
36
|
-
getPreloadedData,
|
|
37
|
-
preloadIncodeFlow,
|
|
38
|
-
} from './preloadFlow';
|
|
39
|
-
|
|
40
|
-
describe('preloadFlow', () => {
|
|
41
|
-
beforeEach(() => {
|
|
42
|
-
vi.clearAllMocks();
|
|
43
|
-
vi.useFakeTimers();
|
|
44
|
-
mockSetupSDK.mockResolvedValue(undefined);
|
|
45
|
-
mockFetchTheme.mockResolvedValue({
|
|
46
|
-
theme: { logo: 'logo.png' },
|
|
47
|
-
uiConfig: { logoSrc: 'logo.png' },
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
afterEach(() => {
|
|
52
|
-
vi.useRealTimers();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('preloadIncodeFlow', () => {
|
|
56
|
-
it('should return a PreloadHandle', () => {
|
|
57
|
-
const handle = preloadIncodeFlow({
|
|
58
|
-
apiURL: 'https://api.example.com',
|
|
59
|
-
token: 'test-token-1',
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
expect(handle).toBeDefined();
|
|
63
|
-
expect(typeof handle.isReady).toBe('boolean');
|
|
64
|
-
expect(typeof handle.error).toBe('object');
|
|
65
|
-
expect(typeof handle.waitUntilReady).toBe('function');
|
|
66
|
-
expect(typeof handle.cancel).toBe('function');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should start in loading state', () => {
|
|
70
|
-
const handle = preloadIncodeFlow({
|
|
71
|
-
apiURL: 'https://api.example.com',
|
|
72
|
-
token: 'test-token-2',
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
expect(handle.isReady).toBe(false);
|
|
76
|
-
expect(handle.error).toBeNull();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should call setupSDK with correct options', async () => {
|
|
80
|
-
preloadIncodeFlow({
|
|
81
|
-
apiURL: 'https://api.example.com',
|
|
82
|
-
token: 'test-token-3',
|
|
83
|
-
lang: 'es',
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
await vi.runAllTimersAsync();
|
|
87
|
-
|
|
88
|
-
expect(mockSetupSDK).toHaveBeenCalledWith({
|
|
89
|
-
apiURL: 'https://api.example.com',
|
|
90
|
-
token: 'test-token-3',
|
|
91
|
-
lang: 'es',
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should skip theme fetch when disableDashboardTheme is true', async () => {
|
|
96
|
-
preloadIncodeFlow({
|
|
97
|
-
apiURL: 'https://api.example.com',
|
|
98
|
-
token: 'test-token-4',
|
|
99
|
-
disableDashboardTheme: true,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
await vi.runAllTimersAsync();
|
|
103
|
-
|
|
104
|
-
expect(mockFetchTheme).not.toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should fetch theme when disableDashboardTheme is false', async () => {
|
|
108
|
-
preloadIncodeFlow({
|
|
109
|
-
apiURL: 'https://api.example.com',
|
|
110
|
-
token: 'test-token-5',
|
|
111
|
-
disableDashboardTheme: false,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
await vi.runAllTimersAsync();
|
|
115
|
-
|
|
116
|
-
expect(mockFetchTheme).toHaveBeenCalled();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should return same handle for same token', () => {
|
|
120
|
-
const handle1 = preloadIncodeFlow({
|
|
121
|
-
apiURL: 'https://api.example.com',
|
|
122
|
-
token: 'test-token-6',
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const handle2 = preloadIncodeFlow({
|
|
126
|
-
apiURL: 'https://api.example.com',
|
|
127
|
-
token: 'test-token-6',
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
expect(handle1.isReady).toBe(handle2.isReady);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should become ready when flow manager reports ready', async () => {
|
|
134
|
-
let subscribeCallback: SubscribeCallback | undefined;
|
|
135
|
-
|
|
136
|
-
mockFlowManager.subscribe.mockImplementation((cb) => {
|
|
137
|
-
subscribeCallback = cb;
|
|
138
|
-
return vi.fn();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const handle = preloadIncodeFlow({
|
|
142
|
-
apiURL: 'https://api.example.com',
|
|
143
|
-
token: 'test-token-7',
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
await vi.runAllTimersAsync();
|
|
147
|
-
|
|
148
|
-
expect(handle.isReady).toBe(false);
|
|
149
|
-
|
|
150
|
-
if (subscribeCallback) {
|
|
151
|
-
subscribeCallback({
|
|
152
|
-
status: 'ready',
|
|
153
|
-
currentStep: 'PHONE',
|
|
154
|
-
flow: { flowModules: [] },
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
expect(handle.isReady).toBe(true);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should call cancel and clean up state', async () => {
|
|
162
|
-
const unsubscribe = vi.fn();
|
|
163
|
-
|
|
164
|
-
mockFlowManager.subscribe.mockImplementation(() => {
|
|
165
|
-
return unsubscribe;
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const handle = preloadIncodeFlow({
|
|
169
|
-
apiURL: 'https://api.example.com',
|
|
170
|
-
token: 'test-token-8',
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const waitPromise = handle.waitUntilReady().catch((e) => e);
|
|
174
|
-
|
|
175
|
-
await vi.runAllTimersAsync();
|
|
176
|
-
|
|
177
|
-
handle.cancel();
|
|
178
|
-
|
|
179
|
-
const error = await waitPromise;
|
|
180
|
-
expect(error).toBeInstanceOf(Error);
|
|
181
|
-
|
|
182
|
-
expect(mockFlowManager.stop).toHaveBeenCalled();
|
|
183
|
-
expect(getPreloadedData('test-token-8')).toBeNull();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should warmup WASM when wasmConfig is provided and flow is ready', async () => {
|
|
187
|
-
let subscribeCallback: SubscribeCallback | undefined;
|
|
188
|
-
|
|
189
|
-
mockFlowManager.subscribe.mockImplementation((cb) => {
|
|
190
|
-
subscribeCallback = cb;
|
|
191
|
-
return vi.fn();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
preloadIncodeFlow({
|
|
195
|
-
apiURL: 'https://api.example.com',
|
|
196
|
-
token: 'test-token-9',
|
|
197
|
-
wasmConfig: {
|
|
198
|
-
wasmPath: 'wasm.wasm',
|
|
199
|
-
wasmSimdPath: 'wasm-simd.wasm',
|
|
200
|
-
glueCodePath: 'glue.js',
|
|
201
|
-
modelsBasePath: 'models',
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
await vi.runAllTimersAsync();
|
|
206
|
-
|
|
207
|
-
if (subscribeCallback) {
|
|
208
|
-
subscribeCallback({
|
|
209
|
-
status: 'ready',
|
|
210
|
-
currentStep: 'SELFIE',
|
|
211
|
-
flow: { flowModules: [{ key: 'SELFIE' }] },
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
expect(mockWarmupWasmIfNeeded).toHaveBeenCalled();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('should preload first module when flow is ready', async () => {
|
|
219
|
-
let subscribeCallback: SubscribeCallback | undefined;
|
|
220
|
-
|
|
221
|
-
mockFlowManager.subscribe.mockImplementation((cb) => {
|
|
222
|
-
subscribeCallback = cb;
|
|
223
|
-
return vi.fn();
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
preloadIncodeFlow({
|
|
227
|
-
apiURL: 'https://api.example.com',
|
|
228
|
-
token: 'test-token-10',
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
await vi.runAllTimersAsync();
|
|
232
|
-
|
|
233
|
-
if (subscribeCallback) {
|
|
234
|
-
subscribeCallback({
|
|
235
|
-
status: 'ready',
|
|
236
|
-
currentStep: 'PHONE',
|
|
237
|
-
flow: { flowModules: [] },
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
expect(mockPreloadFirstModule).toHaveBeenCalled();
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('should handle setupSDK failure and set error state', async () => {
|
|
245
|
-
mockSetupSDK.mockRejectedValueOnce(new Error('SDK setup failed'));
|
|
246
|
-
|
|
247
|
-
const handle = preloadIncodeFlow({
|
|
248
|
-
apiURL: 'https://api.example.com',
|
|
249
|
-
token: 'test-token-setup-error',
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
const waitPromise = handle.waitUntilReady().catch((e) => e);
|
|
253
|
-
|
|
254
|
-
await vi.runAllTimersAsync();
|
|
255
|
-
|
|
256
|
-
const error = await waitPromise;
|
|
257
|
-
expect(error).toBeInstanceOf(Error);
|
|
258
|
-
expect((error as Error).message).toBe('SDK setup failed');
|
|
259
|
-
|
|
260
|
-
expect(handle.error).toBe('SDK setup failed');
|
|
261
|
-
expect(getPreloadedData('test-token-setup-error')).toBeNull();
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('should handle non-Error thrown in setupSDK', async () => {
|
|
265
|
-
mockSetupSDK.mockRejectedValueOnce('string error');
|
|
266
|
-
|
|
267
|
-
const handle = preloadIncodeFlow({
|
|
268
|
-
apiURL: 'https://api.example.com',
|
|
269
|
-
token: 'test-token-string-error',
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
const waitPromise = handle.waitUntilReady().catch((e) => e);
|
|
273
|
-
|
|
274
|
-
await vi.runAllTimersAsync();
|
|
275
|
-
|
|
276
|
-
const error = await waitPromise;
|
|
277
|
-
expect(error).toBeInstanceOf(Error);
|
|
278
|
-
expect((error as Error).message).toBe('Failed to preload');
|
|
279
|
-
|
|
280
|
-
expect(handle.error).toBe('Failed to preload');
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
describe('getPreloadedData', () => {
|
|
285
|
-
it('should return null for unknown token', () => {
|
|
286
|
-
expect(getPreloadedData('unknown-token')).toBeNull();
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it('should return preload state for known token', async () => {
|
|
290
|
-
preloadIncodeFlow({
|
|
291
|
-
apiURL: 'https://api.example.com',
|
|
292
|
-
token: 'test-token-11',
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
await vi.runAllTimersAsync();
|
|
296
|
-
|
|
297
|
-
const data = getPreloadedData('test-token-11');
|
|
298
|
-
expect(data).not.toBeNull();
|
|
299
|
-
expect(data?.status).toBe('loading');
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
describe('consumePreloadedData', () => {
|
|
304
|
-
it('should return null for unknown token', () => {
|
|
305
|
-
expect(consumePreloadedData('unknown-token')).toBeNull();
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('should return and delete preload state', async () => {
|
|
309
|
-
let subscribeCallback: SubscribeCallback | undefined;
|
|
310
|
-
|
|
311
|
-
mockFlowManager.subscribe.mockImplementation((cb) => {
|
|
312
|
-
subscribeCallback = cb;
|
|
313
|
-
return vi.fn();
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
preloadIncodeFlow({
|
|
317
|
-
apiURL: 'https://api.example.com',
|
|
318
|
-
token: 'test-token-12',
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
await vi.runAllTimersAsync();
|
|
322
|
-
|
|
323
|
-
if (subscribeCallback) {
|
|
324
|
-
subscribeCallback({
|
|
325
|
-
status: 'ready',
|
|
326
|
-
currentStep: 'PHONE',
|
|
327
|
-
flow: { flowModules: [] },
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const data = consumePreloadedData('test-token-12');
|
|
332
|
-
expect(data).not.toBeNull();
|
|
333
|
-
expect(data?.status).toBe('ready');
|
|
334
|
-
|
|
335
|
-
expect(getPreloadedData('test-token-12')).toBeNull();
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
describe('PreloadHandle.waitUntilReady', () => {
|
|
340
|
-
it('should resolve immediately if already ready', async () => {
|
|
341
|
-
let subscribeCallback: SubscribeCallback | undefined;
|
|
342
|
-
|
|
343
|
-
mockFlowManager.subscribe.mockImplementation((cb) => {
|
|
344
|
-
subscribeCallback = cb;
|
|
345
|
-
return vi.fn();
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
const handle = preloadIncodeFlow({
|
|
349
|
-
apiURL: 'https://api.example.com',
|
|
350
|
-
token: 'test-token-13',
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
await vi.runAllTimersAsync();
|
|
354
|
-
|
|
355
|
-
if (subscribeCallback) {
|
|
356
|
-
subscribeCallback({
|
|
357
|
-
status: 'ready',
|
|
358
|
-
currentStep: 'PHONE',
|
|
359
|
-
flow: { flowModules: [] },
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
await expect(handle.waitUntilReady()).resolves.toBeUndefined();
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it('should wait for ready state', async () => {
|
|
367
|
-
let subscribeCallback: SubscribeCallback | undefined;
|
|
368
|
-
|
|
369
|
-
mockFlowManager.subscribe.mockImplementation((cb) => {
|
|
370
|
-
subscribeCallback = cb;
|
|
371
|
-
return vi.fn();
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
const handle = preloadIncodeFlow({
|
|
375
|
-
apiURL: 'https://api.example.com',
|
|
376
|
-
token: 'test-token-14',
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
await vi.runAllTimersAsync();
|
|
380
|
-
|
|
381
|
-
const waitPromise = handle.waitUntilReady();
|
|
382
|
-
|
|
383
|
-
if (subscribeCallback) {
|
|
384
|
-
subscribeCallback({
|
|
385
|
-
status: 'ready',
|
|
386
|
-
currentStep: 'PHONE',
|
|
387
|
-
flow: { flowModules: [] },
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
await expect(waitPromise).resolves.toBeUndefined();
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
it('should throw if preload errors', async () => {
|
|
395
|
-
let subscribeCallback: SubscribeCallback | undefined;
|
|
396
|
-
|
|
397
|
-
mockFlowManager.subscribe.mockImplementation((cb) => {
|
|
398
|
-
subscribeCallback = cb;
|
|
399
|
-
return vi.fn();
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
const handle = preloadIncodeFlow({
|
|
403
|
-
apiURL: 'https://api.example.com',
|
|
404
|
-
token: 'test-token-15',
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
const waitPromise = handle.waitUntilReady();
|
|
408
|
-
|
|
409
|
-
await vi.runAllTimersAsync();
|
|
410
|
-
|
|
411
|
-
if (subscribeCallback) {
|
|
412
|
-
subscribeCallback({
|
|
413
|
-
status: 'error',
|
|
414
|
-
error: 'Flow error',
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
await expect(waitPromise).rejects.toThrow('Flow error');
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
});
|
package/src/flow/preloadFlow.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import type { WasmConfig } from '@incodetech/core';
|
|
2
|
-
import type { OrchestratedFlowReadyState } from '@incodetech/core/flow';
|
|
3
|
-
import type { UiConfig } from '../shared/uiConfig/uiConfig';
|
|
4
|
-
import type { ThemeConfig } from '../styles/themeTypes';
|
|
5
|
-
import {
|
|
6
|
-
createFlowManager,
|
|
7
|
-
fetchTheme,
|
|
8
|
-
preloadFirstModule,
|
|
9
|
-
setupSDK,
|
|
10
|
-
warmupWasmIfNeeded,
|
|
11
|
-
} from './flowInit';
|
|
12
|
-
|
|
13
|
-
type PreloadConfig = {
|
|
14
|
-
apiURL: string;
|
|
15
|
-
token: string;
|
|
16
|
-
lang?: string;
|
|
17
|
-
disableDashboardTheme?: boolean;
|
|
18
|
-
wasmConfig?: WasmConfig;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type PreloadState = {
|
|
22
|
-
status: 'loading' | 'ready' | 'error';
|
|
23
|
-
flowManager: ReturnType<typeof createFlowManager>;
|
|
24
|
-
config: PreloadConfig;
|
|
25
|
-
theme?: ThemeConfig;
|
|
26
|
-
uiConfig?: UiConfig;
|
|
27
|
-
error?: string;
|
|
28
|
-
readyPromise: Promise<void>;
|
|
29
|
-
readyResolve: () => void;
|
|
30
|
-
readyReject: (error: Error) => void;
|
|
31
|
-
unsubscribe?: () => void;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const preloadCache = new Map<string, PreloadState>();
|
|
35
|
-
|
|
36
|
-
export type PreloadHandle = {
|
|
37
|
-
get isReady(): boolean;
|
|
38
|
-
get error(): string | null;
|
|
39
|
-
waitUntilReady(): Promise<void>;
|
|
40
|
-
cancel(): void;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function createPreloadHandle(token: string): PreloadHandle {
|
|
44
|
-
const state = preloadCache.get(token);
|
|
45
|
-
if (!state) {
|
|
46
|
-
throw new Error('Preload state not found');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
get isReady() {
|
|
51
|
-
return state.status === 'ready';
|
|
52
|
-
},
|
|
53
|
-
get error() {
|
|
54
|
-
return state.status === 'error' ? (state.error ?? null) : null;
|
|
55
|
-
},
|
|
56
|
-
async waitUntilReady() {
|
|
57
|
-
if (state.status === 'ready') {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (state.status === 'error') {
|
|
61
|
-
throw new Error(state.error ?? 'Preload failed');
|
|
62
|
-
}
|
|
63
|
-
return state.readyPromise;
|
|
64
|
-
},
|
|
65
|
-
cancel() {
|
|
66
|
-
if (state.status === 'loading') {
|
|
67
|
-
if (state.unsubscribe) {
|
|
68
|
-
state.unsubscribe();
|
|
69
|
-
}
|
|
70
|
-
state.flowManager.stop();
|
|
71
|
-
state.readyReject(new Error('Preload cancelled'));
|
|
72
|
-
preloadCache.delete(token);
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function preloadIncodeFlow(config: PreloadConfig): PreloadHandle {
|
|
79
|
-
const { token } = config;
|
|
80
|
-
|
|
81
|
-
if (preloadCache.has(token)) {
|
|
82
|
-
return createPreloadHandle(token);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let readyResolve!: () => void;
|
|
86
|
-
let readyReject!: (error: Error) => void;
|
|
87
|
-
const readyPromise = new Promise<void>((resolve, reject) => {
|
|
88
|
-
readyResolve = resolve;
|
|
89
|
-
readyReject = reject;
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const flowManager = createFlowManager();
|
|
93
|
-
|
|
94
|
-
const state: PreloadState = {
|
|
95
|
-
status: 'loading',
|
|
96
|
-
flowManager,
|
|
97
|
-
config,
|
|
98
|
-
readyPromise,
|
|
99
|
-
readyResolve,
|
|
100
|
-
readyReject,
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
preloadCache.set(token, state);
|
|
104
|
-
|
|
105
|
-
const preload = async () => {
|
|
106
|
-
try {
|
|
107
|
-
await setupSDK({
|
|
108
|
-
apiURL: config.apiURL,
|
|
109
|
-
token: config.token,
|
|
110
|
-
lang: config.lang,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const themePromise = config.disableDashboardTheme
|
|
114
|
-
? Promise.resolve({})
|
|
115
|
-
: fetchTheme().then((result) => {
|
|
116
|
-
state.theme = result.theme;
|
|
117
|
-
state.uiConfig = result.uiConfig;
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const unsubscribe = flowManager.subscribe((managerState) => {
|
|
121
|
-
if (managerState.status === 'ready') {
|
|
122
|
-
const readyState = managerState as OrchestratedFlowReadyState;
|
|
123
|
-
if (config.wasmConfig) {
|
|
124
|
-
warmupWasmIfNeeded(readyState, config.wasmConfig);
|
|
125
|
-
}
|
|
126
|
-
preloadFirstModule(readyState);
|
|
127
|
-
state.unsubscribe?.();
|
|
128
|
-
state.unsubscribe = undefined;
|
|
129
|
-
state.status = 'ready';
|
|
130
|
-
state.readyResolve();
|
|
131
|
-
} else if (managerState.status === 'error') {
|
|
132
|
-
state.unsubscribe?.();
|
|
133
|
-
state.unsubscribe = undefined;
|
|
134
|
-
state.status = 'error';
|
|
135
|
-
state.error = managerState.error;
|
|
136
|
-
state.readyReject(new Error(managerState.error));
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
state.unsubscribe = unsubscribe;
|
|
141
|
-
|
|
142
|
-
flowManager.load();
|
|
143
|
-
|
|
144
|
-
await themePromise;
|
|
145
|
-
} catch (error) {
|
|
146
|
-
state.status = 'error';
|
|
147
|
-
state.error =
|
|
148
|
-
error instanceof Error ? error.message : 'Failed to preload';
|
|
149
|
-
state.readyReject(
|
|
150
|
-
error instanceof Error ? error : new Error('Failed to preload'),
|
|
151
|
-
);
|
|
152
|
-
preloadCache.delete(token);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
preload();
|
|
157
|
-
|
|
158
|
-
return createPreloadHandle(token);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function getPreloadedData(token: string): PreloadState | null {
|
|
162
|
-
return preloadCache.get(token) ?? null;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function consumePreloadedData(token: string): PreloadState | null {
|
|
166
|
-
const state = getPreloadedData(token);
|
|
167
|
-
if (state) {
|
|
168
|
-
preloadCache.delete(token);
|
|
169
|
-
}
|
|
170
|
-
return state;
|
|
171
|
-
}
|
package/src/flow/styles.css
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
@reference "../styles/tailwind.css";
|
|
2
|
-
|
|
3
|
-
.IncodeUnsupportedModule {
|
|
4
|
-
@apply flex flex-col items-center justify-center min-h-screen p-16;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.IncodeUnsupportedModuleContent {
|
|
8
|
-
@apply flex flex-col items-center gap-16 max-w-md text-center;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.IncodeUnsupportedModuleTitle {
|
|
12
|
-
@apply text-24 font-semibold text-text-body-primary;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.IncodeUnsupportedModuleMessage {
|
|
16
|
-
@apply text-16 text-text-body-secondary;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.IncodeUnsupportedModuleButton {
|
|
20
|
-
@apply mt-8;
|
|
21
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { FC } from 'preact/compat';
|
|
2
|
-
import { useTranslation } from '../i18n';
|
|
3
|
-
import { Button } from '../shared/button/button';
|
|
4
|
-
import './unsupportedModule.css';
|
|
5
|
-
|
|
6
|
-
export type UnsupportedModuleProps = {
|
|
7
|
-
moduleKey: string;
|
|
8
|
-
onNext: () => void;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const UnsupportedModule: FC<UnsupportedModuleProps> = ({
|
|
12
|
-
moduleKey,
|
|
13
|
-
onNext,
|
|
14
|
-
}) => {
|
|
15
|
-
const { t } = useTranslation();
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<section class="IncodeUnsupportedModule" aria-live="polite">
|
|
19
|
-
<div class="IncodeUnsupportedModuleContent">
|
|
20
|
-
<h2 class="IncodeUnsupportedModuleTitle">
|
|
21
|
-
{t('unsupportedModule.title', 'Module not available')}
|
|
22
|
-
</h2>
|
|
23
|
-
<p class="IncodeUnsupportedModuleMessage">
|
|
24
|
-
{t(
|
|
25
|
-
'unsupportedModule.message',
|
|
26
|
-
`The "${moduleKey}" module is not yet supported in this version.`,
|
|
27
|
-
)}
|
|
28
|
-
</p>
|
|
29
|
-
<Button
|
|
30
|
-
onClick={onNext}
|
|
31
|
-
class="IncodeUnsupportedModuleButton"
|
|
32
|
-
data-testid="unsupported-module-next-button"
|
|
33
|
-
>
|
|
34
|
-
{t('unsupportedModule.next', 'Next')}
|
|
35
|
-
</Button>
|
|
36
|
-
</div>
|
|
37
|
-
</section>
|
|
38
|
-
);
|
|
39
|
-
};
|