@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,231 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { setup } from '../setup';
3
- import {
4
- api,
5
- getApi,
6
- getToken,
7
- isApiConfigured,
8
- resetApi,
9
- setToken,
10
- } from './api';
11
-
12
- const mockResponse = {
13
- data: {},
14
- status: 200,
15
- headers: {},
16
- ok: true,
17
- statusText: 'OK',
18
- url: 'https://api.test.com/test',
19
- };
20
-
21
- describe('api', () => {
22
- beforeEach(() => {
23
- resetApi();
24
- });
25
-
26
- describe('api wrapper', () => {
27
- it('should throw error when accessing methods before setup()', () => {
28
- expect(() => api.get('/test')).toThrow(
29
- 'SDK not configured. Call setup({ apiURL: "..." }) first.',
30
- );
31
- });
32
-
33
- it('should have method functions after setup()', () => {
34
- setup({ apiURL: 'https://api.test.com', token: 'test-token' });
35
-
36
- expect(typeof api.get).toBe('function');
37
- expect(typeof api.post).toBe('function');
38
- expect(typeof api.put).toBe('function');
39
- expect(typeof api.patch).toBe('function');
40
- expect(typeof api.delete).toBe('function');
41
- });
42
- });
43
-
44
- describe('getApi()', () => {
45
- it('should throw error if setup() was not called', () => {
46
- expect(() => getApi()).toThrow(
47
- 'SDK not configured. Call setup({ apiURL: "..." }) first.',
48
- );
49
- });
50
-
51
- it('should return the client after setup()', () => {
52
- setup({ apiURL: 'https://api.test.com', token: 'test-token' });
53
-
54
- const client = getApi();
55
- expect(client).toBeDefined();
56
- expect(client.defaults.baseURL).toBe('https://api.test.com');
57
- expect(getToken()).toBe('test-token');
58
- });
59
- });
60
-
61
- describe('isApiConfigured()', () => {
62
- it('should return false before setup()', () => {
63
- expect(isApiConfigured()).toBe(false);
64
- });
65
-
66
- it('should return true after setup()', () => {
67
- setup({ apiURL: 'https://api.test.com', token: 'test-token' });
68
-
69
- expect(isApiConfigured()).toBe(true);
70
- });
71
- });
72
-
73
- describe('resetApi()', () => {
74
- it('should reset the client to null', () => {
75
- setup({ apiURL: 'https://api.test.com', token: 'test-token' });
76
- expect(isApiConfigured()).toBe(true);
77
-
78
- resetApi();
79
- expect(isApiConfigured()).toBe(false);
80
- });
81
-
82
- it('should cause getApi() to throw after reset', () => {
83
- setup({ apiURL: 'https://api.test.com', token: 'test-token' });
84
- resetApi();
85
-
86
- expect(() => getApi()).toThrow();
87
- });
88
-
89
- it('should reset the token to null', () => {
90
- setup({ apiURL: 'https://api.test.com', token: 'test-token' });
91
- expect(getToken()).toBe('test-token');
92
-
93
- resetApi();
94
- expect(getToken()).toBeNull();
95
- });
96
- });
97
-
98
- describe('setToken()', () => {
99
- it('should set the token', () => {
100
- setToken('my-token');
101
- expect(getToken()).toBe('my-token');
102
- });
103
-
104
- it('should override existing token', () => {
105
- setToken('first-token');
106
- setToken('second-token');
107
- expect(getToken()).toBe('second-token');
108
- });
109
- });
110
-
111
- describe('api methods with token', () => {
112
- beforeEach(() => {
113
- setup({ apiURL: 'https://api.test.com', token: 'test-token' });
114
- });
115
-
116
- it('should add token header to get requests', async () => {
117
- const client = getApi();
118
- const getSpy = vi.spyOn(client, 'get').mockResolvedValue(mockResponse);
119
-
120
- await api.get('/test');
121
-
122
- expect(getSpy).toHaveBeenCalledWith('/test', {
123
- headers: { 'X-Incode-Hardware-Id': 'test-token' },
124
- });
125
- });
126
-
127
- it('should add token header to post requests', async () => {
128
- const client = getApi();
129
- const postSpy = vi.spyOn(client, 'post').mockResolvedValue(mockResponse);
130
-
131
- await api.post('/test', { foo: 'bar' });
132
-
133
- expect(postSpy).toHaveBeenCalledWith(
134
- '/test',
135
- { foo: 'bar' },
136
- {
137
- headers: { 'X-Incode-Hardware-Id': 'test-token' },
138
- },
139
- );
140
- });
141
-
142
- it('should add token header to put requests', async () => {
143
- const client = getApi();
144
- const putSpy = vi.spyOn(client, 'put').mockResolvedValue(mockResponse);
145
-
146
- await api.put('/test', { foo: 'bar' });
147
-
148
- expect(putSpy).toHaveBeenCalledWith(
149
- '/test',
150
- { foo: 'bar' },
151
- {
152
- headers: { 'X-Incode-Hardware-Id': 'test-token' },
153
- },
154
- );
155
- });
156
-
157
- it('should add token header to patch requests', async () => {
158
- const client = getApi();
159
- const patchSpy = vi
160
- .spyOn(client, 'patch')
161
- .mockResolvedValue(mockResponse);
162
-
163
- await api.patch('/test', { foo: 'bar' });
164
-
165
- expect(patchSpy).toHaveBeenCalledWith(
166
- '/test',
167
- { foo: 'bar' },
168
- {
169
- headers: { 'X-Incode-Hardware-Id': 'test-token' },
170
- },
171
- );
172
- });
173
-
174
- it('should add token header to delete requests', async () => {
175
- const client = getApi();
176
- const deleteSpy = vi
177
- .spyOn(client, 'delete')
178
- .mockResolvedValue(mockResponse);
179
-
180
- await api.delete('/test');
181
-
182
- expect(deleteSpy).toHaveBeenCalledWith('/test', {
183
- headers: { 'X-Incode-Hardware-Id': 'test-token' },
184
- });
185
- });
186
-
187
- it('should merge token header with existing headers', async () => {
188
- const client = getApi();
189
- const getSpy = vi.spyOn(client, 'get').mockResolvedValue(mockResponse);
190
-
191
- await api.get('/test', { headers: { 'X-Custom': 'value' } });
192
-
193
- expect(getSpy).toHaveBeenCalledWith('/test', {
194
- headers: {
195
- 'X-Custom': 'value',
196
- 'X-Incode-Hardware-Id': 'test-token',
197
- },
198
- });
199
- });
200
- });
201
-
202
- describe('api methods without token', () => {
203
- beforeEach(() => {
204
- setup({ apiURL: 'https://api.test.com', token: '' });
205
- resetApi();
206
- setup({ apiURL: 'https://api.test.com', token: '' });
207
- });
208
-
209
- it('should not add token header when token is empty', async () => {
210
- setToken('');
211
- const client = getApi();
212
- const getSpy = vi.spyOn(client, 'get').mockResolvedValue(mockResponse);
213
-
214
- await api.get('/test');
215
-
216
- expect(getSpy).toHaveBeenCalledWith('/test', {});
217
- });
218
-
219
- it('should pass through config without modification when no token', async () => {
220
- setToken('');
221
- const client = getApi();
222
- const getSpy = vi.spyOn(client, 'get').mockResolvedValue(mockResponse);
223
-
224
- await api.get('/test', { headers: { 'X-Custom': 'value' } });
225
-
226
- expect(getSpy).toHaveBeenCalledWith('/test', {
227
- headers: { 'X-Custom': 'value' },
228
- });
229
- });
230
- });
231
- });
package/src/http/api.ts DELETED
@@ -1,90 +0,0 @@
1
- import type { HttpClient, HttpResponse } from '@incodetech/infra';
2
-
3
- type MethodConfig = {
4
- headers?: Record<string, string>;
5
- signal?: AbortSignal;
6
- timeout?: number;
7
- query?: Record<string, string | number | boolean | undefined>;
8
- };
9
-
10
- type ApiClient = {
11
- get<T>(url: string, config?: MethodConfig): Promise<HttpResponse<T>>;
12
- post<T>(
13
- url: string,
14
- data?: unknown,
15
- config?: MethodConfig,
16
- ): Promise<HttpResponse<T>>;
17
- put<T>(
18
- url: string,
19
- data?: unknown,
20
- config?: MethodConfig,
21
- ): Promise<HttpResponse<T>>;
22
- patch<T>(
23
- url: string,
24
- data?: unknown,
25
- config?: MethodConfig,
26
- ): Promise<HttpResponse<T>>;
27
- delete<T>(url: string, config?: MethodConfig): Promise<HttpResponse<T>>;
28
- };
29
-
30
- let client: HttpClient | null = null;
31
- let currentToken: string | null = null;
32
-
33
- export function setClient(httpClient: HttpClient): void {
34
- client = httpClient;
35
- }
36
-
37
- export function setToken(token: string): void {
38
- currentToken = token;
39
- }
40
-
41
- export function getToken(): string | null {
42
- return currentToken;
43
- }
44
-
45
- export function getApi(): HttpClient {
46
- if (!client) {
47
- throw new Error('SDK not configured. Call setup({ apiURL: "..." }) first.');
48
- }
49
- return client;
50
- }
51
-
52
- export function isApiConfigured(): boolean {
53
- return client !== null;
54
- }
55
-
56
- export function resetApi(): void {
57
- client = null;
58
- currentToken = null;
59
- }
60
-
61
- function addTokenHeader(config?: MethodConfig): MethodConfig {
62
- if (!currentToken) {
63
- return config ?? {};
64
- }
65
- return {
66
- ...config,
67
- headers: {
68
- ...config?.headers,
69
- 'X-Incode-Hardware-Id': currentToken,
70
- },
71
- };
72
- }
73
-
74
- export const api: ApiClient = {
75
- get<T>(url: string, config?: MethodConfig) {
76
- return getApi().get<T>(url, addTokenHeader(config));
77
- },
78
- post<T>(url: string, data?: unknown, config?: MethodConfig) {
79
- return getApi().post<T>(url, data, addTokenHeader(config));
80
- },
81
- put<T>(url: string, data?: unknown, config?: MethodConfig) {
82
- return getApi().put<T>(url, data, addTokenHeader(config));
83
- },
84
- patch<T>(url: string, data?: unknown, config?: MethodConfig) {
85
- return getApi().patch<T>(url, data, addTokenHeader(config));
86
- },
87
- delete<T>(url: string, config?: MethodConfig) {
88
- return getApi().delete<T>(url, addTokenHeader(config));
89
- },
90
- };
@@ -1,17 +0,0 @@
1
- export const endpoints = {
2
- createSession: '/omni/start',
3
- flow: '/omni/onboarding/flow',
4
- events: '/omni/interview-events',
5
- selfie: '/omni/add/face',
6
- recordingCreateSessionV2: '/omni/recordings/create-session/v2',
7
- recordingStartV2: '/omni/recordings/record-start/v2',
8
- recordingStopV2: '/omni/recordings/record-stop/v2',
9
- phone: '/omni/add/phone',
10
- phoneInstant: '/omni/instant/add/phone',
11
- getPhone: '/omni/get/phone',
12
- startInfo: '/omni/start-info',
13
- sendSmsOtp: '/omni/send/sms-otp',
14
- compareOtp: '/omni/compare/otp',
15
- email: '/omni/add/email',
16
- getEmail: '/omni/get/email',
17
- } as const;
package/src/index.ts DELETED
@@ -1,33 +0,0 @@
1
- export {
2
- createApi,
3
- type HttpClient,
4
- type WasmPipeline,
5
- warmupWasm,
6
- } from '@incodetech/infra';
7
- export {
8
- type Browser,
9
- type DeviceClass,
10
- getBrowser,
11
- getDeviceClass,
12
- } from './device';
13
- export { api, getApi } from './http/api';
14
- export {
15
- checkPermission as checkCameraPermission,
16
- type PermissionResult,
17
- type PermissionStatus,
18
- requestPermission as requestCameraPermission,
19
- } from './permissions';
20
- export {
21
- type CreateSessionOptions,
22
- createSession,
23
- type Session,
24
- } from './session';
25
- export {
26
- initializeWasmUtil,
27
- isConfigured,
28
- reset,
29
- type SetupOptions,
30
- setup,
31
- setWasmConfig,
32
- type WasmConfig,
33
- } from './setup';
@@ -1,2 +0,0 @@
1
- export { checkPermission, requestPermission } from './permissionServices';
2
- export type { PermissionResult, PermissionStatus } from './types';
@@ -1,31 +0,0 @@
1
- import {
2
- queryCameraPermission,
3
- requestCameraAccess,
4
- stopCameraStream,
5
- } from '@incodetech/infra';
6
- import type { PermissionResult } from './types';
7
-
8
- /**
9
- * Checks the current camera permission state without prompting the user.
10
- */
11
- export async function checkPermission(): Promise<PermissionResult> {
12
- return queryCameraPermission();
13
- }
14
-
15
- /**
16
- * Requests camera permission by attempting to access the camera, then immediately
17
- * stops the obtained stream. This function does not keep or return the stream.
18
- */
19
- export async function requestPermission(): Promise<PermissionResult> {
20
- try {
21
- const stream = await requestCameraAccess({ video: true });
22
- stopCameraStream(stream);
23
- return 'granted';
24
- } catch (error) {
25
- const name = error instanceof Error ? error.name : undefined;
26
- if (name === 'NotAllowedError' || name === 'PermissionDeniedError') {
27
- return 'denied';
28
- }
29
- return 'prompt';
30
- }
31
- }
@@ -1,3 +0,0 @@
1
- export type PermissionResult = 'granted' | 'denied' | 'prompt';
2
-
3
- export type PermissionStatus = 'idle' | 'requesting' | 'denied' | 'learnMore';
@@ -1,71 +0,0 @@
1
- import { vi } from 'vitest';
2
- import type { PhoneConfig, StartInfo, VerifyOtpResponse } from '../types';
3
-
4
- export const mockPhoneConfig: PhoneConfig = {
5
- otpVerification: true,
6
- otpExpirationInMinutes: 5,
7
- prefill: false,
8
- isInstantVerify: false,
9
- optinEnabled: false,
10
- maxOtpAttempts: 3,
11
- };
12
-
13
- export const mockPhoneConfigNoOtp: PhoneConfig = {
14
- ...mockPhoneConfig,
15
- otpVerification: false,
16
- };
17
-
18
- export const mockPhoneConfigWithPrefill: PhoneConfig = {
19
- ...mockPhoneConfig,
20
- prefill: true,
21
- };
22
-
23
- export const mockStartInfo: StartInfo = {
24
- ipIsoCode: 'US',
25
- phonePrefix: '+1',
26
- country: 'United States',
27
- };
28
-
29
- export const mockPrefilledPhone = '+14155551234';
30
-
31
- export function createMockFetchPhone(phone = mockPrefilledPhone) {
32
- return vi.fn().mockResolvedValue({ phone });
33
- }
34
-
35
- export function createMockFetchStartInfo(startInfo = mockStartInfo) {
36
- return vi.fn().mockResolvedValue(startInfo);
37
- }
38
-
39
- export function createMockAddPhone(success = true) {
40
- return vi.fn().mockResolvedValue({ success });
41
- }
42
-
43
- export function createMockSendOtp() {
44
- return vi.fn().mockResolvedValue(undefined);
45
- }
46
-
47
- export function createMockVerifyOtp(
48
- success = true,
49
- ): () => Promise<VerifyOtpResponse> {
50
- return vi.fn().mockResolvedValue({ success });
51
- }
52
-
53
- export function createFailingMockFetchPhone(error: string) {
54
- return vi.fn().mockRejectedValue(new Error(error));
55
- }
56
-
57
- export function createFailingMockAddPhone(error: string) {
58
- return vi.fn().mockRejectedValue(new Error(error));
59
- }
60
-
61
- export function createFailingMockVerifyOtp(error: string) {
62
- return vi.fn().mockRejectedValue(new Error(error));
63
- }
64
-
65
- export function createDelayedMock<T>(value: T, delayMs = 1000) {
66
- return vi
67
- .fn()
68
- .mockImplementation(
69
- () => new Promise((resolve) => setTimeout(() => resolve(value), delayMs)),
70
- );
71
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * Phone verification module - supports headless and UI-driven usage.
3
- *
4
- * ## Headless Usage (Programmatic)
5
- *
6
- * Use `createPhoneManager` to control phone verification without any UI.
7
- * Perfect for custom UI implementations, backend integrations, or automated testing.
8
- *
9
- * ```typescript
10
- * import { createPhoneManager } from '@incodetech/core/phone';
11
- *
12
- * const manager = createPhoneManager({
13
- * config: { otpVerification: true, otpExpirationInMinutes: 5, prefill: false },
14
- * });
15
- *
16
- * manager.subscribe((state) => console.log(state.status));
17
- * manager.load();
18
- * manager.setPhoneNumber('+14155551234', 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 Phone component from `@incodetech/ui/phone`.
27
- *
28
- * @module @incodetech/core/phone
29
- * @see {@link createPhoneManager} for headless API documentation
30
- * @see {@link PhoneConfig} for configuration options
31
- * @see {@link PhoneState} for state machine states
32
- */
33
- export {
34
- createPhoneManager,
35
- type PhoneManager,
36
- type PhoneState,
37
- } from './phoneManager';
38
- export { phoneMachine } from './phoneStateMachine';
39
- export type { PhoneConfig } from './types';
@@ -1,15 +0,0 @@
1
- import { type ActorRefFrom, createActor } from '@incodetech/infra';
2
- import { type PhoneMachine, phoneMachine } from './phoneStateMachine';
3
- import type { PhoneConfig } from './types';
4
-
5
- export type CreatePhoneActorOptions = {
6
- config: PhoneConfig;
7
- };
8
-
9
- export type PhoneActor = ActorRefFrom<PhoneMachine>;
10
-
11
- export function createPhoneActor(options: CreatePhoneActorOptions): PhoneActor {
12
- return createActor(phoneMachine, {
13
- input: { config: options.config },
14
- }).start();
15
- }