@incodetech/core 0.0.0-dev-20261013-c7751a9f → 0.0.0-dev-20261013-c982cdcd
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/{FaceDetectionProvider-XAuZT7P9.esm.js → FaceDetectionProvider-CGDd_ogY.esm.js} +9 -8
- package/dist/{IWasmUtilCapability-VC40Kx9N.d.ts → IWasmUtilCapability-CPX0RGdQ.d.ts} +23 -1
- package/dist/{MotionSensorProvider-MQ80-spU.esm.js → MotionSensorProvider-DYxh8TjR.esm.js} +1 -1
- package/dist/{StreamCanvasCapture-CeBBJ_RC.d.ts → StreamCanvasCapture-DVmzJux5.d.ts} +1 -1
- package/dist/{safeStorage-DDAHV26l.esm.js → WasmUtilProvider-CIdnE7Fx.esm.js} +87 -36
- package/dist/{addressSearch-CoXo7lfZ.esm.js → addressSearch-Bm8zTbQJ.esm.js} +3 -3
- package/dist/ae-signature.esm.js +1 -1
- package/dist/antifraud.esm.js +2 -2
- package/dist/{antifraudManager-nkA1Xfm1.esm.js → antifraudManager-HL08jeDX.esm.js} +3 -3
- package/dist/{antifraudStateMachine-bbi6-rKP.esm.js → antifraudStateMachine-DoJVzblM.esm.js} +3 -3
- package/dist/{apiError-B9McXt0d.esm.js → apiError-B7lJaeTn.esm.js} +1 -1
- package/dist/authentication.d.ts +3 -3
- package/dist/authentication.esm.js +2 -2
- package/dist/{authenticationManager-BhZZQzwi.esm.js → authenticationManager-Bk74vxGj.esm.js} +6 -6
- package/dist/{authenticationManager-MVD0mrCo.d.ts → authenticationManager-CANv5-W5.d.ts} +1 -1
- package/dist/{authenticationStateMachine-PEbpCJ0-.esm.js → authenticationStateMachine-CSqcE4y3.esm.js} +5 -5
- package/dist/camera.esm.js +1 -1
- package/dist/certificate-issuance.esm.js +2 -2
- package/dist/{certificateIssuanceManager-B-qjOJde.esm.js → certificateIssuanceManager-CKJ4qjLc.esm.js} +3 -3
- package/dist/{certificateIssuanceStateMachine-DwLGw_a2.esm.js → certificateIssuanceStateMachine-yizSIonY.esm.js} +3 -3
- package/dist/consent.esm.js +2 -2
- package/dist/{consentManager-BhGljt6D.esm.js → consentManager-CjrxY737.esm.js} +3 -3
- package/dist/{consentStateMachine-fvRt5D6e.esm.js → consentStateMachine-BCj5Jb3g.esm.js} +3 -3
- package/dist/{createCameraCycleOwnership-BvOOxU85.esm.js → createCameraCycleOwnership-kdlhkmmY.esm.js} +2 -2
- package/dist/cross-document-data-match.esm.js +1 -1
- package/dist/{crossDocumentDataMatchManager-hxUaa6y_.esm.js → crossDocumentDataMatchManager-BHnGRsto.esm.js} +4 -4
- package/dist/curp-validation.esm.js +2 -2
- package/dist/{curpValidationManager-u6dRo9Bq.esm.js → curpValidationManager-DBNIn8BF.esm.js} +3 -3
- package/dist/{curpValidationStateMachine-Sf4rGn_0.esm.js → curpValidationStateMachine-DAxImy8p.esm.js} +3 -3
- package/dist/custom-fields.esm.js +1 -1
- package/dist/custom-watchlist.esm.js +2 -2
- package/dist/{customFieldsManager-C5Vw3fdd.esm.js → customFieldsManager-BV6UyLFV.esm.js} +4 -4
- package/dist/{customWatchlistManager-szjmQvYu.esm.js → customWatchlistManager-DML0UPzf.esm.js} +3 -3
- package/dist/{customWatchlistStateMachine-BtlZ6qoX.esm.js → customWatchlistStateMachine-D9gI5uu7.esm.js} +3 -3
- package/dist/deepsightLoader-Bbannll8.esm.js +55 -0
- package/dist/{deepsightLoader-Cbrw8v4S.esm.js → deepsightService-cd1HQvBB.esm.js} +50 -55
- package/dist/document-capture.esm.js +2 -2
- package/dist/{documentCaptureManager-CV_bOPkN.esm.js → documentCaptureManager-C9XUnYU6.esm.js} +3 -3
- package/dist/{documentCaptureStateMachine-CY4BH_nx.esm.js → documentCaptureStateMachine-BHDsCfhL.esm.js} +5 -5
- package/dist/dynamic-forms.esm.js +2 -2
- package/dist/{dynamicFormsManager-Bunapr8H.esm.js → dynamicFormsManager-DvzIRQGp.esm.js} +3 -3
- package/dist/{dynamicFormsStateMachine-Ba7NhLvL.esm.js → dynamicFormsStateMachine-BXq12SGh.esm.js} +4 -4
- package/dist/ekyb.esm.js +3 -3
- package/dist/{ekybManager-BXpy_3I6.esm.js → ekybManager-Bov25P3N.esm.js} +3 -3
- package/dist/{ekybStateMachine-DDyaxJ35.esm.js → ekybStateMachine-iwmM5mCm.esm.js} +5 -5
- package/dist/ekyc.esm.js +2 -2
- package/dist/{ekycManager-DsfBcNxs.esm.js → ekycManager-DZH51PnN.esm.js} +3 -3
- package/dist/{ekycStateMachine-DPMzZNhD.esm.js → ekycStateMachine-DnKlILfu.esm.js} +4 -4
- package/dist/electronic-signature.esm.js +1 -1
- package/dist/{electronicSignatureManager-DYJZjAtq.esm.js → electronicSignatureManager-DBhszLrG.esm.js} +5 -5
- package/dist/email.esm.js +2 -2
- package/dist/{emailManager-ppIDOf_n.esm.js → emailManager-CtlKRRaR.esm.js} +3 -3
- package/dist/{emailStateMachine-NiunNxhH.esm.js → emailStateMachine-5Neq3rE5.esm.js} +4 -4
- package/dist/{endpoints-Bs3D8B_G.esm.js → endpoints-DHzlkQNe.esm.js} +1 -0
- package/dist/{events-CfLLkAh7.esm.js → events-CAgFE-k3.esm.js} +15 -3
- package/dist/events.d.ts +2 -1
- package/dist/events.esm.js +1 -1
- package/dist/extensibility.d.ts +9 -9
- package/dist/extensibility.esm.js +36 -36
- package/dist/face-match.esm.js +2 -2
- package/dist/{faceCaptureManagerFactory-BOWlD2lH.esm.js → faceCaptureManagerFactory-DWHQBeL2.esm.js} +15 -6
- package/dist/{faceCaptureManagerFactory-D-XSP04N.d.ts → faceCaptureManagerFactory-jKQ2QtY-.d.ts} +4 -4
- package/dist/{faceCaptureSetup-CeAyB-yC.esm.js → faceCaptureSetup-BBqAdrqm.esm.js} +11 -11
- package/dist/{faceMatchManager-BSR94HnV.esm.js → faceMatchManager-9Nj9aPci.esm.js} +3 -3
- package/dist/{faceMatchStateMachine-BA9LVrWJ.esm.js → faceMatchStateMachine-B9ZUnlyU.esm.js} +3 -3
- package/dist/{feature-management-DYRVLOMy.esm.js → feature-management-DPIl-FtB.esm.js} +1 -1
- package/dist/feature-management.esm.js +1 -1
- package/dist/field-comparison.esm.js +1 -1
- package/dist/{fieldComparisonManager-B2y1ko1f.esm.js → fieldComparisonManager-Dk38hXZP.esm.js} +4 -4
- package/dist/fiscal-qr.esm.js +1 -1
- package/dist/{fiscalQrManager-gmU-xLHP.esm.js → fiscalQrManager-DmBkQfs0.esm.js} +5 -5
- package/dist/flow.d.ts +2 -2
- package/dist/flow.esm.js +6 -6
- package/dist/{flowCompletionService-xRc0i-x5.esm.js → flowCompletionService-BTxuv1Wb.esm.js} +2 -2
- package/dist/{flowServices-B8SKnzY5.esm.js → flowServices-pk---1Sx.esm.js} +5 -5
- package/dist/geolocation.esm.js +2 -2
- package/dist/{geolocationManager-DPPSB_oq.esm.js → geolocationManager-Ck6DsjTo.esm.js} +3 -3
- package/dist/{geolocationStateMachine-CcrrUnPD.esm.js → geolocationStateMachine-Ap2O_wgT.esm.js} +4 -4
- package/dist/government-validation.esm.js +2 -2
- package/dist/{governmentValidationManager-UuH2s-oi.esm.js → governmentValidationManager-CP0SiOOe.esm.js} +3 -3
- package/dist/{governmentValidationStateMachine-BvvrC_3A.esm.js → governmentValidationStateMachine-C3YQ8yCZ.esm.js} +3 -3
- package/dist/home.esm.js +2 -2
- package/dist/id-ocr.esm.js +2 -2
- package/dist/id-selfie-flow.d.ts +1 -1
- package/dist/id-selfie-flow.esm.js +11 -11
- package/dist/id-verification.esm.js +2 -2
- package/dist/id.d.ts +2 -2
- package/dist/id.esm.js +3 -3
- package/dist/{idCaptureDefaults-CAKXwWww.esm.js → idCaptureDefaults-CQLveJd1.esm.js} +2 -2
- package/dist/{idCaptureManager-BXYldO77.d.ts → idCaptureManager-DW3eER4t.d.ts} +6 -3
- package/dist/{idCaptureManager-Bwpdlvxp.esm.js → idCaptureManager-TokRg0VQ.esm.js} +28 -20
- package/dist/{idCaptureServices-ssbb13iE.esm.js → idCaptureServices-BGhipfoM.esm.js} +8 -8
- package/dist/{idCaptureStateMachine-CL7qwlse.esm.js → idCaptureStateMachine-ByWuXQze.esm.js} +21 -21
- package/dist/{idOcrManager-124LjyWj.esm.js → idOcrManager-DxoCesYP.esm.js} +3 -3
- package/dist/{idOcrStateMachine-Bd0-Hp9V.esm.js → idOcrStateMachine-kPn7DB2I.esm.js} +3 -3
- package/dist/{idVerificationManager-BYVW3pLG.esm.js → idVerificationManager-CDhRUU5n.esm.js} +3 -3
- package/dist/{idVerificationStateMachine-BtrFQSDe.esm.js → idVerificationStateMachine-0HTVVxse.esm.js} +3 -3
- package/dist/identity-reuse.d.ts +1 -1
- package/dist/identity-reuse.esm.js +2 -2
- package/dist/{identityReuseManager-fu5okQhu.esm.js → identityReuseManager-BleUi6TK.esm.js} +3 -3
- package/dist/{identityReuseManager-BUNksfYU.d.ts → identityReuseManager-ooAbp6Kc.d.ts} +8 -8
- package/dist/{identityReuseStateMachine-CCYWIgGl.esm.js → identityReuseStateMachine-BrBUpfn5.esm.js} +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/{invokeOnCaptureCallback-Brs1lo61.esm.js → invokeOnCaptureCallback-BW7V3vub.esm.js} +1 -1
- package/dist/mandatory-consent.d.ts +1 -1
- package/dist/mandatory-consent.esm.js +2 -2
- package/dist/{mandatoryConsentManager-DDixKrq0.d.ts → mandatoryConsentManager-BkaLkcA2.d.ts} +4 -4
- package/dist/{mandatoryConsentManager-tCHVwjtG.esm.js → mandatoryConsentManager-CX_Dyht7.esm.js} +3 -3
- package/dist/{mandatoryConsentStateMachine-CZKXCn6v.esm.js → mandatoryConsentStateMachine-CoaSB7P7.esm.js} +3 -3
- package/dist/{multipartRecordingService-CMjkhS2x.esm.js → multipartRecordingService-DbeQpXdU.esm.js} +2 -2
- package/dist/{permissionGuards-DGU1uh4i.esm.js → permissionGuards-Bf4LbHjC.esm.js} +1 -1
- package/dist/{permissionServices-CPwDYRp8.esm.js → permissionServices-d2UW0r_L.esm.js} +2 -2
- package/dist/phone.esm.js +2 -2
- package/dist/{phoneManager-B6Uu_237.esm.js → phoneManager-BGBcpqsk.esm.js} +3 -3
- package/dist/{phoneStateMachine-pue0_Jsi.esm.js → phoneStateMachine-CEm2y7yG.esm.js} +4 -4
- package/dist/qe-signature.esm.js +1 -1
- package/dist/redirect-to-mobile.esm.js +2 -2
- package/dist/{redirectToMobileManager-CQlyUyc8.esm.js → redirectToMobileManager-D8xpgVHn.esm.js} +4 -4
- package/dist/{redirectToMobileStateMachine-tGbjPhIm.esm.js → redirectToMobileStateMachine-DjKfrc4P.esm.js} +4 -4
- package/dist/{runChildModule-CQWc5KMf.esm.js → runChildModule-CpXjbJfG.esm.js} +4 -4
- package/dist/safeStorage-UxDrnjwa.esm.js +35 -0
- package/dist/{sdkVersion-C6hcFArL.esm.js → sdkVersion-DvwSi-xM.esm.js} +1 -1
- package/dist/selfie.d.ts +4 -4
- package/dist/selfie.esm.js +12 -12
- package/dist/{selfieErrorUtils-LZLapGy6.esm.js → selfieErrorUtils-CQnuPhYb.esm.js} +1 -1
- package/dist/{selfieManager-CizvitYB.d.ts → selfieManager-1J0IEyFq.d.ts} +1 -1
- package/dist/{selfieManager-CG5VP1C-.esm.js → selfieManager-DCzPlJCU.esm.js} +6 -6
- package/dist/{selfieStateMachine-DsVxSp4B.esm.js → selfieStateMachine-IEKFw85T.esm.js} +5 -5
- package/dist/{session-BoAOTj24.esm.js → session-5KHEGxgB.esm.js} +4 -4
- package/dist/session.esm.js +4 -4
- package/dist/{sessionInitializer-Gjn-NrIE.esm.js → sessionInitializer-CiraPSTG.esm.js} +197 -7
- package/dist/{setup-CCsxCTuW.esm.js → setup-BJzlqOTL.esm.js} +176 -104
- package/dist/{setup-CDyTzfIx.d.ts → setup-oKDzNC62.d.ts} +6 -2
- package/dist/signature.esm.js +2 -2
- package/dist/{signatureManager-CEYKCuO4.esm.js → signatureManager-qqXyH93e.esm.js} +3 -3
- package/dist/{signatureStateMachine-C6Wh9ylX.esm.js → signatureStateMachine-BkRSrkKp.esm.js} +3 -3
- package/dist/splitTrackedName-3zJRd2RD.esm.js +19 -0
- package/dist/{stats-Dz3XWA64.esm.js → stats-DmG_tkGk.esm.js} +1 -1
- package/dist/stats.esm.js +1 -1
- package/dist/{trueSightService-BLM6oloV.esm.js → trueSightService-Crpt3M-t.esm.js} +843 -843
- package/dist/trust-graph.esm.js +2 -2
- package/dist/{types-66IWBtU4.d.ts → types-C71Zo6vl.d.ts} +1 -1
- package/dist/{types-D0VzhBS7.d.ts → types-CwCWyBEi.d.ts} +2 -2
- package/dist/{types-nJoHpLPM.d.ts → types-zpO4fU6a.d.ts} +1 -1
- package/dist/video-selfie.d.ts +1 -1
- package/dist/video-selfie.esm.js +10 -10
- package/dist/{videoSelfieCameraWarmer-BctIPNfo.esm.js → videoSelfieCameraWarmer-CND0HDro.esm.js} +8 -8
- package/dist/{videoSelfieFlowModuleMachine-DQTlyw98.esm.js → videoSelfieFlowModuleMachine-BCFVHBQ1.esm.js} +1 -1
- package/dist/{videoSelfieStepDetector-D0Ws77pD.d.ts → videoSelfieStepDetector-C5QHOvWb.d.ts} +2 -2
- package/dist/wasm.d.ts +1 -1
- package/dist/wasm.esm.js +2 -2
- package/dist/{wasmDsFlagSync-BWpBwxxe.esm.js → wasmDsFlagSync-BXCGqP48.esm.js} +1 -1
- package/dist/watchlist-for-business.esm.js +2 -2
- package/dist/watchlist.esm.js +2 -2
- package/dist/{watchlistForBusinessManager-cbMppk5K.esm.js → watchlistForBusinessManager-BvF4jK3S.esm.js} +3 -3
- package/dist/{watchlistForBusinessStateMachine-DsLzqEQG.esm.js → watchlistForBusinessStateMachine-121XK-Et.esm.js} +3 -3
- package/dist/{watchlistManager-F1bI2Ad4.esm.js → watchlistManager-CNWEOYSq.esm.js} +3 -3
- package/dist/{watchlistStateMachine-DU28IiMQ.esm.js → watchlistStateMachine-Dgfm42w2.esm.js} +3 -3
- package/dist/workflow.d.ts +4 -4
- package/dist/workflow.esm.js +38 -38
- package/dist/{xstate-actors.esm-Ccyzgxj1.esm.js → xstate-actors.esm-8Gzepa_A.esm.js} +1 -1
- package/dist/{xstate.esm-Bg3FuvIs.esm.js → xstate.esm-DSajW7CJ.esm.js} +9 -2
- package/package.json +1 -1
- package/dist/virtualCameraCheck-CW8mFdt9.esm.js +0 -48
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { a as setWebApiHttpTransport, f as deriveSiblingJsPath, i as initializeWasmWebClient, o as setupWasmConnection, p as WASM_MODEL_FILES, r as executeWasmRequest, t as WasmWebClientError, v as buildModelVariantSources } from "./wasmWebClient-kbYZ2sxw.esm.js";
|
|
2
2
|
import { t as getTimestamp } from "./IBrowserEnvironmentCapability-DEaRRk-R.esm.js";
|
|
3
|
+
import { n as eventModuleNames } from "./events-CAgFE-k3.esm.js";
|
|
3
4
|
import { i as isApiConfigured, n as getApi, o as setClient, r as getToken, t as api } from "./api-Bx3gKW_y.esm.js";
|
|
5
|
+
import { t as endpoints } from "./endpoints-DHzlkQNe.esm.js";
|
|
6
|
+
import { t as SDK_VERSION } from "./sdkVersion-DvwSi-xM.esm.js";
|
|
4
7
|
import { n as reportHttpError, t as HttpRequestError } from "./HttpRequestError-Bh0pNGSC.esm.js";
|
|
5
|
-
import { n as eventModuleNames } from "./events-CfLLkAh7.esm.js";
|
|
6
|
-
import { t as SDK_VERSION } from "./sdkVersion-C6hcFArL.esm.js";
|
|
7
|
-
import { t as endpoints } from "./endpoints-Bs3D8B_G.esm.js";
|
|
8
8
|
//#region ../infra/src/wasm/wasmDefaults.ts
|
|
9
9
|
const WASM_CDN_BASE_URL = "https://cdn.incodesmile.com/ml-wasm-kit-release";
|
|
10
10
|
/** The WASM version bundled and tested with this SDK release. */
|
|
@@ -144,635 +144,98 @@ function resolveWasmConfig(overrides) {
|
|
|
144
144
|
validateWasmPaths(merged);
|
|
145
145
|
return merged;
|
|
146
146
|
}
|
|
147
|
+
/** Hard cap per log message, UTF-8 bytes (contract). */
|
|
148
|
+
const MESSAGE_MAX_BYTES = 8 * 1024;
|
|
149
|
+
const TRUESIGHT_SDK_ID = "IncdOnboarding";
|
|
150
|
+
/** localStorage key prefix for persisted sealed snapshots (A3: one slot per session). */
|
|
151
|
+
const PENDING_STORAGE_KEY_PREFIX = "incode.truesight.pending.";
|
|
147
152
|
//#endregion
|
|
148
|
-
//#region
|
|
149
|
-
var FetchHttpError = class extends HttpRequestError {
|
|
150
|
-
constructor(..._args) {
|
|
151
|
-
super(..._args);
|
|
152
|
-
this.name = "FetchHttpError";
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const buildQueryString$1 = (query) => {
|
|
156
|
-
if (!query) return "";
|
|
157
|
-
const params = new URLSearchParams();
|
|
158
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
159
|
-
if (value !== void 0 && value !== null) params.append(key, String(value));
|
|
160
|
-
});
|
|
161
|
-
const str = params.toString();
|
|
162
|
-
return str ? `?${str}` : "";
|
|
163
|
-
};
|
|
164
|
-
const buildUrl$1 = (baseURL, url, query) => {
|
|
165
|
-
const queryString = buildQueryString$1(query);
|
|
166
|
-
if (url.startsWith("http://") || url.startsWith("https://")) return `${url}${queryString}`;
|
|
167
|
-
return `${baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL}${url.startsWith("/") ? url : `/${url}`}${queryString}`;
|
|
168
|
-
};
|
|
169
|
-
const prepareBody$1 = (body) => {
|
|
170
|
-
if (body === null || body === void 0) return null;
|
|
171
|
-
if (body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer) return body;
|
|
172
|
-
if (typeof body === "object") return JSON.stringify(body);
|
|
173
|
-
return String(body);
|
|
174
|
-
};
|
|
175
|
-
const parseResponse = async (response, parseType) => {
|
|
176
|
-
if (parseType === "response") return response;
|
|
177
|
-
if (parseType === "blob") return await response.blob();
|
|
178
|
-
if (parseType === "arrayBuffer") return await response.arrayBuffer();
|
|
179
|
-
if (parseType === "text") return await response.text();
|
|
180
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
181
|
-
if (parseType === "json" || contentType.includes("application/json")) {
|
|
182
|
-
const raw = await response.text();
|
|
183
|
-
if (raw.length === 0) return "";
|
|
184
|
-
try {
|
|
185
|
-
return JSON.parse(raw);
|
|
186
|
-
} catch {
|
|
187
|
-
return raw;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return await response.text();
|
|
191
|
-
};
|
|
192
|
-
const requestWithXHR = (fullUrl, method, mergedHeaders, requestBody, timeout, signal, onUploadProgress) => {
|
|
193
|
-
return new Promise((resolve, reject) => {
|
|
194
|
-
const xhr = new XMLHttpRequest();
|
|
195
|
-
xhr.open(method, fullUrl, true);
|
|
196
|
-
Object.entries(mergedHeaders).forEach(([key, value]) => {
|
|
197
|
-
xhr.setRequestHeader(key, value);
|
|
198
|
-
});
|
|
199
|
-
xhr.timeout = timeout;
|
|
200
|
-
xhr.upload.onprogress = (event) => {
|
|
201
|
-
if (event.lengthComputable) {
|
|
202
|
-
const percentComplete = event.loaded / event.total * 100;
|
|
203
|
-
onUploadProgress(Math.round(percentComplete));
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
xhr.onload = () => {
|
|
207
|
-
const responseHeaders = {};
|
|
208
|
-
xhr.getAllResponseHeaders().split("\r\n").forEach((line) => {
|
|
209
|
-
const parts = line.split(": ");
|
|
210
|
-
if (parts.length === 2) responseHeaders[parts[0].toLowerCase()] = parts[1];
|
|
211
|
-
});
|
|
212
|
-
let data;
|
|
213
|
-
try {
|
|
214
|
-
if ((xhr.getResponseHeader("content-type") ?? "").includes("application/json")) data = JSON.parse(xhr.responseText);
|
|
215
|
-
else data = xhr.responseText;
|
|
216
|
-
} catch {
|
|
217
|
-
data = xhr.responseText;
|
|
218
|
-
}
|
|
219
|
-
if (xhr.status >= 200 && xhr.status < 300) resolve({
|
|
220
|
-
ok: true,
|
|
221
|
-
status: xhr.status,
|
|
222
|
-
statusText: xhr.statusText,
|
|
223
|
-
url: fullUrl,
|
|
224
|
-
headers: responseHeaders,
|
|
225
|
-
data
|
|
226
|
-
});
|
|
227
|
-
else reject(reportHttpError(new FetchHttpError(xhr.status, xhr.statusText, fullUrl, method, responseHeaders, data), mergedHeaders));
|
|
228
|
-
};
|
|
229
|
-
xhr.onerror = () => {
|
|
230
|
-
reject(new FetchHttpError(0, "Network Error", fullUrl, method, {}, null));
|
|
231
|
-
};
|
|
232
|
-
xhr.ontimeout = () => {
|
|
233
|
-
reject(new FetchHttpError(0, "Request timeout", fullUrl, method, {}, null));
|
|
234
|
-
};
|
|
235
|
-
if (signal) signal.addEventListener("abort", () => {
|
|
236
|
-
xhr.abort();
|
|
237
|
-
reject(new FetchHttpError(0, "Request aborted", fullUrl, method, {}, null));
|
|
238
|
-
});
|
|
239
|
-
xhr.send(requestBody);
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
const createApi = (config) => {
|
|
243
|
-
const headers = {
|
|
244
|
-
"Content-Type": "application/json",
|
|
245
|
-
Accept: "application/json",
|
|
246
|
-
"api-version": "1.0",
|
|
247
|
-
...config.customHeaders ?? {}
|
|
248
|
-
};
|
|
249
|
-
const defaults = {
|
|
250
|
-
baseURL: config.apiURL,
|
|
251
|
-
headers
|
|
252
|
-
};
|
|
253
|
-
const client = {
|
|
254
|
-
defaults,
|
|
255
|
-
async request(requestConfig) {
|
|
256
|
-
const { method = "GET", url, headers = {}, query, params, body, signal, timeout: timeoutOverride, parse, onUploadProgress, keepalive } = requestConfig;
|
|
257
|
-
const fullUrl = buildUrl$1(defaults.baseURL, url, params ?? query);
|
|
258
|
-
const mergedHeaders = {
|
|
259
|
-
...defaults.headers,
|
|
260
|
-
...headers
|
|
261
|
-
};
|
|
262
|
-
const requestBody = prepareBody$1(body);
|
|
263
|
-
const timeout = timeoutOverride ?? config.timeout;
|
|
264
|
-
let finalHeaders = mergedHeaders;
|
|
265
|
-
if (requestBody === null && (method === "POST" || method === "PUT" || method === "PATCH")) {
|
|
266
|
-
const { "Content-Type": _, ...headersWithoutContentType } = mergedHeaders;
|
|
267
|
-
finalHeaders = headersWithoutContentType;
|
|
268
|
-
}
|
|
269
|
-
if (onUploadProgress) {
|
|
270
|
-
if (requestBody !== null && typeof ReadableStream !== "undefined" && requestBody instanceof ReadableStream) throw new Error("Upload progress tracking is not supported for ReadableStream bodies");
|
|
271
|
-
return requestWithXHR(fullUrl, method, finalHeaders, requestBody, timeout ?? 0, signal, onUploadProgress);
|
|
272
|
-
}
|
|
273
|
-
const controller = new AbortController();
|
|
274
|
-
if (signal) if (signal.aborted) controller.abort();
|
|
275
|
-
else signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
276
|
-
const abortSignal = controller.signal;
|
|
277
|
-
const timeoutId = timeout === void 0 ? void 0 : setTimeout(() => controller.abort(), timeout);
|
|
278
|
-
try {
|
|
279
|
-
const response = await fetch(fullUrl, {
|
|
280
|
-
method,
|
|
281
|
-
headers: finalHeaders,
|
|
282
|
-
body: requestBody,
|
|
283
|
-
signal: abortSignal,
|
|
284
|
-
keepalive
|
|
285
|
-
});
|
|
286
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
287
|
-
const responseHeaders = {};
|
|
288
|
-
response.headers.forEach((value, key) => {
|
|
289
|
-
responseHeaders[key] = value;
|
|
290
|
-
});
|
|
291
|
-
const data = await parseResponse(response, parse);
|
|
292
|
-
if (!response.ok) throw reportHttpError(new FetchHttpError(response.status, response.statusText, fullUrl, method, responseHeaders, data), mergedHeaders);
|
|
293
|
-
return {
|
|
294
|
-
ok: true,
|
|
295
|
-
status: response.status,
|
|
296
|
-
statusText: response.statusText,
|
|
297
|
-
url: fullUrl,
|
|
298
|
-
headers: responseHeaders,
|
|
299
|
-
data
|
|
300
|
-
};
|
|
301
|
-
} catch (error) {
|
|
302
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
303
|
-
if (error instanceof FetchHttpError) throw error;
|
|
304
|
-
if (error instanceof Error && error.name === "AbortError") throw new FetchHttpError(0, "Request timeout", fullUrl, method, {}, null);
|
|
305
|
-
throw error;
|
|
306
|
-
}
|
|
307
|
-
},
|
|
308
|
-
get(url, config) {
|
|
309
|
-
return client.request({
|
|
310
|
-
...config,
|
|
311
|
-
url,
|
|
312
|
-
method: "GET"
|
|
313
|
-
});
|
|
314
|
-
},
|
|
315
|
-
post(url, body, config) {
|
|
316
|
-
return client.request({
|
|
317
|
-
...config,
|
|
318
|
-
url,
|
|
319
|
-
body,
|
|
320
|
-
method: "POST"
|
|
321
|
-
});
|
|
322
|
-
},
|
|
323
|
-
put(url, body, config) {
|
|
324
|
-
return client.request({
|
|
325
|
-
...config,
|
|
326
|
-
url,
|
|
327
|
-
body,
|
|
328
|
-
method: "PUT"
|
|
329
|
-
});
|
|
330
|
-
},
|
|
331
|
-
patch(url, body, config) {
|
|
332
|
-
return client.request({
|
|
333
|
-
...config,
|
|
334
|
-
url,
|
|
335
|
-
body,
|
|
336
|
-
method: "PATCH"
|
|
337
|
-
});
|
|
338
|
-
},
|
|
339
|
-
delete(url, config) {
|
|
340
|
-
return client.request({
|
|
341
|
-
...config,
|
|
342
|
-
url,
|
|
343
|
-
method: "DELETE"
|
|
344
|
-
});
|
|
345
|
-
},
|
|
346
|
-
head(url, config) {
|
|
347
|
-
return client.request({
|
|
348
|
-
...config,
|
|
349
|
-
url,
|
|
350
|
-
method: "HEAD"
|
|
351
|
-
});
|
|
352
|
-
},
|
|
353
|
-
options(url, config) {
|
|
354
|
-
return client.request({
|
|
355
|
-
...config,
|
|
356
|
-
url,
|
|
357
|
-
method: "OPTIONS"
|
|
358
|
-
});
|
|
359
|
-
},
|
|
360
|
-
setHeader(name, value) {
|
|
361
|
-
defaults.headers[name] = value;
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
return client;
|
|
365
|
-
};
|
|
366
|
-
//#endregion
|
|
367
|
-
//#region ../infra/src/http/createWasmApi.ts
|
|
368
|
-
const WASM_TIMEOUT_CEILING_MS = 36e5;
|
|
369
|
-
const RSA_OAEP_SHA256_SCHEME = "RSA/NONE/OAEPWITHSHA-256ANDMGF1PADDING";
|
|
153
|
+
//#region src/internal/trueSight/sanitize.ts
|
|
370
154
|
/**
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
155
|
+
* Deny-by-default message scrubber — runs at INGESTION (inside the log buffer's
|
|
156
|
+
* `append`), so the buffer, every persisted snapshot, and every upload are
|
|
157
|
+
* already clean; there is no code path around it (ENG-48677 plan §1.2).
|
|
158
|
+
*
|
|
159
|
+
* Ordered pipeline. Two deliberate deviations from the plan's original rule
|
|
160
|
+
* order, both from the P1-A adversarial review (2026-07-23, recorded in the
|
|
161
|
+
* plan's Operating-decisions section):
|
|
162
|
+
* - Inputs are pre-clamped to 2× the message cap BEFORE any regex runs — the
|
|
163
|
+
* unanchored patterns are quadratic on pathological non-matching runs
|
|
164
|
+
* (measured ~4.5 s on a 100 KB run), so regex cost must be bounded first.
|
|
165
|
+
* The final 8 KB cap still runs last.
|
|
166
|
+
* - The base64-blob rule runs BEFORE the digit-run rule — a digit run inside a
|
|
167
|
+
* blob would otherwise split it into sub-64-char fragments that escape
|
|
168
|
+
* redaction.
|
|
169
|
+
*
|
|
170
|
+
* The regex table ships in the P1-A PR description for privacy sign-off (see
|
|
171
|
+
* .agents/guides/privacy.md). Known hardening backlog (D4, Phase 4): formatted
|
|
172
|
+
* phone numbers, unicode digits/emails, fuzz/property tests.
|
|
374
173
|
*/
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
174
|
+
/** Three dot-joined base64url segments — JWT/JWS shape. */
|
|
175
|
+
const JWT_PATTERN = /\b[\w-]{8,}\.[\w-]{8,}\.[\w-]{8,}\b/g;
|
|
176
|
+
/**
|
|
177
|
+
* Credential-ish key with a `:`/`=` value (quoted, `Bearer …`, or bare token).
|
|
178
|
+
* The key may carry prefixes (`access_token`, `x-api-key`, `sessionToken`) —
|
|
179
|
+
* a plain \b boundary would miss `_token` since `_` is a word character.
|
|
180
|
+
*/
|
|
181
|
+
const CREDENTIAL_KV_PATTERN = /([\w-]*(?:token|api[-_]?key|authorization|auth|secret|password|passwd))\s*[:=]\s*("[^"]*"|'[^']*'|(?:Bearer\s+)?[^\s,;&]+)/gi;
|
|
182
|
+
/** Userinfo credentials in an absolute URL (`https://user:pass@host/…`). */
|
|
183
|
+
const URL_USERINFO_PATTERN = /(\bhttps?:\/\/)[^\s/@]*(?::[^\s/@]*)?@/gi;
|
|
184
|
+
/** Query string / fragment of an absolute URL — kills signed URLs. */
|
|
185
|
+
const URL_TAIL_PATTERN = /(https?:\/\/[^\s?#]+)[?#][^\s]*/g;
|
|
186
|
+
const EMAIL_PATTERN = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
187
|
+
/** base64-ish blobs (media, keys) — 64+ chars of the base64/base64url alphabet. */
|
|
188
|
+
const BASE64_BLOB_PATTERN = /[-A-Za-z0-9+/_]{64,}={0,2}/g;
|
|
189
|
+
/** Runs of 8+ digits — phones, CURP, document numbers. */
|
|
190
|
+
const DIGIT_RUN_PATTERN = /\d{8,}/g;
|
|
191
|
+
const TRUNCATION_SUFFIX = "…[truncated]";
|
|
192
|
+
/** Regex-cost bound: clamp raw input before any pattern runs (see header note). */
|
|
193
|
+
const REGEX_INPUT_MAX_BYTES = MESSAGE_MAX_BYTES * 2;
|
|
194
|
+
function sanitizeMessage(message) {
|
|
195
|
+
return truncateUtf8(truncateUtf8(message, REGEX_INPUT_MAX_BYTES).replace(JWT_PATTERN, "[jwt]").replace(CREDENTIAL_KV_PATTERN, "$1=[redacted]").replace(URL_USERINFO_PATTERN, "$1[redacted]@").replace(URL_TAIL_PATTERN, "$1").replace(EMAIL_PATTERN, "[email]").replace(BASE64_BLOB_PATTERN, (match) => `[blob:${match.length}]`).replace(DIGIT_RUN_PATTERN, "[digits]"), MESSAGE_MAX_BYTES);
|
|
382
196
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const prepareBody = (body) => {
|
|
411
|
-
if (body === null || body === void 0) return void 0;
|
|
412
|
-
if (body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer || body instanceof Uint8Array || typeof body === "string") return body;
|
|
413
|
-
if (typeof body === "object") return body;
|
|
414
|
-
return String(body);
|
|
415
|
-
};
|
|
416
|
-
const normalizeMethod = (method) => {
|
|
417
|
-
const upper = method.toUpperCase();
|
|
418
|
-
if (!HTTP_METHODS.has(upper)) throw new Error(`Unsupported HTTP method for WASM client: ${method}`);
|
|
419
|
-
return upper;
|
|
420
|
-
};
|
|
421
|
-
const getErrorStatus = (error) => {
|
|
422
|
-
if (error instanceof WasmWebClientError) return error.statusCode;
|
|
423
|
-
if (typeof error === "object" && error !== null) {
|
|
424
|
-
const record = error;
|
|
425
|
-
if (typeof record.statusCode === "number") return record.statusCode;
|
|
426
|
-
if (typeof record.status === "number") return record.status;
|
|
427
|
-
}
|
|
428
|
-
return 0;
|
|
429
|
-
};
|
|
430
|
-
const getErrorData = (error) => {
|
|
431
|
-
if (error instanceof WasmWebClientError) return error.response?.data ?? null;
|
|
432
|
-
return null;
|
|
433
|
-
};
|
|
434
|
-
const getErrorMessage = (error) => {
|
|
435
|
-
if (error instanceof Error) return error.message;
|
|
436
|
-
return "WasmWebClient request failed";
|
|
437
|
-
};
|
|
438
|
-
const withAbortSignal = async (promise, signal, error) => {
|
|
439
|
-
if (!signal) return await promise;
|
|
440
|
-
if (signal.aborted) throw error();
|
|
441
|
-
return await new Promise((resolve, reject) => {
|
|
442
|
-
const onAbort = () => reject(error());
|
|
443
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
444
|
-
promise.then(resolve, reject).finally(() => {
|
|
445
|
-
signal.removeEventListener("abort", onAbort);
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
};
|
|
449
|
-
const createWasmApi = async (config) => {
|
|
450
|
-
const headers = buildWasmDefaultHeaders(config.customHeaders);
|
|
451
|
-
const isEncryptionEnabled = config.isEncryptionEnabled ?? (() => false);
|
|
452
|
-
const useSha256 = config.mgf1 === "sha256";
|
|
453
|
-
await initializeWasmWebClient(config.wasm);
|
|
454
|
-
try {
|
|
455
|
-
await setupWasmConnection(config.apiURL, "", config.encryptionEnabled ?? false, headers, useSha256);
|
|
456
|
-
} catch (error) {
|
|
457
|
-
if (!(error instanceof WasmWebClientError)) throw error;
|
|
458
|
-
throw reportHttpError(new WasmHttpError(error.statusCode, "", config.apiURL, "POST", {}, getErrorData(error)), headers);
|
|
197
|
+
/**
|
|
198
|
+
* UTF-8 byte length without TextEncoder (banned browser global in L1 —
|
|
199
|
+
* see the no-browser-api-in-core lint rule). Counts by code point.
|
|
200
|
+
*/
|
|
201
|
+
function utf8ByteLength(value) {
|
|
202
|
+
let bytes = 0;
|
|
203
|
+
for (const char of value) bytes += codePointByteLength(char);
|
|
204
|
+
return bytes;
|
|
205
|
+
}
|
|
206
|
+
function codePointByteLength(char) {
|
|
207
|
+
const codePoint = char.codePointAt(0) ?? 0;
|
|
208
|
+
if (codePoint < 128) return 1;
|
|
209
|
+
if (codePoint < 2048) return 2;
|
|
210
|
+
if (codePoint < 65536) return 3;
|
|
211
|
+
return 4;
|
|
212
|
+
}
|
|
213
|
+
/** Cuts on a code-point boundary so no surrogate half ever reaches the wire. */
|
|
214
|
+
function truncateUtf8(value, maxBytes) {
|
|
215
|
+
if (utf8ByteLength(value) <= maxBytes) return value;
|
|
216
|
+
const budget = maxBytes - utf8ByteLength(TRUNCATION_SUFFIX);
|
|
217
|
+
let bytes = 0;
|
|
218
|
+
let result = "";
|
|
219
|
+
for (const char of value) {
|
|
220
|
+
const charBytes = codePointByteLength(char);
|
|
221
|
+
if (bytes + charBytes > budget) break;
|
|
222
|
+
bytes += charBytes;
|
|
223
|
+
result += char;
|
|
459
224
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
headers
|
|
463
|
-
};
|
|
464
|
-
const client = {
|
|
465
|
-
defaults,
|
|
466
|
-
async request(requestConfig) {
|
|
467
|
-
const { method = "GET", url, headers: requestHeaders = {}, query, params, body, signal, timeout: timeoutOverride, onUploadProgress, ie = false } = requestConfig;
|
|
468
|
-
const upperMethod = normalizeMethod(method);
|
|
469
|
-
const requestParams = params ?? query;
|
|
470
|
-
const fullUrl = buildUrl(defaults.baseURL, url, requestParams);
|
|
471
|
-
const needsSchemeHeader = useSha256 && isEncryptionEnabled();
|
|
472
|
-
const mergedHeaders = {
|
|
473
|
-
...defaults.headers,
|
|
474
|
-
...needsSchemeHeader ? { "X-RSA-Encryption-Scheme": RSA_OAEP_SHA256_SCHEME } : {},
|
|
475
|
-
...requestHeaders
|
|
476
|
-
};
|
|
477
|
-
const requestBody = prepareBody(body);
|
|
478
|
-
const timeout = timeoutOverride ?? config.timeout ?? WASM_TIMEOUT_CEILING_MS;
|
|
479
|
-
const wasmProgress = onUploadProgress ? (progress) => {
|
|
480
|
-
if (progress.total > 0) onUploadProgress(Math.round(progress.loaded / progress.total * 100));
|
|
481
|
-
} : void 0;
|
|
482
|
-
const abortError = () => new WasmHttpError(0, "Request aborted", fullUrl, upperMethod, {}, null);
|
|
483
|
-
if (signal?.aborted) throw abortError();
|
|
484
|
-
try {
|
|
485
|
-
const response = await withAbortSignal(executeWasmRequest(upperMethod, url, requestBody, mergedHeaders, requestParams, timeout, wasmProgress, ie), signal, abortError);
|
|
486
|
-
if (response.status < 200 || response.status >= 300) throw reportHttpError(new WasmHttpError(response.status, "", fullUrl, upperMethod, {}, response.data), mergedHeaders);
|
|
487
|
-
return {
|
|
488
|
-
ok: true,
|
|
489
|
-
status: response.status,
|
|
490
|
-
statusText: "",
|
|
491
|
-
url: fullUrl,
|
|
492
|
-
headers: {},
|
|
493
|
-
data: response.data
|
|
494
|
-
};
|
|
495
|
-
} catch (error) {
|
|
496
|
-
if (error instanceof WasmHttpError) throw error;
|
|
497
|
-
throw reportHttpError(new WasmHttpError(getErrorStatus(error), getErrorMessage(error), fullUrl, upperMethod, {}, getErrorData(error)), mergedHeaders);
|
|
498
|
-
}
|
|
499
|
-
},
|
|
500
|
-
get(url, requestConfig) {
|
|
501
|
-
return client.request({
|
|
502
|
-
...requestConfig,
|
|
503
|
-
url,
|
|
504
|
-
method: "GET"
|
|
505
|
-
});
|
|
506
|
-
},
|
|
507
|
-
post(url, body, requestConfig) {
|
|
508
|
-
return client.request({
|
|
509
|
-
...requestConfig,
|
|
510
|
-
url,
|
|
511
|
-
body,
|
|
512
|
-
method: "POST"
|
|
513
|
-
});
|
|
514
|
-
},
|
|
515
|
-
put(url, body, requestConfig) {
|
|
516
|
-
return client.request({
|
|
517
|
-
...requestConfig,
|
|
518
|
-
url,
|
|
519
|
-
body,
|
|
520
|
-
method: "PUT"
|
|
521
|
-
});
|
|
522
|
-
},
|
|
523
|
-
patch(url, body, requestConfig) {
|
|
524
|
-
return client.request({
|
|
525
|
-
...requestConfig,
|
|
526
|
-
url,
|
|
527
|
-
body,
|
|
528
|
-
method: "PATCH"
|
|
529
|
-
});
|
|
530
|
-
},
|
|
531
|
-
delete(url, requestConfig) {
|
|
532
|
-
return client.request({
|
|
533
|
-
...requestConfig,
|
|
534
|
-
url,
|
|
535
|
-
method: "DELETE"
|
|
536
|
-
});
|
|
537
|
-
},
|
|
538
|
-
head() {
|
|
539
|
-
return Promise.reject(/* @__PURE__ */ new Error("HEAD is not supported by the WASM HTTP client"));
|
|
540
|
-
},
|
|
541
|
-
options() {
|
|
542
|
-
return Promise.reject(/* @__PURE__ */ new Error("OPTIONS is not supported by the WASM HTTP client"));
|
|
543
|
-
},
|
|
544
|
-
setHeader(name, value) {
|
|
545
|
-
defaults.headers[name] = value;
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
return client;
|
|
549
|
-
};
|
|
225
|
+
return result + TRUNCATION_SUFFIX;
|
|
226
|
+
}
|
|
550
227
|
//#endregion
|
|
551
|
-
//#region src/
|
|
228
|
+
//#region ../infra/src/crypto/randomUUID.ts
|
|
552
229
|
/**
|
|
553
|
-
*
|
|
554
|
-
* adapter. Lets the on-device face-results POST flow through the same
|
|
555
|
-
* `httpClient.request()` pipeline as every other endpoint — header
|
|
556
|
-
* injection, encryption-state handling, default headers, timeout — instead
|
|
557
|
-
* of bypassing it via `executeWasmRequest` directly.
|
|
230
|
+
* Cryptographically-strong UUID v4 (RFC 4122).
|
|
558
231
|
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* host called `setup()` without `wasm` and warmed WASM separately), swap to
|
|
564
|
-
* the WASM client first. The module is already loaded — the payload came
|
|
565
|
-
* out of it — so the swap only creates the `WebClient`.
|
|
232
|
+
* Lives in infra (L0) so Core (L1) can mint secure identifiers without touching
|
|
233
|
+
* the `crypto` browser API directly — Core delegates here, keeping it free of
|
|
234
|
+
* browser globals (enforced by the `no-browser-api-in-core` lint rule). Backed
|
|
235
|
+
* by `crypto.randomUUID`, available in every browser the SDK targets.
|
|
566
236
|
*/
|
|
567
|
-
function
|
|
568
|
-
return
|
|
569
|
-
const response = await (config.ie === true && storedHttpConfig && !storedHttpConfig.isWasm ? await ensureWasmHttpClient() : client).request({
|
|
570
|
-
method: "POST",
|
|
571
|
-
url,
|
|
572
|
-
body,
|
|
573
|
-
headers: config.headers,
|
|
574
|
-
params: config.params,
|
|
575
|
-
timeout: config.timeout,
|
|
576
|
-
ie: config.ie
|
|
577
|
-
});
|
|
578
|
-
return {
|
|
579
|
-
data: response.data,
|
|
580
|
-
status: response.status
|
|
581
|
-
};
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
function installClient(client) {
|
|
585
|
-
setClient(client);
|
|
586
|
-
setWebApiHttpTransport(bindWebApiTransport(client));
|
|
587
|
-
}
|
|
588
|
-
async function ensureWasmHttpClient() {
|
|
589
|
-
await upgradeToWasmHttpClient(resolveWasmConfig());
|
|
590
|
-
return getApi();
|
|
591
|
-
}
|
|
592
|
-
let storedHttpConfig;
|
|
593
|
-
let pendingUpgrade;
|
|
594
|
-
/** Reads the current HTTP-client config (or `undefined` if none installed). */
|
|
595
|
-
function getStoredHttpConfig() {
|
|
596
|
-
return storedHttpConfig;
|
|
597
|
-
}
|
|
598
|
-
/** Whether encryption is currently active on the installed HTTP client. */
|
|
599
|
-
function isHttpEncrypted() {
|
|
600
|
-
return storedHttpConfig?.encryption.enabled ?? false;
|
|
601
|
-
}
|
|
602
|
-
/** Clears all HTTP-client state. Called by `reset()`. */
|
|
603
|
-
function resetHttpClientState() {
|
|
604
|
-
storedHttpConfig = void 0;
|
|
605
|
-
setWebApiHttpTransport(null);
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* Builds (or replaces) the HTTP client when `setup()` receives an `apiURL`.
|
|
609
|
-
* Picks `createWasmApi` when `effectiveWasm` is set, otherwise plain
|
|
610
|
-
* `createApi`. Wraps the call in handshake-failure context when encryption
|
|
611
|
-
* is requested.
|
|
612
|
-
*/
|
|
613
|
-
async function installFreshHttpClient(apiURL, options, effectiveWasm, encryption) {
|
|
614
|
-
installClient(effectiveWasm ? await withHandshakeFailureContext(encryption.enabled, () => createWasmApi({
|
|
615
|
-
apiURL,
|
|
616
|
-
customHeaders: options.customHeaders,
|
|
617
|
-
timeout: options.timeout,
|
|
618
|
-
wasm: effectiveWasm,
|
|
619
|
-
encryptionEnabled: encryption.enabled,
|
|
620
|
-
mgf1: encryption.mgf1,
|
|
621
|
-
isEncryptionEnabled: isHttpEncrypted
|
|
622
|
-
})) : createApi({
|
|
623
|
-
apiURL,
|
|
624
|
-
customHeaders: options.customHeaders,
|
|
625
|
-
timeout: options.timeout
|
|
626
|
-
}));
|
|
627
|
-
storedHttpConfig = {
|
|
628
|
-
apiURL,
|
|
629
|
-
customHeaders: options.customHeaders,
|
|
630
|
-
timeout: options.timeout,
|
|
631
|
-
isWasm: Boolean(effectiveWasm),
|
|
632
|
-
encryption
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Replaces the active HTTP client with the WASM-backed one. Used internally
|
|
637
|
-
* by lazy-loading UI components (`<incode-flow>`, `<incode-workflow>`) when
|
|
638
|
-
* WASM finishes warming up.
|
|
639
|
-
*
|
|
640
|
-
* No-op when no apiURL was previously configured, or when the active client
|
|
641
|
-
* is already WASM-backed. The encryption state (enabled + MGF1 scheme) is
|
|
642
|
-
* preserved across the swap — this is *not* a user-facing encryption change.
|
|
643
|
-
*
|
|
644
|
-
* @internal NOT a public API. Application code should use
|
|
645
|
-
* `setup({ wasm: {...} })` instead.
|
|
646
|
-
*/
|
|
647
|
-
async function upgradeToWasmHttpClient(resolved) {
|
|
648
|
-
const stored = storedHttpConfig;
|
|
649
|
-
if (!stored || stored.isWasm) return;
|
|
650
|
-
pendingUpgrade ??= (async () => {
|
|
651
|
-
installClient(await createWasmApi({
|
|
652
|
-
apiURL: stored.apiURL,
|
|
653
|
-
customHeaders: stored.customHeaders,
|
|
654
|
-
timeout: stored.timeout,
|
|
655
|
-
wasm: resolved,
|
|
656
|
-
encryptionEnabled: stored.encryption.enabled,
|
|
657
|
-
mgf1: stored.encryption.mgf1,
|
|
658
|
-
isEncryptionEnabled: isHttpEncrypted
|
|
659
|
-
}));
|
|
660
|
-
storedHttpConfig = {
|
|
661
|
-
...stored,
|
|
662
|
-
isWasm: true
|
|
663
|
-
};
|
|
664
|
-
})().finally(() => {
|
|
665
|
-
pendingUpgrade = void 0;
|
|
666
|
-
});
|
|
667
|
-
return pendingUpgrade;
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
* When `wantsEncryption` is true, wraps a call that triggers the in-binary
|
|
671
|
-
* RSA/AES handshake so its rejection surfaces as a single, descriptive error
|
|
672
|
-
* with the original error preserved as `cause`. Pass-through otherwise.
|
|
673
|
-
*/
|
|
674
|
-
async function withHandshakeFailureContext(wantsEncryption, fn) {
|
|
675
|
-
if (!wantsEncryption) return fn();
|
|
676
|
-
try {
|
|
677
|
-
return await fn();
|
|
678
|
-
} catch (cause) {
|
|
679
|
-
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.");
|
|
680
|
-
error.cause = cause;
|
|
681
|
-
throw error;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
/** Hard cap per log message, UTF-8 bytes (contract). */
|
|
685
|
-
const MESSAGE_MAX_BYTES = 8 * 1024;
|
|
686
|
-
const TRUESIGHT_SDK_ID = "IncdOnboarding";
|
|
687
|
-
/** localStorage key prefix for persisted sealed snapshots (A3: one slot per session). */
|
|
688
|
-
const PENDING_STORAGE_KEY_PREFIX = "incode.truesight.pending.";
|
|
689
|
-
//#endregion
|
|
690
|
-
//#region src/internal/trueSight/sanitize.ts
|
|
691
|
-
/**
|
|
692
|
-
* Deny-by-default message scrubber — runs at INGESTION (inside the log buffer's
|
|
693
|
-
* `append`), so the buffer, every persisted snapshot, and every upload are
|
|
694
|
-
* already clean; there is no code path around it (ENG-48677 plan §1.2).
|
|
695
|
-
*
|
|
696
|
-
* Ordered pipeline. Two deliberate deviations from the plan's original rule
|
|
697
|
-
* order, both from the P1-A adversarial review (2026-07-23, recorded in the
|
|
698
|
-
* plan's Operating-decisions section):
|
|
699
|
-
* - Inputs are pre-clamped to 2× the message cap BEFORE any regex runs — the
|
|
700
|
-
* unanchored patterns are quadratic on pathological non-matching runs
|
|
701
|
-
* (measured ~4.5 s on a 100 KB run), so regex cost must be bounded first.
|
|
702
|
-
* The final 8 KB cap still runs last.
|
|
703
|
-
* - The base64-blob rule runs BEFORE the digit-run rule — a digit run inside a
|
|
704
|
-
* blob would otherwise split it into sub-64-char fragments that escape
|
|
705
|
-
* redaction.
|
|
706
|
-
*
|
|
707
|
-
* The regex table ships in the P1-A PR description for privacy sign-off (see
|
|
708
|
-
* .agents/guides/privacy.md). Known hardening backlog (D4, Phase 4): formatted
|
|
709
|
-
* phone numbers, unicode digits/emails, fuzz/property tests.
|
|
710
|
-
*/
|
|
711
|
-
/** Three dot-joined base64url segments — JWT/JWS shape. */
|
|
712
|
-
const JWT_PATTERN = /\b[\w-]{8,}\.[\w-]{8,}\.[\w-]{8,}\b/g;
|
|
713
|
-
/**
|
|
714
|
-
* Credential-ish key with a `:`/`=` value (quoted, `Bearer …`, or bare token).
|
|
715
|
-
* The key may carry prefixes (`access_token`, `x-api-key`, `sessionToken`) —
|
|
716
|
-
* a plain \b boundary would miss `_token` since `_` is a word character.
|
|
717
|
-
*/
|
|
718
|
-
const CREDENTIAL_KV_PATTERN = /([\w-]*(?:token|api[-_]?key|authorization|auth|secret|password|passwd))\s*[:=]\s*("[^"]*"|'[^']*'|(?:Bearer\s+)?[^\s,;&]+)/gi;
|
|
719
|
-
/** Userinfo credentials in an absolute URL (`https://user:pass@host/…`). */
|
|
720
|
-
const URL_USERINFO_PATTERN = /(\bhttps?:\/\/)[^\s/@]*(?::[^\s/@]*)?@/gi;
|
|
721
|
-
/** Query string / fragment of an absolute URL — kills signed URLs. */
|
|
722
|
-
const URL_TAIL_PATTERN = /(https?:\/\/[^\s?#]+)[?#][^\s]*/g;
|
|
723
|
-
const EMAIL_PATTERN = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
724
|
-
/** base64-ish blobs (media, keys) — 64+ chars of the base64/base64url alphabet. */
|
|
725
|
-
const BASE64_BLOB_PATTERN = /[-A-Za-z0-9+/_]{64,}={0,2}/g;
|
|
726
|
-
/** Runs of 8+ digits — phones, CURP, document numbers. */
|
|
727
|
-
const DIGIT_RUN_PATTERN = /\d{8,}/g;
|
|
728
|
-
const TRUNCATION_SUFFIX = "…[truncated]";
|
|
729
|
-
/** Regex-cost bound: clamp raw input before any pattern runs (see header note). */
|
|
730
|
-
const REGEX_INPUT_MAX_BYTES = MESSAGE_MAX_BYTES * 2;
|
|
731
|
-
function sanitizeMessage(message) {
|
|
732
|
-
return truncateUtf8(truncateUtf8(message, REGEX_INPUT_MAX_BYTES).replace(JWT_PATTERN, "[jwt]").replace(CREDENTIAL_KV_PATTERN, "$1=[redacted]").replace(URL_USERINFO_PATTERN, "$1[redacted]@").replace(URL_TAIL_PATTERN, "$1").replace(EMAIL_PATTERN, "[email]").replace(BASE64_BLOB_PATTERN, (match) => `[blob:${match.length}]`).replace(DIGIT_RUN_PATTERN, "[digits]"), MESSAGE_MAX_BYTES);
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* UTF-8 byte length without TextEncoder (banned browser global in L1 —
|
|
736
|
-
* see the no-browser-api-in-core lint rule). Counts by code point.
|
|
737
|
-
*/
|
|
738
|
-
function utf8ByteLength(value) {
|
|
739
|
-
let bytes = 0;
|
|
740
|
-
for (const char of value) bytes += codePointByteLength(char);
|
|
741
|
-
return bytes;
|
|
742
|
-
}
|
|
743
|
-
function codePointByteLength(char) {
|
|
744
|
-
const codePoint = char.codePointAt(0) ?? 0;
|
|
745
|
-
if (codePoint < 128) return 1;
|
|
746
|
-
if (codePoint < 2048) return 2;
|
|
747
|
-
if (codePoint < 65536) return 3;
|
|
748
|
-
return 4;
|
|
749
|
-
}
|
|
750
|
-
/** Cuts on a code-point boundary so no surrogate half ever reaches the wire. */
|
|
751
|
-
function truncateUtf8(value, maxBytes) {
|
|
752
|
-
if (utf8ByteLength(value) <= maxBytes) return value;
|
|
753
|
-
const budget = maxBytes - utf8ByteLength(TRUNCATION_SUFFIX);
|
|
754
|
-
let bytes = 0;
|
|
755
|
-
let result = "";
|
|
756
|
-
for (const char of value) {
|
|
757
|
-
const charBytes = codePointByteLength(char);
|
|
758
|
-
if (bytes + charBytes > budget) break;
|
|
759
|
-
bytes += charBytes;
|
|
760
|
-
result += char;
|
|
761
|
-
}
|
|
762
|
-
return result + TRUNCATION_SUFFIX;
|
|
763
|
-
}
|
|
764
|
-
//#endregion
|
|
765
|
-
//#region ../infra/src/crypto/randomUUID.ts
|
|
766
|
-
/**
|
|
767
|
-
* Cryptographically-strong UUID v4 (RFC 4122).
|
|
768
|
-
*
|
|
769
|
-
* Lives in infra (L0) so Core (L1) can mint secure identifiers without touching
|
|
770
|
-
* the `crypto` browser API directly — Core delegates here, keeping it free of
|
|
771
|
-
* browser globals (enforced by the `no-browser-api-in-core` lint rule). Backed
|
|
772
|
-
* by `crypto.randomUUID`, available in every browser the SDK targets.
|
|
773
|
-
*/
|
|
774
|
-
function randomUUID() {
|
|
775
|
-
return crypto.randomUUID();
|
|
237
|
+
function randomUUID() {
|
|
238
|
+
return crypto.randomUUID();
|
|
776
239
|
}
|
|
777
240
|
//#endregion
|
|
778
241
|
//#region ../infra/src/time/epochMsToIsoString.ts
|
|
@@ -858,247 +321,784 @@ function buildDiagnosticsRecord(meta, logs, outcome, failureReason, recordId) {
|
|
|
858
321
|
* branch returns 'standalone' and standalone diagnostics start flowing,
|
|
859
322
|
* coordinated with the BE deploy since off-enum values 400 today.
|
|
860
323
|
*/
|
|
861
|
-
function deriveFlowTypeFromSurface(integrationType) {
|
|
862
|
-
switch (integrationType) {
|
|
863
|
-
case "startWorkflow": return "workflow";
|
|
864
|
-
case "startFlow":
|
|
865
|
-
case "startOnboarding": return "flow";
|
|
866
|
-
case "startOnboardingSection": return null;
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
function toContractEntry(entry) {
|
|
324
|
+
function deriveFlowTypeFromSurface(integrationType) {
|
|
325
|
+
switch (integrationType) {
|
|
326
|
+
case "startWorkflow": return "workflow";
|
|
327
|
+
case "startFlow":
|
|
328
|
+
case "startOnboarding": return "flow";
|
|
329
|
+
case "startOnboardingSection": return null;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function toContractEntry(entry) {
|
|
333
|
+
return {
|
|
334
|
+
index: entry.index,
|
|
335
|
+
timestamp: epochMsToIsoString(entry.timestampMs),
|
|
336
|
+
level: entry.level,
|
|
337
|
+
thread: "main",
|
|
338
|
+
message: entry.message,
|
|
339
|
+
subsystem: entry.subsystem,
|
|
340
|
+
category: entry.category
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function createInitialState() {
|
|
344
|
+
return {
|
|
345
|
+
sessionId: null,
|
|
346
|
+
startedAtMs: null,
|
|
347
|
+
browser: null,
|
|
348
|
+
osVersion: null,
|
|
349
|
+
osLanguage: null,
|
|
350
|
+
sdkLanguage: "en-US",
|
|
351
|
+
integrationType: "startOnboardingSection",
|
|
352
|
+
flowType: null,
|
|
353
|
+
flowId: null,
|
|
354
|
+
workflowId: null,
|
|
355
|
+
testing: false,
|
|
356
|
+
devModeSignal: void 0,
|
|
357
|
+
apiUrlSignal: void 0,
|
|
358
|
+
hasConfigurationId: false,
|
|
359
|
+
hasExternalCustomerId: false,
|
|
360
|
+
hasProvidedSessionId: false,
|
|
361
|
+
hasExternalToken: false
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
let state = createInitialState();
|
|
365
|
+
let sources = {};
|
|
366
|
+
/** Tap for `createSession` — sessionId comes from the returned `interviewId`. */
|
|
367
|
+
function noteSessionCreated(session, options = {}) {}
|
|
368
|
+
function noteEnvironment(environment) {}
|
|
369
|
+
/**
|
|
370
|
+
* `testing` heuristic: devMode OR non-prod API host pattern. Always a boolean —
|
|
371
|
+
* the contract requires the field present on every record. Signals MERGE across
|
|
372
|
+
* calls (a later apiUrl-only call must not erase an earlier devMode signal);
|
|
373
|
+
* `testing` is recomputed from the merged pair.
|
|
374
|
+
*/
|
|
375
|
+
function noteTestingSignals(signals) {}
|
|
376
|
+
/**
|
|
377
|
+
* Live read of the merged testing signal (devMode OR non-prod host). Used to
|
|
378
|
+
* gate host-console self-health noise so production host pages stay quiet while
|
|
379
|
+
* staging/dev keeps the console signal (the record always captures it either
|
|
380
|
+
* way via `trueSightLog`). Same signal the overflow-flush staging gate uses.
|
|
381
|
+
*/
|
|
382
|
+
function isTrueSightTesting() {
|
|
383
|
+
return state.testing;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Wiring tap for every `initializeSession({ token })`: a token activated
|
|
387
|
+
* before any `createSession` was observed on this page is host-minted, i.e.
|
|
388
|
+
* external. (The exact `token`/`externalToken` web-semantics are a pending
|
|
389
|
+
* Phase 0 contract ask — this inference is the interim mapping.)
|
|
390
|
+
*/
|
|
391
|
+
function noteTokenActivated() {}
|
|
392
|
+
/** Explicit literal — the metadata half handed to the record builder. */
|
|
393
|
+
function buildSessionMetadata() {
|
|
394
|
+
return {
|
|
395
|
+
sessionId: state.sessionId,
|
|
396
|
+
startedAtMs: state.startedAtMs,
|
|
397
|
+
browser: state.browser,
|
|
398
|
+
osVersion: state.osVersion,
|
|
399
|
+
osLanguage: state.osLanguage,
|
|
400
|
+
sdkLanguage: state.sdkLanguage,
|
|
401
|
+
integrationType: state.integrationType,
|
|
402
|
+
flowType: state.flowType,
|
|
403
|
+
flowId: state.flowId,
|
|
404
|
+
workflowId: state.workflowId,
|
|
405
|
+
testing: state.testing,
|
|
406
|
+
e2eEncryptionEnabled: readE2eEncryptionEnabled(),
|
|
407
|
+
hasConfigurationId: state.hasConfigurationId,
|
|
408
|
+
hasExternalCustomerId: state.hasExternalCustomerId,
|
|
409
|
+
hasProvidedSessionId: state.hasProvidedSessionId,
|
|
410
|
+
hasToken: readHasToken(),
|
|
411
|
+
hasExternalToken: state.hasExternalToken
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
/** Fail-open: diagnostics must never throw into the host flow. */
|
|
415
|
+
function readE2eEncryptionEnabled() {
|
|
416
|
+
try {
|
|
417
|
+
return sources.getE2eEncryptionEnabled?.() ?? false;
|
|
418
|
+
} catch {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/** Fail-open, like readE2eEncryptionEnabled. */
|
|
423
|
+
function readHasToken() {
|
|
424
|
+
try {
|
|
425
|
+
return sources.getHasToken?.() ?? false;
|
|
426
|
+
} catch {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function resetTrueSightMetadata() {
|
|
431
|
+
state = createInitialState();
|
|
432
|
+
sources = {};
|
|
433
|
+
}
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/internal/trueSight/pendingEnvelopeStore.ts
|
|
436
|
+
/** Index slot listing sessionIds with pending entries (no enumeration API). */
|
|
437
|
+
const PENDING_INDEX_KEY = `${PENDING_STORAGE_KEY_PREFIX}index`;
|
|
438
|
+
function slotKey(sessionId) {
|
|
439
|
+
return `${PENDING_STORAGE_KEY_PREFIX}${sessionId}`;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Adds the session to the pending index. Called once at collection start —
|
|
443
|
+
* long before any page-hide — so the hide path never needs the index
|
|
444
|
+
* read-modify-write and stays a single synchronous-effective write.
|
|
445
|
+
*/
|
|
446
|
+
async function registerPendingSlot(sessionId, deps) {
|
|
447
|
+
try {
|
|
448
|
+
const index = await readIndex(deps.storage);
|
|
449
|
+
if (index.includes(sessionId)) return;
|
|
450
|
+
await deps.storage.set(PENDING_INDEX_KEY, [...index, sessionId]);
|
|
451
|
+
} catch {}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Writes the sealed snapshot into the session's slot. `BrowserStorageProvider`
|
|
455
|
+
* executes the underlying `localStorage.setItem` synchronously in the first
|
|
456
|
+
* slice of the async call, which is what makes this safe to fire (void) from
|
|
457
|
+
* a page-hide handler.
|
|
458
|
+
*/
|
|
459
|
+
async function writePendingEnvelope(sessionId, entry, deps) {
|
|
460
|
+
try {
|
|
461
|
+
await deps.storage.set(slotKey(sessionId), entry);
|
|
462
|
+
} catch {}
|
|
463
|
+
}
|
|
464
|
+
/** Removes the entry and its index membership (terminal upload dispatched). */
|
|
465
|
+
async function clearPending(sessionId, deps) {
|
|
466
|
+
try {
|
|
467
|
+
await deps.storage.remove(slotKey(sessionId));
|
|
468
|
+
const index = await readIndex(deps.storage);
|
|
469
|
+
if (index.includes(sessionId)) await deps.storage.set(PENDING_INDEX_KEY, index.filter((candidate) => candidate !== sessionId));
|
|
470
|
+
} catch {}
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Next-load recovery, invoked from the first-token-observed hook (A1 — never
|
|
474
|
+
* at `setup()`, which has no auth). For each foreign, old-enough entry: the
|
|
475
|
+
* slot is cleared AT DISPATCH, then the envelope is posted fire-and-forget —
|
|
476
|
+
* no 200-tracking, no retries (A2; a crash between clear and fire loses that
|
|
477
|
+
* record, consistent with no-retry). Entries at/past the retention ceiling
|
|
478
|
+
* are deleted unsent (A4). Never rejects; returns the A5 loss counters.
|
|
479
|
+
*/
|
|
480
|
+
async function recoverPendingEnvelopes(options) {
|
|
481
|
+
const { storage, post, currentSessionId } = options;
|
|
482
|
+
const now = options.now ?? getTimestamp;
|
|
483
|
+
const counters = {
|
|
484
|
+
recovered: 0,
|
|
485
|
+
gcExpired: 0
|
|
486
|
+
};
|
|
487
|
+
try {
|
|
488
|
+
const index = await readIndex(storage);
|
|
489
|
+
if (index.length === 0) return counters;
|
|
490
|
+
const keptInIndex = [];
|
|
491
|
+
for (const sessionId of index) {
|
|
492
|
+
if (sessionId === currentSessionId) {
|
|
493
|
+
keptInIndex.push(sessionId);
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
const entry = await readEntry(storage, sessionId);
|
|
497
|
+
if (entry === "missing") continue;
|
|
498
|
+
if (entry === "corrupt") {
|
|
499
|
+
counters.gcExpired += 1;
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const age = now() - entry.persistedAt;
|
|
503
|
+
if (age >= 6048e5) {
|
|
504
|
+
counters.gcExpired += 1;
|
|
505
|
+
await storage.remove(slotKey(sessionId));
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (age < 12e4) {
|
|
509
|
+
keptInIndex.push(sessionId);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
await storage.remove(slotKey(sessionId));
|
|
513
|
+
counters.recovered += 1;
|
|
514
|
+
post(endpoints.diagnosticsData, entry.envelope, {}).catch(() => {});
|
|
515
|
+
}
|
|
516
|
+
await storage.set(PENDING_INDEX_KEY, keptInIndex);
|
|
517
|
+
} catch {}
|
|
518
|
+
return counters;
|
|
519
|
+
}
|
|
520
|
+
async function readIndex(storage) {
|
|
521
|
+
const index = await storage.get(PENDING_INDEX_KEY);
|
|
522
|
+
if (!Array.isArray(index)) return [];
|
|
523
|
+
return index.filter((value) => typeof value === "string");
|
|
524
|
+
}
|
|
525
|
+
/** Reads one entry; malformed slots are pruned and reported as corrupt. */
|
|
526
|
+
async function readEntry(storage, sessionId) {
|
|
527
|
+
try {
|
|
528
|
+
const value = await storage.get(slotKey(sessionId));
|
|
529
|
+
if (value === null) return "missing";
|
|
530
|
+
if (typeof value === "object" && value.v === 1 && typeof value.persistedAt === "number" && typeof value.envelope === "object") return value;
|
|
531
|
+
await storage.remove(slotKey(sessionId));
|
|
532
|
+
return "corrupt";
|
|
533
|
+
} catch {
|
|
534
|
+
try {
|
|
535
|
+
await storage.remove(slotKey(sessionId));
|
|
536
|
+
} catch {}
|
|
537
|
+
return "corrupt";
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/internal/featureConfig/featureConfigService.ts
|
|
542
|
+
let cachedFeatures = null;
|
|
543
|
+
/**
|
|
544
|
+
* Checks if a feature is enabled in the feature config.
|
|
545
|
+
*/
|
|
546
|
+
function isFeatureEnabled(feature, features) {
|
|
547
|
+
return features?.find((f) => f.feature === feature)?.enabled ?? false;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Fetches feature configuration from the backend.
|
|
551
|
+
* Results are cached for the session lifetime.
|
|
552
|
+
*/
|
|
553
|
+
async function fetchFeatureConfig(signal) {
|
|
554
|
+
if (cachedFeatures) return cachedFeatures;
|
|
555
|
+
const response = await api.get(endpoints.featureConfig, { signal });
|
|
556
|
+
if (!response.ok) throw new Error(`Failed to fetch feature config: ${response.status} ${response.statusText}`);
|
|
557
|
+
cachedFeatures = response.data;
|
|
558
|
+
return cachedFeatures;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Resets the cached feature config (useful for testing).
|
|
562
|
+
*/
|
|
563
|
+
function resetFeatureConfigCache() {
|
|
564
|
+
cachedFeatures = null;
|
|
565
|
+
}
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region ../infra/src/http/createApi.ts
|
|
568
|
+
var FetchHttpError = class extends HttpRequestError {
|
|
569
|
+
constructor(..._args) {
|
|
570
|
+
super(..._args);
|
|
571
|
+
this.name = "FetchHttpError";
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
const buildQueryString$1 = (query) => {
|
|
575
|
+
if (!query) return "";
|
|
576
|
+
const params = new URLSearchParams();
|
|
577
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
578
|
+
if (value !== void 0 && value !== null) params.append(key, String(value));
|
|
579
|
+
});
|
|
580
|
+
const str = params.toString();
|
|
581
|
+
return str ? `?${str}` : "";
|
|
582
|
+
};
|
|
583
|
+
const buildUrl$1 = (baseURL, url, query) => {
|
|
584
|
+
const queryString = buildQueryString$1(query);
|
|
585
|
+
if (url.startsWith("http://") || url.startsWith("https://")) return `${url}${queryString}`;
|
|
586
|
+
return `${baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL}${url.startsWith("/") ? url : `/${url}`}${queryString}`;
|
|
587
|
+
};
|
|
588
|
+
const prepareBody$1 = (body) => {
|
|
589
|
+
if (body === null || body === void 0) return null;
|
|
590
|
+
if (body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer) return body;
|
|
591
|
+
if (typeof body === "object") return JSON.stringify(body);
|
|
592
|
+
return String(body);
|
|
593
|
+
};
|
|
594
|
+
const parseResponse = async (response, parseType) => {
|
|
595
|
+
if (parseType === "response") return response;
|
|
596
|
+
if (parseType === "blob") return await response.blob();
|
|
597
|
+
if (parseType === "arrayBuffer") return await response.arrayBuffer();
|
|
598
|
+
if (parseType === "text") return await response.text();
|
|
599
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
600
|
+
if (parseType === "json" || contentType.includes("application/json")) {
|
|
601
|
+
const raw = await response.text();
|
|
602
|
+
if (raw.length === 0) return "";
|
|
603
|
+
try {
|
|
604
|
+
return JSON.parse(raw);
|
|
605
|
+
} catch {
|
|
606
|
+
return raw;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return await response.text();
|
|
610
|
+
};
|
|
611
|
+
const requestWithXHR = (fullUrl, method, mergedHeaders, requestBody, timeout, signal, onUploadProgress) => {
|
|
612
|
+
return new Promise((resolve, reject) => {
|
|
613
|
+
const xhr = new XMLHttpRequest();
|
|
614
|
+
xhr.open(method, fullUrl, true);
|
|
615
|
+
Object.entries(mergedHeaders).forEach(([key, value]) => {
|
|
616
|
+
xhr.setRequestHeader(key, value);
|
|
617
|
+
});
|
|
618
|
+
xhr.timeout = timeout;
|
|
619
|
+
xhr.upload.onprogress = (event) => {
|
|
620
|
+
if (event.lengthComputable) {
|
|
621
|
+
const percentComplete = event.loaded / event.total * 100;
|
|
622
|
+
onUploadProgress(Math.round(percentComplete));
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
xhr.onload = () => {
|
|
626
|
+
const responseHeaders = {};
|
|
627
|
+
xhr.getAllResponseHeaders().split("\r\n").forEach((line) => {
|
|
628
|
+
const parts = line.split(": ");
|
|
629
|
+
if (parts.length === 2) responseHeaders[parts[0].toLowerCase()] = parts[1];
|
|
630
|
+
});
|
|
631
|
+
let data;
|
|
632
|
+
try {
|
|
633
|
+
if ((xhr.getResponseHeader("content-type") ?? "").includes("application/json")) data = JSON.parse(xhr.responseText);
|
|
634
|
+
else data = xhr.responseText;
|
|
635
|
+
} catch {
|
|
636
|
+
data = xhr.responseText;
|
|
637
|
+
}
|
|
638
|
+
if (xhr.status >= 200 && xhr.status < 300) resolve({
|
|
639
|
+
ok: true,
|
|
640
|
+
status: xhr.status,
|
|
641
|
+
statusText: xhr.statusText,
|
|
642
|
+
url: fullUrl,
|
|
643
|
+
headers: responseHeaders,
|
|
644
|
+
data
|
|
645
|
+
});
|
|
646
|
+
else reject(reportHttpError(new FetchHttpError(xhr.status, xhr.statusText, fullUrl, method, responseHeaders, data), mergedHeaders));
|
|
647
|
+
};
|
|
648
|
+
xhr.onerror = () => {
|
|
649
|
+
reject(new FetchHttpError(0, "Network Error", fullUrl, method, {}, null));
|
|
650
|
+
};
|
|
651
|
+
xhr.ontimeout = () => {
|
|
652
|
+
reject(new FetchHttpError(0, "Request timeout", fullUrl, method, {}, null));
|
|
653
|
+
};
|
|
654
|
+
if (signal) signal.addEventListener("abort", () => {
|
|
655
|
+
xhr.abort();
|
|
656
|
+
reject(new FetchHttpError(0, "Request aborted", fullUrl, method, {}, null));
|
|
657
|
+
});
|
|
658
|
+
xhr.send(requestBody);
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
const createApi = (config) => {
|
|
662
|
+
const headers = {
|
|
663
|
+
"Content-Type": "application/json",
|
|
664
|
+
Accept: "application/json",
|
|
665
|
+
"api-version": "1.0",
|
|
666
|
+
...config.customHeaders ?? {}
|
|
667
|
+
};
|
|
668
|
+
const defaults = {
|
|
669
|
+
baseURL: config.apiURL,
|
|
670
|
+
headers
|
|
671
|
+
};
|
|
672
|
+
const client = {
|
|
673
|
+
defaults,
|
|
674
|
+
async request(requestConfig) {
|
|
675
|
+
const { method = "GET", url, headers = {}, query, params, body, signal, timeout: timeoutOverride, parse, onUploadProgress, keepalive } = requestConfig;
|
|
676
|
+
const fullUrl = buildUrl$1(defaults.baseURL, url, params ?? query);
|
|
677
|
+
const mergedHeaders = {
|
|
678
|
+
...defaults.headers,
|
|
679
|
+
...headers
|
|
680
|
+
};
|
|
681
|
+
const requestBody = prepareBody$1(body);
|
|
682
|
+
const timeout = timeoutOverride ?? config.timeout;
|
|
683
|
+
let finalHeaders = mergedHeaders;
|
|
684
|
+
if (requestBody === null && (method === "POST" || method === "PUT" || method === "PATCH")) {
|
|
685
|
+
const { "Content-Type": _, ...headersWithoutContentType } = mergedHeaders;
|
|
686
|
+
finalHeaders = headersWithoutContentType;
|
|
687
|
+
}
|
|
688
|
+
if (onUploadProgress) {
|
|
689
|
+
if (requestBody !== null && typeof ReadableStream !== "undefined" && requestBody instanceof ReadableStream) throw new Error("Upload progress tracking is not supported for ReadableStream bodies");
|
|
690
|
+
return requestWithXHR(fullUrl, method, finalHeaders, requestBody, timeout ?? 0, signal, onUploadProgress);
|
|
691
|
+
}
|
|
692
|
+
const controller = new AbortController();
|
|
693
|
+
if (signal) if (signal.aborted) controller.abort();
|
|
694
|
+
else signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
695
|
+
const abortSignal = controller.signal;
|
|
696
|
+
const timeoutId = timeout === void 0 ? void 0 : setTimeout(() => controller.abort(), timeout);
|
|
697
|
+
try {
|
|
698
|
+
const response = await fetch(fullUrl, {
|
|
699
|
+
method,
|
|
700
|
+
headers: finalHeaders,
|
|
701
|
+
body: requestBody,
|
|
702
|
+
signal: abortSignal,
|
|
703
|
+
keepalive
|
|
704
|
+
});
|
|
705
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
706
|
+
const responseHeaders = {};
|
|
707
|
+
response.headers.forEach((value, key) => {
|
|
708
|
+
responseHeaders[key] = value;
|
|
709
|
+
});
|
|
710
|
+
const data = await parseResponse(response, parse);
|
|
711
|
+
if (!response.ok) throw reportHttpError(new FetchHttpError(response.status, response.statusText, fullUrl, method, responseHeaders, data), mergedHeaders);
|
|
712
|
+
return {
|
|
713
|
+
ok: true,
|
|
714
|
+
status: response.status,
|
|
715
|
+
statusText: response.statusText,
|
|
716
|
+
url: fullUrl,
|
|
717
|
+
headers: responseHeaders,
|
|
718
|
+
data
|
|
719
|
+
};
|
|
720
|
+
} catch (error) {
|
|
721
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
722
|
+
if (error instanceof FetchHttpError) throw error;
|
|
723
|
+
if (error instanceof Error && error.name === "AbortError") throw new FetchHttpError(0, "Request timeout", fullUrl, method, {}, null);
|
|
724
|
+
throw error;
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
get(url, config) {
|
|
728
|
+
return client.request({
|
|
729
|
+
...config,
|
|
730
|
+
url,
|
|
731
|
+
method: "GET"
|
|
732
|
+
});
|
|
733
|
+
},
|
|
734
|
+
post(url, body, config) {
|
|
735
|
+
return client.request({
|
|
736
|
+
...config,
|
|
737
|
+
url,
|
|
738
|
+
body,
|
|
739
|
+
method: "POST"
|
|
740
|
+
});
|
|
741
|
+
},
|
|
742
|
+
put(url, body, config) {
|
|
743
|
+
return client.request({
|
|
744
|
+
...config,
|
|
745
|
+
url,
|
|
746
|
+
body,
|
|
747
|
+
method: "PUT"
|
|
748
|
+
});
|
|
749
|
+
},
|
|
750
|
+
patch(url, body, config) {
|
|
751
|
+
return client.request({
|
|
752
|
+
...config,
|
|
753
|
+
url,
|
|
754
|
+
body,
|
|
755
|
+
method: "PATCH"
|
|
756
|
+
});
|
|
757
|
+
},
|
|
758
|
+
delete(url, config) {
|
|
759
|
+
return client.request({
|
|
760
|
+
...config,
|
|
761
|
+
url,
|
|
762
|
+
method: "DELETE"
|
|
763
|
+
});
|
|
764
|
+
},
|
|
765
|
+
head(url, config) {
|
|
766
|
+
return client.request({
|
|
767
|
+
...config,
|
|
768
|
+
url,
|
|
769
|
+
method: "HEAD"
|
|
770
|
+
});
|
|
771
|
+
},
|
|
772
|
+
options(url, config) {
|
|
773
|
+
return client.request({
|
|
774
|
+
...config,
|
|
775
|
+
url,
|
|
776
|
+
method: "OPTIONS"
|
|
777
|
+
});
|
|
778
|
+
},
|
|
779
|
+
setHeader(name, value) {
|
|
780
|
+
defaults.headers[name] = value;
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
return client;
|
|
784
|
+
};
|
|
785
|
+
//#endregion
|
|
786
|
+
//#region ../infra/src/http/createWasmApi.ts
|
|
787
|
+
const WASM_TIMEOUT_CEILING_MS = 36e5;
|
|
788
|
+
const RSA_OAEP_SHA256_SCHEME = "RSA/NONE/OAEPWITHSHA-256ANDMGF1PADDING";
|
|
789
|
+
/**
|
|
790
|
+
* Builds the base set of HTTP headers that the WASM WebClient sends on every
|
|
791
|
+
* request (including the internal `/e2ee/key/v2` and `/e2ee/key` handshake
|
|
792
|
+
* calls).
|
|
793
|
+
*/
|
|
794
|
+
function buildWasmDefaultHeaders(customHeaders) {
|
|
870
795
|
return {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
message: entry.message,
|
|
876
|
-
subsystem: entry.subsystem,
|
|
877
|
-
category: entry.category
|
|
796
|
+
"Content-Type": "application/json",
|
|
797
|
+
Accept: "application/json",
|
|
798
|
+
"api-version": "1.0",
|
|
799
|
+
...customHeaders ?? {}
|
|
878
800
|
};
|
|
879
801
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
802
|
+
var WasmHttpError = class extends HttpRequestError {
|
|
803
|
+
constructor(..._args) {
|
|
804
|
+
super(..._args);
|
|
805
|
+
this.name = "WasmHttpError";
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
const HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
809
|
+
"GET",
|
|
810
|
+
"POST",
|
|
811
|
+
"PUT",
|
|
812
|
+
"PATCH",
|
|
813
|
+
"DELETE"
|
|
814
|
+
]);
|
|
815
|
+
const buildQueryString = (query) => {
|
|
816
|
+
if (!query) return "";
|
|
817
|
+
const params = new URLSearchParams();
|
|
818
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
819
|
+
if (value !== void 0 && value !== null) params.append(key, String(value));
|
|
820
|
+
});
|
|
821
|
+
const str = params.toString();
|
|
822
|
+
return str ? `?${str}` : "";
|
|
823
|
+
};
|
|
824
|
+
const buildUrl = (baseURL, url, query) => {
|
|
825
|
+
const queryString = buildQueryString(query);
|
|
826
|
+
if (url.startsWith("http://") || url.startsWith("https://")) return `${url}${queryString}`;
|
|
827
|
+
return `${baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL}${url.startsWith("/") ? url : `/${url}`}${queryString}`;
|
|
828
|
+
};
|
|
829
|
+
const prepareBody = (body) => {
|
|
830
|
+
if (body === null || body === void 0) return void 0;
|
|
831
|
+
if (body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer || body instanceof Uint8Array || typeof body === "string") return body;
|
|
832
|
+
if (typeof body === "object") return body;
|
|
833
|
+
return String(body);
|
|
834
|
+
};
|
|
835
|
+
const normalizeMethod = (method) => {
|
|
836
|
+
const upper = method.toUpperCase();
|
|
837
|
+
if (!HTTP_METHODS.has(upper)) throw new Error(`Unsupported HTTP method for WASM client: ${method}`);
|
|
838
|
+
return upper;
|
|
839
|
+
};
|
|
840
|
+
const getErrorStatus = (error) => {
|
|
841
|
+
if (error instanceof WasmWebClientError) return error.statusCode;
|
|
842
|
+
if (typeof error === "object" && error !== null) {
|
|
843
|
+
const record = error;
|
|
844
|
+
if (typeof record.statusCode === "number") return record.statusCode;
|
|
845
|
+
if (typeof record.status === "number") return record.status;
|
|
846
|
+
}
|
|
847
|
+
return 0;
|
|
848
|
+
};
|
|
849
|
+
const getErrorData = (error) => {
|
|
850
|
+
if (error instanceof WasmWebClientError) return error.response?.data ?? null;
|
|
851
|
+
return null;
|
|
852
|
+
};
|
|
853
|
+
const getErrorMessage = (error) => {
|
|
854
|
+
if (error instanceof Error) return error.message;
|
|
855
|
+
return "WasmWebClient request failed";
|
|
856
|
+
};
|
|
857
|
+
const withAbortSignal = async (promise, signal, error) => {
|
|
858
|
+
if (!signal) return await promise;
|
|
859
|
+
if (signal.aborted) throw error();
|
|
860
|
+
return await new Promise((resolve, reject) => {
|
|
861
|
+
const onAbort = () => reject(error());
|
|
862
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
863
|
+
promise.then(resolve, reject).finally(() => {
|
|
864
|
+
signal.removeEventListener("abort", onAbort);
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
};
|
|
868
|
+
const createWasmApi = async (config) => {
|
|
869
|
+
const headers = buildWasmDefaultHeaders(config.customHeaders);
|
|
870
|
+
const isEncryptionEnabled = config.isEncryptionEnabled ?? (() => false);
|
|
871
|
+
const useSha256 = config.mgf1 === "sha256";
|
|
872
|
+
await initializeWasmWebClient(config.wasm);
|
|
873
|
+
try {
|
|
874
|
+
await setupWasmConnection(config.apiURL, "", config.encryptionEnabled ?? false, headers, useSha256);
|
|
875
|
+
} catch (error) {
|
|
876
|
+
if (!(error instanceof WasmWebClientError)) throw error;
|
|
877
|
+
throw reportHttpError(new WasmHttpError(error.statusCode, "", config.apiURL, "POST", {}, getErrorData(error)), headers);
|
|
878
|
+
}
|
|
879
|
+
const defaults = {
|
|
880
|
+
baseURL: config.apiURL,
|
|
881
|
+
headers
|
|
899
882
|
};
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
883
|
+
const client = {
|
|
884
|
+
defaults,
|
|
885
|
+
async request(requestConfig) {
|
|
886
|
+
const { method = "GET", url, headers: requestHeaders = {}, query, params, body, signal, timeout: timeoutOverride, onUploadProgress, ie = false } = requestConfig;
|
|
887
|
+
const upperMethod = normalizeMethod(method);
|
|
888
|
+
const requestParams = params ?? query;
|
|
889
|
+
const fullUrl = buildUrl(defaults.baseURL, url, requestParams);
|
|
890
|
+
const needsSchemeHeader = useSha256 && isEncryptionEnabled();
|
|
891
|
+
const mergedHeaders = {
|
|
892
|
+
...defaults.headers,
|
|
893
|
+
...needsSchemeHeader ? { "X-RSA-Encryption-Scheme": RSA_OAEP_SHA256_SCHEME } : {},
|
|
894
|
+
...requestHeaders
|
|
895
|
+
};
|
|
896
|
+
const requestBody = prepareBody(body);
|
|
897
|
+
const timeout = timeoutOverride ?? config.timeout ?? WASM_TIMEOUT_CEILING_MS;
|
|
898
|
+
const wasmProgress = onUploadProgress ? (progress) => {
|
|
899
|
+
if (progress.total > 0) onUploadProgress(Math.round(progress.loaded / progress.total * 100));
|
|
900
|
+
} : void 0;
|
|
901
|
+
const abortError = () => new WasmHttpError(0, "Request aborted", fullUrl, upperMethod, {}, null);
|
|
902
|
+
if (signal?.aborted) throw abortError();
|
|
903
|
+
try {
|
|
904
|
+
const response = await withAbortSignal(executeWasmRequest(upperMethod, url, requestBody, mergedHeaders, requestParams, timeout, wasmProgress, ie), signal, abortError);
|
|
905
|
+
if (response.status < 200 || response.status >= 300) throw reportHttpError(new WasmHttpError(response.status, "", fullUrl, upperMethod, {}, response.data), mergedHeaders);
|
|
906
|
+
return {
|
|
907
|
+
ok: true,
|
|
908
|
+
status: response.status,
|
|
909
|
+
statusText: "",
|
|
910
|
+
url: fullUrl,
|
|
911
|
+
headers: {},
|
|
912
|
+
data: response.data
|
|
913
|
+
};
|
|
914
|
+
} catch (error) {
|
|
915
|
+
if (error instanceof WasmHttpError) throw error;
|
|
916
|
+
throw reportHttpError(new WasmHttpError(getErrorStatus(error), getErrorMessage(error), fullUrl, upperMethod, {}, getErrorData(error)), mergedHeaders);
|
|
917
|
+
}
|
|
918
|
+
},
|
|
919
|
+
get(url, requestConfig) {
|
|
920
|
+
return client.request({
|
|
921
|
+
...requestConfig,
|
|
922
|
+
url,
|
|
923
|
+
method: "GET"
|
|
924
|
+
});
|
|
925
|
+
},
|
|
926
|
+
post(url, body, requestConfig) {
|
|
927
|
+
return client.request({
|
|
928
|
+
...requestConfig,
|
|
929
|
+
url,
|
|
930
|
+
body,
|
|
931
|
+
method: "POST"
|
|
932
|
+
});
|
|
933
|
+
},
|
|
934
|
+
put(url, body, requestConfig) {
|
|
935
|
+
return client.request({
|
|
936
|
+
...requestConfig,
|
|
937
|
+
url,
|
|
938
|
+
body,
|
|
939
|
+
method: "PUT"
|
|
940
|
+
});
|
|
941
|
+
},
|
|
942
|
+
patch(url, body, requestConfig) {
|
|
943
|
+
return client.request({
|
|
944
|
+
...requestConfig,
|
|
945
|
+
url,
|
|
946
|
+
body,
|
|
947
|
+
method: "PATCH"
|
|
948
|
+
});
|
|
949
|
+
},
|
|
950
|
+
delete(url, requestConfig) {
|
|
951
|
+
return client.request({
|
|
952
|
+
...requestConfig,
|
|
953
|
+
url,
|
|
954
|
+
method: "DELETE"
|
|
955
|
+
});
|
|
956
|
+
},
|
|
957
|
+
head() {
|
|
958
|
+
return Promise.reject(/* @__PURE__ */ new Error("HEAD is not supported by the WASM HTTP client"));
|
|
959
|
+
},
|
|
960
|
+
options() {
|
|
961
|
+
return Promise.reject(/* @__PURE__ */ new Error("OPTIONS is not supported by the WASM HTTP client"));
|
|
962
|
+
},
|
|
963
|
+
setHeader(name, value) {
|
|
964
|
+
defaults.headers[name] = value;
|
|
965
|
+
}
|
|
949
966
|
};
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
function readE2eEncryptionEnabled() {
|
|
953
|
-
try {
|
|
954
|
-
return sources.getE2eEncryptionEnabled?.() ?? false;
|
|
955
|
-
} catch {
|
|
956
|
-
return false;
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
/** Fail-open, like readE2eEncryptionEnabled. */
|
|
960
|
-
function readHasToken() {
|
|
961
|
-
try {
|
|
962
|
-
return sources.getHasToken?.() ?? false;
|
|
963
|
-
} catch {
|
|
964
|
-
return false;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
function resetTrueSightMetadata() {
|
|
968
|
-
state = createInitialState();
|
|
969
|
-
sources = {};
|
|
970
|
-
}
|
|
967
|
+
return client;
|
|
968
|
+
};
|
|
971
969
|
//#endregion
|
|
972
|
-
//#region src/internal/
|
|
973
|
-
/** Index slot listing sessionIds with pending entries (no enumeration API). */
|
|
974
|
-
const PENDING_INDEX_KEY = `${PENDING_STORAGE_KEY_PREFIX}index`;
|
|
975
|
-
function slotKey(sessionId) {
|
|
976
|
-
return `${PENDING_STORAGE_KEY_PREFIX}${sessionId}`;
|
|
977
|
-
}
|
|
970
|
+
//#region src/internal/http/clientLifecycle.ts
|
|
978
971
|
/**
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
972
|
+
* Wraps the active HttpClient as a transport for the C++ `WebApi` host
|
|
973
|
+
* adapter. Lets the on-device face-results POST flow through the same
|
|
974
|
+
* `httpClient.request()` pipeline as every other endpoint — header
|
|
975
|
+
* injection, encryption-state handling, default headers, timeout — instead
|
|
976
|
+
* of bypassing it via `executeWasmRequest` directly.
|
|
977
|
+
*
|
|
978
|
+
* Protected captures arrive with `ie === true`: the C++ `WebApi` already
|
|
979
|
+
* encrypted the body inline, and only the WASM `WebClient` can unwrap it. A
|
|
980
|
+
* plain fetch client would post the ciphertext as JSON and the backend
|
|
981
|
+
* answers 406. If the plain client is still installed at that point (the
|
|
982
|
+
* host called `setup()` without `wasm` and warmed WASM separately), swap to
|
|
983
|
+
* the WASM client first. The module is already loaded — the payload came
|
|
984
|
+
* out of it — so the swap only creates the `WebClient`.
|
|
982
985
|
*/
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
const
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
986
|
+
function bindWebApiTransport(client) {
|
|
987
|
+
return async (url, body, config) => {
|
|
988
|
+
const response = await (config.ie === true && storedHttpConfig && !storedHttpConfig.isWasm ? await ensureWasmHttpClient() : client).request({
|
|
989
|
+
method: "POST",
|
|
990
|
+
url,
|
|
991
|
+
body,
|
|
992
|
+
headers: config.headers,
|
|
993
|
+
params: config.params,
|
|
994
|
+
timeout: config.timeout,
|
|
995
|
+
ie: config.ie
|
|
996
|
+
});
|
|
997
|
+
return {
|
|
998
|
+
data: response.data,
|
|
999
|
+
status: response.status
|
|
1000
|
+
};
|
|
1001
|
+
};
|
|
989
1002
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
* slice of the async call, which is what makes this safe to fire (void) from
|
|
994
|
-
* a page-hide handler.
|
|
995
|
-
*/
|
|
996
|
-
async function writePendingEnvelope(sessionId, entry, deps) {
|
|
997
|
-
try {
|
|
998
|
-
await deps.storage.set(slotKey(sessionId), entry);
|
|
999
|
-
} catch {}
|
|
1003
|
+
function installClient(client) {
|
|
1004
|
+
setClient(client);
|
|
1005
|
+
setWebApiHttpTransport(bindWebApiTransport(client));
|
|
1000
1006
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
await deps.storage.remove(slotKey(sessionId));
|
|
1005
|
-
const index = await readIndex(deps.storage);
|
|
1006
|
-
if (index.includes(sessionId)) await deps.storage.set(PENDING_INDEX_KEY, index.filter((candidate) => candidate !== sessionId));
|
|
1007
|
-
} catch {}
|
|
1007
|
+
async function ensureWasmHttpClient() {
|
|
1008
|
+
await upgradeToWasmHttpClient(resolveWasmConfig());
|
|
1009
|
+
return getApi();
|
|
1008
1010
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
* record, consistent with no-retry). Entries at/past the retention ceiling
|
|
1015
|
-
* are deleted unsent (A4). Never rejects; returns the A5 loss counters.
|
|
1016
|
-
*/
|
|
1017
|
-
async function recoverPendingEnvelopes(options) {
|
|
1018
|
-
const { storage, post, currentSessionId } = options;
|
|
1019
|
-
const now = options.now ?? getTimestamp;
|
|
1020
|
-
const counters = {
|
|
1021
|
-
recovered: 0,
|
|
1022
|
-
gcExpired: 0
|
|
1023
|
-
};
|
|
1024
|
-
try {
|
|
1025
|
-
const index = await readIndex(storage);
|
|
1026
|
-
if (index.length === 0) return counters;
|
|
1027
|
-
const keptInIndex = [];
|
|
1028
|
-
for (const sessionId of index) {
|
|
1029
|
-
if (sessionId === currentSessionId) {
|
|
1030
|
-
keptInIndex.push(sessionId);
|
|
1031
|
-
continue;
|
|
1032
|
-
}
|
|
1033
|
-
const entry = await readEntry(storage, sessionId);
|
|
1034
|
-
if (entry === "missing") continue;
|
|
1035
|
-
if (entry === "corrupt") {
|
|
1036
|
-
counters.gcExpired += 1;
|
|
1037
|
-
continue;
|
|
1038
|
-
}
|
|
1039
|
-
const age = now() - entry.persistedAt;
|
|
1040
|
-
if (age >= 6048e5) {
|
|
1041
|
-
counters.gcExpired += 1;
|
|
1042
|
-
await storage.remove(slotKey(sessionId));
|
|
1043
|
-
continue;
|
|
1044
|
-
}
|
|
1045
|
-
if (age < 12e4) {
|
|
1046
|
-
keptInIndex.push(sessionId);
|
|
1047
|
-
continue;
|
|
1048
|
-
}
|
|
1049
|
-
await storage.remove(slotKey(sessionId));
|
|
1050
|
-
counters.recovered += 1;
|
|
1051
|
-
post(endpoints.diagnosticsData, entry.envelope, {}).catch(() => {});
|
|
1052
|
-
}
|
|
1053
|
-
await storage.set(PENDING_INDEX_KEY, keptInIndex);
|
|
1054
|
-
} catch {}
|
|
1055
|
-
return counters;
|
|
1011
|
+
let storedHttpConfig;
|
|
1012
|
+
let pendingUpgrade;
|
|
1013
|
+
/** Reads the current HTTP-client config (or `undefined` if none installed). */
|
|
1014
|
+
function getStoredHttpConfig() {
|
|
1015
|
+
return storedHttpConfig;
|
|
1056
1016
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
return index.filter((value) => typeof value === "string");
|
|
1017
|
+
/** Whether encryption is currently active on the installed HTTP client. */
|
|
1018
|
+
function isHttpEncrypted() {
|
|
1019
|
+
return storedHttpConfig?.encryption.enabled ?? false;
|
|
1061
1020
|
}
|
|
1062
|
-
/**
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
if (value === null) return "missing";
|
|
1067
|
-
if (typeof value === "object" && value.v === 1 && typeof value.persistedAt === "number" && typeof value.envelope === "object") return value;
|
|
1068
|
-
await storage.remove(slotKey(sessionId));
|
|
1069
|
-
return "corrupt";
|
|
1070
|
-
} catch {
|
|
1071
|
-
try {
|
|
1072
|
-
await storage.remove(slotKey(sessionId));
|
|
1073
|
-
} catch {}
|
|
1074
|
-
return "corrupt";
|
|
1075
|
-
}
|
|
1021
|
+
/** Clears all HTTP-client state. Called by `reset()`. */
|
|
1022
|
+
function resetHttpClientState() {
|
|
1023
|
+
storedHttpConfig = void 0;
|
|
1024
|
+
setWebApiHttpTransport(null);
|
|
1076
1025
|
}
|
|
1077
|
-
//#endregion
|
|
1078
|
-
//#region src/internal/featureConfig/featureConfigService.ts
|
|
1079
|
-
let cachedFeatures = null;
|
|
1080
1026
|
/**
|
|
1081
|
-
*
|
|
1027
|
+
* Builds (or replaces) the HTTP client when `setup()` receives an `apiURL`.
|
|
1028
|
+
* Picks `createWasmApi` when `effectiveWasm` is set, otherwise plain
|
|
1029
|
+
* `createApi`. Wraps the call in handshake-failure context when encryption
|
|
1030
|
+
* is requested.
|
|
1082
1031
|
*/
|
|
1083
|
-
function
|
|
1084
|
-
|
|
1032
|
+
async function installFreshHttpClient(apiURL, options, effectiveWasm, encryption) {
|
|
1033
|
+
installClient(effectiveWasm ? await withHandshakeFailureContext(encryption.enabled, () => createWasmApi({
|
|
1034
|
+
apiURL,
|
|
1035
|
+
customHeaders: options.customHeaders,
|
|
1036
|
+
timeout: options.timeout,
|
|
1037
|
+
wasm: effectiveWasm,
|
|
1038
|
+
encryptionEnabled: encryption.enabled,
|
|
1039
|
+
mgf1: encryption.mgf1,
|
|
1040
|
+
isEncryptionEnabled: isHttpEncrypted
|
|
1041
|
+
})) : createApi({
|
|
1042
|
+
apiURL,
|
|
1043
|
+
customHeaders: options.customHeaders,
|
|
1044
|
+
timeout: options.timeout
|
|
1045
|
+
}));
|
|
1046
|
+
storedHttpConfig = {
|
|
1047
|
+
apiURL,
|
|
1048
|
+
customHeaders: options.customHeaders,
|
|
1049
|
+
timeout: options.timeout,
|
|
1050
|
+
isWasm: Boolean(effectiveWasm),
|
|
1051
|
+
encryption
|
|
1052
|
+
};
|
|
1085
1053
|
}
|
|
1086
1054
|
/**
|
|
1087
|
-
*
|
|
1088
|
-
*
|
|
1055
|
+
* Replaces the active HTTP client with the WASM-backed one. Used internally
|
|
1056
|
+
* by lazy-loading UI components (`<incode-flow>`, `<incode-workflow>`) when
|
|
1057
|
+
* WASM finishes warming up.
|
|
1058
|
+
*
|
|
1059
|
+
* No-op when no apiURL was previously configured, or when the active client
|
|
1060
|
+
* is already WASM-backed. The encryption state (enabled + MGF1 scheme) is
|
|
1061
|
+
* preserved across the swap — this is *not* a user-facing encryption change.
|
|
1062
|
+
*
|
|
1063
|
+
* @internal NOT a public API. Application code should use
|
|
1064
|
+
* `setup({ wasm: {...} })` instead.
|
|
1089
1065
|
*/
|
|
1090
|
-
async function
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1066
|
+
async function upgradeToWasmHttpClient(resolved) {
|
|
1067
|
+
const stored = storedHttpConfig;
|
|
1068
|
+
if (!stored || stored.isWasm) return;
|
|
1069
|
+
pendingUpgrade ??= (async () => {
|
|
1070
|
+
installClient(await createWasmApi({
|
|
1071
|
+
apiURL: stored.apiURL,
|
|
1072
|
+
customHeaders: stored.customHeaders,
|
|
1073
|
+
timeout: stored.timeout,
|
|
1074
|
+
wasm: resolved,
|
|
1075
|
+
encryptionEnabled: stored.encryption.enabled,
|
|
1076
|
+
mgf1: stored.encryption.mgf1,
|
|
1077
|
+
isEncryptionEnabled: isHttpEncrypted
|
|
1078
|
+
}));
|
|
1079
|
+
storedHttpConfig = {
|
|
1080
|
+
...stored,
|
|
1081
|
+
isWasm: true
|
|
1082
|
+
};
|
|
1083
|
+
})().finally(() => {
|
|
1084
|
+
pendingUpgrade = void 0;
|
|
1085
|
+
});
|
|
1086
|
+
return pendingUpgrade;
|
|
1096
1087
|
}
|
|
1097
1088
|
/**
|
|
1098
|
-
*
|
|
1089
|
+
* When `wantsEncryption` is true, wraps a call that triggers the in-binary
|
|
1090
|
+
* RSA/AES handshake so its rejection surfaces as a single, descriptive error
|
|
1091
|
+
* with the original error preserved as `cause`. Pass-through otherwise.
|
|
1099
1092
|
*/
|
|
1100
|
-
function
|
|
1101
|
-
|
|
1093
|
+
async function withHandshakeFailureContext(wantsEncryption, fn) {
|
|
1094
|
+
if (!wantsEncryption) return fn();
|
|
1095
|
+
try {
|
|
1096
|
+
return await fn();
|
|
1097
|
+
} catch (cause) {
|
|
1098
|
+
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.");
|
|
1099
|
+
error.cause = cause;
|
|
1100
|
+
throw error;
|
|
1101
|
+
}
|
|
1102
1102
|
}
|
|
1103
1103
|
eventModuleNames.selfie, eventModuleNames.faceCapture, eventModuleNames.authentication, eventModuleNames.authFace, eventModuleNames.mlConsent, eventModuleNames.combinedConsent, eventModuleNames.curpValidation, eventModuleNames.faceMatch, eventModuleNames.qr, eventModuleNames.videoSelfie, eventModuleNames.id, eventModuleNames.idCapture, eventModuleNames.idVerification, eventModuleNames.idOcr, eventModuleNames.document, eventModuleNames.creditCard, eventModuleNames.creditCardBack, eventModuleNames.conference, eventModuleNames.otp, eventModuleNames.signature, eventModuleNames.ekyc, eventModuleNames.watchlist, eventModuleNames.globalWatchList, eventModuleNames.customWatchList, eventModuleNames.email, eventModuleNames.phone, eventModuleNames.instantVerifyEmail, eventModuleNames.instantVerifyConsent, eventModuleNames.forms, eventModuleNames.customModule, eventModuleNames.geolocation, eventModuleNames.ekyb, eventModuleNames.identityReuse, eventModuleNames.antifraud, eventModuleNames.aeSignature, eventModuleNames.qeSignature, eventModuleNames.crossDocumentDataMatch, eventModuleNames.customFields, eventModuleNames.fieldComparison, eventModuleNames.personhood, eventModuleNames.watchlistForBusiness, eventModuleNames.trustGraph, eventModuleNames.certificateIssuance, eventModuleNames.governmentValidation, eventModuleNames.documentUpload, eventModuleNames.home, eventModuleNames.workflow, eventModuleNames.fiscalQr;
|
|
1104
1104
|
eventModuleNames.id, eventModuleNames.idCapture, eventModuleNames.idVerification, eventModuleNames.idOcr, eventModuleNames.document, eventModuleNames.documentUpload, eventModuleNames.creditCard, eventModuleNames.creditCardBack, eventModuleNames.curpValidation;
|
|
@@ -1501,4 +1501,4 @@ function modulePosition(payload) {
|
|
|
1501
1501
|
return `${typeof moduleIndex === "number" ? ` index=${moduleIndex}` : ""}${typeof totalModules === "number" ? ` total=${totalModules}` : ""}`;
|
|
1502
1502
|
}
|
|
1503
1503
|
//#endregion
|
|
1504
|
-
export { DEFAULT_WASM_VERSION as C, resolveWasmConfig as D, getBarcodeEnhanceModelUrl as E,
|
|
1504
|
+
export { DEFAULT_WASM_VERSION as C, resolveWasmConfig as D, getBarcodeEnhanceModelUrl as E, noteTokenActivated as S, buildWasmConfigFromBasePath as T, resetFeatureConfigCache as _, notifyTrueSightManagerStopped as a, noteSessionCreated as b, trueSightHintTransition as c, getStoredHttpConfig as d, installFreshHttpClient as f, isFeatureEnabled as g, fetchFeatureConfig as h, notifyTrueSightFlowEvent as i, trueSightLog as l, upgradeToWasmHttpClient as m, initializeTrueSightDiagnostics as n, resetTrueSight as o, resetHttpClientState as p, noteTrueSightCaptureActivity as r, startTrueSightCollection as s, finalizeTrueSight as t, categoryForEndpoint as u, isTrueSightTesting as v, buildDefaultWasmConfig as w, noteTestingSignals as x, noteEnvironment as y };
|