Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/recognize-wasm-default-urls.md
Original file line number Diff line number Diff line change
@@ -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.
31 changes: 16 additions & 15 deletions packages/recognize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
8 changes: 8 additions & 0 deletions packages/recognize/src/lib/defs/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
15 changes: 11 additions & 4 deletions packages/recognize/src/lib/functions/set-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -42,15 +48,16 @@ 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;
element.serviceURL = config.serviceURL;
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;
}
6 changes: 6 additions & 0 deletions packages/recognize/src/lib/recognize.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading