@didit-protocol/sdk-web 0.3.0 → 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 CHANGED
@@ -28,6 +28,18 @@ yarn add @didit-protocol/sdk-web
28
28
  <script src="https://unpkg.com/@didit-protocol/sdk-web/dist/didit-sdk.umd.min.js"></script>
29
29
  ```
30
30
 
31
+ ## Package Version
32
+
33
+ Inspect the installed SDK version at runtime:
34
+
35
+ ```typescript
36
+ import { SDK_VERSION } from '@didit-protocol/sdk-web';
37
+
38
+ console.log(SDK_VERSION);
39
+ ```
40
+
41
+ `SDK_VERSION` is injected from `package.json` during the build. Release maintainers should update the package with `npm version <version> --no-git-tag-version`, then run `npm run test:build-version`. That check validates ESM, CommonJS, UMD, minified UMD, and the emitted TypeScript declaration against both the current version and a simulated future version.
42
+
31
43
  ## Quick Start
32
44
 
33
45
  ### ES Modules / TypeScript
@@ -171,12 +183,74 @@ interface DiditSdkConfiguration {
171
183
  * Required when embedded is true
172
184
  */
173
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;
174
213
  }
214
+
215
+ type CameraLens = "front" | "back";
175
216
  ```
176
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
+
245
+ ## Modal Sizing
246
+
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.
248
+
249
+ Browsers that support dynamic viewport units use `dvh`, while older supported browsers fall back to `vh`. At widths of 540px and below, the modal fills the visible viewport. The close button and exit confirmation stay inside the modal at every size.
250
+
177
251
  ## Embedded Mode
178
252
 
179
- Render verification inline instead of a modal overlay:
253
+ Render verification inline instead of a modal overlay. Embedded mode does not apply the modal's 500px by 700px cap; the SDK fills the host element's content box. Give the host an explicit or otherwise resolved height:
180
254
 
181
255
  ```html
182
256
  <div id="verification-container" style="width: 500px; height: 700px;"></div>
@@ -192,6 +266,8 @@ DiditSdk.shared.startVerification({
192
266
  });
193
267
  ```
194
268
 
269
+ If the host element has no resolved height, the embedded iframe also has no usable height. Resize the host element when your layout changes; the SDK continues to fill it automatically.
270
+
195
271
  ## Verification Results
196
272
 
197
273
  The SDK returns three types of results:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Didit SDK for Web v0.3.0
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.2.1";
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);
@@ -646,6 +709,7 @@ class VerificationModal {
646
709
  position: relative;
647
710
  width: 100%;
648
711
  max-width: 500px;
712
+ max-height: 90vh;
649
713
  max-height: 90dvh;
650
714
  border-radius: 16px;
651
715
  overflow: hidden;
@@ -658,7 +722,9 @@ class VerificationModal {
658
722
 
659
723
  .${CSS_CLASSES.iframe} {
660
724
  width: 100%;
661
- height: 700px;
725
+ height: 90vh;
726
+ height: 90dvh;
727
+ max-height: 700px;
662
728
  border: none;
663
729
  display: block;
664
730
  }
@@ -816,12 +882,15 @@ class VerificationModal {
816
882
 
817
883
  .${CSS_CLASSES.container} {
818
884
  max-width: 100%;
885
+ max-height: 100vh;
819
886
  max-height: 100dvh;
820
887
  border-radius: 0;
821
888
  }
822
889
 
823
890
  .${CSS_CLASSES.iframe} {
891
+ height: 100vh;
824
892
  height: 100dvh;
893
+ max-height: none;
825
894
  }
826
895
  }
827
896
 
@@ -834,6 +903,7 @@ class VerificationModal {
834
903
  .${CSS_CLASSES.embedded} .${CSS_CLASSES.iframe} {
835
904
  width: 100%;
836
905
  height: 100%;
906
+ max-height: none;
837
907
  }
838
908
 
839
909
  .${CSS_CLASSES.embedded} .${CSS_CLASSES.loading} {
@@ -1852,7 +1922,7 @@ class DiditSdk {
1852
1922
  if (!url || typeof url !== "string") {
1853
1923
  throw new Error("Invalid options: url is required");
1854
1924
  }
1855
- this._url = url;
1925
+ this._url = buildVerificationUrl(url, config);
1856
1926
  this.setState("loading");
1857
1927
  this.emitInternalEvent("didit:started", {});
1858
1928
  this._modal?.open(this._url);