diff --git a/.changeset/recognize-wasm-default-urls.md b/.changeset/recognize-wasm-default-urls.md new file mode 100644 index 00000000000..b38ffdad43b --- /dev/null +++ b/.changeset/recognize-wasm-default-urls.md @@ -0,0 +1,7 @@ +--- +'@forgerock/recognize': minor +--- + +Default `wasmBinaryURL`, `wasmDataURL` and `wasmScriptURL` to the vendored SDK files when not provided, so bundlers like webpack can resolve them instead of failing with unfetchable `file://` paths. + +Accept `operationId` as an alias of `operationID`, matching the casing the server sends in `webSDKOptions`. `operationID` is unchanged and wins when both are set. diff --git a/packages/recognize/README.md b/packages/recognize/README.md index e5265fe7c96..3b6de9d2041 100644 --- a/packages/recognize/README.md +++ b/packages/recognize/README.md @@ -39,18 +39,19 @@ client.dispose(); ## Configuration -| Option | Type | Required | Description | -| -------------------------- | ---------- | -------- | ------------------------------ | -| `customer` | `string` | Yes | Customer identifier | -| `serviceURL` | `string` | Yes | URL of the recognition service | -| `authorizationToken` | `string` | No | Authorization token | -| `lang` | `string` | No | Language code for the UI | -| `theme` | `unknown` | No | Theme object | -| `disableSteps` | `string[]` | No | Steps to skip in the flow | -| `enableCameraFlash` | `boolean` | No | Enable camera flash | -| `enableCameraInstructions` | `boolean` | No | Show camera instructions | -| `disableLogger` | `boolean` | No | Disable internal logging | -| `disablePoweredBy` | `boolean` | No | Hide the "Powered by" badge | -| `enableWasmPthreads` | `boolean` | No | Enable WASM pthreads | -| `operationID` | `string` | No | Custom operation ID | -| `transactionData` | `string` | No | Transaction data string | +| Option | Type | Required | Description | +| -------------------------- | ---------- | -------- | --------------------------------------------- | +| `customer` | `string` | Yes | Customer identifier | +| `serviceURL` | `string` | Yes | URL of the recognition service | +| `authorizationToken` | `string` | No | Authorization token | +| `lang` | `string` | No | Language code for the UI | +| `theme` | `unknown` | No | Theme object | +| `disableSteps` | `string[]` | No | Steps to skip in the flow | +| `enableCameraFlash` | `boolean` | No | Enable camera flash | +| `enableCameraInstructions` | `boolean` | No | Show camera instructions | +| `disableLogger` | `boolean` | No | Disable internal logging | +| `disablePoweredBy` | `boolean` | No | Hide the "Powered by" badge | +| `enableWasmPthreads` | `boolean` | No | Enable WASM pthreads | +| `operationID` | `string` | No | Custom operation ID | +| `operationId` | `string` | No | Alias of `operationID`, as sent by the server | +| `transactionData` | `string` | No | Transaction data string | diff --git a/packages/recognize/src/lib/defs/constants.ts b/packages/recognize/src/lib/defs/constants.ts index 93af5232b76..6cce9d284f4 100644 --- a/packages/recognize/src/lib/defs/constants.ts +++ b/packages/recognize/src/lib/defs/constants.ts @@ -20,3 +20,11 @@ export const CAMERA_ONLY_DISABLE_STEPS: KeylessComponentsStep[] = [ 'stm-choice', 'stm-qrcode', ]; + +/** @internal */ +// Webpack rewrites import.meta.url in the vendored SDK to a file:// path the browser cannot +// fetch; a literal new URL(..., import.meta.url) here lets webpack resolve the WASM files +// and emit them as assets. +export const DEFAULT_WASM_BINARY_URL = new URL('../recognize-sdk/wasm.wasm', import.meta.url).href; +export const DEFAULT_WASM_DATA_URL = new URL('../recognize-sdk/wasm.data', import.meta.url).href; +export const DEFAULT_WASM_SCRIPT_URL = new URL('../recognize-sdk/wasm.js', import.meta.url).href; diff --git a/packages/recognize/src/lib/functions/set-attributes.ts b/packages/recognize/src/lib/functions/set-attributes.ts index 2f2a48d5c23..6eec995da2b 100644 --- a/packages/recognize/src/lib/functions/set-attributes.ts +++ b/packages/recognize/src/lib/functions/set-attributes.ts @@ -7,6 +7,12 @@ * */ +import { + DEFAULT_WASM_BINARY_URL, + DEFAULT_WASM_DATA_URL, + DEFAULT_WASM_SCRIPT_URL, +} from '../defs/constants.js'; + import type { RecognizeWebComponent, RecognizeWebComponentConfiguration, @@ -42,7 +48,8 @@ export function setAttributes( if (config.localizationVariables !== undefined) element.localizationVariables = config.localizationVariables; if (config.loggerLevel !== undefined) element.loggerLevel = config.loggerLevel; - if (config.operationID !== undefined) element.operationID = config.operationID; + const operationId = config.operationID ?? config.operationId; + if (operationId !== undefined) element.operationID = operationId; if (config.requestRecognitionFrame !== undefined) element.requestRecognitionFrame = config.requestRecognitionFrame; if (config.seedEntropy !== undefined) element.seedEntropy = config.seedEntropy; @@ -50,7 +57,7 @@ export function setAttributes( if (config.theme !== undefined) element.theme = config.theme; if (config.themeOptions !== undefined) element.themeOptions = config.themeOptions; if (config.transactionData !== undefined) element.transactionData = config.transactionData; - if (config.wasmBinaryURL !== undefined) element.wasmBinaryURL = config.wasmBinaryURL; - if (config.wasmDataURL !== undefined) element.wasmDataURL = config.wasmDataURL; - if (config.wasmScriptURL !== undefined) element.wasmScriptURL = config.wasmScriptURL; + element.wasmBinaryURL = config.wasmBinaryURL ?? DEFAULT_WASM_BINARY_URL; + element.wasmDataURL = config.wasmDataURL ?? DEFAULT_WASM_DATA_URL; + element.wasmScriptURL = config.wasmScriptURL ?? DEFAULT_WASM_SCRIPT_URL; } diff --git a/packages/recognize/src/lib/recognize.types.ts b/packages/recognize/src/lib/recognize.types.ts index bba0504ad19..3c456a301e6 100644 --- a/packages/recognize/src/lib/recognize.types.ts +++ b/packages/recognize/src/lib/recognize.types.ts @@ -99,6 +99,12 @@ export interface RecognizeWebComponentConfiguration { localizationVariables?: LocalizationVariables; loggerLevel?: LoggerLevel; operationID?: string; + /** + * Alias of `operationID`. The DaVinci server sends the operation ID as `operationId` in + * `webSDKOptions`, while the web component property is `operationID`, so both spellings are + * accepted. When both are set, `operationID` wins. + */ + operationId?: string; requestRecognitionFrame?: boolean; seedEntropy?: boolean; serviceURL: string;