@incodetech/core 0.0.0-dev-20260512-95ef244 → 0.0.0-dev-20260512-20def2c
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.
- package/dist/{BaseWasmProvider-C2cw9STp.esm.js → BaseWasmProvider-CVktpSfA.esm.js} +246 -21
- package/dist/{WasmUtilProvider-B8VtGgvF.esm.js → WasmUtilProvider-BEQWy5_K.esm.js} +1 -1
- package/dist/ae-signature.d.ts +1 -1
- package/dist/authentication.d.ts +5 -5
- package/dist/authentication.esm.js +16 -16
- package/dist/{authenticationManager-BuChl5GH.d.ts → authenticationManager-BnltMEfq.d.ts} +1 -1
- package/dist/{authenticationManager-D0Yv5R02.esm.js → authenticationManager-DsauZR1g.esm.js} +3 -3
- package/dist/{authenticationStateMachine-CFiP6P_V.esm.js → authenticationStateMachine-B4FQ52zK.esm.js} +11 -3
- package/dist/{backCameraStream-DWZ1cNVA.esm.js → backCameraStream-BKC7QXRJ.esm.js} +2 -2
- package/dist/camera.esm.js +2 -2
- package/dist/consent.d.ts +50 -50
- package/dist/cpf-ocr.d.ts +17 -17
- package/dist/cross-document-data-match.esm.js +1 -1
- package/dist/curp-validation.d.ts +1 -1
- package/dist/{deepsightLoader-CFNSfs2N.esm.js → deepsightLoader-VJ3nFjie.esm.js} +6 -6
- package/dist/{deepsightService-IxmrmdKl.esm.js → deepsightService-Dv6kvzph.esm.js} +2 -2
- package/dist/{deepsightService-CGSDjjBz.d.ts → deepsightService-Kuw9roIJ.d.ts} +1 -1
- package/dist/device.esm.js +3 -3
- package/dist/document-capture.d.ts +71 -71
- package/dist/document-capture.esm.js +4 -4
- package/dist/document-upload.d.ts +43 -43
- package/dist/document-upload.esm.js +3 -3
- package/dist/{documentCaptureStateMachine-CuanhXvs.esm.js → documentCaptureStateMachine-CEm-9zrh.esm.js} +1 -1
- package/dist/ekyb.esm.js +3 -3
- package/dist/{ekybStateMachine-DeQU4Shn.esm.js → ekybStateMachine-DqzhMm0r.esm.js} +1 -1
- package/dist/electronic-signature.d.ts +1 -1
- package/dist/extensibility.d.ts +7 -7
- package/dist/extensibility.esm.js +21 -21
- package/dist/{faceCaptureManagerFactory-FX5Lw2Q5.d.ts → faceCaptureManagerFactory-DmHbKbyC.d.ts} +66 -3
- package/dist/{faceCaptureManagerFactory-ByAGjOLF.esm.js → faceCaptureManagerFactory-fu-9hWf5.esm.js} +2 -0
- package/dist/{faceCaptureSetup-zLRBv0-5.esm.js → faceCaptureSetup-D607PhdL.esm.js} +141 -19
- package/dist/flow-events.d.ts +2 -2
- package/dist/flow.d.ts +9 -5
- package/dist/flow.esm.js +2 -2
- package/dist/{flowServices-CpdnbZ2S.esm.js → flowServices-BVVnH_Fn.esm.js} +14 -1
- package/dist/geolocation.esm.js +2 -2
- package/dist/{geolocationStateMachine-15aagr2_.esm.js → geolocationStateMachine-BYWUPbNs.esm.js} +1 -1
- package/dist/{getDeviceClass-DmoqR7G2.esm.js → getDeviceClass-C1ZS2XJL.esm.js} +1 -1
- package/dist/home.d.ts +11 -11
- package/dist/http.d.ts +9 -0
- package/dist/id-ocr.d.ts +55 -55
- package/dist/id.d.ts +4 -4
- package/dist/id.esm.js +14 -14
- package/dist/{idCaptureManager-DiFBYm7h.d.ts → idCaptureManager-Bg2va24b.d.ts} +2 -2
- package/dist/{idCaptureManager-74SoNR3l.esm.js → idCaptureManager-DbP4E8PO.esm.js} +1 -1
- package/dist/{idCaptureStateMachine-YNISzeyJ.esm.js → idCaptureStateMachine-g5cYnHGD.esm.js} +11 -11
- package/dist/identity-reuse.d.ts +40 -40
- package/dist/{index-B58eizRV.d.ts → index-DXB9aRs0.d.ts} +119 -119
- package/dist/{index-CmFkidgy.d.ts → index-UH-vOq3x.d.ts} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.esm.js +4 -4
- package/dist/mandatory-consent.d.ts +51 -51
- package/dist/{permissionServices-ACBX6sNZ.esm.js → permissionServices-Cdxqlwqz.esm.js} +1 -1
- package/dist/qe-signature.d.ts +1 -1
- package/dist/{recordingService-BsYjkILQ.esm.js → recordingService-Dp-3nA-h.esm.js} +204 -174
- package/dist/selfie.d.ts +5 -5
- package/dist/selfie.esm.js +16 -16
- package/dist/{selfieManager-ByCKxpZC.esm.js → selfieManager-5AG9bMT1.esm.js} +3 -3
- package/dist/{selfieManager-DPQzO4ua.d.ts → selfieManager-CQtRqcjI.d.ts} +1 -1
- package/dist/{selfieStateMachine-ecwZ7tWK.esm.js → selfieStateMachine-D0rrAFIs.esm.js} +22 -10
- package/dist/{session-BuTr4wgh.esm.js → session-BxtuBDwz.esm.js} +1 -1
- package/dist/session.esm.js +1 -1
- package/dist/{setup-DKHwPajl.esm.js → setup-B2Van3Nc.esm.js} +308 -296
- package/dist/{setup-D3rE3N3K.d.ts → setup-CsJ6FYyF.d.ts} +40 -6
- package/dist/stats.esm.js +1 -1
- package/dist/{types-BA181GDD.d.ts → types-DkXZpS0R.d.ts} +14 -0
- package/dist/{warmup-DHGg8wQZ.d.ts → warmup-C6O7yhfX.d.ts} +5 -2
- package/dist/wasm.d.ts +3 -3
- package/dist/wasm.esm.js +4 -4
- package/dist/workflow.d.ts +86 -86
- package/dist/workflow.esm.js +20 -20
- package/package.json +1 -1
- /package/dist/{ITimerCapability-2pw-S97e.esm.js → ITimerCapability-3xSd36bT.esm.js} +0 -0
- /package/dist/{MotionSensorProvider-DJMsPght.esm.js → MotionSensorProvider-Dt_lF3Z8.esm.js} +0 -0
- /package/dist/{getBrowser-Y88tNVud.esm.js → getBrowser-Bl0PlyDu.esm.js} +0 -0
- /package/dist/{platform-Dpzd9p3X.esm.js → platform-CDh4uv5Y.esm.js} +0 -0
- /package/dist/{stats-Bqq9IKre.esm.js → stats-qUsejORa.esm.js} +0 -0
|
@@ -1,11 +1,137 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { t as WasmUtilProvider } from "./WasmUtilProvider-
|
|
1
|
+
import { a as enableWasmEncryption, c as setWebApiHttpTransport, i as WasmWebClientError, l as setupWasmConnection, n as warmupWasm, o as executeWasmRequest, s as initializeWasmWebClient } from "./BaseWasmProvider-CVktpSfA.esm.js";
|
|
2
|
+
import { t as WasmUtilProvider } from "./WasmUtilProvider-BEQWy5_K.esm.js";
|
|
3
3
|
import { t as BrowserTimerProvider } from "./BrowserTimerProvider-BZGH3sYJ.esm.js";
|
|
4
4
|
import { a as resetApi, i as isApiConfigured, n as getApi, o as setClient, r as getToken, s as setToken, t as api } from "./api-eqRXuVG-.esm.js";
|
|
5
5
|
import { _ as resetAnalyticsBatcher, g as getAnalyticsBatcher, m as createAnalyticsBatchingService, v as setAnalyticsBatcher } from "./events-Bt1azl2B.esm.js";
|
|
6
6
|
import { t as endpoints } from "./endpoints-B3V1U9Dg.esm.js";
|
|
7
|
-
import { i as resetSessionInit, r as initializeSession } from "./session-
|
|
7
|
+
import { i as resetSessionInit, r as initializeSession } from "./session-BxtuBDwz.esm.js";
|
|
8
8
|
|
|
9
|
+
//#region ../infra/src/wasm/wasmDefaults.ts
|
|
10
|
+
const WASM_CDN_BASE_URL = "https://cdn.incodesmile.com/ml-wasm-kit-release";
|
|
11
|
+
/** The WASM version bundled and tested with this SDK release. */
|
|
12
|
+
const DEFAULT_WASM_VERSION = "v2.13.20";
|
|
13
|
+
const PATH_KEYS = [
|
|
14
|
+
"wasmPath",
|
|
15
|
+
"wasmSimdPath",
|
|
16
|
+
"glueCodePath",
|
|
17
|
+
"modelsBasePath"
|
|
18
|
+
];
|
|
19
|
+
function isBlank(value) {
|
|
20
|
+
return value.trim() === "";
|
|
21
|
+
}
|
|
22
|
+
function hasDisallowedControlChars(value) {
|
|
23
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
24
|
+
const code = value.charCodeAt(i);
|
|
25
|
+
if (code < 32 || code === 127) return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function isMalformedPath(value) {
|
|
30
|
+
const trimmed = value.trim();
|
|
31
|
+
if (trimmed === "") return false;
|
|
32
|
+
if (hasDisallowedControlChars(trimmed)) return true;
|
|
33
|
+
if (/^https?:\/\//i.test(trimmed)) try {
|
|
34
|
+
new URL(trimmed);
|
|
35
|
+
return false;
|
|
36
|
+
} catch {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
function warnInvalidWasmPath(field, reason) {
|
|
42
|
+
if (reason === "empty") {
|
|
43
|
+
console.warn(`[Incode SDK] wasm.${field} is empty. Falling back to CDN default.`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
console.warn(`[Incode SDK] wasm.${field} appears malformed. Falling back to CDN default.`);
|
|
47
|
+
}
|
|
48
|
+
function warnMalformedWasmPath(field) {
|
|
49
|
+
console.warn(`[Incode SDK] wasm.${field} appears malformed. Check the URL or path.`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validates merged WASM path strings. When overrides contained blank path
|
|
53
|
+
* values, callers should have already fallen back to defaults before this runs.
|
|
54
|
+
*/
|
|
55
|
+
function validateWasmPaths(config) {
|
|
56
|
+
for (const key of PATH_KEYS) {
|
|
57
|
+
const value = config[key];
|
|
58
|
+
if (typeof value === "string" && isMalformedPath(value)) warnMalformedWasmPath(key);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function pickPath(key, overrides, defaultValue) {
|
|
62
|
+
if (!overrides || !(key in overrides)) return defaultValue;
|
|
63
|
+
const raw = overrides[key];
|
|
64
|
+
if (raw === void 0) return defaultValue;
|
|
65
|
+
if (typeof raw !== "string") return defaultValue;
|
|
66
|
+
if (isBlank(raw)) {
|
|
67
|
+
warnInvalidWasmPath(key, "empty");
|
|
68
|
+
return defaultValue;
|
|
69
|
+
}
|
|
70
|
+
if (isMalformedPath(raw)) {
|
|
71
|
+
warnInvalidWasmPath(key, "malformed");
|
|
72
|
+
return defaultValue;
|
|
73
|
+
}
|
|
74
|
+
return raw.trim();
|
|
75
|
+
}
|
|
76
|
+
/** Builds the standard WarmupConfig from the Incode CDN. */
|
|
77
|
+
function buildDefaultWasmConfig() {
|
|
78
|
+
const base = `${WASM_CDN_BASE_URL}/${DEFAULT_WASM_VERSION}`;
|
|
79
|
+
return {
|
|
80
|
+
wasmPath: `${base}/webLib.wasm`,
|
|
81
|
+
wasmSimdPath: `${base}/webLibSimd.wasm`,
|
|
82
|
+
glueCodePath: `${base}/webLib.js`,
|
|
83
|
+
modelsBasePath: `${base}/models`
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Merges optional WASM path overrides with CDN defaults. Explicit non-blank
|
|
88
|
+
* paths take precedence. Blank override strings log a warning and fall back to defaults.
|
|
89
|
+
*/
|
|
90
|
+
function resolveWasmConfig(overrides) {
|
|
91
|
+
const defaults = buildDefaultWasmConfig();
|
|
92
|
+
if (!overrides) return defaults;
|
|
93
|
+
const simdDefault = defaults.wasmSimdPath ?? defaults.wasmPath;
|
|
94
|
+
const modelsDefault = defaults.modelsBasePath ?? (() => {
|
|
95
|
+
const lastSlash = defaults.wasmPath.lastIndexOf("/");
|
|
96
|
+
return lastSlash === -1 ? "models" : `${defaults.wasmPath.substring(0, lastSlash)}/models`;
|
|
97
|
+
})();
|
|
98
|
+
const merged = {
|
|
99
|
+
wasmPath: pickPath("wasmPath", overrides, defaults.wasmPath),
|
|
100
|
+
wasmSimdPath: pickPath("wasmSimdPath", overrides, simdDefault),
|
|
101
|
+
glueCodePath: pickPath("glueCodePath", overrides, defaults.glueCodePath),
|
|
102
|
+
modelsBasePath: pickPath("modelsBasePath", overrides, modelsDefault),
|
|
103
|
+
useSimd: overrides.useSimd,
|
|
104
|
+
pipelines: overrides.pipelines,
|
|
105
|
+
pipelineModels: overrides.pipelineModels
|
|
106
|
+
};
|
|
107
|
+
validateWasmPaths(merged);
|
|
108
|
+
return merged;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region ../infra/src/providers/browser/BrowserPageLifecycleProvider.ts
|
|
113
|
+
var BrowserPageLifecycleProvider = class {
|
|
114
|
+
sendBeacon(url, body, contentType = "application/json") {
|
|
115
|
+
if (typeof navigator === "undefined" || typeof navigator.sendBeacon !== "function") return false;
|
|
116
|
+
const blob = new Blob([body], { type: contentType });
|
|
117
|
+
return navigator.sendBeacon(url, blob);
|
|
118
|
+
}
|
|
119
|
+
onPageHide(listener) {
|
|
120
|
+
const onVisibilityChange = () => {
|
|
121
|
+
if (document.visibilityState === "hidden") listener();
|
|
122
|
+
};
|
|
123
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
124
|
+
window.addEventListener("pagehide", listener);
|
|
125
|
+
window.addEventListener("beforeunload", listener);
|
|
126
|
+
return () => {
|
|
127
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
128
|
+
window.removeEventListener("pagehide", listener);
|
|
129
|
+
window.removeEventListener("beforeunload", listener);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
9
135
|
//#region ../infra/src/http/createApi.ts
|
|
10
136
|
var FetchHttpError = class extends Error {
|
|
11
137
|
constructor(status, statusText, url, method, headers, data) {
|
|
@@ -228,142 +354,23 @@ const createApi = (config) => {
|
|
|
228
354
|
var createApi_default = createApi;
|
|
229
355
|
|
|
230
356
|
//#endregion
|
|
231
|
-
//#region ../infra/src/
|
|
232
|
-
|
|
233
|
-
* JavaScript bridge for the C++ `WebClient` exposed by `webLib.wasm`.
|
|
234
|
-
*
|
|
235
|
-
* The pinned WASM bundle ships a `WebClient` class alongside the ML pipeline
|
|
236
|
-
* APIs. This module instantiates it once (sharing the singleton `wasmModule`
|
|
237
|
-
* with `mlWasmJSApi`) and exposes a small TypeScript-friendly surface that
|
|
238
|
-
* `createWasmApi` can drive.
|
|
239
|
-
*
|
|
240
|
-
* Concurrency model mirrors the legacy implementation:
|
|
241
|
-
* - 4-slot semaphore keyed by per-request `threadId` so multiple HTTP calls
|
|
242
|
-
* can run in parallel without trampling shared C++ state.
|
|
243
|
-
* - Each WASM-side request method returns `false` while in flight; we
|
|
244
|
-
* busy-poll via {@link wasmCallWrapper}.
|
|
245
|
-
* - Result extraction (`getRequestResult`) is per-thread.
|
|
246
|
-
*
|
|
247
|
-
* Encryption is wired through the `encryptionEnabled` flag but defaults to
|
|
248
|
-
* `false`. End-to-end encryption (Phase 2) will re-call `setupConnection` with
|
|
249
|
-
* a real token + `encryptionEnabled = true`; that helper is a follow-up.
|
|
250
|
-
*/
|
|
251
|
-
const HTTP_CONCURRENCY = 4;
|
|
252
|
-
var WasmWebClientError = class extends Error {
|
|
253
|
-
constructor(message, statusCode, data) {
|
|
254
|
-
super(message);
|
|
255
|
-
this.name = "WasmWebClientError";
|
|
256
|
-
this.status = statusCode;
|
|
257
|
-
this.statusCode = statusCode;
|
|
258
|
-
if (statusCode > 0 || data !== void 0) this.response = {
|
|
259
|
-
status: statusCode,
|
|
260
|
-
data
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
let webClientApi = null;
|
|
265
|
-
let initPromise = null;
|
|
266
|
-
let semaphore = new SemaphoreProvider(HTTP_CONCURRENCY);
|
|
267
|
-
const isWebClientWasm = (mod) => {
|
|
268
|
-
return typeof mod.WebClient === "function";
|
|
269
|
-
};
|
|
270
|
-
const toStringRecord = (obj) => {
|
|
271
|
-
if (!obj) return void 0;
|
|
272
|
-
const result = {};
|
|
273
|
-
for (const key of Object.keys(obj)) {
|
|
274
|
-
const value = obj[key];
|
|
275
|
-
if (value === void 0 || value === null) continue;
|
|
276
|
-
result[key] = String(value);
|
|
277
|
-
}
|
|
278
|
-
return result;
|
|
279
|
-
};
|
|
280
|
-
/**
|
|
281
|
-
* Loads the shared WASM module (if not already loaded) and instantiates the
|
|
282
|
-
* C++ `WebClient`. Idempotent — repeated calls reuse the existing instance.
|
|
283
|
-
*/
|
|
284
|
-
async function initializeWasmWebClient(wasmPath, wasmSimdPath, glueCodePath, useSimd) {
|
|
285
|
-
if (webClientApi) return;
|
|
286
|
-
if (initPromise) return initPromise;
|
|
287
|
-
initPromise = (async () => {
|
|
288
|
-
try {
|
|
289
|
-
const { wasmModule } = await loadWasmModule({
|
|
290
|
-
wasmPath,
|
|
291
|
-
wasmSimdPath,
|
|
292
|
-
glueCodePath,
|
|
293
|
-
useSimd
|
|
294
|
-
});
|
|
295
|
-
if (!isWebClientWasm(wasmModule)) throw new Error("WASM module does not expose a WebClient class. Update webLib.wasm to a build that includes WebClient.");
|
|
296
|
-
webClientApi = new wasmModule.WebClient();
|
|
297
|
-
} catch (error) {
|
|
298
|
-
initPromise = null;
|
|
299
|
-
throw error;
|
|
300
|
-
}
|
|
301
|
-
})();
|
|
302
|
-
return initPromise;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Configures the C++ WebClient connection. Safe to call multiple times — each
|
|
306
|
-
* call resets the underlying session and re-applies default headers.
|
|
307
|
-
*/
|
|
308
|
-
async function setupWasmConnection(apiURL, token, useSha256, encryptionEnabled, defaultHeaders) {
|
|
309
|
-
const api$1 = ensureReady();
|
|
310
|
-
api$1.resetSessionState?.();
|
|
311
|
-
api$1.createApi(apiURL, token, useSha256, encryptionEnabled);
|
|
312
|
-
api$1.setDefaultHeaders?.(defaultHeaders);
|
|
313
|
-
}
|
|
357
|
+
//#region ../infra/src/http/createWasmApi.ts
|
|
358
|
+
const RSA_OAEP_SHA256_SCHEME = "RSA/NONE/OAEPWITHSHA-256ANDMGF1PADDING";
|
|
314
359
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* {@link WasmWebClientError} on non-2xx or transport errors.
|
|
360
|
+
* Builds the base set of HTTP headers that the WASM WebClient sends on every
|
|
361
|
+
* request (including the internal `/e2ee/key/v2` and `/e2ee/key` handshake
|
|
362
|
+
* calls). Exported so callers that drive `setupWasmConnection` /
|
|
363
|
+
* `enableWasmEncryption` directly (e.g. core's runtime encryption upgrade
|
|
364
|
+
* path) can build the same headers without duplicating constants.
|
|
321
365
|
*/
|
|
322
|
-
|
|
323
|
-
const api$1 = ensureReady();
|
|
324
|
-
const stringParams = toStringRecord(params);
|
|
325
|
-
return semaphore.withLock(async (threadId) => {
|
|
326
|
-
if (onUploadProgress && api$1.setOnUploadProgress) api$1.setOnUploadProgress((event) => {
|
|
327
|
-
try {
|
|
328
|
-
onUploadProgress(event);
|
|
329
|
-
} catch (error) {
|
|
330
|
-
console.error("WasmWebClient: error in onUploadProgress callback", error);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
try {
|
|
334
|
-
await wasmCallWrapper(semaphore, () => callWasmMethod(api$1, method, threadId, url, body, headers, stringParams, timeout), false);
|
|
335
|
-
return readResult(api$1, threadId);
|
|
336
|
-
} finally {
|
|
337
|
-
api$1.clearOnUploadProgress?.(threadId);
|
|
338
|
-
api$1.clearOnDownloadProgress?.(threadId);
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
function callWasmMethod(api$1, method, threadId, url, body, headers, params, timeout) {
|
|
343
|
-
switch (method) {
|
|
344
|
-
case "GET": return api$1.get(threadId, url, params, headers, timeout);
|
|
345
|
-
case "POST": return api$1.post(threadId, url, body ?? {}, headers, params, timeout, false);
|
|
346
|
-
case "PUT": return api$1.put(threadId, url, body ?? {}, headers, params, timeout, false);
|
|
347
|
-
case "PATCH": return api$1.patch(threadId, url, body ?? {}, headers, params, timeout, false);
|
|
348
|
-
case "DELETE": return api$1.del(threadId, url, body ?? {}, headers, params, timeout, false);
|
|
349
|
-
default: throw new Error(`Unsupported WASM HTTP method: ${method}`);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
function readResult(api$1, threadId) {
|
|
353
|
-
const response = api$1.getRequestResult(threadId);
|
|
354
|
-
if (response.hasError) throw new WasmWebClientError(response.errorMessage || "WasmWebClient request failed", response.statusCode, response.result);
|
|
366
|
+
function buildWasmDefaultHeaders(customHeaders) {
|
|
355
367
|
return {
|
|
356
|
-
|
|
357
|
-
|
|
368
|
+
"Content-Type": "application/json",
|
|
369
|
+
Accept: "application/json",
|
|
370
|
+
"api-version": "1.0",
|
|
371
|
+
...customHeaders ?? {}
|
|
358
372
|
};
|
|
359
373
|
}
|
|
360
|
-
function ensureReady() {
|
|
361
|
-
if (!webClientApi) throw new Error("WasmWebClient not initialized. Call initializeWasmWebClient() first.");
|
|
362
|
-
return webClientApi;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
//#endregion
|
|
366
|
-
//#region ../infra/src/http/createWasmApi.ts
|
|
367
374
|
var WasmHttpError = class extends Error {
|
|
368
375
|
constructor(status, statusText, url, method, headers, data) {
|
|
369
376
|
super(`HTTP ${status} ${statusText}`);
|
|
@@ -439,14 +446,10 @@ const withAbortSignal = async (promise, signal, error) => {
|
|
|
439
446
|
});
|
|
440
447
|
};
|
|
441
448
|
const createWasmApi = async (config) => {
|
|
442
|
-
const headers =
|
|
443
|
-
|
|
444
|
-
Accept: "application/json",
|
|
445
|
-
"api-version": "1.0",
|
|
446
|
-
...config.customHeaders ?? {}
|
|
447
|
-
};
|
|
449
|
+
const headers = buildWasmDefaultHeaders(config.customHeaders);
|
|
450
|
+
const isEncryptionEnabled = config.isEncryptionEnabled ?? (() => false);
|
|
448
451
|
await initializeWasmWebClient(config.wasm.wasmPath, config.wasm.wasmSimdPath ?? config.wasm.wasmPath, config.wasm.glueCodePath, config.wasm.useSimd ?? true);
|
|
449
|
-
await setupWasmConnection(config.apiURL, "", config.
|
|
452
|
+
await setupWasmConnection(config.apiURL, "", config.encryptionEnabled ?? false, headers);
|
|
450
453
|
const defaults = {
|
|
451
454
|
baseURL: config.apiURL,
|
|
452
455
|
headers
|
|
@@ -454,12 +457,14 @@ const createWasmApi = async (config) => {
|
|
|
454
457
|
const client = {
|
|
455
458
|
defaults,
|
|
456
459
|
async request(requestConfig) {
|
|
457
|
-
const { method = "GET", url, headers: requestHeaders = {}, query, params, body, signal, timeout = config.timeout ?? DEFAULT_TIMEOUT, onUploadProgress } = requestConfig;
|
|
460
|
+
const { method = "GET", url, headers: requestHeaders = {}, query, params, body, signal, timeout = config.timeout ?? DEFAULT_TIMEOUT, onUploadProgress, ie = false } = requestConfig;
|
|
458
461
|
const upperMethod = normalizeMethod(method);
|
|
459
462
|
const requestParams = params ?? query;
|
|
460
463
|
const fullUrl = buildUrl(defaults.baseURL, url, requestParams);
|
|
464
|
+
const needsSchemeHeader = ie || isEncryptionEnabled();
|
|
461
465
|
const mergedHeaders = {
|
|
462
466
|
...defaults.headers,
|
|
467
|
+
...needsSchemeHeader ? { "X-RSA-Encryption-Scheme": RSA_OAEP_SHA256_SCHEME } : {},
|
|
463
468
|
...requestHeaders
|
|
464
469
|
};
|
|
465
470
|
const requestBody = prepareBody(body);
|
|
@@ -469,7 +474,7 @@ const createWasmApi = async (config) => {
|
|
|
469
474
|
const abortError = new WasmHttpError(0, "Request aborted", fullUrl, upperMethod, {}, null);
|
|
470
475
|
if (signal?.aborted) throw abortError;
|
|
471
476
|
try {
|
|
472
|
-
const response = await withAbortSignal(executeWasmRequest(upperMethod, url, requestBody, mergedHeaders, requestParams, timeout, wasmProgress), signal, abortError);
|
|
477
|
+
const response = await withAbortSignal(executeWasmRequest(upperMethod, url, requestBody, mergedHeaders, requestParams, timeout, wasmProgress, ie), signal, abortError);
|
|
473
478
|
if (response.status < 200 || response.status >= 300) throw new WasmHttpError(response.status, "", fullUrl, upperMethod, {}, response.data);
|
|
474
479
|
return {
|
|
475
480
|
ok: true,
|
|
@@ -537,135 +542,163 @@ const createWasmApi = async (config) => {
|
|
|
537
542
|
var createWasmApi_default = createWasmApi;
|
|
538
543
|
|
|
539
544
|
//#endregion
|
|
540
|
-
//#region
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
545
|
+
//#region src/internal/http/clientLifecycle.ts
|
|
546
|
+
/**
|
|
547
|
+
* Wraps the active HttpClient as a transport for the C++ `WebApi` host
|
|
548
|
+
* adapter. Lets the on-device face-results POST flow through the same
|
|
549
|
+
* `httpClient.request()` pipeline as every other endpoint — header
|
|
550
|
+
* injection, encryption-state handling, default headers, timeout — instead
|
|
551
|
+
* of bypassing it via `executeWasmRequest` directly.
|
|
552
|
+
*/
|
|
553
|
+
function bindWebApiTransport(client) {
|
|
554
|
+
return async (url, body, config) => {
|
|
555
|
+
const response = await client.request({
|
|
556
|
+
method: "POST",
|
|
557
|
+
url,
|
|
558
|
+
body,
|
|
559
|
+
headers: config.headers,
|
|
560
|
+
params: config.params,
|
|
561
|
+
timeout: config.timeout,
|
|
562
|
+
ie: config.ie
|
|
563
|
+
});
|
|
564
|
+
return {
|
|
565
|
+
data: response.data,
|
|
566
|
+
status: response.status
|
|
567
|
+
};
|
|
568
|
+
};
|
|
552
569
|
}
|
|
553
|
-
function
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
if (code < 32 || code === 127) return true;
|
|
557
|
-
}
|
|
558
|
-
return false;
|
|
570
|
+
function installClient(client) {
|
|
571
|
+
setClient(client);
|
|
572
|
+
setWebApiHttpTransport(bindWebApiTransport(client));
|
|
559
573
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
if (/^https?:\/\//i.test(trimmed)) try {
|
|
565
|
-
new URL(trimmed);
|
|
566
|
-
return false;
|
|
567
|
-
} catch {
|
|
568
|
-
return true;
|
|
569
|
-
}
|
|
570
|
-
return false;
|
|
574
|
+
let storedHttpConfig;
|
|
575
|
+
/** Reads the current HTTP-client config (or `undefined` if none installed). */
|
|
576
|
+
function getStoredHttpConfig() {
|
|
577
|
+
return storedHttpConfig;
|
|
571
578
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
console.warn(`[Incode SDK] wasm.${field} appears malformed. Falling back to CDN default.`);
|
|
579
|
+
/** Whether encryption is currently active on the installed HTTP client. */
|
|
580
|
+
function isHttpEncrypted() {
|
|
581
|
+
return storedHttpConfig?.encryption ?? false;
|
|
578
582
|
}
|
|
579
|
-
|
|
580
|
-
|
|
583
|
+
/** Clears all HTTP-client state. Called by `reset()`. */
|
|
584
|
+
function resetHttpClientState() {
|
|
585
|
+
storedHttpConfig = void 0;
|
|
586
|
+
setWebApiHttpTransport(null);
|
|
581
587
|
}
|
|
582
588
|
/**
|
|
583
|
-
*
|
|
584
|
-
*
|
|
589
|
+
* Builds (or replaces) the HTTP client when `setup()` receives an `apiURL`.
|
|
590
|
+
* Picks `createWasmApi` when `effectiveWasm` is set, otherwise plain
|
|
591
|
+
* `createApi`. Wraps the call in handshake-failure context when encryption
|
|
592
|
+
* is requested.
|
|
585
593
|
*/
|
|
586
|
-
function
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
594
|
+
async function installFreshHttpClient(apiURL, options, effectiveWasm, wantsEncryption) {
|
|
595
|
+
installClient(effectiveWasm ? await withHandshakeFailureContext(wantsEncryption, () => createWasmApi_default({
|
|
596
|
+
apiURL,
|
|
597
|
+
customHeaders: options.customHeaders,
|
|
598
|
+
timeout: options.timeout,
|
|
599
|
+
wasm: effectiveWasm,
|
|
600
|
+
encryptionEnabled: wantsEncryption,
|
|
601
|
+
isEncryptionEnabled: isHttpEncrypted
|
|
602
|
+
})) : createApi_default({
|
|
603
|
+
apiURL,
|
|
604
|
+
customHeaders: options.customHeaders,
|
|
605
|
+
timeout: options.timeout
|
|
606
|
+
}));
|
|
607
|
+
storedHttpConfig = {
|
|
608
|
+
apiURL,
|
|
609
|
+
customHeaders: options.customHeaders,
|
|
610
|
+
timeout: options.timeout,
|
|
611
|
+
isWasm: Boolean(effectiveWasm),
|
|
612
|
+
encryption: wantsEncryption
|
|
613
|
+
};
|
|
606
614
|
}
|
|
607
|
-
/**
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
+
/**
|
|
616
|
+
* Upgrades an existing non-encrypted connection to encrypted. Merges new
|
|
617
|
+
* `customHeaders` / `timeout` over the stored ones (new values win). If the
|
|
618
|
+
* existing client was plain fetch/XHR, swaps it for a WASM client; if it
|
|
619
|
+
* was already a non-encrypted WASM client, flips encryption on in place.
|
|
620
|
+
*
|
|
621
|
+
* No-op if no HTTP client was previously installed.
|
|
622
|
+
*/
|
|
623
|
+
async function enableEncryptionOnExistingClient(options, effectiveWasm) {
|
|
624
|
+
const stored = storedHttpConfig;
|
|
625
|
+
if (!stored) return;
|
|
626
|
+
const customHeaders = mergeHeaders(stored.customHeaders, options.customHeaders);
|
|
627
|
+
const timeout = options.timeout ?? stored.timeout;
|
|
628
|
+
if (!stored.isWasm) installClient(await withHandshakeFailureContext(true, () => createWasmApi_default({
|
|
629
|
+
apiURL: stored.apiURL,
|
|
630
|
+
customHeaders,
|
|
631
|
+
timeout,
|
|
632
|
+
wasm: effectiveWasm,
|
|
633
|
+
encryptionEnabled: true,
|
|
634
|
+
isEncryptionEnabled: isHttpEncrypted
|
|
635
|
+
})));
|
|
636
|
+
else if (!stored.encryption) await withHandshakeFailureContext(true, () => enableWasmEncryption({
|
|
637
|
+
apiURL: stored.apiURL,
|
|
638
|
+
defaultHeaders: buildWasmDefaultHeaders(customHeaders),
|
|
639
|
+
token: options.token
|
|
640
|
+
}));
|
|
641
|
+
storedHttpConfig = {
|
|
642
|
+
...stored,
|
|
643
|
+
customHeaders,
|
|
644
|
+
timeout,
|
|
645
|
+
isWasm: true,
|
|
646
|
+
encryption: true
|
|
615
647
|
};
|
|
616
648
|
}
|
|
617
649
|
/**
|
|
618
|
-
*
|
|
619
|
-
*
|
|
650
|
+
* Replaces the active HTTP client with the WASM-backed one. Used internally
|
|
651
|
+
* by lazy-loading UI components (`<incode-flow>`, `<incode-workflow>`) when
|
|
652
|
+
* WASM finishes warming up.
|
|
653
|
+
*
|
|
654
|
+
* No-op when no apiURL was previously configured, or when the active client
|
|
655
|
+
* is already WASM-backed.
|
|
656
|
+
*
|
|
657
|
+
* @internal NOT a public API. Application code should use
|
|
658
|
+
* `setup({ wasm: {...} })` instead.
|
|
620
659
|
*/
|
|
621
|
-
function
|
|
622
|
-
const
|
|
623
|
-
if (!
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
pipelines: overrides.pipelines,
|
|
636
|
-
pipelineModels: overrides.pipelineModels
|
|
660
|
+
async function upgradeToWasmHttpClient(resolved) {
|
|
661
|
+
const stored = storedHttpConfig;
|
|
662
|
+
if (!stored || stored.isWasm) return;
|
|
663
|
+
installClient(await createWasmApi_default({
|
|
664
|
+
apiURL: stored.apiURL,
|
|
665
|
+
customHeaders: stored.customHeaders,
|
|
666
|
+
timeout: stored.timeout,
|
|
667
|
+
wasm: resolved,
|
|
668
|
+
encryptionEnabled: stored.encryption,
|
|
669
|
+
isEncryptionEnabled: isHttpEncrypted
|
|
670
|
+
}));
|
|
671
|
+
storedHttpConfig = {
|
|
672
|
+
...stored,
|
|
673
|
+
isWasm: true
|
|
637
674
|
};
|
|
638
|
-
validateWasmPaths(merged);
|
|
639
|
-
return merged;
|
|
640
675
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
};
|
|
676
|
+
function mergeHeaders(base, override) {
|
|
677
|
+
if (!base && !override) return void 0;
|
|
678
|
+
return {
|
|
679
|
+
...base ?? {},
|
|
680
|
+
...override ?? {}
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* When `wantsEncryption` is true, wraps a call that triggers the in-binary
|
|
685
|
+
* RSA/AES handshake so its rejection surfaces as a single, descriptive error
|
|
686
|
+
* with the original error preserved as `cause`. Pass-through otherwise.
|
|
687
|
+
*/
|
|
688
|
+
async function withHandshakeFailureContext(wantsEncryption, fn) {
|
|
689
|
+
if (!wantsEncryption) return fn();
|
|
690
|
+
try {
|
|
691
|
+
return await fn();
|
|
692
|
+
} catch (cause) {
|
|
693
|
+
const error = /* @__PURE__ */ new Error("Failed to establish encrypted transport. The /e2ee/key handshake did not complete. Verify the apiURL is reachable and that the environment supports E2EE.");
|
|
694
|
+
error.cause = cause;
|
|
695
|
+
throw error;
|
|
662
696
|
}
|
|
663
|
-
}
|
|
697
|
+
}
|
|
664
698
|
|
|
665
699
|
//#endregion
|
|
666
700
|
//#region src/setup.ts
|
|
667
701
|
let wasmConfig;
|
|
668
|
-
let storedHttpConfig;
|
|
669
702
|
let configured = false;
|
|
670
703
|
/**
|
|
671
704
|
* Initializes the SDK with the provided configuration.
|
|
@@ -717,7 +750,9 @@ let configured = false;
|
|
|
717
750
|
* pipelines: ['selfie'],
|
|
718
751
|
* },
|
|
719
752
|
* });
|
|
720
|
-
*
|
|
753
|
+
*
|
|
754
|
+
* // Enable end-to-end encryption at boot
|
|
755
|
+
* await setup({ apiURL: 'https://api.incode.com', encryption: true });
|
|
721
756
|
*/
|
|
722
757
|
async function setup(options) {
|
|
723
758
|
const batcher = getAnalyticsBatcher() ?? setAnalyticsBatcher(createAnalyticsBatchingService({
|
|
@@ -728,26 +763,12 @@ async function setup(options) {
|
|
|
728
763
|
pageLifecycle: new BrowserPageLifecycleProvider(),
|
|
729
764
|
timer: BrowserTimerProvider.getInstance()
|
|
730
765
|
}));
|
|
731
|
-
const
|
|
732
|
-
if (options.
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
wasm: effectiveWasm
|
|
738
|
-
}) : createApi_default({
|
|
739
|
-
apiURL: options.apiURL,
|
|
740
|
-
customHeaders: options.customHeaders,
|
|
741
|
-
timeout: options.timeout
|
|
742
|
-
});
|
|
743
|
-
storedHttpConfig = {
|
|
744
|
-
apiURL: options.apiURL,
|
|
745
|
-
customHeaders: options.customHeaders,
|
|
746
|
-
timeout: options.timeout,
|
|
747
|
-
isWasm: Boolean(effectiveWasm)
|
|
748
|
-
};
|
|
749
|
-
setClient(client);
|
|
750
|
-
}
|
|
766
|
+
const wantsEncryption = options.encryption === true;
|
|
767
|
+
if (wantsEncryption && options.wasm === false) throw new Error("Encryption is incompatible with `wasm: false`. Either remove `wasm: false` or omit `encryption`.");
|
|
768
|
+
if (options.encryption === false && getStoredHttpConfig()?.encryption === true) throw new Error("Encryption cannot be disabled once enabled. Call reset() to fully reinitialize the SDK if you need a non-encrypted client.");
|
|
769
|
+
const effectiveWasm = options.wasm || wantsEncryption ? resolveWasmConfig(options.wasm || {}) : void 0;
|
|
770
|
+
if (options.apiURL) await installFreshHttpClient(options.apiURL, options, effectiveWasm, wantsEncryption);
|
|
771
|
+
else if (wantsEncryption && getStoredHttpConfig() && effectiveWasm) await enableEncryptionOnExistingClient(options, effectiveWasm);
|
|
751
772
|
if (options.token && isApiConfigured()) {
|
|
752
773
|
setToken(options.token);
|
|
753
774
|
resetSessionInit();
|
|
@@ -793,32 +814,23 @@ async function initializeWasmUtil(config) {
|
|
|
793
814
|
});
|
|
794
815
|
}
|
|
795
816
|
/**
|
|
796
|
-
* Replaces the active HTTP client with the WASM-backed one. Used
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
* `createWasmApi` once the WASM module is ready.
|
|
817
|
+
* Replaces the active HTTP client with the WASM-backed one. Used internally
|
|
818
|
+
* by lazy-loading UI components (`<incode-flow>`, `<incode-workflow>`) when
|
|
819
|
+
* WASM finishes warming up.
|
|
800
820
|
*
|
|
801
821
|
* No-op when no apiURL was originally configured, or when the active client is
|
|
802
822
|
* already the WASM one.
|
|
803
823
|
*
|
|
824
|
+
* @internal NOT a public API. Application code should use
|
|
825
|
+
* `setup({ wasm: {...} })` instead — that path is the supported way to opt
|
|
826
|
+
* into the WASM HTTP client.
|
|
827
|
+
*
|
|
804
828
|
* @param config - Optional WASM configuration. Defaults to the config stored via `setWasmConfig`.
|
|
805
829
|
*/
|
|
806
|
-
async function upgradeToWasmHttpClient(config) {
|
|
807
|
-
|
|
808
|
-
if (
|
|
809
|
-
|
|
810
|
-
if (!wasmConfigToUse) return;
|
|
811
|
-
const resolved = resolveWasmConfig(wasmConfigToUse);
|
|
812
|
-
setClient(await createWasmApi_default({
|
|
813
|
-
apiURL: storedHttpConfig.apiURL,
|
|
814
|
-
customHeaders: storedHttpConfig.customHeaders,
|
|
815
|
-
timeout: storedHttpConfig.timeout,
|
|
816
|
-
wasm: resolved
|
|
817
|
-
}));
|
|
818
|
-
storedHttpConfig = {
|
|
819
|
-
...storedHttpConfig,
|
|
820
|
-
isWasm: true
|
|
821
|
-
};
|
|
830
|
+
async function upgradeToWasmHttpClient$1(config) {
|
|
831
|
+
const configToUse = config ?? wasmConfig;
|
|
832
|
+
if (!configToUse) return;
|
|
833
|
+
await upgradeToWasmHttpClient(resolveWasmConfig(configToUse));
|
|
822
834
|
}
|
|
823
835
|
/**
|
|
824
836
|
* Checks if the SDK has been configured.
|
|
@@ -835,11 +847,11 @@ function reset() {
|
|
|
835
847
|
resetApi();
|
|
836
848
|
resetSessionInit();
|
|
837
849
|
resetAnalyticsBatcher();
|
|
850
|
+
resetHttpClientState();
|
|
838
851
|
configured = false;
|
|
839
852
|
wasmConfig = void 0;
|
|
840
|
-
storedHttpConfig = void 0;
|
|
841
853
|
WasmUtilProvider.resetInstance();
|
|
842
854
|
}
|
|
843
855
|
|
|
844
856
|
//#endregion
|
|
845
|
-
export { setup as a, buildDefaultWasmConfig as c, setWasmConfig as i, resolveWasmConfig as l, isConfigured as n, upgradeToWasmHttpClient as o, reset as r, DEFAULT_WASM_VERSION as s, initializeWasmUtil as t };
|
|
857
|
+
export { setup as a, buildDefaultWasmConfig as c, setWasmConfig as i, resolveWasmConfig as l, isConfigured as n, upgradeToWasmHttpClient$1 as o, reset as r, DEFAULT_WASM_VERSION as s, initializeWasmUtil as t };
|