@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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Didit SDK for Web v0.3.1
2
+ * Didit SDK for Web v0.4.0
3
3
  * (c) 2026 Didit
4
4
  * @license MIT
5
5
  */
@@ -24,7 +24,15 @@
24
24
  confirmBox: "didit-confirm-box",
25
25
  embedded: "didit-embedded"
26
26
  };
27
- const SDK_VERSION = "0.3.1";
27
+ const SDK_VERSION = "0.4.0";
28
+ /** The verification-URL query parameter each camera option is forwarded as. */
29
+ const CAMERA_QUERY_PARAMS = {
30
+ defaultDocumentCamera: "document_camera",
31
+ defaultLivenessCamera: "liveness_camera",
32
+ showDocumentCameraSwitchButton: "document_camera_switch",
33
+ showLivenessCameraSwitchButton: "liveness_camera_switch"
34
+ };
35
+ const CAMERA_LENSES = ["front", "back"];
28
36
  const languages = [
29
37
  "ar",
30
38
  "bg",
@@ -127,6 +135,61 @@
127
135
  message: customMessage || messages[type]
128
136
  };
129
137
  }
138
+ function isCameraLens(value) {
139
+ return CAMERA_LENSES.includes(value);
140
+ }
141
+ const CAMERA_LENS_OPTIONS = ["defaultDocumentCamera", "defaultLivenessCamera"];
142
+ const CAMERA_SWITCH_OPTIONS = ["showDocumentCameraSwitchButton", "showLivenessCameraSwitchButton"];
143
+ /**
144
+ * The URL the verification iframe loads: the integrator's URL with the
145
+ * configuration options the hosted page reads from its query string.
146
+ *
147
+ * The camera options (the same four the native SDKs expose) become query
148
+ * parameters: `defaultDocumentCamera` -> `document_camera=<lens>`,
149
+ * `defaultLivenessCamera` -> `liveness_camera=<lens>`,
150
+ * `showDocumentCameraSwitchButton` -> `document_camera_switch=true|false`,
151
+ * `showLivenessCameraSwitchButton` -> `liveness_camera_switch=true|false`.
152
+ * Each parameter is set (not appended) so the configuration wins over a value
153
+ * already on the URL; existing query parameters and the hash are kept. A
154
+ * value of the wrong shape is ignored with a warning rather than forwarded,
155
+ * and a URL the browser cannot parse is returned as it came (the modal
156
+ * reports it when it loads).
157
+ */
158
+ function buildVerificationUrl(url, configuration) {
159
+ if (!configuration)
160
+ return url;
161
+ const params = [];
162
+ for (const option of CAMERA_LENS_OPTIONS) {
163
+ const value = configuration[option];
164
+ if (value === undefined)
165
+ continue;
166
+ if (!isCameraLens(value)) {
167
+ SDKLogger.warn(`Ignoring ${option}: expected "front" or "back", got`, value);
168
+ continue;
169
+ }
170
+ params.push([CAMERA_QUERY_PARAMS[option], value]);
171
+ }
172
+ for (const option of CAMERA_SWITCH_OPTIONS) {
173
+ const value = configuration[option];
174
+ if (value === undefined)
175
+ continue;
176
+ if (typeof value !== "boolean") {
177
+ SDKLogger.warn(`Ignoring ${option}: expected a boolean, got`, value);
178
+ continue;
179
+ }
180
+ params.push([CAMERA_QUERY_PARAMS[option], value ? "true" : "false"]);
181
+ }
182
+ if (params.length === 0)
183
+ return url;
184
+ try {
185
+ const parsed = new URL(url);
186
+ params.forEach(([name, value]) => parsed.searchParams.set(name, value));
187
+ return parsed.toString();
188
+ }
189
+ catch {
190
+ return url;
191
+ }
192
+ }
130
193
  function detectLanguageFromUrl(url) {
131
194
  try {
132
195
  const { pathname } = new URL(url);
@@ -1861,7 +1924,7 @@
1861
1924
  if (!url || typeof url !== "string") {
1862
1925
  throw new Error("Invalid options: url is required");
1863
1926
  }
1864
- this._url = url;
1927
+ this._url = buildVerificationUrl(url, config);
1865
1928
  this.setState("loading");
1866
1929
  this.emitInternalEvent("didit:started", {});
1867
1930
  this._modal?.open(this._url);