@sparkvault/sdk-js 8.15.0 → 9.0.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 +11 -5
- package/dist/config.d.ts +6 -4
- package/dist/{sparkvault.cjs.js → index.cjs} +112 -18
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +320 -30
- package/dist/{sparkvault.esm.js → index.mjs} +112 -18
- package/dist/index.mjs.map +1 -0
- package/dist/products/index.d.ts +1 -1
- package/dist/products/notify/index.d.ts +72 -11
- package/dist/products/notify/types.d.ts +243 -16
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +17 -6
- package/dist/sparkvault.cjs.js.map +0 -1
- package/dist/sparkvault.esm.js.map +0 -1
package/README.md
CHANGED
|
@@ -32,14 +32,20 @@ The official SparkVault JavaScript SDK for browser applications. Add passwordles
|
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
34
|
npm install @sparkvault/sdk-js
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Both module systems resolve to a working entry through the package's `exports` map:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import SparkVault from '@sparkvault/sdk-js'; // ESM → dist/index.mjs
|
|
41
|
+
const { SparkVault } = require('@sparkvault/sdk-js'); // CJS → dist/index.cjs
|
|
37
42
|
```
|
|
38
43
|
|
|
39
44
|
**Bundle Formats:**
|
|
40
|
-
- `
|
|
41
|
-
- `
|
|
42
|
-
- `sparkvault.
|
|
45
|
+
- `dist/index.mjs` — ES module, resolved by `import`
|
|
46
|
+
- `dist/index.cjs` — CommonJS, resolved by `require`
|
|
47
|
+
- `dist/sparkvault.js` — UMD bundle for a browser `<script>` tag (also served from the CDN)
|
|
48
|
+
- `dist/index.d.ts` — bundled TypeScript declarations
|
|
43
49
|
|
|
44
50
|
### Caching & version pinning
|
|
45
51
|
|
package/dist/config.d.ts
CHANGED
|
@@ -24,10 +24,12 @@ export interface SparkVaultConfig {
|
|
|
24
24
|
/** Request timeout in milliseconds (default: 30000) */
|
|
25
25
|
timeout?: number;
|
|
26
26
|
/**
|
|
27
|
-
* Preload Identity configuration on SDK init (default: true
|
|
28
|
-
* When enabled, the /config call is made immediately when the
|
|
29
|
-
* so verify() opens instantly without waiting for the config
|
|
30
|
-
*
|
|
27
|
+
* Preload Identity configuration on SDK init (default: true in a browser,
|
|
28
|
+
* false off-DOM). When enabled, the /config call is made immediately when the
|
|
29
|
+
* SDK initializes, so verify() opens instantly without waiting for the config
|
|
30
|
+
* fetch. It buys nothing in a server process — there is no dialog to open —
|
|
31
|
+
* so a Node host does not pay for a network call it will never use.
|
|
32
|
+
* Set explicitly to override in either direction.
|
|
31
33
|
*/
|
|
32
34
|
preloadConfig?: boolean;
|
|
33
35
|
/** Enable backdrop blur on dialogs (default: true) */
|
|
@@ -196,7 +196,9 @@ function resolveConfig(config) {
|
|
|
196
196
|
getAccessToken: config.getAccessToken,
|
|
197
197
|
apiKey: config.apiKey,
|
|
198
198
|
clientId: config.clientId,
|
|
199
|
-
|
|
199
|
+
// Preloading warms a dialog that only a browser can open; default it off
|
|
200
|
+
// where there is no DOM so server hosts make no init-time network call.
|
|
201
|
+
preloadConfig: config.preloadConfig ?? typeof window !== 'undefined',
|
|
200
202
|
backdropBlur: config.backdropBlur !== false, // Default: true
|
|
201
203
|
allowedDownloadHostPatterns: config.allowedDownloadHostPatterns ?? DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS,
|
|
202
204
|
};
|
|
@@ -975,11 +977,15 @@ class IdentityApi extends SparkVaultApi {
|
|
|
975
977
|
* If preload fails, getConfig() will clear the cache and retry.
|
|
976
978
|
*/
|
|
977
979
|
preloadConfig() {
|
|
978
|
-
if (
|
|
979
|
-
|
|
980
|
-
// If this fails, getConfig() clears the cache and retries.
|
|
981
|
-
this.configCache = this.request('GET', '/config');
|
|
980
|
+
if (this.configCache) {
|
|
981
|
+
return;
|
|
982
982
|
}
|
|
983
|
+
const pending = this.request('GET', '/config');
|
|
984
|
+
this.configCache = pending;
|
|
985
|
+
// Nobody awaits a background preload, and an unawaited rejection aborts the
|
|
986
|
+
// whole Node process. Attach a terminal handler so the failure stays parked
|
|
987
|
+
// on the cached promise, which getConfig() re-raises to its caller on demand.
|
|
988
|
+
pending.catch(() => { });
|
|
983
989
|
}
|
|
984
990
|
/**
|
|
985
991
|
* Check if config has been preloaded and is ready.
|
|
@@ -9425,8 +9431,9 @@ class IdentityModule {
|
|
|
9425
9431
|
*
|
|
9426
9432
|
* The counterpart to `sv.notify`: where that module is session-scoped and reads
|
|
9427
9433
|
* only the signed-in person's OWN inbox, this one is the account-scoped product
|
|
9428
|
-
* surface a tenant's BACKEND drives — send, sender-side
|
|
9429
|
-
* send status, receipts, and the account's Notify config.
|
|
9434
|
+
* surface a tenant's BACKEND drives — send, send history, recall, sender-side
|
|
9435
|
+
* inbox reads and state, send status, receipts, and the account's Notify config.
|
|
9436
|
+
* Every method maps to
|
|
9430
9437
|
* `/v1/products/notify/*` and is authorized by the caller's account, so the
|
|
9431
9438
|
* recipient is supplied explicitly rather than derived from a session.
|
|
9432
9439
|
*
|
|
@@ -9478,15 +9485,22 @@ const NOTIFY_PRESETS = Object.freeze({
|
|
|
9478
9485
|
channels: ['in_app', 'push', 'web_push', 'email'],
|
|
9479
9486
|
policy: { verificationLevel: 'identifier', interaction: 'reply' },
|
|
9480
9487
|
},
|
|
9488
|
+
// `approval` and `signatureRequest` verify at `identifier`, not `passkey`: a
|
|
9489
|
+
// passkey-level grant is only satisfiable by a recipient who ALREADY has a
|
|
9490
|
+
// passkey registered with SparkVault, and the recipient ceremony cannot enrol
|
|
9491
|
+
// one mid-flight — a passkey default strands every first-time raw-email
|
|
9492
|
+
// recipient on a request they can never answer. Pass
|
|
9493
|
+
// `policy: { verificationLevel: 'passkey' }` explicitly when the audience is
|
|
9494
|
+
// known to be enrolled.
|
|
9481
9495
|
approval: {
|
|
9482
9496
|
category: 'approval',
|
|
9483
9497
|
channels: ['in_app', 'push', 'web_push', 'email'],
|
|
9484
|
-
policy: { verificationLevel: '
|
|
9498
|
+
policy: { verificationLevel: 'identifier', interaction: 'approve' },
|
|
9485
9499
|
},
|
|
9486
9500
|
signatureRequest: {
|
|
9487
9501
|
category: 'signature',
|
|
9488
9502
|
channels: ['in_app', 'push', 'web_push', 'email'],
|
|
9489
|
-
policy: { verificationLevel: '
|
|
9503
|
+
policy: { verificationLevel: 'identifier', interaction: 'sign' },
|
|
9490
9504
|
},
|
|
9491
9505
|
});
|
|
9492
9506
|
/**
|
|
@@ -9576,11 +9590,11 @@ class NotifyProductModule {
|
|
|
9576
9590
|
async sendConversation(options) {
|
|
9577
9591
|
return this.send(buildNotifyPresetSend('conversation', options));
|
|
9578
9592
|
}
|
|
9579
|
-
/** High-stakes approve/deny —
|
|
9593
|
+
/** High-stakes approve/deny — identifier-verified, with `action_hash` binding. */
|
|
9580
9594
|
async sendApproval(options) {
|
|
9581
9595
|
return this.send(buildNotifyPresetSend('approval', options));
|
|
9582
9596
|
}
|
|
9583
|
-
/** Signature-on-delivery —
|
|
9597
|
+
/** Signature-on-delivery — identifier-verified, with `action_hash` binding. */
|
|
9584
9598
|
async sendSignatureRequest(options) {
|
|
9585
9599
|
return this.send(buildNotifyPresetSend('signatureRequest', options));
|
|
9586
9600
|
}
|
|
@@ -9666,6 +9680,76 @@ class NotifyProductModule {
|
|
|
9666
9680
|
});
|
|
9667
9681
|
return response.data;
|
|
9668
9682
|
}
|
|
9683
|
+
// ── Send history & recall ───────────────────────────────────────────────────
|
|
9684
|
+
/**
|
|
9685
|
+
* The account's send history, newest first — what you sent, to how many, and
|
|
9686
|
+
* how it landed.
|
|
9687
|
+
*
|
|
9688
|
+
* Metadata only by construction: the history index does not project the
|
|
9689
|
+
* audience, so no recipient contact or SparkLink pointer can travel here. Take
|
|
9690
|
+
* `getSendStatus(sendId)` for the per-recipient detail.
|
|
9691
|
+
*
|
|
9692
|
+
* Real pagination: a null `cursor` means the end of the account's history.
|
|
9693
|
+
*
|
|
9694
|
+
* @example
|
|
9695
|
+
* let cursor: string | undefined;
|
|
9696
|
+
* do {
|
|
9697
|
+
* const page = await sv.products.notify.listSends({ cursor, limit: 50 });
|
|
9698
|
+
* for (const send of page.sends) {
|
|
9699
|
+
* console.log(send.created_at, send.title, send.state,
|
|
9700
|
+
* `${send.delivered_count ?? '?'} / ${send.recipient_count ?? '?'}`);
|
|
9701
|
+
* }
|
|
9702
|
+
* cursor = page.cursor ?? undefined;
|
|
9703
|
+
* } while (cursor);
|
|
9704
|
+
*/
|
|
9705
|
+
async listSends(options = {}) {
|
|
9706
|
+
const query = buildQuery$3({ limit: options.limit, cursor: options.cursor });
|
|
9707
|
+
const response = await this.http.get(`${BASE_PATH}/sends${query}`);
|
|
9708
|
+
return response.data;
|
|
9709
|
+
}
|
|
9710
|
+
/**
|
|
9711
|
+
* Recall a sealed send: revoke the single-use SparkLink grants it minted, so
|
|
9712
|
+
* the content can no longer be revealed.
|
|
9713
|
+
*
|
|
9714
|
+
* `mode: 'grant'` (the default) drops access and leaves the content intact.
|
|
9715
|
+
* `mode: 'content'` hard-burns the sealed spark so it is unreadable for
|
|
9716
|
+
* everyone — spark-backed sends only, since an ingot send merely references the
|
|
9717
|
+
* owner's durable vault content.
|
|
9718
|
+
*
|
|
9719
|
+
* Idempotent: a grant already revoked (or already consumed) counts as recalled,
|
|
9720
|
+
* so a repeated call converges rather than accumulating failures. One
|
|
9721
|
+
* recipient's failure never stops the rest — the response reports every one.
|
|
9722
|
+
*
|
|
9723
|
+
* PLAINTEXT SENDS CANNOT BE RECALLED (400): they delivered their body inline,
|
|
9724
|
+
* in the clear, and minted no grant. There is nothing to revoke, and saying
|
|
9725
|
+
* otherwise would be a lie about the one thing you are asking.
|
|
9726
|
+
*
|
|
9727
|
+
* @example
|
|
9728
|
+
* // Whole audience, access only
|
|
9729
|
+
* await sv.products.notify.recallSend(send.send_id);
|
|
9730
|
+
*
|
|
9731
|
+
* // One recipient, burn the content for everyone
|
|
9732
|
+
* const { recalled, failed } = await sv.products.notify.recallSend(send.send_id, {
|
|
9733
|
+
* recipientIds: [user.svid],
|
|
9734
|
+
* mode: 'content',
|
|
9735
|
+
* });
|
|
9736
|
+
*/
|
|
9737
|
+
async recallSend(sendId, options = {}) {
|
|
9738
|
+
requireSendId(sendId);
|
|
9739
|
+
if (options.recipientIds !== undefined) {
|
|
9740
|
+
if (!Array.isArray(options.recipientIds) || options.recipientIds.length === 0) {
|
|
9741
|
+
throw new ValidationError('recipientIds must be a non-empty array; omit it entirely to recall the whole audience', { field: 'recipientIds', received: options.recipientIds });
|
|
9742
|
+
}
|
|
9743
|
+
}
|
|
9744
|
+
if (options.mode !== undefined && options.mode !== 'grant' && options.mode !== 'content') {
|
|
9745
|
+
throw new ValidationError("mode must be 'grant' or 'content'", {
|
|
9746
|
+
field: 'mode',
|
|
9747
|
+
received: options.mode,
|
|
9748
|
+
});
|
|
9749
|
+
}
|
|
9750
|
+
const response = await this.http.post(`${BASE_PATH}/sends/${encodeURIComponent(sendId)}/recall`, { recipient_ids: options.recipientIds, mode: options.mode });
|
|
9751
|
+
return response.data;
|
|
9752
|
+
}
|
|
9669
9753
|
// ── Status & receipts ───────────────────────────────────────────────────────
|
|
9670
9754
|
/**
|
|
9671
9755
|
* The sender's per-recipient delivery rollup for one send: who it reached and
|
|
@@ -9683,13 +9767,14 @@ class NotifyProductModule {
|
|
|
9683
9767
|
* The account's verified-interaction receipts (portable, JWKS-verifiable
|
|
9684
9768
|
* proofs), newest first. Follow `cursor` to page.
|
|
9685
9769
|
*
|
|
9686
|
-
*
|
|
9687
|
-
*
|
|
9688
|
-
*
|
|
9689
|
-
*
|
|
9770
|
+
* `source` says which store answered. `receipt_index` is the normal path — a
|
|
9771
|
+
* bounded query with real pagination. `legacy_scan` appears only for an account
|
|
9772
|
+
* whose receipts all predate that index; it filters the account audit log, so
|
|
9773
|
+
* it can hand back EMPTY pages that are nowhere near the end. On EITHER source,
|
|
9774
|
+
* follow the cursor until it is null before concluding there are none.
|
|
9690
9775
|
*
|
|
9691
9776
|
* @example
|
|
9692
|
-
* const { receipts, cursor } = await sv.products.notify.listReceipts({ interaction: 'approve' });
|
|
9777
|
+
* const { receipts, cursor, source } = await sv.products.notify.listReceipts({ interaction: 'approve' });
|
|
9693
9778
|
*/
|
|
9694
9779
|
async listReceipts(options = {}) {
|
|
9695
9780
|
const query = buildQuery$3({
|
|
@@ -9742,12 +9827,21 @@ class NotifyProductModule {
|
|
|
9742
9827
|
* a seeded default from re-appearing on the next merge. The reserved `security`
|
|
9743
9828
|
* category can neither be removed nor made optional.
|
|
9744
9829
|
*
|
|
9830
|
+
* The `events` section configures the outbound event webhook: `webhook_url`
|
|
9831
|
+
* must be https on a public host, and `secret` (16-256 chars) signs every event
|
|
9832
|
+
* body as `X-SparkVault-Signature: hex(HMAC-SHA256(secret, rawBody))`. The
|
|
9833
|
+
* secret is WRITE-ONLY — reads report `events.secret_set`, never the value.
|
|
9834
|
+
*
|
|
9745
9835
|
* @example
|
|
9746
9836
|
* await sv.products.notify.updateConfig({
|
|
9747
9837
|
* categories: {
|
|
9748
9838
|
* weekly_newsletter: { label: 'Weekly newsletter', required: false },
|
|
9749
9839
|
* marketing: null, // tombstone — remove the seeded default
|
|
9750
9840
|
* },
|
|
9841
|
+
* events: {
|
|
9842
|
+
* webhook_url: 'https://api.example.com/hooks/sparkvault',
|
|
9843
|
+
* secret: process.env.SPARKVAULT_EVENT_SECRET,
|
|
9844
|
+
* },
|
|
9751
9845
|
* });
|
|
9752
9846
|
*/
|
|
9753
9847
|
async updateConfig(patch) {
|
|
@@ -14703,7 +14797,7 @@ class SparkVault {
|
|
|
14703
14797
|
}
|
|
14704
14798
|
/** Get the SDK version */
|
|
14705
14799
|
static get version() {
|
|
14706
|
-
return '
|
|
14800
|
+
return '9.0.0';
|
|
14707
14801
|
}
|
|
14708
14802
|
}
|
|
14709
14803
|
if (typeof window !== 'undefined') {
|
|
@@ -14739,4 +14833,4 @@ exports.buildNotifyPresetSend = buildNotifyPresetSend;
|
|
|
14739
14833
|
exports.default = SparkVault;
|
|
14740
14834
|
exports.logger = logger;
|
|
14741
14835
|
exports.setDebugMode = setDebugMode;
|
|
14742
|
-
//# sourceMappingURL=
|
|
14836
|
+
//# sourceMappingURL=index.cjs.map
|