@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
@@ -0,0 +1,226 @@
1
+ import { n as warmupWasm, t as WasmPipeline } from "./warmup-Dr7OcFND.js";
2
+ import { n as PermissionStatus, t as PermissionResult } from "./types-tq1ypYSL.js";
3
+
4
+ //#region ../infra/src/http/types.d.ts
5
+ type CreateApiConfig = {
6
+ apiURL: string;
7
+ customHeaders?: Record<string, string>;
8
+ timeout?: number;
9
+ };
10
+ type RequestConfig = {
11
+ method?: string;
12
+ url: string;
13
+ headers?: Record<string, string>;
14
+ query?: Record<string, string | number | boolean | undefined>;
15
+ params?: Record<string, string | number | boolean | undefined>;
16
+ body?: unknown;
17
+ signal?: AbortSignal;
18
+ timeout?: number;
19
+ parse?: 'json' | 'text' | 'blob' | 'arrayBuffer' | 'response';
20
+ };
21
+ type HttpResponse<T = unknown> = {
22
+ ok: boolean;
23
+ status: number;
24
+ statusText: string;
25
+ url: string;
26
+ headers: Record<string, string>;
27
+ data: T;
28
+ };
29
+ type HttpClient = {
30
+ defaults: {
31
+ baseURL: string;
32
+ headers: Record<string, string>;
33
+ };
34
+ request<T = unknown>(config: RequestConfig): Promise<HttpResponse<T>>;
35
+ get<T = unknown>(url: string, config?: Omit<RequestConfig, 'method' | 'url'>): Promise<HttpResponse<T>>;
36
+ post<T = unknown>(url: string, body?: unknown, config?: Omit<RequestConfig, 'method' | 'url' | 'body'>): Promise<HttpResponse<T>>;
37
+ put<T = unknown>(url: string, body?: unknown, config?: Omit<RequestConfig, 'method' | 'url' | 'body'>): Promise<HttpResponse<T>>;
38
+ patch<T = unknown>(url: string, body?: unknown, config?: Omit<RequestConfig, 'method' | 'url' | 'body'>): Promise<HttpResponse<T>>;
39
+ delete<T = unknown>(url: string, config?: Omit<RequestConfig, 'method' | 'url'>): Promise<HttpResponse<T>>;
40
+ head<T = unknown>(url: string, config?: Omit<RequestConfig, 'method' | 'url'>): Promise<HttpResponse<T>>;
41
+ options<T = unknown>(url: string, config?: Omit<RequestConfig, 'method' | 'url'>): Promise<HttpResponse<T>>;
42
+ setHeader(name: string, value: string): void;
43
+ };
44
+ //#endregion
45
+ //#region ../infra/src/http/createApi.d.ts
46
+ declare const createApi: (config: CreateApiConfig) => HttpClient;
47
+ //#endregion
48
+ //#region src/device/getBrowser.d.ts
49
+ type Browser = 'chrome' | 'firefox' | 'safari' | 'edge' | 'other';
50
+ declare function getBrowser(): Browser;
51
+ //#endregion
52
+ //#region src/device/getDeviceClass.d.ts
53
+ type DeviceClass = 'ios' | 'android' | 'desktop';
54
+ declare function getDeviceClass(): DeviceClass;
55
+ //#endregion
56
+ //#region src/http/api.d.ts
57
+ type MethodConfig = {
58
+ headers?: Record<string, string>;
59
+ signal?: AbortSignal;
60
+ timeout?: number;
61
+ query?: Record<string, string | number | boolean | undefined>;
62
+ };
63
+ type ApiClient = {
64
+ get<T>(url: string, config?: MethodConfig): Promise<HttpResponse<T>>;
65
+ post<T>(url: string, data?: unknown, config?: MethodConfig): Promise<HttpResponse<T>>;
66
+ put<T>(url: string, data?: unknown, config?: MethodConfig): Promise<HttpResponse<T>>;
67
+ patch<T>(url: string, data?: unknown, config?: MethodConfig): Promise<HttpResponse<T>>;
68
+ delete<T>(url: string, config?: MethodConfig): Promise<HttpResponse<T>>;
69
+ };
70
+ declare function getApi(): HttpClient;
71
+ declare const api: ApiClient;
72
+ //#endregion
73
+ //#region src/permissions/permissionServices.d.ts
74
+ /**
75
+ * Checks the current camera permission state without prompting the user.
76
+ */
77
+ declare function checkPermission(): Promise<PermissionResult>;
78
+ /**
79
+ * Requests camera permission by attempting to access the camera, then immediately
80
+ * stops the obtained stream. This function does not keep or return the stream.
81
+ */
82
+ declare function requestPermission(): Promise<PermissionResult>;
83
+ //#endregion
84
+ //#region src/session/sessionService.d.ts
85
+ type CreateSessionOptions = {
86
+ /** The configuration/flow ID from the Incode dashboard */
87
+ configurationId: string;
88
+ /** External ID to associate with this session */
89
+ externalId?: string;
90
+ /** External customer ID */
91
+ externalCustomerId?: string;
92
+ /** Language for the session (e.g., 'en-US', 'es-MX') */
93
+ language?: string;
94
+ /** Custom fields to attach to the session */
95
+ customFields?: Record<string, unknown>;
96
+ /** UUID for continuing an existing session */
97
+ uuid?: string;
98
+ /** Interview ID for continuing an existing interview */
99
+ interviewId?: string;
100
+ };
101
+ type Session = {
102
+ token: string;
103
+ interviewId: string;
104
+ uuid?: string;
105
+ regulationType?: string;
106
+ showMandatoryConsent?: boolean;
107
+ };
108
+ /**
109
+ * Creates a new onboarding session.
110
+ *
111
+ * @param apiKey - The API key from the Incode dashboard
112
+ * @param options - Session creation options
113
+ * @param signal - Optional AbortSignal for request cancellation
114
+ * @returns The created session with token
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const session = await createSession('your-api-key', {
119
+ * configurationId: 'your-flow-id',
120
+ * language: 'en-US',
121
+ * });
122
+ * console.log(session.token); // Use this token for subsequent API calls
123
+ * ```
124
+ */
125
+ declare function createSession(apiKey: string, options: CreateSessionOptions, signal?: AbortSignal): Promise<Session>;
126
+ //#endregion
127
+ //#region src/setup.d.ts
128
+ /**
129
+ * WASM warmup configuration.
130
+ */
131
+ type WasmConfig = {
132
+ /** Path to the WASM binary */
133
+ wasmPath: string;
134
+ /** Path to the SIMD-optimized WASM binary (optional) */
135
+ wasmSimdPath?: string;
136
+ /** Path to the WASM glue code */
137
+ glueCodePath: string;
138
+ /** Whether to use SIMD optimizations (default: true) */
139
+ useSimd?: boolean;
140
+ /** Which pipelines to preload models for */
141
+ pipelines?: WasmPipeline[];
142
+ /**
143
+ * Base path for ML model files. Models will be loaded from `${modelsBasePath}/${modelFileName}`.
144
+ * If not provided, models are expected in a 'models' subdirectory relative to the WASM binary.
145
+ */
146
+ modelsBasePath?: string;
147
+ };
148
+ /**
149
+ * Configuration options for the SDK setup.
150
+ */
151
+ type SetupOptions = {
152
+ /** The base URL for the API */
153
+ apiURL: string;
154
+ /** The session token for API requests (optional - can be set later or omitted for createSession calls) */
155
+ token?: string;
156
+ /** Custom headers to include in all requests */
157
+ customHeaders?: Record<string, string>;
158
+ /** Request timeout in milliseconds */
159
+ timeout?: number;
160
+ /** Optional WASM warmup config - if provided, preloads WASM and ML models */
161
+ wasm?: WasmConfig;
162
+ };
163
+ /**
164
+ * Initializes the SDK with the provided configuration.
165
+ * Must be called before using any SDK functionality.
166
+ *
167
+ * If `wasm` config is provided, this function becomes async and will
168
+ * preload WASM binary and ML models. Otherwise, it's synchronous.
169
+ *
170
+ * @param options - Configuration options for the SDK
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * import { setup, createSession } from '@incodetech/core';
175
+ *
176
+ * // Setup with API URL first (for session creation)
177
+ * await setup({ apiURL: 'https://api.incode.com' });
178
+ * const session = await createSession('api-key', { configurationId: 'flow-id' });
179
+ *
180
+ * // Basic setup with token
181
+ * await setup({
182
+ * apiURL: 'https://api.incode.com',
183
+ * token: 'session-token',
184
+ * });
185
+ *
186
+ * // Setup with WASM warmup
187
+ * await setup({
188
+ * apiURL: 'https://api.incode.com',
189
+ * token: 'session-token',
190
+ * wasm: {
191
+ * wasmPath: '/wasm/ml-wasm.wasm',
192
+ * glueCodePath: '/wasm/ml-wasm.js',
193
+ * pipelines: ['selfie', 'idCapture'],
194
+ * },
195
+ * });
196
+ * ```
197
+ */
198
+ declare function setup(options: SetupOptions): Promise<void>;
199
+ /**
200
+ * Sets the WASM configuration without performing warmup.
201
+ * Useful when WASM warmup is handled separately (e.g., conditionally based on flow).
202
+ *
203
+ * @param config - WASM configuration to store
204
+ */
205
+ declare function setWasmConfig(config: WasmConfig): void;
206
+ /**
207
+ * Initializes WasmUtilProvider with the stored WASM configuration.
208
+ * Should be called after warmupWasm() completes when using conditional warmup.
209
+ * This ensures image encryption works properly.
210
+ *
211
+ * @param config - Optional WASM configuration. If not provided, uses the stored config from setWasmConfig().
212
+ * @throws Error if no config is provided and none is stored
213
+ */
214
+ declare function initializeWasmUtil(config?: WasmConfig): Promise<void>;
215
+ /**
216
+ * Checks if the SDK has been configured.
217
+ *
218
+ * @returns true if setup() has been called, false otherwise
219
+ */
220
+ declare function isConfigured(): boolean;
221
+ /**
222
+ * Resets the SDK configuration. Useful for testing.
223
+ */
224
+ declare function reset(): void;
225
+ //#endregion
226
+ export { type Browser, type CreateSessionOptions, type DeviceClass, type HttpClient, type PermissionResult, type PermissionStatus, type Session, type SetupOptions, type WasmConfig, type WasmPipeline, api, checkPermission as checkCameraPermission, createApi, createSession, getApi, getBrowser, getDeviceClass, initializeWasmUtil, isConfigured, requestPermission as requestCameraPermission, reset, setWasmConfig, setup, warmupWasm };
@@ -0,0 +1,155 @@
1
+ import { i as getBrowser, n as requestPermission, r as getDeviceClass, t as checkPermission } from "./permissionServices-CVR0Pq38.esm.js";
2
+ import { _ as createApi_default, a as setClient, i as resetApi, l as warmupWasm, n as api, o as setToken, r as getApi, s as WasmUtilProvider, t as endpoints } from "./endpoints-D_pUMaqA.esm.js";
3
+
4
+ //#region src/session/sessionService.ts
5
+ /**
6
+ * Creates a new onboarding session.
7
+ *
8
+ * @param apiKey - The API key from the Incode dashboard
9
+ * @param options - Session creation options
10
+ * @param signal - Optional AbortSignal for request cancellation
11
+ * @returns The created session with token
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const session = await createSession('your-api-key', {
16
+ * configurationId: 'your-flow-id',
17
+ * language: 'en-US',
18
+ * });
19
+ * console.log(session.token); // Use this token for subsequent API calls
20
+ * ```
21
+ */
22
+ async function createSession(apiKey, options, signal) {
23
+ const res = await getApi().post(endpoints.createSession, {
24
+ configurationId: options.configurationId,
25
+ externalId: options.externalId,
26
+ externalCustomerId: options.externalCustomerId,
27
+ language: options.language ?? "en-US",
28
+ customFields: options.customFields,
29
+ uuid: options.uuid ?? null,
30
+ interviewId: options.interviewId ?? null
31
+ }, {
32
+ headers: {
33
+ "x-api-key": apiKey,
34
+ "api-version": "1.0"
35
+ },
36
+ signal
37
+ });
38
+ if (!res.ok) throw new Error(`POST ${endpoints.createSession} failed: ${res.status} ${res.statusText}`);
39
+ return res.data;
40
+ }
41
+
42
+ //#endregion
43
+ //#region src/setup.ts
44
+ let wasmConfig;
45
+ let configured = false;
46
+ /**
47
+ * Initializes the SDK with the provided configuration.
48
+ * Must be called before using any SDK functionality.
49
+ *
50
+ * If `wasm` config is provided, this function becomes async and will
51
+ * preload WASM binary and ML models. Otherwise, it's synchronous.
52
+ *
53
+ * @param options - Configuration options for the SDK
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { setup, createSession } from '@incodetech/core';
58
+ *
59
+ * // Setup with API URL first (for session creation)
60
+ * await setup({ apiURL: 'https://api.incode.com' });
61
+ * const session = await createSession('api-key', { configurationId: 'flow-id' });
62
+ *
63
+ * // Basic setup with token
64
+ * await setup({
65
+ * apiURL: 'https://api.incode.com',
66
+ * token: 'session-token',
67
+ * });
68
+ *
69
+ * // Setup with WASM warmup
70
+ * await setup({
71
+ * apiURL: 'https://api.incode.com',
72
+ * token: 'session-token',
73
+ * wasm: {
74
+ * wasmPath: '/wasm/ml-wasm.wasm',
75
+ * glueCodePath: '/wasm/ml-wasm.js',
76
+ * pipelines: ['selfie', 'idCapture'],
77
+ * },
78
+ * });
79
+ * ```
80
+ */
81
+ async function setup(options) {
82
+ setClient(createApi_default({
83
+ apiURL: options.apiURL,
84
+ customHeaders: options.customHeaders,
85
+ timeout: options.timeout
86
+ }));
87
+ if (options.token) setToken(options.token);
88
+ configured = true;
89
+ if (options.wasm) {
90
+ await warmupWasm({
91
+ wasmPath: options.wasm.wasmPath,
92
+ wasmSimdPath: options.wasm.wasmSimdPath,
93
+ glueCodePath: options.wasm.glueCodePath,
94
+ useSimd: options.wasm.useSimd,
95
+ pipelines: options.wasm.pipelines,
96
+ modelsBasePath: options.wasm.modelsBasePath
97
+ });
98
+ await (await WasmUtilProvider.getInstance()).initialize({
99
+ wasmPath: options.wasm.wasmPath,
100
+ wasmSimdPath: options.wasm.wasmSimdPath,
101
+ glueCodePath: options.wasm.glueCodePath,
102
+ useSimd: options.wasm.useSimd,
103
+ pipelines: options.wasm.pipelines,
104
+ modelsBasePath: options.wasm.modelsBasePath
105
+ });
106
+ }
107
+ }
108
+ /**
109
+ * Sets the WASM configuration without performing warmup.
110
+ * Useful when WASM warmup is handled separately (e.g., conditionally based on flow).
111
+ *
112
+ * @param config - WASM configuration to store
113
+ */
114
+ function setWasmConfig(config) {
115
+ wasmConfig = config;
116
+ }
117
+ /**
118
+ * Initializes WasmUtilProvider with the stored WASM configuration.
119
+ * Should be called after warmupWasm() completes when using conditional warmup.
120
+ * This ensures image encryption works properly.
121
+ *
122
+ * @param config - Optional WASM configuration. If not provided, uses the stored config from setWasmConfig().
123
+ * @throws Error if no config is provided and none is stored
124
+ */
125
+ async function initializeWasmUtil(config) {
126
+ const wasmConfigToUse = config ?? wasmConfig;
127
+ if (!wasmConfigToUse) throw new Error("WASM config is required. Provide config parameter or call setWasmConfig() first.");
128
+ await (await WasmUtilProvider.getInstance()).initialize({
129
+ wasmPath: wasmConfigToUse.wasmPath,
130
+ wasmSimdPath: wasmConfigToUse.wasmSimdPath,
131
+ glueCodePath: wasmConfigToUse.glueCodePath,
132
+ useSimd: wasmConfigToUse.useSimd,
133
+ pipelines: wasmConfigToUse.pipelines,
134
+ modelsBasePath: wasmConfigToUse.modelsBasePath
135
+ });
136
+ }
137
+ /**
138
+ * Checks if the SDK has been configured.
139
+ *
140
+ * @returns true if setup() has been called, false otherwise
141
+ */
142
+ function isConfigured() {
143
+ return configured;
144
+ }
145
+ /**
146
+ * Resets the SDK configuration. Useful for testing.
147
+ */
148
+ function reset() {
149
+ resetApi();
150
+ configured = false;
151
+ WasmUtilProvider.resetInstance();
152
+ }
153
+
154
+ //#endregion
155
+ export { api, checkPermission as checkCameraPermission, createApi_default as createApi, createSession, getApi, getBrowser, getDeviceClass, initializeWasmUtil, isConfigured, requestPermission as requestCameraPermission, reset, setWasmConfig, setup, warmupWasm };