@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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Didit SDK for Web v0.5.0
2
+ * Didit SDK for Web v0.5.1
3
3
  * (c) 2026 Didit
4
4
  * @license MIT
5
5
  */
@@ -24,13 +24,14 @@ const CSS_CLASSES = {
24
24
  confirmBox: "didit-confirm-box",
25
25
  embedded: "didit-embedded"
26
26
  };
27
- const SDK_VERSION = "0.5.0";
27
+ const SDK_VERSION = "0.5.1";
28
28
  /**
29
29
  * The permissions the verification iframe gets, in a modal and embedded:
30
- * camera and microphone for capture, and clipboard-write for the flow's copy
31
- * buttons.
30
+ * camera and microphone for capture, clipboard-write for the flow's copy
31
+ * buttons, and digital-credentials-get so the flow can ask a digital ID wallet
32
+ * (Google Wallet) through the W3C Digital Credentials API from inside the iframe.
32
33
  */
33
- const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write";
34
+ const IFRAME_ALLOW = "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation; clipboard-write; digital-credentials-get";
34
35
  /** The verification-URL query parameter each camera option is forwarded as. */
35
36
  const CAMERA_QUERY_PARAMS = {
36
37
  defaultDocumentCamera: "document_camera",
@@ -1045,6 +1046,9 @@ class VerificationModal {
1045
1046
  max-width: max(300px, 18.75rem);
1046
1047
  margin: auto;
1047
1048
  overflow-wrap: anywhere;
1049
+ /* Focusing the dialog scrolls it into view start-aligned; this keeps
1050
+ * the overlay's top padding visible so the title is never clipped. */
1051
+ scroll-margin-top: 1rem;
1048
1052
  }
1049
1053
 
1050
1054
  .${CSS_CLASSES.flowSized} .didit-confirm-actions {
@@ -1829,6 +1833,23 @@ async function pollTransactionAfterAction(args) {
1829
1833
  return latest;
1830
1834
  }
1831
1835
 
1836
+ /**
1837
+ * Embedded mode renders inside an element that already exists on the
1838
+ * integrator's page. Without it the modal never shows anything (embedded mode
1839
+ * never activates the overlay), so the launch fails with a message the
1840
+ * integrator can act on instead of silently presenting nothing.
1841
+ */
1842
+ function assertEmbeddedHostExists(configuration) {
1843
+ if (!configuration?.embedded)
1844
+ return;
1845
+ const containerId = configuration.embeddedContainerId;
1846
+ if (!containerId) {
1847
+ throw new Error("Embedded mode requires embeddedContainerId: the id of the element that hosts the verification.");
1848
+ }
1849
+ if (typeof document === "undefined" || !document.getElementById(containerId)) {
1850
+ throw new Error(`Embedded container "#${containerId}" was not found in the page.`);
1851
+ }
1852
+ }
1832
1853
  class DiditSdk {
1833
1854
  static get shared() {
1834
1855
  if (!DiditSdk._instance) {
@@ -1888,17 +1909,20 @@ class DiditSdk {
1888
1909
  this._modal.destroy();
1889
1910
  this._modal = null;
1890
1911
  }
1891
- this._modal = new VerificationModal(config, {
1892
- onClose: () => this.handleModalClose(),
1893
- onCloseConfirmed: () => this.handleModalCloseConfirmed(),
1894
- onMessage: (event) => this.handleVerificationEvent(event),
1895
- onIframeLoad: () => this.handleIframeLoad()
1896
- });
1912
+ // A new launch is not in an error state any more, whatever the last one did.
1913
+ this._errorMessage = undefined;
1897
1914
  try {
1898
1915
  const { url } = options;
1899
1916
  if (!url || typeof url !== "string") {
1900
1917
  throw new Error("Invalid options: url is required");
1901
1918
  }
1919
+ assertEmbeddedHostExists(config);
1920
+ this._modal = new VerificationModal(config, {
1921
+ onClose: () => this.handleModalClose(),
1922
+ onCloseConfirmed: () => this.handleModalCloseConfirmed(),
1923
+ onMessage: (event) => this.handleVerificationEvent(event),
1924
+ onIframeLoad: () => this.handleIframeLoad()
1925
+ });
1902
1926
  this._url = buildVerificationUrl(url, config);
1903
1927
  this.setState("loading");
1904
1928
  this.emitInternalEvent("didit:started", {});
@@ -2015,6 +2039,7 @@ class DiditSdk {
2015
2039
  this._modal?.destroy();
2016
2040
  this._modal = null;
2017
2041
  this.reset();
2042
+ this.setState("idle");
2018
2043
  }
2019
2044
  async runTransactionAction(baseUrl, transactionToken, submitResult, onActionCompleted) {
2020
2045
  const generation = this._actionGeneration;
@@ -2130,6 +2155,7 @@ class DiditSdk {
2130
2155
  const sessionData = this.buildSessionData();
2131
2156
  this._modal?.close();
2132
2157
  this.reset();
2158
+ this.setState("idle");
2133
2159
  const result = {
2134
2160
  type: "cancelled",
2135
2161
  session: sessionData
@@ -2150,6 +2176,11 @@ class DiditSdk {
2150
2176
  }
2151
2177
  handleVerificationEvent(event) {
2152
2178
  SDKLogger.log("Verification event:", event);
2179
+ // Keep the session the flow told us about so a modal the user closes by
2180
+ // hand still reports the session it belongs to in the cancelled result.
2181
+ if (event.data?.sessionId) {
2182
+ this._sessionId = event.data.sessionId;
2183
+ }
2153
2184
  this.onEvent?.(event);
2154
2185
  switch (event.type) {
2155
2186
  case "didit:ready":
@@ -2205,6 +2236,7 @@ class DiditSdk {
2205
2236
  if (this._configuration?.closeModalOnComplete) {
2206
2237
  this._modal?.close();
2207
2238
  this.reset();
2239
+ this.setState("idle");
2208
2240
  }
2209
2241
  const result = {
2210
2242
  type: "completed",
@@ -2217,6 +2249,7 @@ class DiditSdk {
2217
2249
  const sessionData = this.buildSessionData(event.data);
2218
2250
  this._modal?.close();
2219
2251
  this.reset();
2252
+ this.setState("idle");
2220
2253
  const result = {
2221
2254
  type: "cancelled",
2222
2255
  session: sessionData
@@ -2235,10 +2268,14 @@ class DiditSdk {
2235
2268
  else {
2236
2269
  verificationError = createVerificationError("unknown", "An unknown error occurred");
2237
2270
  }
2238
- this._errorMessage = verificationError.message;
2239
- this.setState("error");
2240
2271
  this._modal?.close();
2272
+ this._modal = null;
2273
+ // Clear what the failed launch left behind, then report the error as the
2274
+ // state the SDK is in: reset() alone would leave callers reading "idle"
2275
+ // with no error message right after onStateChange("error").
2241
2276
  this.reset();
2277
+ this._errorMessage = verificationError.message;
2278
+ this.setState("error");
2242
2279
  const result = {
2243
2280
  type: "failed",
2244
2281
  error: verificationError
@@ -2254,7 +2291,6 @@ class DiditSdk {
2254
2291
  }
2255
2292
  }
2256
2293
  reset() {
2257
- this._state = "idle";
2258
2294
  this._sessionId = undefined;
2259
2295
  this._url = undefined;
2260
2296
  this._errorMessage = undefined;