@didit-protocol/sdk-web 0.4.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 +93 -0
- package/dist/didit-sdk.cjs +2326 -0
- package/dist/didit-sdk.cjs.js +422 -376
- package/dist/didit-sdk.cjs.js.map +1 -1
- package/dist/didit-sdk.cjs.map +1 -0
- package/dist/didit-sdk.esm.js +1665 -856
- package/dist/didit-sdk.esm.js.map +1 -1
- package/dist/didit-sdk.module.js +2313 -0
- package/dist/didit-sdk.module.js.map +1 -0
- package/dist/didit-sdk.umd.js +1631 -815
- 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 +25 -1
- package/package.json +31 -13
package/README.md
CHANGED
|
@@ -7,11 +7,22 @@ A lightweight JavaScript/TypeScript SDK for embedding Didit identity verificatio
|
|
|
7
7
|
- 🎯 **Simple API** - Singleton pattern with easy-to-use methods
|
|
8
8
|
- 🔐 **Flexible Integration** - Use UniLink URL directly or create sessions via backend
|
|
9
9
|
- 💸 **Transaction Submission** - Submit monitored transactions (incl. Travel Rule) with a scoped token, automatic device intelligence, and an auto-launched wallet-ownership flow
|
|
10
|
+
- 🛡️ **Event Monitoring** - Send sign-ups, logins, failed logins and other end-user events to Didit in batches, tied to the same person as their verifications and transactions
|
|
10
11
|
- 📱 **Responsive** - Works on desktop and mobile browsers
|
|
11
12
|
- 🎨 **Customizable** - Configuration options for styling and behavior
|
|
12
13
|
- 📦 **Multiple Formats** - ESM, CommonJS, and UMD builds
|
|
13
14
|
- 🔷 **TypeScript** - Full type definitions included
|
|
14
15
|
|
|
16
|
+
## Authentication packages
|
|
17
|
+
|
|
18
|
+
This repository also holds Didit Authentication for web apps:
|
|
19
|
+
|
|
20
|
+
- [`@didit-protocol/auth`](packages/auth): the headless browser client and server-side token verification.
|
|
21
|
+
- [`@didit-protocol/auth-react`](packages/auth-react): React components and hooks.
|
|
22
|
+
- [`@didit-protocol/auth-nextjs`](packages/auth-nextjs): the Next.js App Router integration, with server-side `auth()`.
|
|
23
|
+
- [`examples/react`](examples/react): a browser app using `@didit-protocol/auth`.
|
|
24
|
+
- [`examples/nextjs`](examples/nextjs): an app with sign-up, sign-in, password reset, signing in again and connected agents.
|
|
25
|
+
|
|
15
26
|
## Installation
|
|
16
27
|
|
|
17
28
|
### NPM/Yarn
|
|
@@ -28,6 +39,8 @@ yarn add @didit-protocol/sdk-web
|
|
|
28
39
|
<script src="https://unpkg.com/@didit-protocol/sdk-web/dist/didit-sdk.umd.min.js"></script>
|
|
29
40
|
```
|
|
30
41
|
|
|
42
|
+
Event monitoring and device signals live in [`@didit-protocol/signals`](packages/signals), a small package that `@didit-protocol/sdk-web` depends on and re-exports. Install it on its own when you only need events: `npm install @didit-protocol/signals`.
|
|
43
|
+
|
|
31
44
|
## Package Version
|
|
32
45
|
|
|
33
46
|
Inspect the installed SDK version at runtime:
|
|
@@ -248,6 +261,20 @@ Modal mode uses a maximum width of 500px and a maximum height of 700px. On short
|
|
|
248
261
|
|
|
249
262
|
Browsers that support dynamic viewport units use `dvh`, while older supported browsers fall back to `vh`. At widths of 540px and below, the modal fills the visible viewport. The close button and exit confirmation stay inside the modal at every size.
|
|
250
263
|
|
|
264
|
+
### Redesigned verification flow
|
|
265
|
+
|
|
266
|
+
When the hosted verification page reports its layout with a `didit:layout` message, the modal sizes itself around it:
|
|
267
|
+
|
|
268
|
+
| Window width | Modal |
|
|
269
|
+
|---|---|
|
|
270
|
+
| 1024px and wider | The handoff card: 960px by 660px in every state, at most 90% of the window's width and height |
|
|
271
|
+
| 541px to 1023px | 500px wide, as tall as the page's content, at most 90% of the window's height |
|
|
272
|
+
| 540px and below | Full screen, as above |
|
|
273
|
+
|
|
274
|
+
The close button becomes a 44px circle over the page's top bar. It follows the page's light or dark theme and moves to the left for right-to-left languages. If a large text size makes the exit confirmation taller than a short page, the confirmation scrolls inside the modal. Until the page reports its layout, and for pages that never do, the modal keeps the 500px by 700px size above. Embedded mode keeps filling its host element. There is nothing to configure, and every existing option keeps working.
|
|
275
|
+
|
|
276
|
+
The SDK tells the page how it is shown with two query parameters on the verification URL: `sdk_presentation` (`modal` or `embedded`) and, in a modal, `sdk_close_button` (`true` or `false`, following `showCloseButton`). The SDK handles the `didit:layout` message itself and does not pass it to `onEvent`.
|
|
277
|
+
|
|
251
278
|
## Embedded Mode
|
|
252
279
|
|
|
253
280
|
Render verification inline instead of a modal overlay. Embedded mode does not apply the modal's 500px by 700px cap; the SDK fills the host element's content box. Give the host an explicit or otherwise resolved height:
|
|
@@ -268,6 +295,8 @@ DiditSdk.shared.startVerification({
|
|
|
268
295
|
|
|
269
296
|
If the host element has no resolved height, the embedded iframe also has no usable height. Resize the host element when your layout changes; the SDK continues to fill it automatically.
|
|
270
297
|
|
|
298
|
+
If `embeddedContainerId` is missing or no element carries it, the launch fails with the `failed` result (and the `error` state) instead of silently rendering nothing: embedded mode never falls back to the modal overlay.
|
|
299
|
+
|
|
271
300
|
## Verification Results
|
|
272
301
|
|
|
273
302
|
The SDK returns three types of results:
|
|
@@ -406,6 +435,57 @@ Key points:
|
|
|
406
435
|
|
|
407
436
|
Full guide: [SDK Transaction Submission](https://docs.didit.me/transaction-monitoring/sdk-transaction-submission).
|
|
408
437
|
|
|
438
|
+
## Event Monitoring
|
|
439
|
+
|
|
440
|
+
Send what your end users do (sign-up, login, failed login, logout, password reset, MFA, device change) to Didit's [event monitoring](https://docs.didit.me/transaction-monitoring/events), where accepted events are associated with the same person as their verifications and transactions.
|
|
441
|
+
|
|
442
|
+
Your backend mints a short-lived monitoring token for the signed-in person with `POST /v3/events/sdk-token/`, then hands it to the page:
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
import { DiditSdk, DiditEventError, configureEvents, flush } from "@didit-protocol/sdk-web";
|
|
446
|
+
|
|
447
|
+
// Optional: hear about events Didit refused or the SDK had to drop.
|
|
448
|
+
configureEvents({
|
|
449
|
+
onError: (error: DiditEventError) => console.warn(error.type, error.eventIds, error.errors),
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
DiditSdk.shared.submitEvent({
|
|
453
|
+
monitoringToken, // minted by YOUR backend for this person - never ship an API key
|
|
454
|
+
event: { category: "auth", actionType: "login", payload: { method: "password" } },
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
DiditSdk.shared.submitEvent({
|
|
458
|
+
monitoringToken,
|
|
459
|
+
event: { category: "auth", actionType: "login_failed", payload: { reason: "wrong_password" } },
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// Before a redirect you control, send what is waiting and read the outcome of each event:
|
|
463
|
+
const { acceptedCount, rejectedCount, pendingCount, results } = await flush();
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
How events travel:
|
|
467
|
+
|
|
468
|
+
- **Batched** to `POST /v1/events/batch/` with the `X-Monitoring-Token` header: as soon as 25 events are waiting, after 5 seconds, and when the page is hidden or closed. Change the numbers with `configureEvents({ batchSize, flushIntervalMs })`.
|
|
469
|
+
- **The person comes from the token**, never from the page: Didit binds every event to the `vendor_data` the token was minted for. Each event keeps the token it was submitted with, so events from before and after a sign-in never mix people.
|
|
470
|
+
- **Device intelligence** is attached to every batch (the same fingerprint as transaction submissions); IP address, user agent and origin are taken server-side.
|
|
471
|
+
- **Leaving the page** starts sending waiting events immediately with `fetch` and `keepalive`, which outlives the page (browsers allow 64 KiB per page for this). If fingerprint hashing is still pending, the request retains the persistent device id and collected signals but omits the unfinished hash. See the [device-context tradeoff](packages/signals/README.md#how-events-are-sent) for stored events. `sendBeacon` is not used because it cannot carry the token header.
|
|
472
|
+
- **Safe retries**: on a network error, HTTP timeout, rate limit or server error the same events are sent again after 10, 20 and 40 seconds, then every minute (or right away when you call `flush()`). An event Didit already stored comes back as `replayed`, never as a duplicate.
|
|
473
|
+
- **Refusals are final**: an invalid, expired, revoked or used-up token (`invalid_token`, `expired_token`), event monitoring switched off for the application (`monitoring_disabled`) or an event that fails validation (`validation`) is reported through `onError` and in the `flush()` results, and is not sent again.
|
|
474
|
+
- **Queue pressure**: the queue targets 1,000 waiting events (`maxQueueSize`). When the queue is full, page views and other low-value events are dropped first (`dropped`); security, payment, dispute, responsible-gambling and bet events are never dropped, so protected events can exceed that target.
|
|
475
|
+
|
|
476
|
+
| Event field | Description |
|
|
477
|
+
|-------------|-------------|
|
|
478
|
+
| `category` | `auth`, `session`, `security`, `payment`, `dispute`, `gameplay`, `bonus`, `affiliate`, `responsible_gambling` or `custom` |
|
|
479
|
+
| `actionType` | What happened, e.g. `signup`, `login`, `login_failed`, `logout`, `password_reset`, `mfa_challenge` |
|
|
480
|
+
| `eventId` | Your idempotency key; a UUID is generated when omitted. `submitEvent` returns it |
|
|
481
|
+
| `occurredAt` | `Date` or ISO 8601 string; defaults to now |
|
|
482
|
+
| `payload` | Category-specific keys, e.g. `payment_reference_id`, `amount`, `currency`, `payment_method` and `status` for payments |
|
|
483
|
+
| `session`, `transactionContext`, `customValues`, `subject`, `business`, `timeZone` | Optional context; `subject` only adds profile hints, the person always comes from the token |
|
|
484
|
+
|
|
485
|
+
Delivery is best effort: the queue is in memory, and browsers can terminate pending requests. Await `flush()` and check `pendingCount` before a redirect you control. Browser delivery requires the API to allow `X-Monitoring-Token` and the fingerprint headers in its CORS policy.
|
|
486
|
+
|
|
487
|
+
Full guide: [SDK Event Submission](https://docs.didit.me/transaction-monitoring/sdk-event-submission).
|
|
488
|
+
|
|
409
489
|
## API Reference
|
|
410
490
|
|
|
411
491
|
### DiditSdk.shared
|
|
@@ -418,6 +498,7 @@ The singleton SDK instance.
|
|
|
418
498
|
|--------|-------------|
|
|
419
499
|
| `startVerification(options)` | Start the verification flow |
|
|
420
500
|
| `submitTransaction(options)` | Submit a monitored transaction with a scoped token ([guide](https://docs.didit.me/transaction-monitoring/sdk-transaction-submission)) |
|
|
501
|
+
| `submitEvent(options)` | Queue an end-user event for event monitoring with a monitoring token; returns the event id ([Event Monitoring](#event-monitoring)) |
|
|
421
502
|
| `close()` | Programmatically close the verification modal |
|
|
422
503
|
| `destroy()` | Destroy the SDK instance and clean up |
|
|
423
504
|
|
|
@@ -500,6 +581,18 @@ The `codeSize` field in `code_sent` indicates the OTP code length (e.g., 4 or 6
|
|
|
500
581
|
- Edge 79+
|
|
501
582
|
|
|
502
583
|
|
|
584
|
+
## Releasing
|
|
585
|
+
|
|
586
|
+
Each release starts from a tag pushed to a commit on `master`. The workflow checks that the tag matches the package versions and that each package's `CHANGELOG.md` has a section for that version, then creates the GitHub release and publishes to npm with trusted publishing.
|
|
587
|
+
|
|
588
|
+
| Tag | Publishes | Workflow |
|
|
589
|
+
| --- | --- | --- |
|
|
590
|
+
| `signals-v<version>` | `@didit-protocol/signals` | `release-signals.yml` |
|
|
591
|
+
| `auth-v<version>` | `@didit-protocol/auth`, then `@didit-protocol/auth-react`, then `@didit-protocol/auth-nextjs`, all at the same version | `release-auth.yml` |
|
|
592
|
+
| `v<version>` | `@didit-protocol/sdk-web` | `release.yml` |
|
|
593
|
+
|
|
594
|
+
When versions depend on each other, release in this order and wait for each to reach npm: signals, then auth, then sdk-web. The auth and sdk-web workflows stop before publishing if the `@didit-protocol/signals` version they depend on is not on npm yet. `@didit-protocol/auth-nextjs` pins `@didit-protocol/auth` and `@didit-protocol/auth-react` at exactly its own version, so bump all three together; `npm run test:release` checks that before a tag does.
|
|
595
|
+
|
|
503
596
|
## License
|
|
504
597
|
|
|
505
598
|
Copyright © 2026 Didit. All rights reserved.
|