@incodetech/core 2.0.0-alpha.1 → 2.0.0-alpha.3

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.
Files changed (104) hide show
  1. package/dist/Manager-6BwbaI_H.d.ts +19 -0
  2. package/dist/StateMachine-7c1gcu94.d.ts +2 -0
  3. package/dist/addEvent-1Mi5CEiq.esm.js +16 -0
  4. package/dist/chunk-C_Yo44FK.esm.js +49 -0
  5. package/dist/email.d.ts +264 -0
  6. package/dist/email.esm.js +479 -0
  7. package/dist/endpoints-D_pUMaqA.esm.js +1701 -0
  8. package/dist/flow.d.ts +578 -0
  9. package/dist/flow.esm.js +628 -0
  10. package/dist/index.d.ts +226 -0
  11. package/dist/index.esm.js +155 -0
  12. package/dist/lib-CyIAFRfr.esm.js +12499 -0
  13. package/dist/permissionServices-CVR0Pq38.esm.js +72 -0
  14. package/dist/phone.d.ts +292 -0
  15. package/dist/phone.esm.js +550 -0
  16. package/dist/selfie.d.ts +758 -0
  17. package/dist/selfie.esm.js +978 -0
  18. package/dist/types-tq1ypYSL.d.ts +5 -0
  19. package/dist/warmup-Dr7OcFND.d.ts +55 -0
  20. package/dist/xstate.esm-B_rda9yU.esm.js +3261 -0
  21. package/package.json +14 -11
  22. package/src/camera/cameraActor.ts +0 -21
  23. package/src/camera/cameraService.test.ts +0 -437
  24. package/src/camera/cameraService.ts +0 -165
  25. package/src/camera/cameraServices.test.ts +0 -66
  26. package/src/camera/cameraServices.ts +0 -26
  27. package/src/camera/cameraStateMachine.test.ts +0 -602
  28. package/src/camera/cameraStateMachine.ts +0 -264
  29. package/src/camera/index.ts +0 -5
  30. package/src/camera/types.ts +0 -17
  31. package/src/device/getBrowser.ts +0 -31
  32. package/src/device/getDeviceClass.ts +0 -29
  33. package/src/device/index.ts +0 -2
  34. package/src/email/__mocks__/emailMocks.ts +0 -59
  35. package/src/email/emailActor.ts +0 -15
  36. package/src/email/emailManager.test.ts +0 -573
  37. package/src/email/emailManager.ts +0 -427
  38. package/src/email/emailServices.ts +0 -66
  39. package/src/email/emailStateMachine.test.ts +0 -741
  40. package/src/email/emailStateMachine.ts +0 -367
  41. package/src/email/index.ts +0 -39
  42. package/src/email/types.ts +0 -60
  43. package/src/events/addEvent.ts +0 -20
  44. package/src/events/types.ts +0 -7
  45. package/src/flow/__mocks__/flowMocks.ts +0 -84
  46. package/src/flow/flowActor.ts +0 -13
  47. package/src/flow/flowAnalyzer.test.ts +0 -266
  48. package/src/flow/flowAnalyzer.ts +0 -37
  49. package/src/flow/flowCompletionService.ts +0 -21
  50. package/src/flow/flowManager.test.ts +0 -560
  51. package/src/flow/flowManager.ts +0 -235
  52. package/src/flow/flowServices.test.ts +0 -109
  53. package/src/flow/flowServices.ts +0 -13
  54. package/src/flow/flowStateMachine.test.ts +0 -334
  55. package/src/flow/flowStateMachine.ts +0 -182
  56. package/src/flow/index.ts +0 -21
  57. package/src/flow/moduleLoader.test.ts +0 -136
  58. package/src/flow/moduleLoader.ts +0 -73
  59. package/src/flow/orchestratedFlowManager.test.ts +0 -240
  60. package/src/flow/orchestratedFlowManager.ts +0 -231
  61. package/src/flow/orchestratedFlowStateMachine.test.ts +0 -199
  62. package/src/flow/orchestratedFlowStateMachine.ts +0 -325
  63. package/src/flow/types.ts +0 -434
  64. package/src/http/__mocks__/api.ts +0 -88
  65. package/src/http/api.test.ts +0 -231
  66. package/src/http/api.ts +0 -90
  67. package/src/http/endpoints.ts +0 -17
  68. package/src/index.ts +0 -33
  69. package/src/permissions/index.ts +0 -2
  70. package/src/permissions/permissionServices.ts +0 -31
  71. package/src/permissions/types.ts +0 -3
  72. package/src/phone/__mocks__/phoneMocks.ts +0 -71
  73. package/src/phone/index.ts +0 -39
  74. package/src/phone/phoneActor.ts +0 -15
  75. package/src/phone/phoneManager.test.ts +0 -393
  76. package/src/phone/phoneManager.ts +0 -458
  77. package/src/phone/phoneServices.ts +0 -98
  78. package/src/phone/phoneStateMachine.test.ts +0 -918
  79. package/src/phone/phoneStateMachine.ts +0 -422
  80. package/src/phone/types.ts +0 -83
  81. package/src/recordings/recordingsRepository.test.ts +0 -87
  82. package/src/recordings/recordingsRepository.ts +0 -48
  83. package/src/recordings/streamingEvents.ts +0 -10
  84. package/src/selfie/__mocks__/selfieMocks.ts +0 -26
  85. package/src/selfie/index.ts +0 -14
  86. package/src/selfie/selfieActor.ts +0 -17
  87. package/src/selfie/selfieErrorUtils.test.ts +0 -116
  88. package/src/selfie/selfieErrorUtils.ts +0 -66
  89. package/src/selfie/selfieManager.test.ts +0 -297
  90. package/src/selfie/selfieManager.ts +0 -301
  91. package/src/selfie/selfieServices.ts +0 -362
  92. package/src/selfie/selfieStateMachine.test.ts +0 -283
  93. package/src/selfie/selfieStateMachine.ts +0 -804
  94. package/src/selfie/selfieUploadService.test.ts +0 -90
  95. package/src/selfie/selfieUploadService.ts +0 -81
  96. package/src/selfie/types.ts +0 -103
  97. package/src/session/index.ts +0 -5
  98. package/src/session/sessionService.ts +0 -78
  99. package/src/setup.test.ts +0 -61
  100. package/src/setup.ts +0 -171
  101. package/tsconfig.json +0 -13
  102. package/tsdown.config.ts +0 -22
  103. package/vitest.config.ts +0 -37
  104. 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
- });
@@ -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
- });