@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,367 +0,0 @@
1
- import { assign, fromCallback, fromPromise, setup } from '@incodetech/infra';
2
- import { addEvent } from '../events/addEvent';
3
- import {
4
- addEmail,
5
- fetchEmail,
6
- sendEmailOtp,
7
- verifyEmailOtp,
8
- } from './emailServices';
9
- import type { EmailConfig } from './types';
10
-
11
- export type EmailContext = {
12
- config: EmailConfig;
13
- email: string;
14
- isValid: boolean;
15
- emailError: string | undefined;
16
- prefilledEmail: string | undefined;
17
- error: string | undefined;
18
- otpCode: string;
19
- otpError: string | undefined;
20
- attemptsRemaining: number;
21
- resendTimer: number;
22
- resendTimerActive: boolean;
23
- };
24
-
25
- export type EmailEvent =
26
- | { type: 'LOAD' }
27
- | { type: 'EMAIL_CHANGED'; email: string; isValid: boolean }
28
- | { type: 'SUBMIT' }
29
- | { type: 'OTP_CHANGED'; code: string }
30
- | { type: 'VERIFY_OTP' }
31
- | { type: 'RESEND_OTP' }
32
- | { type: 'BACK' }
33
- | { type: 'RESET' }
34
- | { type: 'TICK' };
35
-
36
- export type EmailInput = {
37
- config: EmailConfig;
38
- };
39
-
40
- const RESEND_TIMER_SECONDS = 30;
41
-
42
- export const emailMachine = setup({
43
- types: {
44
- context: {} as EmailContext,
45
- events: {} as EmailEvent,
46
- input: {} as EmailInput,
47
- },
48
- actors: {
49
- fetchEmail: fromPromise<{ email: string }, void>(async ({ signal }) => {
50
- return fetchEmail(signal);
51
- }),
52
- submitEmail: fromPromise<{ success: boolean }, { email: string }>(
53
- async ({ input, signal }) => {
54
- return addEmail({ email: input.email }, signal);
55
- },
56
- ),
57
- sendOtp: fromPromise<void, void>(async ({ signal }) => {
58
- return sendEmailOtp(signal);
59
- }),
60
- verifyOtp: fromPromise<{ success: boolean }, { code: string }>(
61
- async ({ input, signal }) => {
62
- return verifyEmailOtp(input.code, signal);
63
- },
64
- ),
65
- resendTimer: fromCallback(({ sendBack }) => {
66
- let seconds = RESEND_TIMER_SECONDS;
67
- const interval = setInterval(() => {
68
- seconds -= 1;
69
- sendBack({ type: 'TICK' });
70
- if (seconds <= 0) {
71
- clearInterval(interval);
72
- }
73
- }, 1000);
74
- return () => clearInterval(interval);
75
- }),
76
- },
77
- actions: {
78
- setPrefilledEmail: assign(({ event }) => {
79
- const email = (event as unknown as { output: { email: string } }).output
80
- .email;
81
- return {
82
- prefilledEmail: email,
83
- email,
84
- };
85
- }),
86
- setEmail: assign(({ event }) => {
87
- const e = event as {
88
- type: 'EMAIL_CHANGED';
89
- email: string;
90
- isValid: boolean;
91
- };
92
- return {
93
- email: e.email,
94
- isValid: e.isValid,
95
- emailError: e.isValid ? undefined : 'Invalid email address',
96
- };
97
- }),
98
- setEmailError: assign(({ event }) => ({
99
- emailError: String((event as unknown as { error: unknown }).error),
100
- })),
101
- setError: assign(({ event }) => ({
102
- error: String((event as unknown as { error: unknown }).error),
103
- })),
104
- clearError: assign({
105
- error: () => undefined,
106
- }),
107
- clearEmailError: assign({
108
- emailError: () => undefined,
109
- }),
110
- setOtpCode: assign(({ event }) => ({
111
- otpCode: (event as { type: 'OTP_CHANGED'; code: string }).code,
112
- otpError: undefined,
113
- })),
114
- setOtpError: assign(({ context, event }) => ({
115
- otpError: String((event as unknown as { error: unknown }).error),
116
- attemptsRemaining: context.attemptsRemaining - 1,
117
- })),
118
- clearOtpError: assign({
119
- otpError: () => undefined,
120
- otpCode: () => '',
121
- }),
122
- startResendTimer: assign({
123
- resendTimer: () => RESEND_TIMER_SECONDS,
124
- resendTimerActive: () => true,
125
- }),
126
- tickResendTimer: assign(({ context }) => {
127
- const newTimer = Math.max(0, context.resendTimer - 1);
128
- return {
129
- resendTimer: newTimer,
130
- resendTimerActive: newTimer > 0,
131
- };
132
- }),
133
- stopResendTimer: assign({
134
- resendTimerActive: () => false,
135
- }),
136
- resetContext: assign(({ context }) => ({
137
- config: context.config,
138
- email: '',
139
- isValid: false,
140
- emailError: undefined,
141
- prefilledEmail: undefined,
142
- error: undefined,
143
- otpCode: '',
144
- otpError: undefined,
145
- attemptsRemaining: context.config.maxOtpAttempts ?? 3,
146
- resendTimer: 0,
147
- resendTimerActive: false,
148
- })),
149
- sendEmailSubmitEvent: () => {
150
- addEvent({
151
- code: 'continue',
152
- module: 'email',
153
- screen: 'emailInput',
154
- });
155
- },
156
- },
157
- guards: {
158
- hasPrefill: ({ context }): boolean => context.config.prefill,
159
- hasOtpVerification: ({ context }): boolean =>
160
- context.config.otpVerification,
161
- isValidEmail: ({ context }): boolean => context.isValid,
162
- hasAttemptsRemaining: ({ context }): boolean =>
163
- context.attemptsRemaining > 0,
164
- canResend: ({ context }): boolean => !context.resendTimerActive,
165
- },
166
- }).createMachine({
167
- id: 'email',
168
- initial: 'idle',
169
- context: ({ input }) => ({
170
- config: input.config,
171
- email: '',
172
- isValid: false,
173
- emailError: undefined,
174
- prefilledEmail: undefined,
175
- error: undefined,
176
- otpCode: '',
177
- otpError: undefined,
178
- attemptsRemaining: input.config.maxOtpAttempts ?? 3,
179
- resendTimer: 0,
180
- resendTimerActive: false,
181
- }),
182
- states: {
183
- idle: {
184
- on: {
185
- LOAD: [
186
- {
187
- target: 'loadingPrefill',
188
- guard: 'hasPrefill',
189
- },
190
- {
191
- target: 'inputting',
192
- },
193
- ],
194
- },
195
- },
196
-
197
- loadingPrefill: {
198
- invoke: {
199
- id: 'fetchEmail',
200
- src: 'fetchEmail',
201
- onDone: {
202
- target: 'inputting',
203
- actions: 'setPrefilledEmail',
204
- },
205
- onError: {
206
- target: 'inputting',
207
- },
208
- },
209
- },
210
-
211
- inputting: {
212
- entry: 'clearEmailError',
213
- on: {
214
- EMAIL_CHANGED: {
215
- actions: 'setEmail',
216
- },
217
- SUBMIT: {
218
- target: 'submitting',
219
- guard: 'isValidEmail',
220
- },
221
- },
222
- },
223
-
224
- submitting: {
225
- invoke: {
226
- id: 'submitEmail',
227
- src: 'submitEmail',
228
- input: ({ context }) => ({
229
- email: context.email,
230
- }),
231
- onDone: [
232
- {
233
- target: 'sendingOtp',
234
- guard: 'hasOtpVerification',
235
- actions: 'sendEmailSubmitEvent',
236
- },
237
- {
238
- target: 'success',
239
- actions: 'sendEmailSubmitEvent',
240
- },
241
- ],
242
- onError: {
243
- target: 'inputting',
244
- actions: 'setEmailError',
245
- },
246
- },
247
- },
248
-
249
- sendingOtp: {
250
- invoke: {
251
- id: 'sendOtp',
252
- src: 'sendOtp',
253
- onDone: {
254
- target: 'awaitingOtp',
255
- },
256
- onError: {
257
- target: 'awaitingOtp',
258
- actions: 'setError',
259
- },
260
- },
261
- },
262
-
263
- awaitingOtp: {
264
- entry: 'startResendTimer',
265
- invoke: {
266
- id: 'resendTimer',
267
- src: 'resendTimer',
268
- },
269
- on: {
270
- TICK: {
271
- actions: 'tickResendTimer',
272
- },
273
- OTP_CHANGED: {
274
- actions: 'setOtpCode',
275
- },
276
- VERIFY_OTP: {
277
- target: 'verifyingOtp',
278
- },
279
- RESEND_OTP: {
280
- target: 'sendingOtp',
281
- guard: 'canResend',
282
- },
283
- BACK: {
284
- target: 'inputting',
285
- },
286
- },
287
- },
288
-
289
- verifyingOtp: {
290
- invoke: {
291
- id: 'verifyOtp',
292
- src: 'verifyOtp',
293
- input: ({ context }) => ({
294
- code: context.otpCode,
295
- }),
296
- onDone: [
297
- {
298
- target: 'success',
299
- guard: ({ event }) => event.output.success === true,
300
- },
301
- {
302
- target: 'otpError',
303
- guard: 'hasAttemptsRemaining',
304
- actions: assign(({ context }) => ({
305
- otpError: 'Invalid OTP code',
306
- attemptsRemaining: context.attemptsRemaining - 1,
307
- })),
308
- },
309
- {
310
- target: 'error',
311
- actions: assign({
312
- error: () => 'Maximum OTP attempts exceeded',
313
- }),
314
- },
315
- ],
316
- onError: [
317
- {
318
- target: 'otpError',
319
- guard: 'hasAttemptsRemaining',
320
- actions: 'setOtpError',
321
- },
322
- {
323
- target: 'error',
324
- actions: 'setError',
325
- },
326
- ],
327
- },
328
- },
329
-
330
- otpError: {
331
- on: {
332
- OTP_CHANGED: {
333
- target: 'awaitingOtp',
334
- actions: 'setOtpCode',
335
- },
336
- RESEND_OTP: {
337
- target: 'sendingOtp',
338
- guard: 'canResend',
339
- },
340
- BACK: {
341
- target: 'inputting',
342
- },
343
- },
344
- },
345
-
346
- success: {
347
- on: {
348
- RESET: {
349
- target: 'idle',
350
- actions: 'resetContext',
351
- },
352
- },
353
- },
354
-
355
- error: {
356
- on: {
357
- RESET: {
358
- target: 'idle',
359
- actions: 'resetContext',
360
- },
361
- },
362
- },
363
- },
364
- // biome-ignore lint/suspicious/noExplicitAny: XState type inference issue with guards in declaration files
365
- }) as any;
366
-
367
- export type EmailMachine = typeof emailMachine;
@@ -1,39 +0,0 @@
1
- /**
2
- * Email verification module - supports headless and UI-driven usage.
3
- *
4
- * ## Headless Usage (Programmatic)
5
- *
6
- * Use `createEmailManager` to control email verification without any UI.
7
- * Perfect for custom UI implementations, backend integrations, or automated testing.
8
- *
9
- * ```typescript
10
- * import { createEmailManager } from '@incodetech/core/email';
11
- *
12
- * const manager = createEmailManager({
13
- * config: { otpVerification: true, otpExpirationInMinutes: 5, prefill: false },
14
- * });
15
- *
16
- * manager.subscribe((state) => console.log(state.status));
17
- * manager.load();
18
- * manager.setEmail('user@example.com', true);
19
- * manager.submit();
20
- * manager.submitOtp('ABC123');
21
- * manager.stop();
22
- * ```
23
- *
24
- * ## UI Usage
25
- *
26
- * For a ready-to-use UI, import the Email component from `@incodetech/ui/email`.
27
- *
28
- * @module @incodetech/core/email
29
- * @see {@link createEmailManager} for headless API documentation
30
- * @see {@link EmailConfig} for configuration options
31
- * @see {@link EmailState} for state machine states
32
- */
33
- export {
34
- createEmailManager,
35
- type EmailManager,
36
- type EmailState,
37
- } from './emailManager';
38
- export { emailMachine } from './emailStateMachine';
39
- export type { EmailConfig } from './types';
@@ -1,60 +0,0 @@
1
- /**
2
- * Configuration options for email verification.
3
- *
4
- * @example Standard OTP verification
5
- * ```typescript
6
- * const config: EmailConfig = {
7
- * otpVerification: true,
8
- * otpExpirationInMinutes: 5,
9
- * prefill: false,
10
- * };
11
- * ```
12
- *
13
- * @example With all options
14
- * ```typescript
15
- * const config: EmailConfig = {
16
- * otpVerification: true,
17
- * otpExpirationInMinutes: 10,
18
- * prefill: true,
19
- * maxOtpAttempts: 3,
20
- * };
21
- * ```
22
- */
23
- export type EmailConfig = {
24
- /**
25
- * Whether to require OTP (email code) verification.
26
- * If false, email is verified immediately after submission.
27
- */
28
- otpVerification: boolean;
29
-
30
- /**
31
- * How long the OTP code remains valid, in minutes.
32
- * After expiration, user must request a new code.
33
- */
34
- otpExpirationInMinutes: number;
35
-
36
- /**
37
- * Whether to pre-populate with user's previously stored email address.
38
- * Useful for returning users.
39
- */
40
- prefill: boolean;
41
-
42
- /**
43
- * Maximum number of OTP verification attempts before lockout.
44
- * After exhausting attempts, user sees an error state.
45
- * @default 3
46
- */
47
- maxOtpAttempts?: number;
48
- };
49
-
50
- export type AddEmailResponse = {
51
- success: boolean;
52
- };
53
-
54
- export type VerifyOtpResponse = {
55
- success: boolean;
56
- };
57
-
58
- export type AddEmailParams = {
59
- email: string;
60
- };
@@ -1,20 +0,0 @@
1
- import { api } from '../http/api';
2
- import { endpoints } from '../http/endpoints';
3
- import type { Event } from './types';
4
-
5
- export function addEvent(event: Event): Promise<void> {
6
- const { code, module, screen, clientTimestamp, payload = {} } = event;
7
-
8
- return api
9
- .post(endpoints.events, [
10
- {
11
- code,
12
- module,
13
- screen,
14
- clientTimestamp: clientTimestamp ?? Date.now(),
15
- payload,
16
- },
17
- ])
18
- .then(() => undefined)
19
- .catch(() => undefined);
20
- }
@@ -1,7 +0,0 @@
1
- export type Event = {
2
- code: string;
3
- module?: string;
4
- screen?: string;
5
- payload?: Record<string, unknown>;
6
- clientTimestamp?: number;
7
- };
@@ -1,84 +0,0 @@
1
- import { vi } from 'vitest';
2
- import type { Flow, FlowModule } from '../types';
3
-
4
- export const mockTutorialIdModule: FlowModule = {
5
- key: 'TUTORIAL_ID',
6
- configuration: {
7
- showTutorial: true,
8
- enableId: true,
9
- enablePassport: false,
10
- onlyFront: false,
11
- onlyBack: false,
12
- barcodeCapture: false,
13
- fetchAdditionalPage: false,
14
- secondId: false,
15
- thirdId: false,
16
- autoCaptureTimeout: 30,
17
- deviceIdleTimeout: 60,
18
- captureAttempts: 3,
19
- manualUploadIdCapture: false,
20
- digitalIdsUpload: false,
21
- showDocumentChooserScreen: false,
22
- enableIdRecording: false,
23
- usSmartCapture: false,
24
- perCountryPerDocOverrides: {},
25
- },
26
- };
27
-
28
- export const mockSelfieModule: FlowModule = {
29
- key: 'SELFIE',
30
- configuration: {
31
- showTutorial: false,
32
- showPreview: true,
33
- assistedOnboarding: false,
34
- enableFaceRecording: false,
35
- autoCaptureTimeout: 30,
36
- captureAttempts: 3,
37
- validateLenses: false,
38
- validateFaceMask: false,
39
- validateHeadCover: false,
40
- validateClosedEyes: false,
41
- validateBrightness: false,
42
- deepsightLiveness: 'SINGLE_FRAME',
43
- },
44
- };
45
-
46
- export const mockFaceMatchModule: FlowModule = {
47
- key: 'FACE_MATCH',
48
- configuration: {
49
- matchingType: 'selfieVsId',
50
- disableFaceMatchAnimation: false,
51
- },
52
- };
53
-
54
- export const mockModules: FlowModule[] = [
55
- mockTutorialIdModule,
56
- mockSelfieModule,
57
- mockFaceMatchModule,
58
- ];
59
-
60
- export function createMockFlow(modules: FlowModule[] = mockModules): Flow {
61
- return {
62
- flowId: 'test-flow-id',
63
- name: 'Test Flow',
64
- flowModules: modules,
65
- };
66
- }
67
-
68
- export const mockFlow = createMockFlow();
69
-
70
- export function createMockGetFlow(flow: Flow = mockFlow) {
71
- return vi.fn().mockResolvedValue(flow);
72
- }
73
-
74
- export function createFailingGetFlow(error: string) {
75
- return vi.fn().mockRejectedValue(new Error(error));
76
- }
77
-
78
- export function createDelayedGetFlow(flow: Flow = mockFlow, delayMs = 1000) {
79
- return vi
80
- .fn()
81
- .mockImplementation(
82
- () => new Promise((resolve) => setTimeout(() => resolve(flow), delayMs)),
83
- );
84
- }
@@ -1,13 +0,0 @@
1
- import { createActor } from '@incodetech/infra';
2
- import { getFlow as defaultGetFlow, type GetFlow } from './flowServices';
3
- import { flowMachine } from './flowStateMachine';
4
-
5
- export type CreateFlowActorOptions = {
6
- getFlow?: GetFlow;
7
- };
8
-
9
- export function createFlowActor(options?: CreateFlowActorOptions) {
10
- const getFlow = options?.getFlow ?? defaultGetFlow;
11
-
12
- return createActor(flowMachine, { input: { getFlow } }).start();
13
- }