@incodetech/core 2.0.0-alpha.1 → 2.0.0-alpha.11
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/Manager-Cy9-TMC9.d.ts +19 -0
- package/dist/OpenViduLogger-20ZYS-mT.esm.js +3 -0
- package/dist/OpenViduLogger-5b7KqNTo.esm.js +803 -0
- package/dist/StateMachine-BqPpBhOz.d.ts +2 -0
- package/dist/addEvent-s2Za-pK3.esm.js +16 -0
- package/dist/chunk-C_Yo44FK.esm.js +49 -0
- package/dist/deepsightLoader-Bn2D0REl.esm.js +25 -0
- package/dist/email.d.ts +264 -0
- package/dist/email.esm.js +479 -0
- package/dist/endpoints-B0ltwtb5.esm.js +2335 -0
- package/dist/flow.d.ts +578 -0
- package/dist/flow.esm.js +628 -0
- package/dist/getBrowser-CLEzz0Hi.esm.js +8 -0
- package/dist/index.d.ts +226 -0
- package/dist/index.esm.js +156 -0
- package/dist/lib-CykGFCEr.esm.js +11700 -0
- package/dist/permissionServices-BhD0KxsO.esm.js +66 -0
- package/dist/phone.d.ts +292 -0
- package/dist/phone.esm.js +550 -0
- package/dist/recordingsRepository-CTjaf-ER.esm.js +256 -0
- package/dist/selfie.d.ts +821 -0
- package/dist/selfie.esm.js +1087 -0
- package/dist/types-Dif6MQmX.d.ts +5 -0
- package/dist/warmup-Cijuyvoc.d.ts +55 -0
- package/dist/xstate.esm-2T5fOCTq.esm.js +3261 -0
- package/package.json +14 -11
- package/src/camera/cameraActor.ts +0 -21
- package/src/camera/cameraService.test.ts +0 -437
- package/src/camera/cameraService.ts +0 -165
- package/src/camera/cameraServices.test.ts +0 -66
- package/src/camera/cameraServices.ts +0 -26
- package/src/camera/cameraStateMachine.test.ts +0 -602
- package/src/camera/cameraStateMachine.ts +0 -264
- package/src/camera/index.ts +0 -5
- package/src/camera/types.ts +0 -17
- package/src/device/getBrowser.ts +0 -31
- package/src/device/getDeviceClass.ts +0 -29
- package/src/device/index.ts +0 -2
- package/src/email/__mocks__/emailMocks.ts +0 -59
- package/src/email/emailActor.ts +0 -15
- package/src/email/emailManager.test.ts +0 -573
- package/src/email/emailManager.ts +0 -427
- package/src/email/emailServices.ts +0 -66
- package/src/email/emailStateMachine.test.ts +0 -741
- package/src/email/emailStateMachine.ts +0 -367
- package/src/email/index.ts +0 -39
- package/src/email/types.ts +0 -60
- package/src/events/addEvent.ts +0 -20
- package/src/events/types.ts +0 -7
- package/src/flow/__mocks__/flowMocks.ts +0 -84
- package/src/flow/flowActor.ts +0 -13
- package/src/flow/flowAnalyzer.test.ts +0 -266
- package/src/flow/flowAnalyzer.ts +0 -37
- package/src/flow/flowCompletionService.ts +0 -21
- package/src/flow/flowManager.test.ts +0 -560
- package/src/flow/flowManager.ts +0 -235
- package/src/flow/flowServices.test.ts +0 -109
- package/src/flow/flowServices.ts +0 -13
- package/src/flow/flowStateMachine.test.ts +0 -334
- package/src/flow/flowStateMachine.ts +0 -182
- package/src/flow/index.ts +0 -21
- package/src/flow/moduleLoader.test.ts +0 -136
- package/src/flow/moduleLoader.ts +0 -73
- package/src/flow/orchestratedFlowManager.test.ts +0 -240
- package/src/flow/orchestratedFlowManager.ts +0 -231
- package/src/flow/orchestratedFlowStateMachine.test.ts +0 -199
- package/src/flow/orchestratedFlowStateMachine.ts +0 -325
- package/src/flow/types.ts +0 -434
- package/src/http/__mocks__/api.ts +0 -88
- package/src/http/api.test.ts +0 -231
- package/src/http/api.ts +0 -90
- package/src/http/endpoints.ts +0 -17
- package/src/index.ts +0 -33
- package/src/permissions/index.ts +0 -2
- package/src/permissions/permissionServices.ts +0 -31
- package/src/permissions/types.ts +0 -3
- package/src/phone/__mocks__/phoneMocks.ts +0 -71
- package/src/phone/index.ts +0 -39
- package/src/phone/phoneActor.ts +0 -15
- package/src/phone/phoneManager.test.ts +0 -393
- package/src/phone/phoneManager.ts +0 -458
- package/src/phone/phoneServices.ts +0 -98
- package/src/phone/phoneStateMachine.test.ts +0 -918
- package/src/phone/phoneStateMachine.ts +0 -422
- package/src/phone/types.ts +0 -83
- package/src/recordings/recordingsRepository.test.ts +0 -87
- package/src/recordings/recordingsRepository.ts +0 -48
- package/src/recordings/streamingEvents.ts +0 -10
- package/src/selfie/__mocks__/selfieMocks.ts +0 -26
- package/src/selfie/index.ts +0 -14
- package/src/selfie/selfieActor.ts +0 -17
- package/src/selfie/selfieErrorUtils.test.ts +0 -116
- package/src/selfie/selfieErrorUtils.ts +0 -66
- package/src/selfie/selfieManager.test.ts +0 -297
- package/src/selfie/selfieManager.ts +0 -301
- package/src/selfie/selfieServices.ts +0 -362
- package/src/selfie/selfieStateMachine.test.ts +0 -283
- package/src/selfie/selfieStateMachine.ts +0 -804
- package/src/selfie/selfieUploadService.test.ts +0 -90
- package/src/selfie/selfieUploadService.ts +0 -81
- package/src/selfie/types.ts +0 -103
- package/src/session/index.ts +0 -5
- package/src/session/sessionService.ts +0 -78
- package/src/setup.test.ts +0 -61
- package/src/setup.ts +0 -171
- package/tsconfig.json +0 -13
- package/tsdown.config.ts +0 -22
- package/vitest.config.ts +0 -37
- package/vitest.setup.ts +0 -135
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { assign, fromPromise, setup } from '@incodetech/infra';
|
|
2
|
-
import type { Flow } from './types';
|
|
3
|
-
|
|
4
|
-
export type GetFlowFn = (signal: AbortSignal) => Promise<Flow>;
|
|
5
|
-
|
|
6
|
-
export type FlowContext = {
|
|
7
|
-
flow: Flow | undefined;
|
|
8
|
-
error: string | undefined;
|
|
9
|
-
steps: string[];
|
|
10
|
-
currentStepIndex: number;
|
|
11
|
-
currentStep: string | undefined;
|
|
12
|
-
config: unknown;
|
|
13
|
-
getFlow: GetFlowFn;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type FlowEvent =
|
|
17
|
-
| { type: 'LOAD' }
|
|
18
|
-
| { type: 'CANCEL' }
|
|
19
|
-
| { type: 'RESET' }
|
|
20
|
-
| { type: 'NEXT_STEP' }
|
|
21
|
-
| { type: 'PREV_STEP' };
|
|
22
|
-
|
|
23
|
-
export type FlowInput = {
|
|
24
|
-
getFlow: GetFlowFn;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const flowMachine = setup({
|
|
28
|
-
types: {
|
|
29
|
-
context: {} as FlowContext,
|
|
30
|
-
events: {} as FlowEvent,
|
|
31
|
-
input: {} as FlowInput,
|
|
32
|
-
},
|
|
33
|
-
actors: {
|
|
34
|
-
fetchFlow: fromPromise<Flow, { getFlow: GetFlowFn }>(
|
|
35
|
-
async ({ input, signal }) => {
|
|
36
|
-
return input.getFlow(signal);
|
|
37
|
-
},
|
|
38
|
-
),
|
|
39
|
-
},
|
|
40
|
-
actions: {
|
|
41
|
-
resetContext: assign(({ context }) => ({
|
|
42
|
-
flow: undefined,
|
|
43
|
-
error: undefined,
|
|
44
|
-
steps: [],
|
|
45
|
-
currentStepIndex: -1,
|
|
46
|
-
currentStep: undefined,
|
|
47
|
-
config: undefined,
|
|
48
|
-
getFlow: context.getFlow,
|
|
49
|
-
})),
|
|
50
|
-
setFlowData: assign(({ event }) => {
|
|
51
|
-
const flow = (event as unknown as { output: Flow }).output;
|
|
52
|
-
return {
|
|
53
|
-
flow,
|
|
54
|
-
steps: (flow.flowModules ?? []).map((m) => m.key),
|
|
55
|
-
currentStepIndex: (flow.flowModules ?? []).length > 0 ? 0 : -1,
|
|
56
|
-
currentStep: flow.flowModules?.[0]?.key,
|
|
57
|
-
config: flow.flowModules?.[0]?.configuration,
|
|
58
|
-
};
|
|
59
|
-
}),
|
|
60
|
-
setError: assign(({ event }) => ({
|
|
61
|
-
error: String((event as unknown as { error: unknown }).error),
|
|
62
|
-
})),
|
|
63
|
-
incrementStep: assign(({ context }) => {
|
|
64
|
-
const nextIndex = context.currentStepIndex + 1;
|
|
65
|
-
const module = context.flow?.flowModules?.[nextIndex];
|
|
66
|
-
return {
|
|
67
|
-
currentStepIndex: nextIndex,
|
|
68
|
-
currentStep: module?.key,
|
|
69
|
-
config: module?.configuration,
|
|
70
|
-
};
|
|
71
|
-
}),
|
|
72
|
-
decrementStep: assign(({ context }) => {
|
|
73
|
-
const prevIndex = context.currentStepIndex - 1;
|
|
74
|
-
const module = context.flow?.flowModules?.[prevIndex];
|
|
75
|
-
return {
|
|
76
|
-
currentStepIndex: prevIndex,
|
|
77
|
-
currentStep: module?.key,
|
|
78
|
-
config: module?.configuration,
|
|
79
|
-
};
|
|
80
|
-
}),
|
|
81
|
-
},
|
|
82
|
-
guards: {
|
|
83
|
-
isLastStep: ({ context }) =>
|
|
84
|
-
context.currentStepIndex >= 0 &&
|
|
85
|
-
context.currentStepIndex === context.steps.length - 1,
|
|
86
|
-
canGoNext: ({ context }) =>
|
|
87
|
-
context.currentStepIndex >= 0 &&
|
|
88
|
-
context.currentStepIndex < context.steps.length - 1,
|
|
89
|
-
canGoPrev: ({ context }) => context.currentStepIndex > 0,
|
|
90
|
-
},
|
|
91
|
-
}).createMachine({
|
|
92
|
-
id: 'flow',
|
|
93
|
-
initial: 'idle',
|
|
94
|
-
context: ({ input }) => ({
|
|
95
|
-
flow: undefined,
|
|
96
|
-
error: undefined,
|
|
97
|
-
steps: [],
|
|
98
|
-
currentStepIndex: -1,
|
|
99
|
-
currentStep: undefined,
|
|
100
|
-
config: undefined,
|
|
101
|
-
getFlow: input.getFlow,
|
|
102
|
-
}),
|
|
103
|
-
states: {
|
|
104
|
-
idle: {
|
|
105
|
-
on: {
|
|
106
|
-
LOAD: {
|
|
107
|
-
target: 'loading',
|
|
108
|
-
actions: 'resetContext',
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
loading: {
|
|
114
|
-
invoke: {
|
|
115
|
-
id: 'fetchFlow',
|
|
116
|
-
src: 'fetchFlow',
|
|
117
|
-
input: ({ context }) => ({
|
|
118
|
-
getFlow: context.getFlow,
|
|
119
|
-
}),
|
|
120
|
-
onDone: {
|
|
121
|
-
target: 'ready',
|
|
122
|
-
actions: 'setFlowData',
|
|
123
|
-
},
|
|
124
|
-
onError: {
|
|
125
|
-
target: 'error',
|
|
126
|
-
actions: 'setError',
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
on: {
|
|
130
|
-
CANCEL: {
|
|
131
|
-
target: 'idle',
|
|
132
|
-
actions: 'resetContext',
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
ready: {
|
|
138
|
-
on: {
|
|
139
|
-
NEXT_STEP: [
|
|
140
|
-
{
|
|
141
|
-
target: 'finished',
|
|
142
|
-
guard: 'isLastStep',
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
target: 'ready',
|
|
146
|
-
guard: 'canGoNext',
|
|
147
|
-
actions: 'incrementStep',
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
PREV_STEP: {
|
|
151
|
-
target: 'ready',
|
|
152
|
-
guard: 'canGoPrev',
|
|
153
|
-
actions: 'decrementStep',
|
|
154
|
-
},
|
|
155
|
-
RESET: {
|
|
156
|
-
target: 'idle',
|
|
157
|
-
actions: 'resetContext',
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
finished: {
|
|
163
|
-
on: {
|
|
164
|
-
RESET: {
|
|
165
|
-
target: 'idle',
|
|
166
|
-
actions: 'resetContext',
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
error: {
|
|
172
|
-
on: {
|
|
173
|
-
RESET: {
|
|
174
|
-
target: 'idle',
|
|
175
|
-
actions: 'resetContext',
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
export type FlowMachine = typeof flowMachine;
|
package/src/flow/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export { getRequiredWasmPipelines } from './flowAnalyzer';
|
|
2
|
-
export type { FinishStatus } from './flowCompletionService';
|
|
3
|
-
export type { FlowReadyState, FlowState } from './flowManager';
|
|
4
|
-
export { createFlowManager } from './flowManager';
|
|
5
|
-
export {
|
|
6
|
-
createModuleLoader,
|
|
7
|
-
type LazyModule,
|
|
8
|
-
type ModuleLoader,
|
|
9
|
-
type ModuleLoaderRegistry,
|
|
10
|
-
} from './moduleLoader';
|
|
11
|
-
export {
|
|
12
|
-
createOrchestratedFlowManager,
|
|
13
|
-
type OrchestratedFlowFinishedState,
|
|
14
|
-
type OrchestratedFlowReadyState,
|
|
15
|
-
type OrchestratedFlowState,
|
|
16
|
-
} from './orchestratedFlowManager';
|
|
17
|
-
export type {
|
|
18
|
-
ModuleRegistry,
|
|
19
|
-
OrchestratedFlowInput,
|
|
20
|
-
} from './orchestratedFlowStateMachine';
|
|
21
|
-
export type { Flow, FlowModule, FlowModuleConfig } from './types';
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { createModuleLoader, type ModuleLoaderRegistry } from './moduleLoader';
|
|
3
|
-
|
|
4
|
-
describe('createModuleLoader', () => {
|
|
5
|
-
it('should create a module loader', () => {
|
|
6
|
-
const registry: ModuleLoaderRegistry = {
|
|
7
|
-
TEST: async () => ({ default: 'test' }),
|
|
8
|
-
};
|
|
9
|
-
const loader = createModuleLoader(registry);
|
|
10
|
-
|
|
11
|
-
expect(loader).toBeDefined();
|
|
12
|
-
expect(loader.load).toBeDefined();
|
|
13
|
-
expect(loader.prefetch).toBeDefined();
|
|
14
|
-
expect(loader.isLoaded).toBeDefined();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('load', () => {
|
|
18
|
-
it('should load a module', async () => {
|
|
19
|
-
const registry: ModuleLoaderRegistry = {
|
|
20
|
-
TEST: async () => ({ default: 'test-value' }),
|
|
21
|
-
};
|
|
22
|
-
const loader = createModuleLoader(registry);
|
|
23
|
-
|
|
24
|
-
const result = await loader.load('TEST');
|
|
25
|
-
expect(result).toBe('test-value');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should cache loaded modules', async () => {
|
|
29
|
-
const loadFn = vi.fn().mockResolvedValue({ default: 'test-value' });
|
|
30
|
-
const registry: ModuleLoaderRegistry = {
|
|
31
|
-
TEST: loadFn,
|
|
32
|
-
};
|
|
33
|
-
const loader = createModuleLoader(registry);
|
|
34
|
-
|
|
35
|
-
await loader.load('TEST');
|
|
36
|
-
await loader.load('TEST');
|
|
37
|
-
|
|
38
|
-
expect(loadFn).toHaveBeenCalledTimes(1);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should throw error for unknown module', async () => {
|
|
42
|
-
const registry: ModuleLoaderRegistry = {};
|
|
43
|
-
const loader = createModuleLoader(registry);
|
|
44
|
-
|
|
45
|
-
await expect(loader.load('UNKNOWN')).rejects.toThrow(
|
|
46
|
-
'Module UNKNOWN not found in registry',
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should remove from cache on load error', async () => {
|
|
51
|
-
const loadFn = vi
|
|
52
|
-
.fn()
|
|
53
|
-
.mockRejectedValueOnce(new Error('Load failed'))
|
|
54
|
-
.mockResolvedValueOnce({ default: 'test-value' });
|
|
55
|
-
const registry: ModuleLoaderRegistry = {
|
|
56
|
-
TEST: loadFn,
|
|
57
|
-
};
|
|
58
|
-
const loader = createModuleLoader(registry);
|
|
59
|
-
|
|
60
|
-
await expect(loader.load('TEST')).rejects.toThrow('Load failed');
|
|
61
|
-
expect(loader.isLoaded('TEST')).toBe(false);
|
|
62
|
-
|
|
63
|
-
const result = await loader.load('TEST');
|
|
64
|
-
expect(result).toBe('test-value');
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('prefetch', () => {
|
|
69
|
-
it('should prefetch a module', () => {
|
|
70
|
-
const loadFn = vi.fn().mockResolvedValue({ default: 'test-value' });
|
|
71
|
-
const registry: ModuleLoaderRegistry = {
|
|
72
|
-
TEST: loadFn,
|
|
73
|
-
};
|
|
74
|
-
const loader = createModuleLoader(registry);
|
|
75
|
-
|
|
76
|
-
loader.prefetch('TEST');
|
|
77
|
-
|
|
78
|
-
expect(loadFn).toHaveBeenCalledTimes(1);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should not prefetch already loaded modules', () => {
|
|
82
|
-
const loadFn = vi.fn().mockResolvedValue({ default: 'test-value' });
|
|
83
|
-
const registry: ModuleLoaderRegistry = {
|
|
84
|
-
TEST: loadFn,
|
|
85
|
-
};
|
|
86
|
-
const loader = createModuleLoader(registry);
|
|
87
|
-
|
|
88
|
-
loader.prefetch('TEST');
|
|
89
|
-
loader.prefetch('TEST');
|
|
90
|
-
|
|
91
|
-
expect(loadFn).toHaveBeenCalledTimes(1);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should not prefetch unknown modules', () => {
|
|
95
|
-
const registry: ModuleLoaderRegistry = {};
|
|
96
|
-
const loader = createModuleLoader(registry);
|
|
97
|
-
|
|
98
|
-
expect(() => loader.prefetch('UNKNOWN')).not.toThrow();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should handle prefetch errors gracefully', async () => {
|
|
102
|
-
const loadFn = vi.fn().mockRejectedValue(new Error('Prefetch failed'));
|
|
103
|
-
const registry: ModuleLoaderRegistry = {
|
|
104
|
-
TEST: loadFn,
|
|
105
|
-
};
|
|
106
|
-
const loader = createModuleLoader(registry);
|
|
107
|
-
|
|
108
|
-
loader.prefetch('TEST');
|
|
109
|
-
|
|
110
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
111
|
-
|
|
112
|
-
expect(loader.isLoaded('TEST')).toBe(false);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('isLoaded', () => {
|
|
117
|
-
it('should return false for unloaded module', () => {
|
|
118
|
-
const registry: ModuleLoaderRegistry = {
|
|
119
|
-
TEST: async () => ({ default: 'test-value' }),
|
|
120
|
-
};
|
|
121
|
-
const loader = createModuleLoader(registry);
|
|
122
|
-
|
|
123
|
-
expect(loader.isLoaded('TEST')).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('should return true for loaded module', async () => {
|
|
127
|
-
const registry: ModuleLoaderRegistry = {
|
|
128
|
-
TEST: async () => ({ default: 'test-value' }),
|
|
129
|
-
};
|
|
130
|
-
const loader = createModuleLoader(registry);
|
|
131
|
-
|
|
132
|
-
await loader.load('TEST');
|
|
133
|
-
expect(loader.isLoaded('TEST')).toBe(true);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
package/src/flow/moduleLoader.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export type LazyModule<T> = () => Promise<T>;
|
|
2
|
-
|
|
3
|
-
export type ModuleLoaderRegistry = {
|
|
4
|
-
[key: string]: LazyModule<{ default: unknown }>;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export interface ModuleLoader {
|
|
8
|
-
load<T>(moduleKey: string): Promise<T>;
|
|
9
|
-
prefetch(moduleKey: string): void;
|
|
10
|
-
isLoaded(moduleKey: string): boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
class ModuleLoaderImpl implements ModuleLoader {
|
|
14
|
-
private loadedModules = new Map<string, Promise<unknown>>();
|
|
15
|
-
private prefetchedModules = new Set<string>();
|
|
16
|
-
|
|
17
|
-
constructor(private registry: ModuleLoaderRegistry) {}
|
|
18
|
-
|
|
19
|
-
async load<T>(moduleKey: string): Promise<T> {
|
|
20
|
-
if (!this.registry[moduleKey]) {
|
|
21
|
-
throw new Error(`Module ${moduleKey} not found in registry`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const cached = this.loadedModules.get(moduleKey);
|
|
25
|
-
if (cached) {
|
|
26
|
-
return (await cached) as T;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const loadPromise = this.registry[moduleKey]().then((module) => {
|
|
30
|
-
if (module && typeof module === 'object' && 'default' in module) {
|
|
31
|
-
return module.default;
|
|
32
|
-
}
|
|
33
|
-
return module;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
this.loadedModules.set(moduleKey, loadPromise);
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
return (await loadPromise) as T;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
this.loadedModules.delete(moduleKey);
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
prefetch(moduleKey: string): void {
|
|
47
|
-
if (!this.registry[moduleKey]) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
this.prefetchedModules.has(moduleKey) ||
|
|
53
|
-
this.loadedModules.has(moduleKey)
|
|
54
|
-
) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.prefetchedModules.add(moduleKey);
|
|
59
|
-
this.registry[moduleKey]().catch(() => {
|
|
60
|
-
this.prefetchedModules.delete(moduleKey);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
isLoaded(moduleKey: string): boolean {
|
|
65
|
-
return this.loadedModules.has(moduleKey);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function createModuleLoader(
|
|
70
|
-
registry: ModuleLoaderRegistry,
|
|
71
|
-
): ModuleLoader {
|
|
72
|
-
return new ModuleLoaderImpl(registry);
|
|
73
|
-
}
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { mockPhoneConfig } from '../phone/__mocks__/phoneMocks';
|
|
3
|
-
import { phoneMachine } from '../phone/phoneStateMachine';
|
|
4
|
-
import {
|
|
5
|
-
createFailingGetFlow,
|
|
6
|
-
createMockGetFlow,
|
|
7
|
-
mockFlow,
|
|
8
|
-
} from './__mocks__/flowMocks';
|
|
9
|
-
import { createOrchestratedFlowManager } from './orchestratedFlowManager';
|
|
10
|
-
import type { FlowModule } from './types';
|
|
11
|
-
|
|
12
|
-
vi.mock('./flowCompletionService', () => ({
|
|
13
|
-
getFinishStatus: vi.fn().mockResolvedValue({
|
|
14
|
-
redirectionUrl: 'https://example.com/success',
|
|
15
|
-
action: 'approved' as const,
|
|
16
|
-
scoreStatus: 'OK' as const,
|
|
17
|
-
}),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
vi.mock('../phone/phoneServices', () => ({
|
|
21
|
-
fetchPhone: vi.fn().mockResolvedValue({ phone: '+14155551234' }),
|
|
22
|
-
fetchStartInfo: vi.fn().mockResolvedValue({
|
|
23
|
-
ipIsoCode: 'US',
|
|
24
|
-
phonePrefix: '+1',
|
|
25
|
-
country: 'United States',
|
|
26
|
-
}),
|
|
27
|
-
addPhone: vi.fn().mockResolvedValue({ success: true }),
|
|
28
|
-
addPhoneInstantVerify: vi.fn().mockResolvedValue({ success: true }),
|
|
29
|
-
sendOtp: vi.fn().mockResolvedValue(undefined),
|
|
30
|
-
verifyOtp: vi.fn().mockResolvedValue({ success: true }),
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
vi.mock('../events/addEvent', () => ({
|
|
34
|
-
addEvent: vi.fn().mockResolvedValue(undefined),
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
describe('createOrchestratedFlowManager', () => {
|
|
38
|
-
describe('Initial state', () => {
|
|
39
|
-
it('should create an orchestrated flow manager', () => {
|
|
40
|
-
const getFlow = createMockGetFlow();
|
|
41
|
-
const manager = createOrchestratedFlowManager({
|
|
42
|
-
getFlow,
|
|
43
|
-
modules: { PHONE: phoneMachine },
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
expect(manager).toBeDefined();
|
|
47
|
-
expect(manager.getState).toBeDefined();
|
|
48
|
-
expect(manager.subscribe).toBeDefined();
|
|
49
|
-
expect(manager.stop).toBeDefined();
|
|
50
|
-
expect(manager.load).toBeDefined();
|
|
51
|
-
expect(manager.cancel).toBeDefined();
|
|
52
|
-
expect(manager.reset).toBeDefined();
|
|
53
|
-
expect(manager.send).toBeDefined();
|
|
54
|
-
expect(manager.getModuleConfig).toBeDefined();
|
|
55
|
-
expect(manager.isModuleEnabled).toBeDefined();
|
|
56
|
-
manager.stop();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should start in idle state', () => {
|
|
60
|
-
const getFlow = createMockGetFlow();
|
|
61
|
-
const manager = createOrchestratedFlowManager({
|
|
62
|
-
getFlow,
|
|
63
|
-
modules: { PHONE: phoneMachine },
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
expect(manager.getState()).toEqual({ status: 'idle' });
|
|
67
|
-
manager.stop();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('Loading flow', () => {
|
|
72
|
-
it('should transition to loading when load() is called', () => {
|
|
73
|
-
const getFlow = createMockGetFlow();
|
|
74
|
-
const manager = createOrchestratedFlowManager({
|
|
75
|
-
getFlow,
|
|
76
|
-
modules: { PHONE: phoneMachine },
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
manager.load();
|
|
80
|
-
expect(manager.getState().status).toBe('loading');
|
|
81
|
-
manager.stop();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should transition to ready when flow is loaded', async () => {
|
|
85
|
-
const flowWithPhone = {
|
|
86
|
-
...mockFlow,
|
|
87
|
-
flowModules: [
|
|
88
|
-
{
|
|
89
|
-
key: 'PHONE',
|
|
90
|
-
configuration: mockPhoneConfig,
|
|
91
|
-
} as FlowModule,
|
|
92
|
-
],
|
|
93
|
-
};
|
|
94
|
-
const getFlow = createMockGetFlow(flowWithPhone);
|
|
95
|
-
const manager = createOrchestratedFlowManager({
|
|
96
|
-
getFlow,
|
|
97
|
-
modules: { PHONE: phoneMachine },
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
manager.load();
|
|
101
|
-
|
|
102
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
103
|
-
|
|
104
|
-
const state = manager.getState();
|
|
105
|
-
expect(state.status).toBe('ready');
|
|
106
|
-
if (state.status === 'ready') {
|
|
107
|
-
expect(state.currentStep).toBe('PHONE');
|
|
108
|
-
expect(state.config).toBeDefined();
|
|
109
|
-
}
|
|
110
|
-
manager.stop();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should transition to error when flow loading fails', async () => {
|
|
114
|
-
const getFlow = createFailingGetFlow('Network error');
|
|
115
|
-
const manager = createOrchestratedFlowManager({
|
|
116
|
-
getFlow,
|
|
117
|
-
modules: { PHONE: phoneMachine },
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
manager.load();
|
|
121
|
-
|
|
122
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
123
|
-
|
|
124
|
-
const state = manager.getState();
|
|
125
|
-
expect(state.status).toBe('error');
|
|
126
|
-
if (state.status === 'error') {
|
|
127
|
-
expect(state.error).toContain('Network error');
|
|
128
|
-
}
|
|
129
|
-
manager.stop();
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe('State exposure', () => {
|
|
134
|
-
it('should expose module state in ready state', async () => {
|
|
135
|
-
const flowWithPhone = {
|
|
136
|
-
...mockFlow,
|
|
137
|
-
flowModules: [
|
|
138
|
-
{
|
|
139
|
-
key: 'PHONE',
|
|
140
|
-
configuration: mockPhoneConfig,
|
|
141
|
-
} as FlowModule,
|
|
142
|
-
],
|
|
143
|
-
};
|
|
144
|
-
const getFlow = createMockGetFlow(flowWithPhone);
|
|
145
|
-
const manager = createOrchestratedFlowManager({
|
|
146
|
-
getFlow,
|
|
147
|
-
modules: { PHONE: phoneMachine },
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
manager.load();
|
|
151
|
-
|
|
152
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
153
|
-
|
|
154
|
-
const state = manager.getState();
|
|
155
|
-
expect(state.status).toBe('ready');
|
|
156
|
-
if (state.status === 'ready') {
|
|
157
|
-
expect(state.moduleState).toBeDefined();
|
|
158
|
-
}
|
|
159
|
-
manager.stop();
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe('Module configuration', () => {
|
|
164
|
-
it('should get module config for registered module', async () => {
|
|
165
|
-
const flowWithPhone = {
|
|
166
|
-
...mockFlow,
|
|
167
|
-
flowModules: [
|
|
168
|
-
{
|
|
169
|
-
key: 'PHONE',
|
|
170
|
-
configuration: mockPhoneConfig,
|
|
171
|
-
} as FlowModule,
|
|
172
|
-
],
|
|
173
|
-
};
|
|
174
|
-
const getFlow = createMockGetFlow(flowWithPhone);
|
|
175
|
-
const manager = createOrchestratedFlowManager({
|
|
176
|
-
getFlow,
|
|
177
|
-
modules: { PHONE: phoneMachine },
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
manager.load();
|
|
181
|
-
|
|
182
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
183
|
-
|
|
184
|
-
const config = manager.getModuleConfig<typeof mockPhoneConfig>('PHONE');
|
|
185
|
-
expect(config).toBeDefined();
|
|
186
|
-
manager.stop();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('should return undefined for unregistered module', async () => {
|
|
190
|
-
const flowWithPhone = {
|
|
191
|
-
...mockFlow,
|
|
192
|
-
flowModules: [
|
|
193
|
-
{
|
|
194
|
-
key: 'PHONE',
|
|
195
|
-
configuration: mockPhoneConfig,
|
|
196
|
-
} as FlowModule,
|
|
197
|
-
],
|
|
198
|
-
};
|
|
199
|
-
const getFlow = createMockGetFlow(flowWithPhone);
|
|
200
|
-
const manager = createOrchestratedFlowManager({
|
|
201
|
-
getFlow,
|
|
202
|
-
modules: { PHONE: phoneMachine },
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
manager.load();
|
|
206
|
-
|
|
207
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
208
|
-
|
|
209
|
-
// SELFIE is not in the flow, so should return undefined
|
|
210
|
-
const config = manager.getModuleConfig('SELFIE');
|
|
211
|
-
expect(config).toBeUndefined();
|
|
212
|
-
manager.stop();
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('should check if module is enabled', async () => {
|
|
216
|
-
const flowWithPhone = {
|
|
217
|
-
...mockFlow,
|
|
218
|
-
flowModules: [
|
|
219
|
-
{
|
|
220
|
-
key: 'PHONE',
|
|
221
|
-
configuration: mockPhoneConfig,
|
|
222
|
-
} as FlowModule,
|
|
223
|
-
],
|
|
224
|
-
};
|
|
225
|
-
const getFlow = createMockGetFlow(flowWithPhone);
|
|
226
|
-
const manager = createOrchestratedFlowManager({
|
|
227
|
-
getFlow,
|
|
228
|
-
modules: { PHONE: phoneMachine },
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
manager.load();
|
|
232
|
-
|
|
233
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
234
|
-
|
|
235
|
-
expect(manager.isModuleEnabled('PHONE')).toBe(true);
|
|
236
|
-
expect(manager.isModuleEnabled('SELFIE')).toBe(false);
|
|
237
|
-
manager.stop();
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
});
|