@didit-protocol/sdk-web 0.5.0 → 0.5.1
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 +14 -0
- package/dist/didit-sdk.cjs +50 -14
- package/dist/didit-sdk.cjs.js +50 -14
- package/dist/didit-sdk.cjs.js.map +1 -1
- package/dist/didit-sdk.cjs.map +1 -1
- package/dist/didit-sdk.esm.js +53 -14
- package/dist/didit-sdk.esm.js.map +1 -1
- package/dist/didit-sdk.module.js +50 -14
- package/dist/didit-sdk.module.js.map +1 -1
- package/dist/didit-sdk.umd.js +53 -14
- 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 +1 -1
- package/package.json +3 -2
package/dist/didit-sdk.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Didit SDK for Web v0.5.
|
|
2
|
+
* Didit SDK for Web v0.5.1
|
|
3
3
|
* (c) 2026 Didit
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -732,6 +732,9 @@
|
|
|
732
732
|
if (!isRecord(event) || !event.category || typeof event.actionType !== "string" || !event.actionType.trim()) {
|
|
733
733
|
throw new DiditEventError("validation", "event.category and event.actionType are required.");
|
|
734
734
|
}
|
|
735
|
+
if (event.occurredAt instanceof Date && Number.isNaN(event.occurredAt.getTime())) {
|
|
736
|
+
throw new DiditEventError("validation", "event.occurredAt must be a valid date.");
|
|
737
|
+
}
|
|
735
738
|
if (typeof fetch !== "function") {
|
|
736
739
|
throw new DiditEventError("network", "fetch is not available in this environment.");
|
|
737
740
|
}
|
|
@@ -795,13 +798,14 @@
|
|
|
795
798
|
confirmBox: "didit-confirm-box",
|
|
796
799
|
embedded: "didit-embedded"
|
|
797
800
|
};
|
|
798
|
-
const SDK_VERSION = "0.5.
|
|
801
|
+
const SDK_VERSION = "0.5.1";
|
|
799
802
|
/**
|
|
800
803
|
* The permissions the verification iframe gets, in a modal and embedded:
|
|
801
|
-
* camera and microphone for capture,
|
|
802
|
-
* buttons
|
|
804
|
+
* camera and microphone for capture, clipboard-write for the flow's copy
|
|
805
|
+
* buttons, and digital-credentials-get so the flow can ask a digital ID wallet
|
|
806
|
+
* (Google Wallet) through the W3C Digital Credentials API from inside the iframe.
|
|
803
807
|
*/
|
|
804
|
-
const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write";
|
|
808
|
+
const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write; digital-credentials-get";
|
|
805
809
|
/** The verification-URL query parameter each camera option is forwarded as. */
|
|
806
810
|
const CAMERA_QUERY_PARAMS = {
|
|
807
811
|
defaultDocumentCamera: "document_camera",
|
|
@@ -1816,6 +1820,9 @@
|
|
|
1816
1820
|
max-width: max(300px, 18.75rem);
|
|
1817
1821
|
margin: auto;
|
|
1818
1822
|
overflow-wrap: anywhere;
|
|
1823
|
+
/* Focusing the dialog scrolls it into view start-aligned; this keeps
|
|
1824
|
+
* the overlay's top padding visible so the title is never clipped. */
|
|
1825
|
+
scroll-margin-top: 1rem;
|
|
1819
1826
|
}
|
|
1820
1827
|
|
|
1821
1828
|
.${CSS_CLASSES.flowSized} .didit-confirm-actions {
|
|
@@ -2600,6 +2607,23 @@
|
|
|
2600
2607
|
return latest;
|
|
2601
2608
|
}
|
|
2602
2609
|
|
|
2610
|
+
/**
|
|
2611
|
+
* Embedded mode renders inside an element that already exists on the
|
|
2612
|
+
* integrator's page. Without it the modal never shows anything (embedded mode
|
|
2613
|
+
* never activates the overlay), so the launch fails with a message the
|
|
2614
|
+
* integrator can act on instead of silently presenting nothing.
|
|
2615
|
+
*/
|
|
2616
|
+
function assertEmbeddedHostExists(configuration) {
|
|
2617
|
+
if (!configuration?.embedded)
|
|
2618
|
+
return;
|
|
2619
|
+
const containerId = configuration.embeddedContainerId;
|
|
2620
|
+
if (!containerId) {
|
|
2621
|
+
throw new Error("Embedded mode requires embeddedContainerId: the id of the element that hosts the verification.");
|
|
2622
|
+
}
|
|
2623
|
+
if (typeof document === "undefined" || !document.getElementById(containerId)) {
|
|
2624
|
+
throw new Error(`Embedded container "#${containerId}" was not found in the page.`);
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2603
2627
|
class DiditSdk {
|
|
2604
2628
|
static get shared() {
|
|
2605
2629
|
if (!DiditSdk._instance) {
|
|
@@ -2659,17 +2683,20 @@
|
|
|
2659
2683
|
this._modal.destroy();
|
|
2660
2684
|
this._modal = null;
|
|
2661
2685
|
}
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
onCloseConfirmed: () => this.handleModalCloseConfirmed(),
|
|
2665
|
-
onMessage: (event) => this.handleVerificationEvent(event),
|
|
2666
|
-
onIframeLoad: () => this.handleIframeLoad()
|
|
2667
|
-
});
|
|
2686
|
+
// A new launch is not in an error state any more, whatever the last one did.
|
|
2687
|
+
this._errorMessage = undefined;
|
|
2668
2688
|
try {
|
|
2669
2689
|
const { url } = options;
|
|
2670
2690
|
if (!url || typeof url !== "string") {
|
|
2671
2691
|
throw new Error("Invalid options: url is required");
|
|
2672
2692
|
}
|
|
2693
|
+
assertEmbeddedHostExists(config);
|
|
2694
|
+
this._modal = new VerificationModal(config, {
|
|
2695
|
+
onClose: () => this.handleModalClose(),
|
|
2696
|
+
onCloseConfirmed: () => this.handleModalCloseConfirmed(),
|
|
2697
|
+
onMessage: (event) => this.handleVerificationEvent(event),
|
|
2698
|
+
onIframeLoad: () => this.handleIframeLoad()
|
|
2699
|
+
});
|
|
2673
2700
|
this._url = buildVerificationUrl(url, config);
|
|
2674
2701
|
this.setState("loading");
|
|
2675
2702
|
this.emitInternalEvent("didit:started", {});
|
|
@@ -2786,6 +2813,7 @@
|
|
|
2786
2813
|
this._modal?.destroy();
|
|
2787
2814
|
this._modal = null;
|
|
2788
2815
|
this.reset();
|
|
2816
|
+
this.setState("idle");
|
|
2789
2817
|
}
|
|
2790
2818
|
async runTransactionAction(baseUrl, transactionToken, submitResult, onActionCompleted) {
|
|
2791
2819
|
const generation = this._actionGeneration;
|
|
@@ -2901,6 +2929,7 @@
|
|
|
2901
2929
|
const sessionData = this.buildSessionData();
|
|
2902
2930
|
this._modal?.close();
|
|
2903
2931
|
this.reset();
|
|
2932
|
+
this.setState("idle");
|
|
2904
2933
|
const result = {
|
|
2905
2934
|
type: "cancelled",
|
|
2906
2935
|
session: sessionData
|
|
@@ -2921,6 +2950,11 @@
|
|
|
2921
2950
|
}
|
|
2922
2951
|
handleVerificationEvent(event) {
|
|
2923
2952
|
SDKLogger.log("Verification event:", event);
|
|
2953
|
+
// Keep the session the flow told us about so a modal the user closes by
|
|
2954
|
+
// hand still reports the session it belongs to in the cancelled result.
|
|
2955
|
+
if (event.data?.sessionId) {
|
|
2956
|
+
this._sessionId = event.data.sessionId;
|
|
2957
|
+
}
|
|
2924
2958
|
this.onEvent?.(event);
|
|
2925
2959
|
switch (event.type) {
|
|
2926
2960
|
case "didit:ready":
|
|
@@ -2976,6 +3010,7 @@
|
|
|
2976
3010
|
if (this._configuration?.closeModalOnComplete) {
|
|
2977
3011
|
this._modal?.close();
|
|
2978
3012
|
this.reset();
|
|
3013
|
+
this.setState("idle");
|
|
2979
3014
|
}
|
|
2980
3015
|
const result = {
|
|
2981
3016
|
type: "completed",
|
|
@@ -2988,6 +3023,7 @@
|
|
|
2988
3023
|
const sessionData = this.buildSessionData(event.data);
|
|
2989
3024
|
this._modal?.close();
|
|
2990
3025
|
this.reset();
|
|
3026
|
+
this.setState("idle");
|
|
2991
3027
|
const result = {
|
|
2992
3028
|
type: "cancelled",
|
|
2993
3029
|
session: sessionData
|
|
@@ -3006,10 +3042,14 @@
|
|
|
3006
3042
|
else {
|
|
3007
3043
|
verificationError = createVerificationError("unknown", "An unknown error occurred");
|
|
3008
3044
|
}
|
|
3009
|
-
this._errorMessage = verificationError.message;
|
|
3010
|
-
this.setState("error");
|
|
3011
3045
|
this._modal?.close();
|
|
3046
|
+
this._modal = null;
|
|
3047
|
+
// Clear what the failed launch left behind, then report the error as the
|
|
3048
|
+
// state the SDK is in: reset() alone would leave callers reading "idle"
|
|
3049
|
+
// with no error message right after onStateChange("error").
|
|
3012
3050
|
this.reset();
|
|
3051
|
+
this._errorMessage = verificationError.message;
|
|
3052
|
+
this.setState("error");
|
|
3013
3053
|
const result = {
|
|
3014
3054
|
type: "failed",
|
|
3015
3055
|
error: verificationError
|
|
@@ -3025,7 +3065,6 @@
|
|
|
3025
3065
|
}
|
|
3026
3066
|
}
|
|
3027
3067
|
reset() {
|
|
3028
|
-
this._state = "idle";
|
|
3029
3068
|
this._sessionId = undefined;
|
|
3030
3069
|
this._url = undefined;
|
|
3031
3070
|
this._errorMessage = undefined;
|