@didit-protocol/sdk-web 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/dist/didit-sdk.cjs.js +66 -3
- package/dist/didit-sdk.cjs.js.map +1 -1
- package/dist/didit-sdk.esm.js +66 -3
- package/dist/didit-sdk.esm.js.map +1 -1
- package/dist/didit-sdk.umd.js +66 -3
- package/dist/didit-sdk.umd.js.map +1 -1
- package/dist/didit-sdk.umd.min.js +2 -2
- package/dist/didit-sdk.umd.min.js.map +1 -1
- package/dist/index.d.ts +41 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -183,9 +183,65 @@ interface DiditSdkConfiguration {
|
|
|
183
183
|
* Required when embedded is true
|
|
184
184
|
*/
|
|
185
185
|
embeddedContainerId?: string;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Camera the document capture opens first: "front" or "back"
|
|
189
|
+
* @default "back"
|
|
190
|
+
*/
|
|
191
|
+
defaultDocumentCamera?: CameraLens;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Camera the face (liveness) capture opens first: "front" or "back"
|
|
195
|
+
* Applies to passive liveness; devices without a rear camera keep the front one
|
|
196
|
+
* @default "front"
|
|
197
|
+
*/
|
|
198
|
+
defaultLivenessCamera?: CameraLens;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Show the in-capture camera switcher on the document step
|
|
202
|
+
* false locks the user to defaultDocumentCamera
|
|
203
|
+
* @default true
|
|
204
|
+
*/
|
|
205
|
+
showDocumentCameraSwitchButton?: boolean;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Show the in-capture camera switcher on the liveness step
|
|
209
|
+
* false locks the user to defaultLivenessCamera
|
|
210
|
+
* @default true
|
|
211
|
+
*/
|
|
212
|
+
showLivenessCameraSwitchButton?: boolean;
|
|
186
213
|
}
|
|
214
|
+
|
|
215
|
+
type CameraLens = "front" | "back";
|
|
187
216
|
```
|
|
188
217
|
|
|
218
|
+
## Camera Options
|
|
219
|
+
|
|
220
|
+
The same four camera options the native SDKs expose. By default the document capture opens the rear camera and the face capture opens the front (selfie) camera, and both steps offer an in-capture camera switcher on devices with more than one camera.
|
|
221
|
+
|
|
222
|
+
| Option | Type | Default | Description |
|
|
223
|
+
|--------|------|---------|-------------|
|
|
224
|
+
| `defaultDocumentCamera` | `CameraLens` | `'back'` | Lens used when first entering the document capture screen |
|
|
225
|
+
| `defaultLivenessCamera` | `CameraLens` | `'front'` | Lens used when first entering the liveness (passive face) capture screen |
|
|
226
|
+
| `showDocumentCameraSwitchButton` | `boolean` | `true` | Show the in-capture camera switcher on the document screen; `false` locks the user to `defaultDocumentCamera` |
|
|
227
|
+
| `showLivenessCameraSwitchButton` | `boolean` | `true` | Show the in-capture camera switcher on the liveness screen; `false` locks the user to `defaultLivenessCamera` |
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// A kiosk: the operator points the device at the person, on the rear camera, with no way to switch
|
|
231
|
+
DiditSdk.shared.startVerification({
|
|
232
|
+
url,
|
|
233
|
+
configuration: {
|
|
234
|
+
defaultLivenessCamera: 'back',
|
|
235
|
+
showLivenessCameraSwitchButton: false
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
- `CameraLens` is `'front'` or `'back'`; any other value is ignored, as is a non-boolean switcher flag.
|
|
241
|
+
- A device without the requested camera keeps the one it has (a laptop asked for `'back'` still uses its webcam), and the switcher is hidden on single-camera devices regardless of the flags.
|
|
242
|
+
- The liveness options apply to the passive liveness check. Active liveness is not affected.
|
|
243
|
+
- The SDK forwards the options to the verification page as query parameters of the verification URL: `document_camera`, `liveness_camera`, `document_camera_switch` and `liveness_camera_switch`. If you open the verification URL directly instead of through the SDK, set them on the URL yourself (with `&` when the URL already has a query string, or through the `URL` API's `searchParams`).
|
|
244
|
+
|
|
189
245
|
## Modal Sizing
|
|
190
246
|
|
|
191
247
|
Modal mode uses a maximum width of 500px and a maximum height of 700px. On shorter desktop and landscape viewports, the iframe tracks 90% of the visible viewport so the modal never extends beyond its container. The hosted flow owns the scrollbar inside the iframe, keeping later steps reachable without scrolling the page behind the modal.
|
package/dist/didit-sdk.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Didit SDK for Web v0.
|
|
2
|
+
* Didit SDK for Web v0.4.0
|
|
3
3
|
* (c) 2026 Didit
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -22,7 +22,15 @@ const CSS_CLASSES = {
|
|
|
22
22
|
confirmBox: "didit-confirm-box",
|
|
23
23
|
embedded: "didit-embedded"
|
|
24
24
|
};
|
|
25
|
-
const SDK_VERSION = "0.
|
|
25
|
+
const SDK_VERSION = "0.4.0";
|
|
26
|
+
/** The verification-URL query parameter each camera option is forwarded as. */
|
|
27
|
+
const CAMERA_QUERY_PARAMS = {
|
|
28
|
+
defaultDocumentCamera: "document_camera",
|
|
29
|
+
defaultLivenessCamera: "liveness_camera",
|
|
30
|
+
showDocumentCameraSwitchButton: "document_camera_switch",
|
|
31
|
+
showLivenessCameraSwitchButton: "liveness_camera_switch"
|
|
32
|
+
};
|
|
33
|
+
const CAMERA_LENSES = ["front", "back"];
|
|
26
34
|
const languages = [
|
|
27
35
|
"ar",
|
|
28
36
|
"bg",
|
|
@@ -125,6 +133,61 @@ function createVerificationError(type, customMessage) {
|
|
|
125
133
|
message: customMessage || messages[type]
|
|
126
134
|
};
|
|
127
135
|
}
|
|
136
|
+
function isCameraLens(value) {
|
|
137
|
+
return CAMERA_LENSES.includes(value);
|
|
138
|
+
}
|
|
139
|
+
const CAMERA_LENS_OPTIONS = ["defaultDocumentCamera", "defaultLivenessCamera"];
|
|
140
|
+
const CAMERA_SWITCH_OPTIONS = ["showDocumentCameraSwitchButton", "showLivenessCameraSwitchButton"];
|
|
141
|
+
/**
|
|
142
|
+
* The URL the verification iframe loads: the integrator's URL with the
|
|
143
|
+
* configuration options the hosted page reads from its query string.
|
|
144
|
+
*
|
|
145
|
+
* The camera options (the same four the native SDKs expose) become query
|
|
146
|
+
* parameters: `defaultDocumentCamera` -> `document_camera=<lens>`,
|
|
147
|
+
* `defaultLivenessCamera` -> `liveness_camera=<lens>`,
|
|
148
|
+
* `showDocumentCameraSwitchButton` -> `document_camera_switch=true|false`,
|
|
149
|
+
* `showLivenessCameraSwitchButton` -> `liveness_camera_switch=true|false`.
|
|
150
|
+
* Each parameter is set (not appended) so the configuration wins over a value
|
|
151
|
+
* already on the URL; existing query parameters and the hash are kept. A
|
|
152
|
+
* value of the wrong shape is ignored with a warning rather than forwarded,
|
|
153
|
+
* and a URL the browser cannot parse is returned as it came (the modal
|
|
154
|
+
* reports it when it loads).
|
|
155
|
+
*/
|
|
156
|
+
function buildVerificationUrl(url, configuration) {
|
|
157
|
+
if (!configuration)
|
|
158
|
+
return url;
|
|
159
|
+
const params = [];
|
|
160
|
+
for (const option of CAMERA_LENS_OPTIONS) {
|
|
161
|
+
const value = configuration[option];
|
|
162
|
+
if (value === undefined)
|
|
163
|
+
continue;
|
|
164
|
+
if (!isCameraLens(value)) {
|
|
165
|
+
SDKLogger.warn(`Ignoring ${option}: expected "front" or "back", got`, value);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
params.push([CAMERA_QUERY_PARAMS[option], value]);
|
|
169
|
+
}
|
|
170
|
+
for (const option of CAMERA_SWITCH_OPTIONS) {
|
|
171
|
+
const value = configuration[option];
|
|
172
|
+
if (value === undefined)
|
|
173
|
+
continue;
|
|
174
|
+
if (typeof value !== "boolean") {
|
|
175
|
+
SDKLogger.warn(`Ignoring ${option}: expected a boolean, got`, value);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
params.push([CAMERA_QUERY_PARAMS[option], value ? "true" : "false"]);
|
|
179
|
+
}
|
|
180
|
+
if (params.length === 0)
|
|
181
|
+
return url;
|
|
182
|
+
try {
|
|
183
|
+
const parsed = new URL(url);
|
|
184
|
+
params.forEach(([name, value]) => parsed.searchParams.set(name, value));
|
|
185
|
+
return parsed.toString();
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return url;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
128
191
|
function detectLanguageFromUrl(url) {
|
|
129
192
|
try {
|
|
130
193
|
const { pathname } = new URL(url);
|
|
@@ -1859,7 +1922,7 @@ class DiditSdk {
|
|
|
1859
1922
|
if (!url || typeof url !== "string") {
|
|
1860
1923
|
throw new Error("Invalid options: url is required");
|
|
1861
1924
|
}
|
|
1862
|
-
this._url = url;
|
|
1925
|
+
this._url = buildVerificationUrl(url, config);
|
|
1863
1926
|
this.setState("loading");
|
|
1864
1927
|
this.emitInternalEvent("didit:started", {});
|
|
1865
1928
|
this._modal?.open(this._url);
|