@didit-protocol/sdk-web 0.1.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.
@@ -0,0 +1,732 @@
1
+ /**
2
+ * Didit SDK for Web v0.1.0
3
+ * (c) 2026 Didit
4
+ * @license MIT
5
+ */
6
+ const DEFAULT_CONFIG = {
7
+ zIndex: 9999,
8
+ showCloseButton: true,
9
+ showExitConfirmation: true,
10
+ loggingEnabled: false,
11
+ };
12
+ const CSS_CLASSES = {
13
+ overlay: "didit-modal-overlay",
14
+ container: "didit-modal-container",
15
+ iframe: "didit-verification-iframe",
16
+ closeButton: "didit-close-button",
17
+ loading: "didit-loading",
18
+ confirmOverlay: "didit-confirm-overlay",
19
+ confirmBox: "didit-confirm-box"
20
+ };
21
+ const SDK_VERSION = "0.1.0";
22
+
23
+ class SDKLogger {
24
+ static get isEnabled() {
25
+ return this._enabled;
26
+ }
27
+ static set isEnabled(value) {
28
+ this._enabled = value;
29
+ }
30
+ static log(...args) {
31
+ if (this._enabled) {
32
+ console.log("[DiditSDK]", ...args);
33
+ }
34
+ }
35
+ static warn(...args) {
36
+ if (this._enabled) {
37
+ console.warn("[DiditSDK]", ...args);
38
+ }
39
+ }
40
+ static error(...args) {
41
+ if (this._enabled) {
42
+ console.error("[DiditSDK]", ...args);
43
+ }
44
+ }
45
+ }
46
+ SDKLogger._enabled = false;
47
+ function generateModalId() {
48
+ return `didit-modal-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
49
+ }
50
+ function isAllowedOrigin(origin) {
51
+ try {
52
+ const url = new URL(origin);
53
+ return url.hostname.endsWith('.didit.me');
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ }
59
+ function createVerificationError(type, customMessage) {
60
+ const messages = {
61
+ sessionExpired: "Your verification session has expired.",
62
+ networkError: "A network error occurred. Please try again.",
63
+ cameraAccessDenied: "Camera access is required for verification.",
64
+ unknown: customMessage || "An unknown error occurred."
65
+ };
66
+ return {
67
+ type,
68
+ message: customMessage || messages[type]
69
+ };
70
+ }
71
+
72
+ class VerificationModal {
73
+ constructor(configuration, callbacks) {
74
+ this.state = {
75
+ isOpen: false,
76
+ isLoading: true,
77
+ showConfirmation: false
78
+ };
79
+ this.overlay = null;
80
+ this.container = null;
81
+ this.iframe = null;
82
+ this.loadingEl = null;
83
+ this.confirmOverlay = null;
84
+ this.boundHandleMessage = null;
85
+ this.boundHandleKeydown = null;
86
+ this.modalId = generateModalId();
87
+ this.config = {
88
+ zIndex: configuration?.zIndex ?? DEFAULT_CONFIG.zIndex,
89
+ showCloseButton: configuration?.showCloseButton ?? DEFAULT_CONFIG.showCloseButton,
90
+ showExitConfirmation: configuration?.showExitConfirmation ?? DEFAULT_CONFIG.showExitConfirmation
91
+ };
92
+ this.callbacks = callbacks;
93
+ this.containerElement = configuration?.containerElement ?? document.body;
94
+ }
95
+ injectStyles() {
96
+ const styleId = "didit-sdk-styles";
97
+ if (document.getElementById(styleId)) {
98
+ return;
99
+ }
100
+ const styles = document.createElement("style");
101
+ styles.id = styleId;
102
+ styles.textContent = `
103
+ .${CSS_CLASSES.overlay} {
104
+ display: none;
105
+ position: fixed;
106
+ inset: 0;
107
+ background: rgba(0, 0, 0, 0.6);
108
+ z-index: ${this.config.zIndex};
109
+ justify-content: center;
110
+ align-items: center;
111
+ padding: 1rem;
112
+ opacity: 0;
113
+ transition: opacity 0.2s ease-out;
114
+ }
115
+
116
+ .${CSS_CLASSES.overlay}.active {
117
+ display: flex;
118
+ opacity: 1;
119
+ }
120
+
121
+ .${CSS_CLASSES.container} {
122
+ position: relative;
123
+ width: 100%;
124
+ max-width: 500px;
125
+ max-height: 90vh;
126
+ border-radius: 16px;
127
+ overflow: hidden;
128
+ background: transparent;
129
+ }
130
+
131
+ .${CSS_CLASSES.overlay}.active .${CSS_CLASSES.container} {
132
+ transform: scale(1);
133
+ }
134
+
135
+ .${CSS_CLASSES.iframe} {
136
+ width: 100%;
137
+ height: 700px;
138
+ border: none;
139
+ display: block;
140
+ }
141
+
142
+ .${CSS_CLASSES.closeButton} {
143
+ position: absolute;
144
+ top: 12px;
145
+ right: 12px;
146
+ width: 24px;
147
+ height: 24px;
148
+ background: transparent;
149
+ border: none;
150
+ cursor: pointer;
151
+ padding: 0;
152
+ z-index: 10;
153
+ outline: none;
154
+ }
155
+
156
+ .${CSS_CLASSES.closeButton}:hover,
157
+ .${CSS_CLASSES.closeButton}:focus {
158
+ background: transparent;
159
+ opacity: 0.5;
160
+ }
161
+
162
+ .${CSS_CLASSES.closeButton} svg {
163
+ stroke: #666;
164
+ stroke-width: 2;
165
+ stroke-linecap: round;
166
+ }
167
+
168
+ .${CSS_CLASSES.loading} {
169
+ position: absolute;
170
+ inset: 0;
171
+ display: flex;
172
+ align-items: center;
173
+ justify-content: center;
174
+ background: #fafafa;
175
+ z-index: 5;
176
+ }
177
+
178
+ .${CSS_CLASSES.loading}.hidden {
179
+ display: none;
180
+ }
181
+
182
+ .${CSS_CLASSES.loading} svg {
183
+ width: 48px;
184
+ height: 48px;
185
+ animation: didit-spin 1s linear infinite;
186
+ }
187
+
188
+ .${CSS_CLASSES.loading} circle {
189
+ stroke: #e5e5e5;
190
+ stroke-width: 3;
191
+ fill: none;
192
+ }
193
+
194
+ .${CSS_CLASSES.loading} path {
195
+ stroke: #525252;
196
+ stroke-width: 3;
197
+ stroke-linecap: round;
198
+ fill: none;
199
+ }
200
+
201
+ @keyframes didit-spin {
202
+ from { transform: rotate(0deg); }
203
+ to { transform: rotate(360deg); }
204
+ }
205
+
206
+ .${CSS_CLASSES.confirmOverlay} {
207
+ display: none;
208
+ position: absolute;
209
+ inset: 0;
210
+ background: rgba(0, 0, 0, 0.5);
211
+ z-index: 20;
212
+ justify-content: center;
213
+ align-items: center;
214
+ opacity: 0;
215
+ transition: opacity 0.15s ease-out;
216
+ }
217
+
218
+ .${CSS_CLASSES.confirmOverlay}.active {
219
+ display: flex;
220
+ opacity: 1;
221
+ }
222
+
223
+ .${CSS_CLASSES.confirmBox} {
224
+ background: #fff;
225
+ border-radius: 12px;
226
+ padding: 1.5rem;
227
+ text-align: center;
228
+ max-width: 300px;
229
+ margin: 1rem;
230
+ transform: scale(0.95);
231
+ transition: transform 0.15s ease-out;
232
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
233
+ }
234
+
235
+ .${CSS_CLASSES.confirmOverlay}.active .${CSS_CLASSES.confirmBox} {
236
+ transform: scale(1);
237
+ }
238
+
239
+ .${CSS_CLASSES.confirmBox} h3 {
240
+ color: #1a1a2e;
241
+ margin: 0 0 0.5rem 0;
242
+ font-size: 1.125rem;
243
+ font-weight: 600;
244
+ }
245
+
246
+ .${CSS_CLASSES.confirmBox} p {
247
+ color: #666;
248
+ font-size: 0.875rem;
249
+ margin: 0 0 1.25rem 0;
250
+ line-height: 1.5;
251
+ }
252
+
253
+ .didit-confirm-actions {
254
+ display: flex;
255
+ align-items: center;
256
+ justify-content: center;
257
+ gap: 1rem;
258
+ }
259
+
260
+ .didit-confirm-actions button {
261
+ background: #2563eb;
262
+ color: #fff;
263
+ border: none;
264
+ padding: 0.625rem 1.25rem;
265
+ border-radius: 8px;
266
+ font-size: 0.875rem;
267
+ font-weight: 500;
268
+ cursor: pointer;
269
+ transition: background 0.15s ease;
270
+ }
271
+
272
+ .didit-confirm-actions button:hover {
273
+ background: #1d4ed8;
274
+ }
275
+
276
+ .didit-confirm-actions span {
277
+ color: #666;
278
+ font-size: 0.875rem;
279
+ cursor: pointer;
280
+ padding: 0.625rem;
281
+ transition: color 0.15s ease;
282
+ }
283
+
284
+ .didit-confirm-actions span:hover {
285
+ color: #1a1a2e;
286
+ }
287
+
288
+ @media (max-width: 540px) {
289
+ .${CSS_CLASSES.overlay} {
290
+ padding: 0;
291
+ }
292
+
293
+ .${CSS_CLASSES.container} {
294
+ max-width: 100%;
295
+ max-height: 100vh;
296
+ border-radius: 0;
297
+ }
298
+
299
+ .${CSS_CLASSES.iframe} {
300
+ height: 100vh;
301
+ }
302
+ }
303
+ `;
304
+ document.head.appendChild(styles);
305
+ }
306
+ createDOM() {
307
+ this.injectStyles();
308
+ this.overlay = document.createElement("div");
309
+ this.overlay.id = this.modalId;
310
+ this.overlay.className = CSS_CLASSES.overlay;
311
+ this.overlay.setAttribute("role", "dialog");
312
+ this.overlay.setAttribute("aria-modal", "true");
313
+ this.overlay.setAttribute("aria-label", "Didit Verification");
314
+ this.container = document.createElement("div");
315
+ this.container.className = CSS_CLASSES.container;
316
+ this.loadingEl = document.createElement("div");
317
+ this.loadingEl.className = CSS_CLASSES.loading;
318
+ this.loadingEl.innerHTML = `
319
+ <svg viewBox="0 0 24 24">
320
+ <circle cx="12" cy="12" r="10" />
321
+ <path d="M12 2a10 10 0 0 1 10 10" />
322
+ </svg>
323
+ `;
324
+ if (this.config.showCloseButton) {
325
+ const closeBtn = document.createElement("button");
326
+ closeBtn.className = CSS_CLASSES.closeButton;
327
+ closeBtn.setAttribute("aria-label", "Close verification");
328
+ closeBtn.innerHTML = `
329
+ <svg width="14" height="14" viewBox="0 0 14 14">
330
+ <line x1="1" y1="1" x2="13" y2="13" />
331
+ <line x1="13" y1="1" x2="1" y2="13" />
332
+ </svg>
333
+ `;
334
+ closeBtn.addEventListener("click", () => this.handleCloseRequest());
335
+ this.container.appendChild(closeBtn);
336
+ }
337
+ this.iframe = document.createElement("iframe");
338
+ this.iframe.className = CSS_CLASSES.iframe;
339
+ this.iframe.setAttribute("allow", "camera; microphone; fullscreen; autoplay; encrypted-media; geolocation");
340
+ this.iframe.setAttribute("title", "Didit Verification");
341
+ this.iframe.addEventListener("load", () => this.handleIframeLoad());
342
+ this.confirmOverlay = document.createElement("div");
343
+ this.confirmOverlay.className = CSS_CLASSES.confirmOverlay;
344
+ this.confirmOverlay.innerHTML = `
345
+ <div class="${CSS_CLASSES.confirmBox}">
346
+ <h3>Exit verification?</h3>
347
+ <p>Exiting will end your verification process. Are you sure?</p>
348
+ <div class="didit-confirm-actions">
349
+ <button type="button" data-action="continue">Continue</button>
350
+ <span data-action="exit">Exit</span>
351
+ </div>
352
+ </div>
353
+ `;
354
+ this.confirmOverlay.querySelector('[data-action="continue"]')?.addEventListener("click", () => {
355
+ this.hideConfirmation();
356
+ });
357
+ this.confirmOverlay.querySelector('[data-action="exit"]')?.addEventListener("click", () => {
358
+ this.confirmExit();
359
+ });
360
+ this.container.appendChild(this.loadingEl);
361
+ this.container.appendChild(this.iframe);
362
+ this.container.appendChild(this.confirmOverlay);
363
+ this.overlay.appendChild(this.container);
364
+ this.overlay.addEventListener("click", (e) => {
365
+ if (e.target === this.overlay) {
366
+ this.handleCloseRequest();
367
+ }
368
+ });
369
+ this.containerElement.appendChild(this.overlay);
370
+ }
371
+ setupEventListeners() {
372
+ this.boundHandleMessage = this.handleMessage.bind(this);
373
+ window.addEventListener("message", this.boundHandleMessage);
374
+ this.boundHandleKeydown = this.handleKeydown.bind(this);
375
+ document.addEventListener("keydown", this.boundHandleKeydown);
376
+ }
377
+ removeEventListeners() {
378
+ if (this.boundHandleMessage) {
379
+ window.removeEventListener("message", this.boundHandleMessage);
380
+ this.boundHandleMessage = null;
381
+ }
382
+ if (this.boundHandleKeydown) {
383
+ document.removeEventListener("keydown", this.boundHandleKeydown);
384
+ this.boundHandleKeydown = null;
385
+ }
386
+ }
387
+ handleMessage(event) {
388
+ if (!isAllowedOrigin(event.origin)) {
389
+ return;
390
+ }
391
+ SDKLogger.log("Received postMessage:", event.data);
392
+ let messageData;
393
+ try {
394
+ if (typeof event.data === "string") {
395
+ messageData = JSON.parse(event.data);
396
+ }
397
+ else {
398
+ messageData = event.data;
399
+ }
400
+ }
401
+ catch {
402
+ SDKLogger.warn("Failed to parse postMessage:", event.data);
403
+ return;
404
+ }
405
+ if (messageData.type === "didit:close_request") {
406
+ this.handleCloseRequest();
407
+ return;
408
+ }
409
+ this.callbacks.onMessage(messageData);
410
+ }
411
+ handleKeydown(event) {
412
+ if (!this.state.isOpen)
413
+ return;
414
+ if (event.key === "Escape") {
415
+ event.preventDefault();
416
+ if (this.state.showConfirmation) {
417
+ this.hideConfirmation();
418
+ }
419
+ else {
420
+ this.handleCloseRequest();
421
+ }
422
+ }
423
+ }
424
+ handleIframeLoad() {
425
+ if (this.iframe?.src && this.iframe.src !== "about:blank") {
426
+ this.state.isLoading = false;
427
+ this.loadingEl?.classList.add("hidden");
428
+ this.callbacks.onIframeLoad();
429
+ }
430
+ }
431
+ handleCloseRequest() {
432
+ if (this.config.showExitConfirmation) {
433
+ this.showConfirmation();
434
+ }
435
+ else {
436
+ this.callbacks.onCloseConfirmed();
437
+ }
438
+ }
439
+ showConfirmation() {
440
+ this.state.showConfirmation = true;
441
+ this.confirmOverlay?.classList.add("active");
442
+ this.callbacks.onClose();
443
+ }
444
+ hideConfirmation() {
445
+ this.state.showConfirmation = false;
446
+ this.confirmOverlay?.classList.remove("active");
447
+ }
448
+ confirmExit() {
449
+ this.hideConfirmation();
450
+ this.callbacks.onCloseConfirmed();
451
+ }
452
+ open(verificationUrl) {
453
+ if (!this.overlay) {
454
+ this.createDOM();
455
+ this.setupEventListeners();
456
+ }
457
+ SDKLogger.log("Opening modal with URL:", verificationUrl);
458
+ this.state.isLoading = true;
459
+ this.state.showConfirmation = false;
460
+ this.loadingEl?.classList.remove("hidden");
461
+ this.confirmOverlay?.classList.remove("active");
462
+ if (this.iframe) {
463
+ this.iframe.src = verificationUrl;
464
+ }
465
+ this.state.isOpen = true;
466
+ this.overlay?.classList.add("active");
467
+ document.body.style.overflow = "hidden";
468
+ }
469
+ close() {
470
+ SDKLogger.log("Closing modal");
471
+ this.state.isOpen = false;
472
+ this.state.isLoading = true;
473
+ this.state.showConfirmation = false;
474
+ this.overlay?.classList.remove("active");
475
+ if (this.iframe) {
476
+ this.iframe.src = "about:blank";
477
+ }
478
+ document.body.style.overflow = "";
479
+ }
480
+ destroy() {
481
+ SDKLogger.log("Destroying modal");
482
+ this.close();
483
+ this.removeEventListeners();
484
+ if (this.overlay && this.overlay.parentNode) {
485
+ this.overlay.parentNode.removeChild(this.overlay);
486
+ }
487
+ this.overlay = null;
488
+ this.container = null;
489
+ this.iframe = null;
490
+ this.loadingEl = null;
491
+ this.confirmOverlay = null;
492
+ }
493
+ isOpen() {
494
+ return this.state.isOpen;
495
+ }
496
+ isLoading() {
497
+ return this.state.isLoading;
498
+ }
499
+ }
500
+
501
+ class DiditSdk {
502
+ static get shared() {
503
+ if (!DiditSdk._instance) {
504
+ DiditSdk._instance = new DiditSdk();
505
+ }
506
+ return DiditSdk._instance;
507
+ }
508
+ static reset() {
509
+ if (DiditSdk._instance) {
510
+ DiditSdk._instance.destroy();
511
+ DiditSdk._instance = null;
512
+ }
513
+ }
514
+ get state() {
515
+ return this._state;
516
+ }
517
+ get configuration() {
518
+ return this._configuration;
519
+ }
520
+ get isPresented() {
521
+ return this._modal?.isOpen() ?? false;
522
+ }
523
+ get errorMessage() {
524
+ return this._errorMessage;
525
+ }
526
+ constructor() {
527
+ this._state = "idle";
528
+ this._modal = null;
529
+ SDKLogger.log("DiditSdk initialized");
530
+ }
531
+ async startVerification(options) {
532
+ const config = options.configuration;
533
+ this._configuration = config;
534
+ SDKLogger.isEnabled = config?.loggingEnabled ?? DEFAULT_CONFIG.loggingEnabled;
535
+ SDKLogger.log("Starting verification with options:", options);
536
+ this._modal = new VerificationModal(config, {
537
+ onClose: () => this.handleModalClose(),
538
+ onCloseConfirmed: () => this.handleModalCloseConfirmed(),
539
+ onMessage: (event) => this.handleVerificationEvent(event),
540
+ onIframeLoad: () => this.handleIframeLoad()
541
+ });
542
+ try {
543
+ const { url } = options;
544
+ if (!url || typeof url !== "string") {
545
+ throw new Error("Invalid options: url is required");
546
+ }
547
+ this._url = url;
548
+ this.setState("loading");
549
+ this.emitInternalEvent("didit:started", {});
550
+ this._modal?.open(this._url);
551
+ this.setState("ready");
552
+ }
553
+ catch (error) {
554
+ this.handleError(error);
555
+ }
556
+ }
557
+ close() {
558
+ SDKLogger.log("Closing verification programmatically");
559
+ this.handleModalCloseConfirmed();
560
+ }
561
+ destroy() {
562
+ SDKLogger.log("Destroying SDK instance");
563
+ this._modal?.destroy();
564
+ this._modal = null;
565
+ this.reset();
566
+ }
567
+ handleModalClose() {
568
+ SDKLogger.log("Modal close requested");
569
+ }
570
+ handleModalCloseConfirmed() {
571
+ SDKLogger.log("Modal close confirmed");
572
+ const sessionData = this.buildSessionData();
573
+ this._modal?.close();
574
+ this.reset();
575
+ const result = {
576
+ type: "cancelled",
577
+ session: sessionData
578
+ };
579
+ this.onComplete?.(result);
580
+ }
581
+ handleIframeLoad() {
582
+ SDKLogger.log("Iframe loaded");
583
+ this.emitInternalEvent("didit:ready", {
584
+ sessionId: this._sessionId
585
+ });
586
+ }
587
+ emitInternalEvent(type, data) {
588
+ const event = {
589
+ type,
590
+ data,
591
+ timestamp: Date.now()
592
+ };
593
+ SDKLogger.log("Emitting internal event:", event);
594
+ this.onEvent?.(event);
595
+ }
596
+ handleVerificationEvent(event) {
597
+ SDKLogger.log("Verification event:", event);
598
+ this.onEvent?.(event);
599
+ switch (event.type) {
600
+ case "didit:ready":
601
+ SDKLogger.log("Verification iframe ready");
602
+ break;
603
+ case "didit:started":
604
+ SDKLogger.log("User started verification");
605
+ break;
606
+ case "didit:step_started":
607
+ SDKLogger.log("Step started:", event.data?.step);
608
+ break;
609
+ case "didit:step_completed":
610
+ SDKLogger.log("Step completed:", event.data?.step, "-> next:", event.data?.nextStep);
611
+ break;
612
+ case "didit:media_started":
613
+ SDKLogger.log("Media started:", event.data?.mediaType, "for step:", event.data?.step);
614
+ break;
615
+ case "didit:media_captured":
616
+ SDKLogger.log("Media captured for step:", event.data?.step, "isAuto:", event.data?.isAuto);
617
+ break;
618
+ case "didit:document_selected":
619
+ SDKLogger.log("Document selected:", event.data?.documentType, "country:", event.data?.country);
620
+ break;
621
+ case "didit:verification_submitted":
622
+ SDKLogger.log("Verification submitted for step:", event.data?.step);
623
+ break;
624
+ case "didit:code_sent":
625
+ SDKLogger.log("Code sent via:", event.data?.channel, "codeSize:", event.data?.codeSize);
626
+ break;
627
+ case "didit:code_verified":
628
+ SDKLogger.log("Code verified via:", event.data?.channel);
629
+ break;
630
+ case "didit:status_updated":
631
+ SDKLogger.log("Status updated:", event.data?.status, "step:", event.data?.step);
632
+ break;
633
+ case "didit:completed":
634
+ this.handleVerificationCompleted(event);
635
+ break;
636
+ case "didit:cancelled":
637
+ this.handleVerificationCancelled(event);
638
+ break;
639
+ case "didit:error":
640
+ this.handleVerificationError(event);
641
+ break;
642
+ case "didit:step_changed":
643
+ SDKLogger.log("Step changed:", event.data?.step);
644
+ break;
645
+ }
646
+ }
647
+ handleVerificationCompleted(event) {
648
+ SDKLogger.log("Verification completed:", event.data);
649
+ const sessionData = this.buildSessionData(event.data);
650
+ this._modal?.close();
651
+ this.reset();
652
+ const result = {
653
+ type: "completed",
654
+ session: sessionData
655
+ };
656
+ this.onComplete?.(result);
657
+ }
658
+ handleVerificationCancelled(event) {
659
+ SDKLogger.log("Verification cancelled:", event.data);
660
+ const sessionData = this.buildSessionData(event.data);
661
+ this._modal?.close();
662
+ this.reset();
663
+ const result = {
664
+ type: "cancelled",
665
+ session: sessionData
666
+ };
667
+ this.onComplete?.(result);
668
+ }
669
+ handleVerificationError(event) {
670
+ SDKLogger.log("Verification error:", event.data);
671
+ const sessionData = this.buildSessionData(event.data);
672
+ const error = createVerificationError("unknown", event.data?.error);
673
+ this._modal?.close();
674
+ this.reset();
675
+ const result = {
676
+ type: "failed",
677
+ session: sessionData,
678
+ error
679
+ };
680
+ this.onComplete?.(result);
681
+ }
682
+ handleError(error) {
683
+ SDKLogger.error("SDK error:", error);
684
+ let verificationError;
685
+ if (error instanceof Error) {
686
+ verificationError = createVerificationError("unknown", error.message);
687
+ }
688
+ else {
689
+ verificationError = createVerificationError("unknown", "An unknown error occurred");
690
+ }
691
+ this._errorMessage = verificationError.message;
692
+ this.setState("error");
693
+ this._modal?.close();
694
+ this.reset();
695
+ const result = {
696
+ type: "failed",
697
+ error: verificationError
698
+ };
699
+ this.onComplete?.(result);
700
+ }
701
+ setState(state) {
702
+ const previousState = this._state;
703
+ this._state = state;
704
+ if (previousState !== state) {
705
+ SDKLogger.log("State changed:", previousState, "->", state);
706
+ this.onStateChange?.(state, this._errorMessage);
707
+ }
708
+ }
709
+ reset() {
710
+ this._state = "idle";
711
+ this._sessionId = undefined;
712
+ this._url = undefined;
713
+ this._errorMessage = undefined;
714
+ this._configuration = undefined;
715
+ }
716
+ buildSessionData(eventData) {
717
+ const sessionId = eventData?.sessionId || this._sessionId;
718
+ if (!sessionId) {
719
+ return undefined;
720
+ }
721
+ return {
722
+ sessionId,
723
+ status: (eventData?.status || "Pending"),
724
+ country: eventData?.country,
725
+ documentType: eventData?.documentType
726
+ };
727
+ }
728
+ }
729
+ DiditSdk._instance = null;
730
+
731
+ export { DiditSdk, SDK_VERSION, DiditSdk as default };
732
+ //# sourceMappingURL=didit-sdk.esm.js.map