@incodetech/core 2.0.0-rc.0 → 2.0.0
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/package.json +3 -3
- package/dist/Actor-CI32dTbG.d.ts +0 -2
- package/dist/BaseWasmProvider-C_DLEI40.esm.js +0 -1118
- package/dist/BrowserStorageProvider-CuOW1Er2.esm.js +0 -55
- package/dist/BrowserTimerProvider-DhNc_x02.esm.js +0 -22
- package/dist/ITimerCapability-C67ZRskg.esm.js +0 -7
- package/dist/IpifyProvider-D7jx52AL.esm.js +0 -139
- package/dist/Manager-C8PrhBOx.d.ts +0 -19
- package/dist/MotionSensorProvider-4v7xkqAp.esm.js +0 -254
- package/dist/OpenViduRecordingProvider-CMu6XVdc.esm.js +0 -87
- package/dist/StateMachine-BCQrZJhf.d.ts +0 -2
- package/dist/WasmUtilProvider-j98OJf-S.esm.js +0 -114
- package/dist/addressSearch-BpTbTWCa.esm.js +0 -430
- package/dist/ae-signature-DDDZmWXj.esm.js +0 -12
- package/dist/ae-signature.d.ts +0 -25
- package/dist/ae-signature.esm.js +0 -8
- package/dist/antifraud.d.ts +0 -57
- package/dist/antifraud.esm.js +0 -45
- package/dist/antifraudStateMachine-O0TMf6yc.esm.js +0 -39
- package/dist/api-CESGtpbH.esm.js +0 -53
- package/dist/authentication.d.ts +0 -12
- package/dist/authentication.esm.js +0 -25
- package/dist/authenticationManager-5M-fKzXx.esm.js +0 -67
- package/dist/authenticationManager-C83GNIhl.d.ts +0 -66
- package/dist/authenticationStateMachine-BMZqatiF.esm.js +0 -139
- package/dist/backCameraStream-DMdMeGk2.esm.js +0 -346
- package/dist/browserSimulation-gxD8cSpM.esm.js +0 -20
- package/dist/camera-DBSxa6ML.d.ts +0 -4
- package/dist/camera-PA2Ljri3.esm.js +0 -22
- package/dist/camera.d.ts +0 -15
- package/dist/camera.esm.js +0 -5
- package/dist/chunk-CRF6K_H_.esm.js +0 -49
- package/dist/consent.d.ts +0 -398
- package/dist/consent.esm.js +0 -79
- package/dist/consentStateMachine-CCT-B60O.esm.js +0 -151
- package/dist/cpf-PPz2Njto.esm.js +0 -38
- package/dist/cpf-ocr.d.ts +0 -204
- package/dist/cpf-ocr.esm.js +0 -177
- package/dist/cross-document-data-match.d.ts +0 -34
- package/dist/cross-document-data-match.esm.js +0 -71
- package/dist/curp-validation.d.ts +0 -188
- package/dist/curp-validation.esm.js +0 -110
- package/dist/curpValidationStateMachine-CitWLr2c.esm.js +0 -595
- package/dist/custom-fields.d.ts +0 -115
- package/dist/custom-fields.esm.js +0 -177
- package/dist/custom-watchlist.d.ts +0 -66
- package/dist/custom-watchlist.esm.js +0 -86
- package/dist/dateUtils-UoN5xswP.esm.js +0 -23
- package/dist/deepsightLoader-Cm4JIT_z.esm.js +0 -52
- package/dist/deepsightService-CEVxzehb.d.ts +0 -412
- package/dist/deepsightService-O74l4Y__.esm.js +0 -489
- package/dist/device.d.ts +0 -46
- package/dist/device.esm.js +0 -106
- package/dist/displayErrors-DqJ_IbsG.d.ts +0 -39
- package/dist/document-capture.d.ts +0 -906
- package/dist/document-capture.esm.js +0 -156
- package/dist/document-upload.d.ts +0 -331
- package/dist/document-upload.esm.js +0 -203
- package/dist/documentCaptureStateMachine-BqzTDy9k.esm.js +0 -394
- package/dist/dynamic-forms.d.ts +0 -178
- package/dist/dynamic-forms.esm.js +0 -323
- package/dist/ekyb.d.ts +0 -148
- package/dist/ekyb.esm.js +0 -127
- package/dist/ekybStateMachine-B59rQjgj.esm.js +0 -674
- package/dist/ekyc.d.ts +0 -164
- package/dist/ekyc.esm.js +0 -104
- package/dist/ekycStateMachine-oeO0Iekd.esm.js +0 -10626
- package/dist/electronic-signature.d.ts +0 -4
- package/dist/electronic-signature.esm.js +0 -7
- package/dist/electronicSignatureManager-D9OHzTpG.esm.js +0 -428
- package/dist/email.d.ts +0 -4
- package/dist/email.esm.js +0 -9
- package/dist/emailManager-DIfnS5g1.d.ts +0 -352
- package/dist/emailManager-wAV0LE-H.esm.js +0 -238
- package/dist/emailStateMachine-DOf4j58N.esm.js +0 -292
- package/dist/endpoints-CnN3SyDa.esm.js +0 -87
- package/dist/events-D6-e4vok.esm.js +0 -596
- package/dist/events.d.ts +0 -265
- package/dist/events.esm.js +0 -4
- package/dist/extensibility.d.ts +0 -122
- package/dist/extensibility.esm.js +0 -43
- package/dist/face-match.d.ts +0 -228
- package/dist/face-match.esm.js +0 -173
- package/dist/faceCaptureManagerFactory-Dh2PdGlF.esm.js +0 -290
- package/dist/faceCaptureManagerFactory-yqtpxjnN.d.ts +0 -690
- package/dist/faceCaptureSetup-B3faSpYA.esm.js +0 -873
- package/dist/faceMatchStateMachine-DNFrxTFS.esm.js +0 -127
- package/dist/flow-events.d.ts +0 -6
- package/dist/flow-events.esm.js +0 -0
- package/dist/flow.d.ts +0 -358
- package/dist/flow.esm.js +0 -825
- package/dist/flowCompletionService-DhkT4SRY.d.ts +0 -10
- package/dist/flowCompletionService-P54yzGvA.esm.js +0 -13
- package/dist/flowServices-DTsm-Vf1.esm.js +0 -188
- package/dist/geolocation.d.ts +0 -127
- package/dist/geolocation.esm.js +0 -89
- package/dist/geolocationStateMachine-asasuHY2.esm.js +0 -105
- package/dist/getBrowser-BSXUTWXw.esm.js +0 -41
- package/dist/getDeviceClass-BSntT9_j.esm.js +0 -14
- package/dist/government-validation.d.ts +0 -67
- package/dist/government-validation.esm.js +0 -81
- package/dist/governmentValidationStateMachine-BDDYrJTo.esm.js +0 -271
- package/dist/home.d.ts +0 -99
- package/dist/home.esm.js +0 -61
- package/dist/http.d.ts +0 -68
- package/dist/http.esm.js +0 -3
- package/dist/id-ocr.d.ts +0 -635
- package/dist/id-ocr.esm.js +0 -86
- package/dist/id-verification.d.ts +0 -190
- package/dist/id-verification.esm.js +0 -43
- package/dist/id.d.ts +0 -24
- package/dist/id.esm.js +0 -164
- package/dist/idCaptureManager-B9TGA5dq.d.ts +0 -956
- package/dist/idCaptureManager-DMK0GIt3.esm.js +0 -581
- package/dist/idCaptureStateMachine-Bq0fVZXl.esm.js +0 -2954
- package/dist/idOcrStateMachine-YbjjC_Gg.esm.js +0 -388
- package/dist/idVerificationStateMachine-xbw9HP1Z.esm.js +0 -71
- package/dist/identity-reuse.d.ts +0 -530
- package/dist/identity-reuse.esm.js +0 -274
- package/dist/index-BLKtMA0g.d.ts +0 -1177
- package/dist/index-BcRG8rtJ.d.ts +0 -97
- package/dist/index.d.ts +0 -3
- package/dist/index.esm.js +0 -12
- package/dist/invokeOnCaptureCallback-rc6kBHo5.esm.js +0 -30
- package/dist/lib-BB0B_qQX.esm.js +0 -12499
- package/dist/mandatory-consent.d.ts +0 -412
- package/dist/mandatory-consent.esm.js +0 -78
- package/dist/mandatoryConsentStateMachine-Cnco1jvn.esm.js +0 -126
- package/dist/openviduLazy-Cm0XFh_v.esm.js +0 -3
- package/dist/openviduLazy-Cok70ZSg.esm.js +0 -12
- package/dist/permissionServices-D_i6nzEw.esm.js +0 -50
- package/dist/phone.d.ts +0 -4
- package/dist/phone.esm.js +0 -9
- package/dist/phoneManager-B6M30hKE.d.ts +0 -397
- package/dist/phoneManager-DAJbGhlY.esm.js +0 -256
- package/dist/phoneStateMachine-CuPARRaT.esm.js +0 -351
- package/dist/platform-CfrjKhmi.esm.js +0 -83
- package/dist/qe-signature-DFo_Cc-I.esm.js +0 -12
- package/dist/qe-signature.d.ts +0 -25
- package/dist/qe-signature.esm.js +0 -8
- package/dist/recordingService-Ig2UgbLv.esm.js +0 -1003
- package/dist/redirect-to-mobile.d.ts +0 -107
- package/dist/redirect-to-mobile.esm.js +0 -102
- package/dist/redirectToMobileStateMachine-BOEqe46A.esm.js +0 -249
- package/dist/runChildModule-CqqwqAkW.esm.js +0 -219
- package/dist/selfie.d.ts +0 -26
- package/dist/selfie.esm.js +0 -146
- package/dist/selfieManager-D0lSgd-J.d.ts +0 -68
- package/dist/selfieManager-Duisl7qN.esm.js +0 -60
- package/dist/selfieStateMachine-D76whWEf.esm.js +0 -68
- package/dist/session-BS-d_vuE.esm.js +0 -3206
- package/dist/session.d.ts +0 -217
- package/dist/session.esm.js +0 -9
- package/dist/setup-Buy-hyj4.esm.js +0 -887
- package/dist/setup-C5AITV8m.d.ts +0 -254
- package/dist/signature.d.ts +0 -94
- package/dist/signature.esm.js +0 -66
- package/dist/signatureStateMachine-B5-QVUve.esm.js +0 -132
- package/dist/stats-CIfiPzb1.esm.js +0 -16
- package/dist/stats.d.ts +0 -16
- package/dist/stats.esm.js +0 -4
- package/dist/trust-graph.d.ts +0 -54
- package/dist/trust-graph.esm.js +0 -56
- package/dist/types-B06Ypu2F.d.ts +0 -49
- package/dist/types-BP1m8VRw.d.ts +0 -340
- package/dist/types-CAD4va6a.d.ts +0 -5
- package/dist/types-CFV9G_7j.d.ts +0 -24
- package/dist/warmup-CEcppFiS.d.ts +0 -63
- package/dist/wasm.d.ts +0 -15
- package/dist/wasm.esm.js +0 -12
- package/dist/watchlist-for-business.d.ts +0 -79
- package/dist/watchlist-for-business.esm.js +0 -148
- package/dist/watchlist.d.ts +0 -62
- package/dist/watchlist.esm.js +0 -86
- package/dist/watchlistServices-DMbUhkBX.esm.js +0 -12
- package/dist/workflow.d.ts +0 -907
- package/dist/workflow.esm.js +0 -702
- package/dist/xstate.esm-B70JrNqo.esm.js +0 -3404
|
@@ -1,887 +0,0 @@
|
|
|
1
|
-
import { a as executeWasmRequest, c as setupWasmConnection, i as WasmWebClientError, n as warmupWasm, o as initializeWasmWebClient, s as setWebApiHttpTransport } from "./BaseWasmProvider-C_DLEI40.esm.js";
|
|
2
|
-
import { t as WasmUtilProvider } from "./WasmUtilProvider-j98OJf-S.esm.js";
|
|
3
|
-
import { t as BrowserTimerProvider } from "./BrowserTimerProvider-DhNc_x02.esm.js";
|
|
4
|
-
import { a as resetApi, i as isApiConfigured, n as getApi, o as setClient, r as getToken, t as api } from "./api-CESGtpbH.esm.js";
|
|
5
|
-
import { _ as resetAnalyticsBatcher, g as getAnalyticsBatcher, m as createAnalyticsBatchingService, v as setAnalyticsBatcher } from "./events-D6-e4vok.esm.js";
|
|
6
|
-
import { t as endpoints } from "./endpoints-CnN3SyDa.esm.js";
|
|
7
|
-
import { i as resetSessionInit, r as initializeSession } from "./session-BS-d_vuE.esm.js";
|
|
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.21";
|
|
13
|
-
const PATH_KEYS = [
|
|
14
|
-
"wasmPath",
|
|
15
|
-
"wasmSimdPath",
|
|
16
|
-
"glueCodePath",
|
|
17
|
-
"glueCodeSimdPath",
|
|
18
|
-
"modelsBasePath"
|
|
19
|
-
];
|
|
20
|
-
function isBlank(value) {
|
|
21
|
-
return value.trim() === "";
|
|
22
|
-
}
|
|
23
|
-
function hasDisallowedControlChars(value) {
|
|
24
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
25
|
-
const code = value.charCodeAt(i);
|
|
26
|
-
if (code < 32 || code === 127) return true;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
function isMalformedPath(value) {
|
|
31
|
-
const trimmed = value.trim();
|
|
32
|
-
if (trimmed === "") return false;
|
|
33
|
-
if (hasDisallowedControlChars(trimmed)) return true;
|
|
34
|
-
if (/^https?:\/\//i.test(trimmed)) try {
|
|
35
|
-
new URL(trimmed);
|
|
36
|
-
return false;
|
|
37
|
-
} catch {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
function warnInvalidWasmPath(field, reason) {
|
|
43
|
-
if (reason === "empty") {
|
|
44
|
-
console.warn(`[Incode SDK] wasm.${field} is empty. Falling back to CDN default.`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
console.warn(`[Incode SDK] wasm.${field} appears malformed. Falling back to CDN default.`);
|
|
48
|
-
}
|
|
49
|
-
function warnMalformedWasmPath(field) {
|
|
50
|
-
console.warn(`[Incode SDK] wasm.${field} appears malformed. Check the URL or path.`);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Validates merged WASM path strings. When overrides contained blank path
|
|
54
|
-
* values, callers should have already fallen back to defaults before this runs.
|
|
55
|
-
*/
|
|
56
|
-
function validateWasmPaths(config) {
|
|
57
|
-
for (const key of PATH_KEYS) {
|
|
58
|
-
const value = config[key];
|
|
59
|
-
if (typeof value === "string" && isMalformedPath(value)) warnMalformedWasmPath(key);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function pickPath(key, overrides, defaultValue) {
|
|
63
|
-
if (!overrides || !(key in overrides)) return defaultValue;
|
|
64
|
-
const raw = overrides[key];
|
|
65
|
-
if (raw === void 0) return defaultValue;
|
|
66
|
-
if (typeof raw !== "string") return defaultValue;
|
|
67
|
-
if (isBlank(raw)) {
|
|
68
|
-
warnInvalidWasmPath(key, "empty");
|
|
69
|
-
return defaultValue;
|
|
70
|
-
}
|
|
71
|
-
if (isMalformedPath(raw)) {
|
|
72
|
-
warnInvalidWasmPath(key, "malformed");
|
|
73
|
-
return defaultValue;
|
|
74
|
-
}
|
|
75
|
-
return raw.trim();
|
|
76
|
-
}
|
|
77
|
-
/** Builds the standard WarmupConfig from the Incode CDN. */
|
|
78
|
-
function buildDefaultWasmConfig() {
|
|
79
|
-
const base = `${WASM_CDN_BASE_URL}/${DEFAULT_WASM_VERSION}`;
|
|
80
|
-
return {
|
|
81
|
-
wasmPath: `${base}/webLib.wasm`,
|
|
82
|
-
wasmSimdPath: `${base}/webLibSimd.wasm`,
|
|
83
|
-
glueCodePath: `${base}/webLib.js`,
|
|
84
|
-
glueCodeSimdPath: `${base}/webLibSimd.js`,
|
|
85
|
-
modelsBasePath: `${base}/models`
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Derives a sibling `.js` glue path from a `.wasm` binary path. Used when the
|
|
90
|
-
* caller supplies `wasmSimdPath` but no explicit `glueCodeSimdPath`, mirroring
|
|
91
|
-
* the legacy CDN naming convention (`webLibSimd.wasm` <-> `webLibSimd.js`).
|
|
92
|
-
*/
|
|
93
|
-
function deriveSiblingJsPath(wasmPath) {
|
|
94
|
-
return wasmPath.replace(/\.wasm($|\?)/, ".js$1");
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Merges optional WASM path overrides with CDN defaults. Explicit non-blank
|
|
98
|
-
* paths take precedence. Blank override strings log a warning and fall back to defaults.
|
|
99
|
-
*/
|
|
100
|
-
function resolveWasmConfig(overrides) {
|
|
101
|
-
const defaults = buildDefaultWasmConfig();
|
|
102
|
-
if (!overrides) return defaults;
|
|
103
|
-
const simdDefault = defaults.wasmSimdPath ?? defaults.wasmPath;
|
|
104
|
-
const modelsDefault = defaults.modelsBasePath ?? (() => {
|
|
105
|
-
const lastSlash = defaults.wasmPath.lastIndexOf("/");
|
|
106
|
-
return lastSlash === -1 ? "models" : `${defaults.wasmPath.substring(0, lastSlash)}/models`;
|
|
107
|
-
})();
|
|
108
|
-
const resolvedWasmSimdPath = pickPath("wasmSimdPath", overrides, simdDefault);
|
|
109
|
-
const glueCodeSimdDefault = deriveSiblingJsPath(resolvedWasmSimdPath);
|
|
110
|
-
const merged = {
|
|
111
|
-
wasmPath: pickPath("wasmPath", overrides, defaults.wasmPath),
|
|
112
|
-
wasmSimdPath: resolvedWasmSimdPath,
|
|
113
|
-
glueCodePath: pickPath("glueCodePath", overrides, defaults.glueCodePath),
|
|
114
|
-
glueCodeSimdPath: pickPath("glueCodeSimdPath", overrides, glueCodeSimdDefault),
|
|
115
|
-
modelsBasePath: pickPath("modelsBasePath", overrides, modelsDefault),
|
|
116
|
-
useSimd: overrides.useSimd,
|
|
117
|
-
pipelines: overrides.pipelines,
|
|
118
|
-
pipelineModels: overrides.pipelineModels
|
|
119
|
-
};
|
|
120
|
-
validateWasmPaths(merged);
|
|
121
|
-
return merged;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region ../infra/src/providers/browser/BrowserPageLifecycleProvider.ts
|
|
126
|
-
var BrowserPageLifecycleProvider = class {
|
|
127
|
-
sendBeacon(url, body, contentType = "application/json") {
|
|
128
|
-
if (typeof navigator === "undefined" || typeof navigator.sendBeacon !== "function") return false;
|
|
129
|
-
const blob = new Blob([body], { type: contentType });
|
|
130
|
-
return navigator.sendBeacon(url, blob);
|
|
131
|
-
}
|
|
132
|
-
onPageHide(listener) {
|
|
133
|
-
const onVisibilityChange = () => {
|
|
134
|
-
if (document.visibilityState === "hidden") listener();
|
|
135
|
-
};
|
|
136
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
137
|
-
window.addEventListener("pagehide", listener);
|
|
138
|
-
window.addEventListener("beforeunload", listener);
|
|
139
|
-
return () => {
|
|
140
|
-
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
141
|
-
window.removeEventListener("pagehide", listener);
|
|
142
|
-
window.removeEventListener("beforeunload", listener);
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region ../infra/src/http/createApi.ts
|
|
149
|
-
var FetchHttpError = class extends Error {
|
|
150
|
-
constructor(status, statusText, url, method, headers, data) {
|
|
151
|
-
super(`HTTP ${status} ${statusText}`);
|
|
152
|
-
this.ok = false;
|
|
153
|
-
this.status = status;
|
|
154
|
-
this.statusText = statusText;
|
|
155
|
-
this.url = url;
|
|
156
|
-
this.method = method;
|
|
157
|
-
this.headers = headers;
|
|
158
|
-
this.data = data;
|
|
159
|
-
this.name = "FetchHttpError";
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
const buildQueryString$1 = (query) => {
|
|
163
|
-
if (!query) return "";
|
|
164
|
-
const params = new URLSearchParams();
|
|
165
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
166
|
-
if (value !== void 0 && value !== null) params.append(key, String(value));
|
|
167
|
-
});
|
|
168
|
-
const str = params.toString();
|
|
169
|
-
return str ? `?${str}` : "";
|
|
170
|
-
};
|
|
171
|
-
const buildUrl$1 = (baseURL, url, query) => {
|
|
172
|
-
const queryString = buildQueryString$1(query);
|
|
173
|
-
if (url.startsWith("http://") || url.startsWith("https://")) return `${url}${queryString}`;
|
|
174
|
-
return `${baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL}${url.startsWith("/") ? url : `/${url}`}${queryString}`;
|
|
175
|
-
};
|
|
176
|
-
const prepareBody$1 = (body) => {
|
|
177
|
-
if (body === null || body === void 0) return null;
|
|
178
|
-
if (body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer) return body;
|
|
179
|
-
if (typeof body === "object") return JSON.stringify(body);
|
|
180
|
-
return String(body);
|
|
181
|
-
};
|
|
182
|
-
const parseResponse = async (response, parseType) => {
|
|
183
|
-
if (parseType === "response") return response;
|
|
184
|
-
if (parseType === "blob") return await response.blob();
|
|
185
|
-
if (parseType === "arrayBuffer") return await response.arrayBuffer();
|
|
186
|
-
if (parseType === "text") return await response.text();
|
|
187
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
188
|
-
if (parseType === "json" || contentType.includes("application/json")) try {
|
|
189
|
-
return await response.json();
|
|
190
|
-
} catch {
|
|
191
|
-
return await response.text();
|
|
192
|
-
}
|
|
193
|
-
return await response.text();
|
|
194
|
-
};
|
|
195
|
-
const DEFAULT_TIMEOUT$1 = 3e4;
|
|
196
|
-
const requestWithXHR = (fullUrl, method, mergedHeaders, requestBody, timeout, signal, onUploadProgress) => {
|
|
197
|
-
return new Promise((resolve, reject) => {
|
|
198
|
-
const xhr = new XMLHttpRequest();
|
|
199
|
-
xhr.open(method, fullUrl, true);
|
|
200
|
-
Object.entries(mergedHeaders).forEach(([key, value]) => {
|
|
201
|
-
xhr.setRequestHeader(key, value);
|
|
202
|
-
});
|
|
203
|
-
xhr.timeout = timeout;
|
|
204
|
-
xhr.upload.onprogress = (event) => {
|
|
205
|
-
if (event.lengthComputable) {
|
|
206
|
-
const percentComplete = event.loaded / event.total * 100;
|
|
207
|
-
onUploadProgress(Math.round(percentComplete));
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
xhr.onload = () => {
|
|
211
|
-
const responseHeaders = {};
|
|
212
|
-
xhr.getAllResponseHeaders().split("\r\n").forEach((line) => {
|
|
213
|
-
const parts = line.split(": ");
|
|
214
|
-
if (parts.length === 2) responseHeaders[parts[0].toLowerCase()] = parts[1];
|
|
215
|
-
});
|
|
216
|
-
let data;
|
|
217
|
-
try {
|
|
218
|
-
if ((xhr.getResponseHeader("content-type") ?? "").includes("application/json")) data = JSON.parse(xhr.responseText);
|
|
219
|
-
else data = xhr.responseText;
|
|
220
|
-
} catch {
|
|
221
|
-
data = xhr.responseText;
|
|
222
|
-
}
|
|
223
|
-
if (xhr.status >= 200 && xhr.status < 300) resolve({
|
|
224
|
-
ok: true,
|
|
225
|
-
status: xhr.status,
|
|
226
|
-
statusText: xhr.statusText,
|
|
227
|
-
url: fullUrl,
|
|
228
|
-
headers: responseHeaders,
|
|
229
|
-
data
|
|
230
|
-
});
|
|
231
|
-
else reject(new FetchHttpError(xhr.status, xhr.statusText, fullUrl, method, responseHeaders, data));
|
|
232
|
-
};
|
|
233
|
-
xhr.onerror = () => {
|
|
234
|
-
reject(new FetchHttpError(0, "Network Error", fullUrl, method, {}, null));
|
|
235
|
-
};
|
|
236
|
-
xhr.ontimeout = () => {
|
|
237
|
-
reject(new FetchHttpError(0, "Request timeout", fullUrl, method, {}, null));
|
|
238
|
-
};
|
|
239
|
-
if (signal) signal.addEventListener("abort", () => {
|
|
240
|
-
xhr.abort();
|
|
241
|
-
reject(new FetchHttpError(0, "Request aborted", fullUrl, method, {}, null));
|
|
242
|
-
});
|
|
243
|
-
xhr.send(requestBody);
|
|
244
|
-
});
|
|
245
|
-
};
|
|
246
|
-
const createApi = (config) => {
|
|
247
|
-
const headers = {
|
|
248
|
-
"Content-Type": "application/json",
|
|
249
|
-
Accept: "application/json",
|
|
250
|
-
"api-version": "1.0",
|
|
251
|
-
...config.customHeaders ?? {}
|
|
252
|
-
};
|
|
253
|
-
const defaults = {
|
|
254
|
-
baseURL: config.apiURL,
|
|
255
|
-
headers
|
|
256
|
-
};
|
|
257
|
-
const client = {
|
|
258
|
-
defaults,
|
|
259
|
-
async request(requestConfig) {
|
|
260
|
-
const { method = "GET", url, headers: headers$1 = {}, query, params, body, signal, timeout = config.timeout ?? DEFAULT_TIMEOUT$1, parse, onUploadProgress, keepalive } = requestConfig;
|
|
261
|
-
const fullUrl = buildUrl$1(defaults.baseURL, url, params ?? query);
|
|
262
|
-
const mergedHeaders = {
|
|
263
|
-
...defaults.headers,
|
|
264
|
-
...headers$1
|
|
265
|
-
};
|
|
266
|
-
const requestBody = prepareBody$1(body);
|
|
267
|
-
let finalHeaders = mergedHeaders;
|
|
268
|
-
if (requestBody === null && (method === "POST" || method === "PUT" || method === "PATCH")) {
|
|
269
|
-
const { "Content-Type": _, ...headersWithoutContentType } = mergedHeaders;
|
|
270
|
-
finalHeaders = headersWithoutContentType;
|
|
271
|
-
}
|
|
272
|
-
if (onUploadProgress) {
|
|
273
|
-
if (requestBody !== null && typeof ReadableStream !== "undefined" && requestBody instanceof ReadableStream) throw new Error("Upload progress tracking is not supported for ReadableStream bodies");
|
|
274
|
-
return requestWithXHR(fullUrl, method, finalHeaders, requestBody, timeout, signal, onUploadProgress);
|
|
275
|
-
}
|
|
276
|
-
const controller = new AbortController();
|
|
277
|
-
const abortSignal = signal ?? controller.signal;
|
|
278
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
279
|
-
try {
|
|
280
|
-
const response = await fetch(fullUrl, {
|
|
281
|
-
method,
|
|
282
|
-
headers: finalHeaders,
|
|
283
|
-
body: requestBody,
|
|
284
|
-
signal: abortSignal,
|
|
285
|
-
keepalive
|
|
286
|
-
});
|
|
287
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
288
|
-
const responseHeaders = {};
|
|
289
|
-
response.headers.forEach((value, key) => {
|
|
290
|
-
responseHeaders[key] = value;
|
|
291
|
-
});
|
|
292
|
-
const data = await parseResponse(response, parse);
|
|
293
|
-
if (!response.ok) throw new FetchHttpError(response.status, response.statusText, fullUrl, method, responseHeaders, data);
|
|
294
|
-
return {
|
|
295
|
-
ok: true,
|
|
296
|
-
status: response.status,
|
|
297
|
-
statusText: response.statusText,
|
|
298
|
-
url: fullUrl,
|
|
299
|
-
headers: responseHeaders,
|
|
300
|
-
data
|
|
301
|
-
};
|
|
302
|
-
} catch (error) {
|
|
303
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
304
|
-
if (error instanceof FetchHttpError) throw error;
|
|
305
|
-
if (error instanceof Error && error.name === "AbortError") throw new FetchHttpError(0, "Request timeout", fullUrl, method, {}, null);
|
|
306
|
-
throw error;
|
|
307
|
-
}
|
|
308
|
-
},
|
|
309
|
-
get(url, config$1) {
|
|
310
|
-
return client.request({
|
|
311
|
-
...config$1,
|
|
312
|
-
url,
|
|
313
|
-
method: "GET"
|
|
314
|
-
});
|
|
315
|
-
},
|
|
316
|
-
post(url, body, config$1) {
|
|
317
|
-
return client.request({
|
|
318
|
-
...config$1,
|
|
319
|
-
url,
|
|
320
|
-
body,
|
|
321
|
-
method: "POST"
|
|
322
|
-
});
|
|
323
|
-
},
|
|
324
|
-
put(url, body, config$1) {
|
|
325
|
-
return client.request({
|
|
326
|
-
...config$1,
|
|
327
|
-
url,
|
|
328
|
-
body,
|
|
329
|
-
method: "PUT"
|
|
330
|
-
});
|
|
331
|
-
},
|
|
332
|
-
patch(url, body, config$1) {
|
|
333
|
-
return client.request({
|
|
334
|
-
...config$1,
|
|
335
|
-
url,
|
|
336
|
-
body,
|
|
337
|
-
method: "PATCH"
|
|
338
|
-
});
|
|
339
|
-
},
|
|
340
|
-
delete(url, config$1) {
|
|
341
|
-
return client.request({
|
|
342
|
-
...config$1,
|
|
343
|
-
url,
|
|
344
|
-
method: "DELETE"
|
|
345
|
-
});
|
|
346
|
-
},
|
|
347
|
-
head(url, config$1) {
|
|
348
|
-
return client.request({
|
|
349
|
-
...config$1,
|
|
350
|
-
url,
|
|
351
|
-
method: "HEAD"
|
|
352
|
-
});
|
|
353
|
-
},
|
|
354
|
-
options(url, config$1) {
|
|
355
|
-
return client.request({
|
|
356
|
-
...config$1,
|
|
357
|
-
url,
|
|
358
|
-
method: "OPTIONS"
|
|
359
|
-
});
|
|
360
|
-
},
|
|
361
|
-
setHeader(name, value) {
|
|
362
|
-
defaults.headers[name] = value;
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
return client;
|
|
366
|
-
};
|
|
367
|
-
var createApi_default = createApi;
|
|
368
|
-
|
|
369
|
-
//#endregion
|
|
370
|
-
//#region ../infra/src/http/createWasmApi.ts
|
|
371
|
-
const RSA_OAEP_SHA256_SCHEME = "RSA/NONE/OAEPWITHSHA-256ANDMGF1PADDING";
|
|
372
|
-
/**
|
|
373
|
-
* Builds the base set of HTTP headers that the WASM WebClient sends on every
|
|
374
|
-
* request (including the internal `/e2ee/key/v2` and `/e2ee/key` handshake
|
|
375
|
-
* calls).
|
|
376
|
-
*/
|
|
377
|
-
function buildWasmDefaultHeaders(customHeaders) {
|
|
378
|
-
return {
|
|
379
|
-
"Content-Type": "application/json",
|
|
380
|
-
Accept: "application/json",
|
|
381
|
-
"api-version": "1.0",
|
|
382
|
-
...customHeaders ?? {}
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
var WasmHttpError = class extends Error {
|
|
386
|
-
constructor(status, statusText, url, method, headers, data) {
|
|
387
|
-
super(`HTTP ${status} ${statusText}`);
|
|
388
|
-
this.ok = false;
|
|
389
|
-
this.status = status;
|
|
390
|
-
this.statusText = statusText;
|
|
391
|
-
this.url = url;
|
|
392
|
-
this.method = method;
|
|
393
|
-
this.headers = headers;
|
|
394
|
-
this.data = data;
|
|
395
|
-
this.name = "WasmHttpError";
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
const DEFAULT_TIMEOUT = 3e4;
|
|
399
|
-
const HTTP_METHODS = new Set([
|
|
400
|
-
"GET",
|
|
401
|
-
"POST",
|
|
402
|
-
"PUT",
|
|
403
|
-
"PATCH",
|
|
404
|
-
"DELETE"
|
|
405
|
-
]);
|
|
406
|
-
const buildQueryString = (query) => {
|
|
407
|
-
if (!query) return "";
|
|
408
|
-
const params = new URLSearchParams();
|
|
409
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
410
|
-
if (value !== void 0 && value !== null) params.append(key, String(value));
|
|
411
|
-
});
|
|
412
|
-
const str = params.toString();
|
|
413
|
-
return str ? `?${str}` : "";
|
|
414
|
-
};
|
|
415
|
-
const buildUrl = (baseURL, url, query) => {
|
|
416
|
-
const queryString = buildQueryString(query);
|
|
417
|
-
if (url.startsWith("http://") || url.startsWith("https://")) return `${url}${queryString}`;
|
|
418
|
-
return `${baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL}${url.startsWith("/") ? url : `/${url}`}${queryString}`;
|
|
419
|
-
};
|
|
420
|
-
const prepareBody = (body) => {
|
|
421
|
-
if (body === null || body === void 0) return void 0;
|
|
422
|
-
if (body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer || body instanceof Uint8Array || typeof body === "string") return body;
|
|
423
|
-
if (typeof body === "object") return body;
|
|
424
|
-
return String(body);
|
|
425
|
-
};
|
|
426
|
-
const normalizeMethod = (method) => {
|
|
427
|
-
const upper = method.toUpperCase();
|
|
428
|
-
if (!HTTP_METHODS.has(upper)) throw new Error(`Unsupported HTTP method for WASM client: ${method}`);
|
|
429
|
-
return upper;
|
|
430
|
-
};
|
|
431
|
-
const getErrorStatus = (error) => {
|
|
432
|
-
if (error instanceof WasmWebClientError) return error.statusCode;
|
|
433
|
-
if (typeof error === "object" && error !== null) {
|
|
434
|
-
const record = error;
|
|
435
|
-
if (typeof record.statusCode === "number") return record.statusCode;
|
|
436
|
-
if (typeof record.status === "number") return record.status;
|
|
437
|
-
}
|
|
438
|
-
return 0;
|
|
439
|
-
};
|
|
440
|
-
const getErrorData = (error) => {
|
|
441
|
-
if (error instanceof WasmWebClientError) return error.response?.data ?? null;
|
|
442
|
-
return null;
|
|
443
|
-
};
|
|
444
|
-
const getErrorMessage = (error) => {
|
|
445
|
-
if (error instanceof Error) return error.message;
|
|
446
|
-
return "WasmWebClient request failed";
|
|
447
|
-
};
|
|
448
|
-
const withAbortSignal = async (promise, signal, error) => {
|
|
449
|
-
if (!signal) return await promise;
|
|
450
|
-
if (signal.aborted) throw error;
|
|
451
|
-
return await new Promise((resolve, reject) => {
|
|
452
|
-
const onAbort = () => reject(error);
|
|
453
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
454
|
-
promise.then(resolve, reject).finally(() => {
|
|
455
|
-
signal.removeEventListener("abort", onAbort);
|
|
456
|
-
});
|
|
457
|
-
});
|
|
458
|
-
};
|
|
459
|
-
const createWasmApi = async (config) => {
|
|
460
|
-
const headers = buildWasmDefaultHeaders(config.customHeaders);
|
|
461
|
-
const isEncryptionEnabled = config.isEncryptionEnabled ?? (() => false);
|
|
462
|
-
const useSha256 = config.mgf1 === "sha256";
|
|
463
|
-
await initializeWasmWebClient(config.wasm.wasmPath, config.wasm.wasmSimdPath ?? config.wasm.wasmPath, config.wasm.glueCodePath, config.wasm.glueCodeSimdPath ?? "", config.wasm.useSimd ?? true);
|
|
464
|
-
await setupWasmConnection(config.apiURL, "", config.encryptionEnabled ?? false, headers, useSha256);
|
|
465
|
-
const defaults = {
|
|
466
|
-
baseURL: config.apiURL,
|
|
467
|
-
headers
|
|
468
|
-
};
|
|
469
|
-
const client = {
|
|
470
|
-
defaults,
|
|
471
|
-
async request(requestConfig) {
|
|
472
|
-
const { method = "GET", url, headers: requestHeaders = {}, query, params, body, signal, timeout = config.timeout ?? DEFAULT_TIMEOUT, onUploadProgress, ie = false } = requestConfig;
|
|
473
|
-
const upperMethod = normalizeMethod(method);
|
|
474
|
-
const requestParams = params ?? query;
|
|
475
|
-
const fullUrl = buildUrl(defaults.baseURL, url, requestParams);
|
|
476
|
-
const needsSchemeHeader = ie || useSha256 && isEncryptionEnabled();
|
|
477
|
-
const mergedHeaders = {
|
|
478
|
-
...defaults.headers,
|
|
479
|
-
...needsSchemeHeader ? { "X-RSA-Encryption-Scheme": RSA_OAEP_SHA256_SCHEME } : {},
|
|
480
|
-
...requestHeaders
|
|
481
|
-
};
|
|
482
|
-
const requestBody = prepareBody(body);
|
|
483
|
-
const wasmProgress = onUploadProgress ? (progress) => {
|
|
484
|
-
if (progress.total > 0) onUploadProgress(Math.round(progress.loaded / progress.total * 100));
|
|
485
|
-
} : void 0;
|
|
486
|
-
const abortError = new WasmHttpError(0, "Request aborted", fullUrl, upperMethod, {}, null);
|
|
487
|
-
if (signal?.aborted) throw abortError;
|
|
488
|
-
try {
|
|
489
|
-
const response = await withAbortSignal(executeWasmRequest(upperMethod, url, requestBody, mergedHeaders, requestParams, timeout, wasmProgress, ie), signal, abortError);
|
|
490
|
-
if (response.status < 200 || response.status >= 300) throw new WasmHttpError(response.status, "", fullUrl, upperMethod, {}, response.data);
|
|
491
|
-
return {
|
|
492
|
-
ok: true,
|
|
493
|
-
status: response.status,
|
|
494
|
-
statusText: "",
|
|
495
|
-
url: fullUrl,
|
|
496
|
-
headers: {},
|
|
497
|
-
data: response.data
|
|
498
|
-
};
|
|
499
|
-
} catch (error) {
|
|
500
|
-
if (error instanceof WasmHttpError) throw error;
|
|
501
|
-
throw new WasmHttpError(getErrorStatus(error), getErrorMessage(error), fullUrl, upperMethod, {}, getErrorData(error));
|
|
502
|
-
}
|
|
503
|
-
},
|
|
504
|
-
get(url, requestConfig) {
|
|
505
|
-
return client.request({
|
|
506
|
-
...requestConfig,
|
|
507
|
-
url,
|
|
508
|
-
method: "GET"
|
|
509
|
-
});
|
|
510
|
-
},
|
|
511
|
-
post(url, body, requestConfig) {
|
|
512
|
-
return client.request({
|
|
513
|
-
...requestConfig,
|
|
514
|
-
url,
|
|
515
|
-
body,
|
|
516
|
-
method: "POST"
|
|
517
|
-
});
|
|
518
|
-
},
|
|
519
|
-
put(url, body, requestConfig) {
|
|
520
|
-
return client.request({
|
|
521
|
-
...requestConfig,
|
|
522
|
-
url,
|
|
523
|
-
body,
|
|
524
|
-
method: "PUT"
|
|
525
|
-
});
|
|
526
|
-
},
|
|
527
|
-
patch(url, body, requestConfig) {
|
|
528
|
-
return client.request({
|
|
529
|
-
...requestConfig,
|
|
530
|
-
url,
|
|
531
|
-
body,
|
|
532
|
-
method: "PATCH"
|
|
533
|
-
});
|
|
534
|
-
},
|
|
535
|
-
delete(url, requestConfig) {
|
|
536
|
-
return client.request({
|
|
537
|
-
...requestConfig,
|
|
538
|
-
url,
|
|
539
|
-
method: "DELETE"
|
|
540
|
-
});
|
|
541
|
-
},
|
|
542
|
-
head() {
|
|
543
|
-
return Promise.reject(/* @__PURE__ */ new Error("HEAD is not supported by the WASM HTTP client"));
|
|
544
|
-
},
|
|
545
|
-
options() {
|
|
546
|
-
return Promise.reject(/* @__PURE__ */ new Error("OPTIONS is not supported by the WASM HTTP client"));
|
|
547
|
-
},
|
|
548
|
-
setHeader(name, value) {
|
|
549
|
-
defaults.headers[name] = value;
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
return client;
|
|
553
|
-
};
|
|
554
|
-
var createWasmApi_default = createWasmApi;
|
|
555
|
-
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region src/internal/http/clientLifecycle.ts
|
|
558
|
-
/**
|
|
559
|
-
* Wraps the active HttpClient as a transport for the C++ `WebApi` host
|
|
560
|
-
* adapter. Lets the on-device face-results POST flow through the same
|
|
561
|
-
* `httpClient.request()` pipeline as every other endpoint — header
|
|
562
|
-
* injection, encryption-state handling, default headers, timeout — instead
|
|
563
|
-
* of bypassing it via `executeWasmRequest` directly.
|
|
564
|
-
*/
|
|
565
|
-
function bindWebApiTransport(client) {
|
|
566
|
-
return async (url, body, config) => {
|
|
567
|
-
const response = await client.request({
|
|
568
|
-
method: "POST",
|
|
569
|
-
url,
|
|
570
|
-
body,
|
|
571
|
-
headers: config.headers,
|
|
572
|
-
params: config.params,
|
|
573
|
-
timeout: config.timeout,
|
|
574
|
-
ie: config.ie
|
|
575
|
-
});
|
|
576
|
-
return {
|
|
577
|
-
data: response.data,
|
|
578
|
-
status: response.status
|
|
579
|
-
};
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
function installClient(client) {
|
|
583
|
-
setClient(client);
|
|
584
|
-
setWebApiHttpTransport(bindWebApiTransport(client));
|
|
585
|
-
}
|
|
586
|
-
let storedHttpConfig;
|
|
587
|
-
/** Reads the current HTTP-client config (or `undefined` if none installed). */
|
|
588
|
-
function getStoredHttpConfig() {
|
|
589
|
-
return storedHttpConfig;
|
|
590
|
-
}
|
|
591
|
-
/** Whether encryption is currently active on the installed HTTP client. */
|
|
592
|
-
function isHttpEncrypted() {
|
|
593
|
-
return storedHttpConfig?.encryption.enabled ?? false;
|
|
594
|
-
}
|
|
595
|
-
/** Clears all HTTP-client state. Called by `reset()`. */
|
|
596
|
-
function resetHttpClientState() {
|
|
597
|
-
storedHttpConfig = void 0;
|
|
598
|
-
setWebApiHttpTransport(null);
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* Builds (or replaces) the HTTP client when `setup()` receives an `apiURL`.
|
|
602
|
-
* Picks `createWasmApi` when `effectiveWasm` is set, otherwise plain
|
|
603
|
-
* `createApi`. Wraps the call in handshake-failure context when encryption
|
|
604
|
-
* is requested.
|
|
605
|
-
*/
|
|
606
|
-
async function installFreshHttpClient(apiURL, options, effectiveWasm, encryption) {
|
|
607
|
-
installClient(effectiveWasm ? await withHandshakeFailureContext(encryption.enabled, () => createWasmApi_default({
|
|
608
|
-
apiURL,
|
|
609
|
-
customHeaders: options.customHeaders,
|
|
610
|
-
timeout: options.timeout,
|
|
611
|
-
wasm: effectiveWasm,
|
|
612
|
-
encryptionEnabled: encryption.enabled,
|
|
613
|
-
mgf1: encryption.mgf1,
|
|
614
|
-
isEncryptionEnabled: isHttpEncrypted
|
|
615
|
-
})) : createApi_default({
|
|
616
|
-
apiURL,
|
|
617
|
-
customHeaders: options.customHeaders,
|
|
618
|
-
timeout: options.timeout
|
|
619
|
-
}));
|
|
620
|
-
storedHttpConfig = {
|
|
621
|
-
apiURL,
|
|
622
|
-
customHeaders: options.customHeaders,
|
|
623
|
-
timeout: options.timeout,
|
|
624
|
-
isWasm: Boolean(effectiveWasm),
|
|
625
|
-
encryption
|
|
626
|
-
};
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Replaces the active HTTP client with the WASM-backed one. Used internally
|
|
630
|
-
* by lazy-loading UI components (`<incode-flow>`, `<incode-workflow>`) when
|
|
631
|
-
* WASM finishes warming up.
|
|
632
|
-
*
|
|
633
|
-
* No-op when no apiURL was previously configured, or when the active client
|
|
634
|
-
* is already WASM-backed. The encryption state (enabled + MGF1 scheme) is
|
|
635
|
-
* preserved across the swap — this is *not* a user-facing encryption change.
|
|
636
|
-
*
|
|
637
|
-
* @internal NOT a public API. Application code should use
|
|
638
|
-
* `setup({ wasm: {...} })` instead.
|
|
639
|
-
*/
|
|
640
|
-
async function upgradeToWasmHttpClient(resolved) {
|
|
641
|
-
const stored = storedHttpConfig;
|
|
642
|
-
if (!stored || stored.isWasm) return;
|
|
643
|
-
installClient(await createWasmApi_default({
|
|
644
|
-
apiURL: stored.apiURL,
|
|
645
|
-
customHeaders: stored.customHeaders,
|
|
646
|
-
timeout: stored.timeout,
|
|
647
|
-
wasm: resolved,
|
|
648
|
-
encryptionEnabled: stored.encryption.enabled,
|
|
649
|
-
mgf1: stored.encryption.mgf1,
|
|
650
|
-
isEncryptionEnabled: isHttpEncrypted
|
|
651
|
-
}));
|
|
652
|
-
storedHttpConfig = {
|
|
653
|
-
...stored,
|
|
654
|
-
isWasm: true
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* When `wantsEncryption` is true, wraps a call that triggers the in-binary
|
|
659
|
-
* RSA/AES handshake so its rejection surfaces as a single, descriptive error
|
|
660
|
-
* with the original error preserved as `cause`. Pass-through otherwise.
|
|
661
|
-
*/
|
|
662
|
-
async function withHandshakeFailureContext(wantsEncryption, fn) {
|
|
663
|
-
if (!wantsEncryption) return fn();
|
|
664
|
-
try {
|
|
665
|
-
return await fn();
|
|
666
|
-
} catch (cause) {
|
|
667
|
-
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.");
|
|
668
|
-
error.cause = cause;
|
|
669
|
-
throw error;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
//#endregion
|
|
674
|
-
//#region src/setup.ts
|
|
675
|
-
let wasmConfig;
|
|
676
|
-
const DEFAULT_MGF1 = "sha1";
|
|
677
|
-
/**
|
|
678
|
-
* Normalizes the public `encryption` option into the internal shape used by
|
|
679
|
-
* the HTTP client lifecycle. Returns `undefined` when the caller did not
|
|
680
|
-
* specify `encryption` at all (so callers can distinguish "preserve stored
|
|
681
|
-
* value" from "explicitly off").
|
|
682
|
-
*/
|
|
683
|
-
function normalizeEncryption(input) {
|
|
684
|
-
if (input === void 0) return void 0;
|
|
685
|
-
if (input === false) return {
|
|
686
|
-
enabled: false,
|
|
687
|
-
mgf1: DEFAULT_MGF1
|
|
688
|
-
};
|
|
689
|
-
if (input === true) return {
|
|
690
|
-
enabled: true,
|
|
691
|
-
mgf1: DEFAULT_MGF1
|
|
692
|
-
};
|
|
693
|
-
return {
|
|
694
|
-
enabled: true,
|
|
695
|
-
mgf1: input.mgf1 ?? DEFAULT_MGF1
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
let configured = false;
|
|
699
|
-
/**
|
|
700
|
-
* Initializes the SDK with the provided configuration.
|
|
701
|
-
* Must be called before using any SDK functionality.
|
|
702
|
-
*
|
|
703
|
-
* WASM loads only when `options.wasm` is provided as an object.
|
|
704
|
-
*
|
|
705
|
-
* `setup` is boot — it provisions the HTTP client, the optional E2EE
|
|
706
|
-
* handshake, WASM warmup, and the analytics batcher. The session token is a
|
|
707
|
-
* separate concern: hand it off via `initializeSession({ token })` from
|
|
708
|
-
* `@incodetech/core/session`, or pass it inline as `setup({ apiURL, token })`
|
|
709
|
-
* (a convenience that delegates to `initializeSession` for you).
|
|
710
|
-
*
|
|
711
|
-
* @param options - Configuration options for the SDK
|
|
712
|
-
*
|
|
713
|
-
* @example Boot first, activate the session later (preferred)
|
|
714
|
-
* ```ts
|
|
715
|
-
* import { setup } from '@incodetech/core';
|
|
716
|
-
* import { createSession, initializeSession } from '@incodetech/core/session';
|
|
717
|
-
*
|
|
718
|
-
* await setup({ apiURL: 'https://api.incode.com' });
|
|
719
|
-
* const session = await createSession(apiKey, { configurationId });
|
|
720
|
-
* await initializeSession({ token: session.token });
|
|
721
|
-
* ```
|
|
722
|
-
*
|
|
723
|
-
* @example One-shot convenience
|
|
724
|
-
* ```ts
|
|
725
|
-
* await setup({ apiURL: 'https://api.incode.com', token: 'session-token' });
|
|
726
|
-
* ```
|
|
727
|
-
*
|
|
728
|
-
* @example Explicitly disable WASM
|
|
729
|
-
* ```ts
|
|
730
|
-
* await setup({ apiURL: 'https://api.incode.com', wasm: false });
|
|
731
|
-
* ```
|
|
732
|
-
*
|
|
733
|
-
* @example Use CDN defaults for paths and preload only one pipeline
|
|
734
|
-
* ```ts
|
|
735
|
-
* await setup({
|
|
736
|
-
* apiURL: 'https://api.incode.com',
|
|
737
|
-
* wasm: { pipelines: ['selfie'] },
|
|
738
|
-
* });
|
|
739
|
-
* ```
|
|
740
|
-
*
|
|
741
|
-
* @example Self-hosted / custom version (full or partial path overrides)
|
|
742
|
-
* ```ts
|
|
743
|
-
* await setup({
|
|
744
|
-
* apiURL: 'https://api.incode.com',
|
|
745
|
-
* wasm: {
|
|
746
|
-
* wasmPath: '/my-cdn/webLib.wasm',
|
|
747
|
-
* glueCodePath: '/my-cdn/webLib.js',
|
|
748
|
-
* },
|
|
749
|
-
* });
|
|
750
|
-
* ```
|
|
751
|
-
*
|
|
752
|
-
* @example Partial override: only models path, rest from CDN
|
|
753
|
-
* ```ts
|
|
754
|
-
* await setup({
|
|
755
|
-
* apiURL: 'https://api.incode.com',
|
|
756
|
-
* wasm: { modelsBasePath: 'https://my-cdn/models' },
|
|
757
|
-
* });
|
|
758
|
-
* ```
|
|
759
|
-
*
|
|
760
|
-
* @example Sessionless setup (all API actors overridden via .provide())
|
|
761
|
-
* ```ts
|
|
762
|
-
* await setup({
|
|
763
|
-
* wasm: {
|
|
764
|
-
* wasmPath: '/wasm/ml-wasm.wasm',
|
|
765
|
-
* glueCodePath: '/wasm/ml-wasm.js',
|
|
766
|
-
* pipelines: ['selfie'],
|
|
767
|
-
* },
|
|
768
|
-
* });
|
|
769
|
-
* ```
|
|
770
|
-
*
|
|
771
|
-
* @example Enable end-to-end encryption at boot (defaults to MGF1 = SHA-1)
|
|
772
|
-
* ```ts
|
|
773
|
-
* await setup({ apiURL: 'https://api.incode.com', encryption: true });
|
|
774
|
-
* ```
|
|
775
|
-
*
|
|
776
|
-
* @example Enable encryption with the SHA-256 MGF1 padding
|
|
777
|
-
* ```ts
|
|
778
|
-
* await setup({
|
|
779
|
-
* apiURL: 'https://api.incode.com',
|
|
780
|
-
* encryption: { mgf1: 'sha256' },
|
|
781
|
-
* });
|
|
782
|
-
* ```
|
|
783
|
-
*/
|
|
784
|
-
async function setup(options) {
|
|
785
|
-
if (!getAnalyticsBatcher()) setAnalyticsBatcher(createAnalyticsBatchingService({
|
|
786
|
-
endpoint: endpoints.events,
|
|
787
|
-
authToken: () => getToken(),
|
|
788
|
-
apiBaseUrl: () => getApi().defaults.baseURL,
|
|
789
|
-
apiClient: api,
|
|
790
|
-
pageLifecycle: new BrowserPageLifecycleProvider(),
|
|
791
|
-
timer: BrowserTimerProvider.getInstance()
|
|
792
|
-
}));
|
|
793
|
-
const requestedEncryption = normalizeEncryption(options.encryption);
|
|
794
|
-
const stored = getStoredHttpConfig();
|
|
795
|
-
if (requestedEncryption && stored) {
|
|
796
|
-
if (requestedEncryption.enabled !== stored.encryption.enabled || requestedEncryption.enabled && requestedEncryption.mgf1 !== stored.encryption.mgf1) throw new Error("Encryption is locked at the first setup() call and cannot be changed at runtime. Call reset() to fully reinitialize the SDK if you need a different encryption configuration.");
|
|
797
|
-
}
|
|
798
|
-
if (requestedEncryption?.enabled && options.wasm === false) throw new Error("Encryption is incompatible with `wasm: false`. Either remove `wasm: false` or omit `encryption`.");
|
|
799
|
-
const effectiveEncryption = requestedEncryption ?? stored?.encryption ?? {
|
|
800
|
-
enabled: false,
|
|
801
|
-
mgf1: "sha1"
|
|
802
|
-
};
|
|
803
|
-
const effectiveWasm = options.wasm || requestedEncryption?.enabled ? resolveWasmConfig(options.wasm || {}) : void 0;
|
|
804
|
-
if (options.apiURL) await installFreshHttpClient(options.apiURL, options, effectiveWasm, effectiveEncryption);
|
|
805
|
-
if (options.token && isApiConfigured()) initializeSession({
|
|
806
|
-
token: options.token,
|
|
807
|
-
hostingApp: options.hostingApp
|
|
808
|
-
}).catch((error) => {
|
|
809
|
-
console.warn("Session initialization failed:", error);
|
|
810
|
-
});
|
|
811
|
-
configured = true;
|
|
812
|
-
if (effectiveWasm) {
|
|
813
|
-
await warmupWasm(effectiveWasm);
|
|
814
|
-
await (await WasmUtilProvider.getInstance()).initialize({
|
|
815
|
-
...effectiveWasm,
|
|
816
|
-
pipelines: effectiveWasm.pipelines ? [...effectiveWasm.pipelines] : void 0
|
|
817
|
-
});
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Sets the WASM configuration without performing warmup.
|
|
822
|
-
* Useful when WASM warmup is handled separately (e.g., conditionally based on flow).
|
|
823
|
-
*
|
|
824
|
-
* @param config - WASM configuration to store
|
|
825
|
-
*/
|
|
826
|
-
function setWasmConfig(config) {
|
|
827
|
-
wasmConfig = config;
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* Initializes WasmUtilProvider with the stored WASM configuration.
|
|
831
|
-
* Should be called after warmupWasm() completes when using conditional warmup.
|
|
832
|
-
* This ensures image encryption works properly.
|
|
833
|
-
*
|
|
834
|
-
* @param config - Optional WASM configuration. If not provided, uses the stored config from setWasmConfig().
|
|
835
|
-
* @throws Error if no config is provided and none is stored
|
|
836
|
-
*/
|
|
837
|
-
async function initializeWasmUtil(config) {
|
|
838
|
-
const wasmConfigToUse = config ?? wasmConfig;
|
|
839
|
-
if (!wasmConfigToUse) throw new Error("WASM config is required. Provide config parameter or call setWasmConfig() first.");
|
|
840
|
-
const resolved = resolveWasmConfig(wasmConfigToUse);
|
|
841
|
-
await (await WasmUtilProvider.getInstance()).initialize({
|
|
842
|
-
...resolved,
|
|
843
|
-
pipelines: resolved.pipelines ? [...resolved.pipelines] : void 0
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Replaces the active HTTP client with the WASM-backed one. Used internally
|
|
848
|
-
* by lazy-loading UI components (`<incode-flow>`, `<incode-workflow>`) when
|
|
849
|
-
* WASM finishes warming up.
|
|
850
|
-
*
|
|
851
|
-
* No-op when no apiURL was originally configured, or when the active client is
|
|
852
|
-
* already the WASM one.
|
|
853
|
-
*
|
|
854
|
-
* @internal NOT a public API. Application code should use
|
|
855
|
-
* `setup({ wasm: {...} })` instead — that path is the supported way to opt
|
|
856
|
-
* into the WASM HTTP client.
|
|
857
|
-
*
|
|
858
|
-
* @param config - Optional WASM configuration. Defaults to the config stored via `setWasmConfig`.
|
|
859
|
-
*/
|
|
860
|
-
async function upgradeToWasmHttpClient$1(config) {
|
|
861
|
-
const configToUse = config ?? wasmConfig;
|
|
862
|
-
if (!configToUse) return;
|
|
863
|
-
await upgradeToWasmHttpClient(resolveWasmConfig(configToUse));
|
|
864
|
-
}
|
|
865
|
-
/**
|
|
866
|
-
* Checks if the SDK has been configured.
|
|
867
|
-
*
|
|
868
|
-
* @returns true if setup() has been called, false otherwise
|
|
869
|
-
*/
|
|
870
|
-
function isConfigured() {
|
|
871
|
-
return configured;
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* Resets the SDK configuration. Useful for testing.
|
|
875
|
-
*/
|
|
876
|
-
function reset() {
|
|
877
|
-
resetApi();
|
|
878
|
-
resetSessionInit();
|
|
879
|
-
resetAnalyticsBatcher();
|
|
880
|
-
resetHttpClientState();
|
|
881
|
-
configured = false;
|
|
882
|
-
wasmConfig = void 0;
|
|
883
|
-
WasmUtilProvider.resetInstance();
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
//#endregion
|
|
887
|
-
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 };
|