@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/dist/didit-sdk.esm.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
|
*/
|
|
@@ -18,7 +18,15 @@ const CSS_CLASSES = {
|
|
|
18
18
|
confirmBox: "didit-confirm-box",
|
|
19
19
|
embedded: "didit-embedded"
|
|
20
20
|
};
|
|
21
|
-
const SDK_VERSION = "0.
|
|
21
|
+
const SDK_VERSION = "0.4.0";
|
|
22
|
+
/** The verification-URL query parameter each camera option is forwarded as. */
|
|
23
|
+
const CAMERA_QUERY_PARAMS = {
|
|
24
|
+
defaultDocumentCamera: "document_camera",
|
|
25
|
+
defaultLivenessCamera: "liveness_camera",
|
|
26
|
+
showDocumentCameraSwitchButton: "document_camera_switch",
|
|
27
|
+
showLivenessCameraSwitchButton: "liveness_camera_switch"
|
|
28
|
+
};
|
|
29
|
+
const CAMERA_LENSES = ["front", "back"];
|
|
22
30
|
const languages = [
|
|
23
31
|
"ar",
|
|
24
32
|
"bg",
|
|
@@ -121,6 +129,61 @@ function createVerificationError(type, customMessage) {
|
|
|
121
129
|
message: customMessage || messages[type]
|
|
122
130
|
};
|
|
123
131
|
}
|
|
132
|
+
function isCameraLens(value) {
|
|
133
|
+
return CAMERA_LENSES.includes(value);
|
|
134
|
+
}
|
|
135
|
+
const CAMERA_LENS_OPTIONS = ["defaultDocumentCamera", "defaultLivenessCamera"];
|
|
136
|
+
const CAMERA_SWITCH_OPTIONS = ["showDocumentCameraSwitchButton", "showLivenessCameraSwitchButton"];
|
|
137
|
+
/**
|
|
138
|
+
* The URL the verification iframe loads: the integrator's URL with the
|
|
139
|
+
* configuration options the hosted page reads from its query string.
|
|
140
|
+
*
|
|
141
|
+
* The camera options (the same four the native SDKs expose) become query
|
|
142
|
+
* parameters: `defaultDocumentCamera` -> `document_camera=<lens>`,
|
|
143
|
+
* `defaultLivenessCamera` -> `liveness_camera=<lens>`,
|
|
144
|
+
* `showDocumentCameraSwitchButton` -> `document_camera_switch=true|false`,
|
|
145
|
+
* `showLivenessCameraSwitchButton` -> `liveness_camera_switch=true|false`.
|
|
146
|
+
* Each parameter is set (not appended) so the configuration wins over a value
|
|
147
|
+
* already on the URL; existing query parameters and the hash are kept. A
|
|
148
|
+
* value of the wrong shape is ignored with a warning rather than forwarded,
|
|
149
|
+
* and a URL the browser cannot parse is returned as it came (the modal
|
|
150
|
+
* reports it when it loads).
|
|
151
|
+
*/
|
|
152
|
+
function buildVerificationUrl(url, configuration) {
|
|
153
|
+
if (!configuration)
|
|
154
|
+
return url;
|
|
155
|
+
const params = [];
|
|
156
|
+
for (const option of CAMERA_LENS_OPTIONS) {
|
|
157
|
+
const value = configuration[option];
|
|
158
|
+
if (value === undefined)
|
|
159
|
+
continue;
|
|
160
|
+
if (!isCameraLens(value)) {
|
|
161
|
+
SDKLogger.warn(`Ignoring ${option}: expected "front" or "back", got`, value);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
params.push([CAMERA_QUERY_PARAMS[option], value]);
|
|
165
|
+
}
|
|
166
|
+
for (const option of CAMERA_SWITCH_OPTIONS) {
|
|
167
|
+
const value = configuration[option];
|
|
168
|
+
if (value === undefined)
|
|
169
|
+
continue;
|
|
170
|
+
if (typeof value !== "boolean") {
|
|
171
|
+
SDKLogger.warn(`Ignoring ${option}: expected a boolean, got`, value);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
params.push([CAMERA_QUERY_PARAMS[option], value ? "true" : "false"]);
|
|
175
|
+
}
|
|
176
|
+
if (params.length === 0)
|
|
177
|
+
return url;
|
|
178
|
+
try {
|
|
179
|
+
const parsed = new URL(url);
|
|
180
|
+
params.forEach(([name, value]) => parsed.searchParams.set(name, value));
|
|
181
|
+
return parsed.toString();
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return url;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
124
187
|
function detectLanguageFromUrl(url) {
|
|
125
188
|
try {
|
|
126
189
|
const { pathname } = new URL(url);
|
|
@@ -1855,7 +1918,7 @@ class DiditSdk {
|
|
|
1855
1918
|
if (!url || typeof url !== "string") {
|
|
1856
1919
|
throw new Error("Invalid options: url is required");
|
|
1857
1920
|
}
|
|
1858
|
-
this._url = url;
|
|
1921
|
+
this._url = buildVerificationUrl(url, config);
|
|
1859
1922
|
this.setState("loading");
|
|
1860
1923
|
this.emitInternalEvent("didit:started", {});
|
|
1861
1924
|
this._modal?.open(this._url);
|