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

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 (106) hide show
  1. package/dist/Manager-BGfxEmyv.d.ts +19 -0
  2. package/dist/OpenViduLogger-BdPfiZO6.esm.js +3 -0
  3. package/dist/OpenViduLogger-CQyDxBvM.esm.js +803 -0
  4. package/dist/StateMachine-DRE1oH2B.d.ts +2 -0
  5. package/dist/addEvent-W0ORK0jT.esm.js +16 -0
  6. package/dist/chunk-C_Yo44FK.esm.js +49 -0
  7. package/dist/email.d.ts +264 -0
  8. package/dist/email.esm.js +479 -0
  9. package/dist/endpoints-BSTFaHYo.esm.js +1706 -0
  10. package/dist/flow.d.ts +578 -0
  11. package/dist/flow.esm.js +628 -0
  12. package/dist/index.d.ts +226 -0
  13. package/dist/index.esm.js +155 -0
  14. package/dist/lib-Bu9XGMBW.esm.js +11700 -0
  15. package/dist/permissionServices-I6vX6DBy.esm.js +72 -0
  16. package/dist/phone.d.ts +292 -0
  17. package/dist/phone.esm.js +550 -0
  18. package/dist/selfie.d.ts +759 -0
  19. package/dist/selfie.esm.js +995 -0
  20. package/dist/types-iZi2rawo.d.ts +5 -0
  21. package/dist/warmup-CEJTfxQr.d.ts +55 -0
  22. package/dist/xstate.esm-B_rda9yU.esm.js +3261 -0
  23. package/package.json +14 -11
  24. package/src/camera/cameraActor.ts +0 -21
  25. package/src/camera/cameraService.test.ts +0 -437
  26. package/src/camera/cameraService.ts +0 -165
  27. package/src/camera/cameraServices.test.ts +0 -66
  28. package/src/camera/cameraServices.ts +0 -26
  29. package/src/camera/cameraStateMachine.test.ts +0 -602
  30. package/src/camera/cameraStateMachine.ts +0 -264
  31. package/src/camera/index.ts +0 -5
  32. package/src/camera/types.ts +0 -17
  33. package/src/device/getBrowser.ts +0 -31
  34. package/src/device/getDeviceClass.ts +0 -29
  35. package/src/device/index.ts +0 -2
  36. package/src/email/__mocks__/emailMocks.ts +0 -59
  37. package/src/email/emailActor.ts +0 -15
  38. package/src/email/emailManager.test.ts +0 -573
  39. package/src/email/emailManager.ts +0 -427
  40. package/src/email/emailServices.ts +0 -66
  41. package/src/email/emailStateMachine.test.ts +0 -741
  42. package/src/email/emailStateMachine.ts +0 -367
  43. package/src/email/index.ts +0 -39
  44. package/src/email/types.ts +0 -60
  45. package/src/events/addEvent.ts +0 -20
  46. package/src/events/types.ts +0 -7
  47. package/src/flow/__mocks__/flowMocks.ts +0 -84
  48. package/src/flow/flowActor.ts +0 -13
  49. package/src/flow/flowAnalyzer.test.ts +0 -266
  50. package/src/flow/flowAnalyzer.ts +0 -37
  51. package/src/flow/flowCompletionService.ts +0 -21
  52. package/src/flow/flowManager.test.ts +0 -560
  53. package/src/flow/flowManager.ts +0 -235
  54. package/src/flow/flowServices.test.ts +0 -109
  55. package/src/flow/flowServices.ts +0 -13
  56. package/src/flow/flowStateMachine.test.ts +0 -334
  57. package/src/flow/flowStateMachine.ts +0 -182
  58. package/src/flow/index.ts +0 -21
  59. package/src/flow/moduleLoader.test.ts +0 -136
  60. package/src/flow/moduleLoader.ts +0 -73
  61. package/src/flow/orchestratedFlowManager.test.ts +0 -240
  62. package/src/flow/orchestratedFlowManager.ts +0 -231
  63. package/src/flow/orchestratedFlowStateMachine.test.ts +0 -199
  64. package/src/flow/orchestratedFlowStateMachine.ts +0 -325
  65. package/src/flow/types.ts +0 -434
  66. package/src/http/__mocks__/api.ts +0 -88
  67. package/src/http/api.test.ts +0 -231
  68. package/src/http/api.ts +0 -90
  69. package/src/http/endpoints.ts +0 -17
  70. package/src/index.ts +0 -33
  71. package/src/permissions/index.ts +0 -2
  72. package/src/permissions/permissionServices.ts +0 -31
  73. package/src/permissions/types.ts +0 -3
  74. package/src/phone/__mocks__/phoneMocks.ts +0 -71
  75. package/src/phone/index.ts +0 -39
  76. package/src/phone/phoneActor.ts +0 -15
  77. package/src/phone/phoneManager.test.ts +0 -393
  78. package/src/phone/phoneManager.ts +0 -458
  79. package/src/phone/phoneServices.ts +0 -98
  80. package/src/phone/phoneStateMachine.test.ts +0 -918
  81. package/src/phone/phoneStateMachine.ts +0 -422
  82. package/src/phone/types.ts +0 -83
  83. package/src/recordings/recordingsRepository.test.ts +0 -87
  84. package/src/recordings/recordingsRepository.ts +0 -48
  85. package/src/recordings/streamingEvents.ts +0 -10
  86. package/src/selfie/__mocks__/selfieMocks.ts +0 -26
  87. package/src/selfie/index.ts +0 -14
  88. package/src/selfie/selfieActor.ts +0 -17
  89. package/src/selfie/selfieErrorUtils.test.ts +0 -116
  90. package/src/selfie/selfieErrorUtils.ts +0 -66
  91. package/src/selfie/selfieManager.test.ts +0 -297
  92. package/src/selfie/selfieManager.ts +0 -301
  93. package/src/selfie/selfieServices.ts +0 -362
  94. package/src/selfie/selfieStateMachine.test.ts +0 -283
  95. package/src/selfie/selfieStateMachine.ts +0 -804
  96. package/src/selfie/selfieUploadService.test.ts +0 -90
  97. package/src/selfie/selfieUploadService.ts +0 -81
  98. package/src/selfie/types.ts +0 -103
  99. package/src/session/index.ts +0 -5
  100. package/src/session/sessionService.ts +0 -78
  101. package/src/setup.test.ts +0 -61
  102. package/src/setup.ts +0 -171
  103. package/tsconfig.json +0 -13
  104. package/tsdown.config.ts +0 -22
  105. package/vitest.config.ts +0 -37
  106. package/vitest.setup.ts +0 -135
@@ -1,427 +0,0 @@
1
- /**
2
- * @module @incodetech/core/email
3
- *
4
- * Email verification module for the Incode Web SDK.
5
- * Supports both headless (programmatic) and UI-driven usage patterns.
6
- *
7
- * ## Headless Usage
8
- *
9
- * The email manager can be used entirely without UI for backend integrations,
10
- * custom UI implementations, or automated workflows.
11
- *
12
- * @example Basic headless email verification with OTP
13
- * ```typescript
14
- * import { createEmailManager } from '@incodetech/core/email';
15
- * import { setup } from '@incodetech/core';
16
- *
17
- * // 1. Configure the SDK (required before using any module)
18
- * setup({ apiURL: 'https://api.example.com', token: 'your-token' });
19
- *
20
- * // 2. Create the email manager
21
- * const emailManager = createEmailManager({
22
- * config: {
23
- * otpVerification: true,
24
- * otpExpirationInMinutes: 5,
25
- * prefill: false,
26
- * },
27
- * });
28
- *
29
- * // 3. Subscribe to state changes (optional but recommended)
30
- * emailManager.subscribe((state) => {
31
- * console.log('Email state:', state.status);
32
- * if (state.status === 'success') {
33
- * console.log('Email verified successfully!');
34
- * }
35
- * if (state.status === 'error') {
36
- * console.error('Error:', state.error);
37
- * }
38
- * });
39
- *
40
- * // 4. Start the flow
41
- * emailManager.load();
42
- *
43
- * // 5. When state is 'inputting', set the email address
44
- * emailManager.setEmail('user@example.com', true);
45
- *
46
- * // 6. Submit the email address
47
- * emailManager.submit();
48
- *
49
- * // 7. When state is 'awaitingOtp', submit the OTP code
50
- * emailManager.submitOtp('ABC123');
51
- *
52
- * // 8. Clean up when done
53
- * emailManager.stop();
54
- * ```
55
- *
56
- * @example Polling-based headless usage
57
- * ```typescript
58
- * const emailManager = createEmailManager({ config });
59
- *
60
- * emailManager.load();
61
- *
62
- * // Poll for state changes
63
- * const interval = setInterval(() => {
64
- * const state = emailManager.getState();
65
- *
66
- * switch (state.status) {
67
- * case 'inputting':
68
- * emailManager.setEmail('user@example.com', true);
69
- * emailManager.submit();
70
- * break;
71
- * case 'awaitingOtp':
72
- * // Get OTP from user or external source
73
- * emailManager.submitOtp(otpCode);
74
- * break;
75
- * case 'success':
76
- * clearInterval(interval);
77
- * emailManager.stop();
78
- * break;
79
- * case 'error':
80
- * clearInterval(interval);
81
- * console.error(state.error);
82
- * emailManager.stop();
83
- * break;
84
- * }
85
- * }, 100);
86
- * ```
87
- */
88
- import {
89
- type CreateApiOptions,
90
- createManager,
91
- type ManagerSnapshot,
92
- } from '@incodetech/infra';
93
- import { type CreateEmailActorOptions, createEmailActor } from './emailActor';
94
- import type { EmailMachine } from './emailStateMachine';
95
-
96
- type EmailSnapshot = ManagerSnapshot<EmailMachine>;
97
-
98
- /** Email manager is in initial state, waiting for `load()` to be called */
99
- export type EmailIdleState = {
100
- status: 'idle';
101
- };
102
-
103
- /** Loading prefilled email address from backend (if prefill is enabled) */
104
- export type EmailLoadingPrefillState = {
105
- status: 'loadingPrefill';
106
- };
107
-
108
- /**
109
- * Ready for email input - use `setEmail()` and `submit()`
110
- * @property prefilledEmail - Pre-populated email address (if prefill enabled)
111
- * @property emailError - Validation error message if email was rejected
112
- */
113
- export type EmailInputtingState = {
114
- status: 'inputting';
115
- prefilledEmail?: string;
116
- emailError?: string;
117
- };
118
-
119
- /** Email address is being submitted to the backend */
120
- export type EmailSubmittingState = {
121
- status: 'submitting';
122
- };
123
-
124
- /** OTP is being sent to the email address */
125
- export type EmailSendingOtpState = {
126
- status: 'sendingOtp';
127
- };
128
-
129
- /**
130
- * Waiting for OTP code - use `submitOtp()`, `resendOtp()`, or `back()`
131
- * @property resendTimer - Seconds remaining before resend is allowed
132
- * @property canResend - Whether the resend button should be enabled
133
- * @property attemptsRemaining - Number of OTP verification attempts left
134
- */
135
- export type EmailAwaitingOtpState = {
136
- status: 'awaitingOtp';
137
- resendTimer: number;
138
- canResend: boolean;
139
- attemptsRemaining: number;
140
- };
141
-
142
- /** OTP code is being verified against the backend */
143
- export type EmailVerifyingOtpState = {
144
- status: 'verifyingOtp';
145
- };
146
-
147
- /**
148
- * OTP verification failed - user can retry with `submitOtp()`
149
- * @property error - Error message describing why verification failed
150
- * @property attemptsRemaining - Number of remaining attempts before lockout
151
- */
152
- export type EmailOtpErrorState = {
153
- status: 'otpError';
154
- error: string;
155
- attemptsRemaining: number;
156
- };
157
-
158
- /** Email verification completed successfully - call `reset()` to start over */
159
- export type EmailSuccessState = {
160
- status: 'success';
161
- };
162
-
163
- /**
164
- * Fatal error occurred - call `reset()` to start over
165
- * @property error - Error message describing what went wrong
166
- */
167
- export type EmailErrorState = {
168
- status: 'error';
169
- error: string;
170
- };
171
-
172
- /**
173
- * Union of all possible email manager states.
174
- * Use discriminated union pattern to narrow the type:
175
- *
176
- * @example
177
- * ```typescript
178
- * const state = emailManager.getState();
179
- * if (state.status === 'inputting') {
180
- * // TypeScript knows state has prefilledEmail, emailError, etc.
181
- * console.log(state.prefilledEmail);
182
- * }
183
- * ```
184
- */
185
- export type EmailState =
186
- | EmailIdleState
187
- | EmailLoadingPrefillState
188
- | EmailInputtingState
189
- | EmailSubmittingState
190
- | EmailSendingOtpState
191
- | EmailAwaitingOtpState
192
- | EmailVerifyingOtpState
193
- | EmailOtpErrorState
194
- | EmailSuccessState
195
- | EmailErrorState;
196
-
197
- function mapState(snapshot: EmailSnapshot): EmailState {
198
- // Type assertion needed because EmailMachine uses 'as any' for declaration file generation
199
- const typedSnapshot = snapshot as EmailSnapshot & {
200
- matches: (state: string) => boolean;
201
- context: {
202
- prefilledEmail?: string;
203
- emailError?: string;
204
- resendTimer: number;
205
- resendTimerActive: boolean;
206
- attemptsRemaining: number;
207
- otpError?: string;
208
- error?: string;
209
- };
210
- };
211
- const { context } = typedSnapshot;
212
-
213
- if (typedSnapshot.matches('idle')) {
214
- return { status: 'idle' };
215
- }
216
-
217
- if (typedSnapshot.matches('loadingPrefill')) {
218
- return { status: 'loadingPrefill' };
219
- }
220
-
221
- if (typedSnapshot.matches('inputting')) {
222
- return {
223
- status: 'inputting',
224
- prefilledEmail: context.prefilledEmail,
225
- emailError: context.emailError,
226
- };
227
- }
228
-
229
- if (typedSnapshot.matches('submitting')) {
230
- return { status: 'submitting' };
231
- }
232
-
233
- if (typedSnapshot.matches('sendingOtp')) {
234
- return { status: 'sendingOtp' };
235
- }
236
-
237
- if (typedSnapshot.matches('awaitingOtp')) {
238
- return {
239
- status: 'awaitingOtp',
240
- resendTimer: context.resendTimer,
241
- canResend: !context.resendTimerActive,
242
- attemptsRemaining: context.attemptsRemaining,
243
- };
244
- }
245
-
246
- if (typedSnapshot.matches('verifyingOtp')) {
247
- return { status: 'verifyingOtp' };
248
- }
249
-
250
- if (typedSnapshot.matches('otpError')) {
251
- return {
252
- status: 'otpError',
253
- error: context.otpError ?? 'Invalid OTP code',
254
- attemptsRemaining: context.attemptsRemaining,
255
- };
256
- }
257
-
258
- if (typedSnapshot.matches('success')) {
259
- return { status: 'success' };
260
- }
261
-
262
- if (typedSnapshot.matches('error')) {
263
- return {
264
- status: 'error',
265
- error: context.error ?? 'An error occurred',
266
- };
267
- }
268
-
269
- return { status: 'idle' };
270
- }
271
-
272
- function createApi({ actor }: CreateApiOptions<EmailMachine>) {
273
- return {
274
- /**
275
- * Initializes the email verification flow.
276
- * Transitions from 'idle' to 'loadingPrefill' or 'inputting'.
277
- * Must be called before any other method.
278
- */
279
- load() {
280
- actor.send({ type: 'LOAD' });
281
- },
282
-
283
- /**
284
- * Sets the email address for verification.
285
- * Should be called when state is 'inputting'.
286
- *
287
- * @param email - Email address (e.g., 'user@example.com')
288
- * @param isValid - Whether the email address passes validation
289
- *
290
- * @example
291
- * ```typescript
292
- * // Using regex for validation
293
- * const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
294
- * const email = 'user@example.com';
295
- * emailManager.setEmail(email, emailRegex.test(email));
296
- * ```
297
- */
298
- setEmail(email: string, isValid: boolean) {
299
- actor.send({ type: 'EMAIL_CHANGED', email, isValid });
300
- },
301
-
302
- /**
303
- * Submits the email address for verification.
304
- * Requires a valid email address to be set via `setEmail()`.
305
- * Transitions to 'submitting', then to 'sendingOtp' or 'success' (if no OTP).
306
- */
307
- submit() {
308
- actor.send({ type: 'SUBMIT' });
309
- },
310
-
311
- /**
312
- * Sets the OTP code without submitting.
313
- * Use this for controlled input components.
314
- *
315
- * @param code - The OTP code entered by the user
316
- */
317
- setOtpCode(code: string) {
318
- actor.send({ type: 'OTP_CHANGED', code });
319
- },
320
-
321
- /**
322
- * Sets and submits the OTP code in one call.
323
- * Should be called when state is 'awaitingOtp' or 'otpError'.
324
- *
325
- * @param code - The complete OTP code (typically 6 alphanumeric characters)
326
- *
327
- * @example
328
- * ```typescript
329
- * // Submit OTP when user completes entry
330
- * emailManager.submitOtp('HH36LP');
331
- * ```
332
- */
333
- submitOtp(code: string) {
334
- actor.send({ type: 'OTP_CHANGED', code });
335
- actor.send({ type: 'VERIFY_OTP' });
336
- },
337
-
338
- /**
339
- * Requests a new OTP code to be sent.
340
- * Only works when state is 'awaitingOtp' and `canResend` is true.
341
- * Resets the resend timer.
342
- */
343
- resendOtp() {
344
- actor.send({ type: 'RESEND_OTP' });
345
- },
346
-
347
- /**
348
- * Returns to the email input screen from OTP entry.
349
- * Allows the user to change their email address.
350
- * Transitions from 'awaitingOtp' or 'otpError' back to 'inputting'.
351
- */
352
- back() {
353
- actor.send({ type: 'BACK' });
354
- },
355
-
356
- /**
357
- * Resets the manager to initial state.
358
- * Can be called from 'success' or 'error' states to start over.
359
- * Clears all stored data including email address and OTP.
360
- */
361
- reset() {
362
- actor.send({ type: 'RESET' });
363
- },
364
- };
365
- }
366
-
367
- /**
368
- * Creates an email verification manager for headless or UI-driven usage.
369
- *
370
- * The manager provides a state machine-based API for email address verification
371
- * with optional OTP (one-time password) verification.
372
- *
373
- * @param options - Configuration options
374
- * @param options.config - Email verification configuration
375
- * @param options.config.otpVerification - Whether to require OTP verification
376
- * @param options.config.otpExpirationInMinutes - How long the OTP is valid
377
- * @param options.config.prefill - Whether to fetch a pre-filled email address
378
- * @param options.config.maxOtpAttempts - Maximum OTP verification attempts (default: 3)
379
- *
380
- * @returns Email manager with state, API methods, and subscription
381
- *
382
- * @example Headless usage
383
- * ```typescript
384
- * const manager = createEmailManager({
385
- * config: { otpVerification: true, otpExpirationInMinutes: 5, prefill: false },
386
- * });
387
- *
388
- * manager.subscribe((state) => console.log(state.status));
389
- * manager.load();
390
- * manager.setEmail('user@example.com', true);
391
- * manager.submit();
392
- * // ... wait for 'awaitingOtp' state ...
393
- * manager.submitOtp('ABC123');
394
- * manager.stop();
395
- * ```
396
- *
397
- * @example With React/Preact UI hook
398
- * ```tsx
399
- * const [state, manager] = useManager(() => createEmailManager({ config }));
400
- *
401
- * if (state.status === 'inputting') {
402
- * return <input onChange={(e) => manager.setEmail(e.target.value, true)} />;
403
- * }
404
- * ```
405
- */
406
- export function createEmailManager(options: CreateEmailActorOptions) {
407
- const actor = createEmailActor(options);
408
- return createManager({ actor, mapState, createApi });
409
- }
410
-
411
- /**
412
- * Type representing an email manager instance.
413
- * Includes state access, API methods, and lifecycle management.
414
- *
415
- * @property getState - Returns the current EmailState
416
- * @property subscribe - Subscribes to state changes, returns unsubscribe function
417
- * @property stop - Stops the manager and cleans up resources
418
- * @property load - Initializes the verification flow
419
- * @property setEmail - Sets the email address
420
- * @property submit - Submits the email address
421
- * @property setOtpCode - Sets OTP code without submitting
422
- * @property submitOtp - Sets and submits OTP code
423
- * @property resendOtp - Requests new OTP code
424
- * @property back - Returns to email input from OTP screen
425
- * @property reset - Resets to initial state
426
- */
427
- export type EmailManager = ReturnType<typeof createEmailManager>;
@@ -1,66 +0,0 @@
1
- import { api } from '../http/api';
2
- import { endpoints } from '../http/endpoints';
3
- import type {
4
- AddEmailParams,
5
- AddEmailResponse,
6
- VerifyOtpResponse,
7
- } from './types';
8
-
9
- export async function fetchEmail(
10
- signal?: AbortSignal,
11
- ): Promise<{ email: string }> {
12
- const res = await api.get<{ email: string }>(endpoints.getEmail, { signal });
13
- if (!res.ok) {
14
- throw new Error(
15
- `GET ${endpoints.getEmail} failed: ${res.status} ${res.statusText}`,
16
- );
17
- }
18
- return res.data as { email: string };
19
- }
20
-
21
- export async function addEmail(
22
- params: AddEmailParams,
23
- signal?: AbortSignal,
24
- ): Promise<AddEmailResponse> {
25
- const res = await api.post<AddEmailResponse>(
26
- endpoints.email,
27
- {
28
- email: params.email,
29
- },
30
- { signal },
31
- );
32
- if (!res.ok) {
33
- throw new Error(
34
- `POST ${endpoints.email} failed: ${res.status} ${res.statusText}`,
35
- );
36
- }
37
- return res.data as AddEmailResponse;
38
- }
39
-
40
- export async function sendEmailOtp(signal?: AbortSignal): Promise<void> {
41
- const res = await api.get(
42
- `${endpoints.sendSmsOtp}?communicationchannel=EMAIL`,
43
- { signal },
44
- );
45
- if (!res.ok) {
46
- throw new Error(
47
- `GET ${endpoints.sendSmsOtp} failed: ${res.status} ${res.statusText}`,
48
- );
49
- }
50
- }
51
-
52
- export async function verifyEmailOtp(
53
- code: string,
54
- signal?: AbortSignal,
55
- ): Promise<VerifyOtpResponse> {
56
- const res = await api.get<VerifyOtpResponse>(
57
- `${endpoints.compareOtp}?code=${code}&channel=EMAIL`,
58
- { signal },
59
- );
60
- if (!res.ok) {
61
- throw new Error(
62
- `GET ${endpoints.compareOtp} failed: ${res.status} ${res.statusText}`,
63
- );
64
- }
65
- return res.data as VerifyOtpResponse;
66
- }