@sparkvault/sdk-js 8.15.0 → 9.0.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 +11 -5
- package/dist/config.d.ts +6 -4
- package/dist/{sparkvault.cjs.js → index.cjs} +125 -72
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +321 -31
- package/dist/{sparkvault.esm.js → index.mjs} +125 -72
- package/dist/index.mjs.map +1 -0
- package/dist/products/identity/index.d.ts +1 -1
- 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
|
@@ -192,7 +192,9 @@ function resolveConfig(config) {
|
|
|
192
192
|
getAccessToken: config.getAccessToken,
|
|
193
193
|
apiKey: config.apiKey,
|
|
194
194
|
clientId: config.clientId,
|
|
195
|
-
|
|
195
|
+
// Preloading warms a dialog that only a browser can open; default it off
|
|
196
|
+
// where there is no DOM so server hosts make no init-time network call.
|
|
197
|
+
preloadConfig: config.preloadConfig ?? typeof window !== 'undefined',
|
|
196
198
|
backdropBlur: config.backdropBlur !== false, // Default: true
|
|
197
199
|
allowedDownloadHostPatterns: config.allowedDownloadHostPatterns ?? DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS,
|
|
198
200
|
};
|
|
@@ -971,11 +973,15 @@ class IdentityApi extends SparkVaultApi {
|
|
|
971
973
|
* If preload fails, getConfig() will clear the cache and retry.
|
|
972
974
|
*/
|
|
973
975
|
preloadConfig() {
|
|
974
|
-
if (
|
|
975
|
-
|
|
976
|
-
// If this fails, getConfig() clears the cache and retries.
|
|
977
|
-
this.configCache = this.request('GET', '/config');
|
|
976
|
+
if (this.configCache) {
|
|
977
|
+
return;
|
|
978
978
|
}
|
|
979
|
+
const pending = this.request('GET', '/config');
|
|
980
|
+
this.configCache = pending;
|
|
981
|
+
// Nobody awaits a background preload, and an unawaited rejection aborts the
|
|
982
|
+
// whole Node process. Attach a terminal handler so the failure stays parked
|
|
983
|
+
// on the cached promise, which getConfig() re-raises to its caller on demand.
|
|
984
|
+
pending.catch(() => { });
|
|
979
985
|
}
|
|
980
986
|
/**
|
|
981
987
|
* Check if config has been preloaded and is ready.
|
|
@@ -8568,18 +8574,6 @@ const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
|
|
|
8568
8574
|
// listener but not sessionStorage) is what lets the next load self-heal.
|
|
8569
8575
|
const PENDING_KEY = 'sv_signin_pending';
|
|
8570
8576
|
const PENDING_TTL_MS = 10 * 60 * 1000;
|
|
8571
|
-
// One-shot: the identifier the recovery bounce is re-minting for. Written only
|
|
8572
|
-
// by the recovery bounce; the return leg consumes it to verify the redeemed
|
|
8573
|
-
// result is for that same account (see consumeHandoffFragment).
|
|
8574
|
-
const RECOVERY_HINT_KEY = 'sv_recovery_hint';
|
|
8575
|
-
/**
|
|
8576
|
-
* Normalize an identifier for equality, mirroring the server: trim, and
|
|
8577
|
-
* lowercase emails (a value containing '@'). Phones compare trimmed-exact.
|
|
8578
|
-
*/
|
|
8579
|
-
function normalizeIdentity(value) {
|
|
8580
|
-
const trimmed = value.trim();
|
|
8581
|
-
return trimmed.includes('@') ? trimmed.toLowerCase() : trimmed;
|
|
8582
|
-
}
|
|
8583
8577
|
/**
|
|
8584
8578
|
* Read and parse the pending marker — JSON `{ at, hint }`, where `hint` is the
|
|
8585
8579
|
* email or phone the sign-in was started with (null when the flow collects the
|
|
@@ -9081,11 +9075,9 @@ class IdentityModule {
|
|
|
9081
9075
|
// (and a StrictMode double-invocation finds an empty hash and no-ops).
|
|
9082
9076
|
let expectedState = null;
|
|
9083
9077
|
let codeVerifier = null;
|
|
9084
|
-
let expectedRecoveryIdentity = null;
|
|
9085
9078
|
try {
|
|
9086
9079
|
expectedState = sessionStorage.getItem('sv_oauth_state');
|
|
9087
9080
|
codeVerifier = sessionStorage.getItem('sv_pkce_verifier');
|
|
9088
|
-
expectedRecoveryIdentity = sessionStorage.getItem(RECOVERY_HINT_KEY);
|
|
9089
9081
|
this.clearOneShotAuthState();
|
|
9090
9082
|
}
|
|
9091
9083
|
catch {
|
|
@@ -9106,6 +9098,12 @@ class IdentityModule {
|
|
|
9106
9098
|
if (!codeVerifier) {
|
|
9107
9099
|
throw new ValidationError('Sign-in session was lost — please sign in again.');
|
|
9108
9100
|
}
|
|
9101
|
+
// WHICH account the code carries is settled where it is minted, never
|
|
9102
|
+
// here: the code is PKCE- and origin-bound to this tab, and a recovery
|
|
9103
|
+
// bounce only ever mints for the account its `login_hint` named (see
|
|
9104
|
+
// startRecoveryBounce). The redeemed result exposes just that account's
|
|
9105
|
+
// PRIMARY identifier — not necessarily the one the caller signed in
|
|
9106
|
+
// with — so re-checking it here could only discard valid sign-ins.
|
|
9109
9107
|
const raw = await this.api.redeemHandoffCode(code, codeVerifier);
|
|
9110
9108
|
const result = {
|
|
9111
9109
|
token: raw.token,
|
|
@@ -9115,18 +9113,6 @@ class IdentityModule {
|
|
|
9115
9113
|
sessionId: raw.session_id ?? undefined,
|
|
9116
9114
|
refreshToken: raw.refresh_token ?? undefined,
|
|
9117
9115
|
};
|
|
9118
|
-
// A recovery bounce carries the identifier the interrupted sign-in was
|
|
9119
|
-
// addressing, but /sso treats a hint matching no hub session like no hint
|
|
9120
|
-
// at all (anti-oracle) — so the bounce can come back holding a DIFFERENT
|
|
9121
|
-
// single-eligible account. The client is the one place that knows which
|
|
9122
|
-
// account the person was signing in to: a mismatched result is discarded,
|
|
9123
|
-
// never handed to the host (a wrong-account handoff). Silent — no
|
|
9124
|
-
// onError — falling through to interactive sign-in, matching the recovery
|
|
9125
|
-
// flow's non-oracle posture.
|
|
9126
|
-
if (expectedRecoveryIdentity &&
|
|
9127
|
-
normalizeIdentity(expectedRecoveryIdentity) !== normalizeIdentity(result.identity)) {
|
|
9128
|
-
return null;
|
|
9129
|
-
}
|
|
9130
9116
|
options.onSuccess?.(result);
|
|
9131
9117
|
return result;
|
|
9132
9118
|
}
|
|
@@ -9147,22 +9133,12 @@ class IdentityModule {
|
|
|
9147
9133
|
*/
|
|
9148
9134
|
async startRecoveryBounce(loginHint) {
|
|
9149
9135
|
const sso = new URL(`${this.config.identityBaseUrl}/${this.config.accountId}/sso`);
|
|
9150
|
-
// With several hub sessions, login_hint
|
|
9151
|
-
//
|
|
9152
|
-
//
|
|
9153
|
-
//
|
|
9154
|
-
//
|
|
9155
|
-
|
|
9156
|
-
if (loginHint) {
|
|
9157
|
-
sessionStorage.setItem(RECOVERY_HINT_KEY, loginHint);
|
|
9158
|
-
}
|
|
9159
|
-
else {
|
|
9160
|
-
sessionStorage.removeItem(RECOVERY_HINT_KEY);
|
|
9161
|
-
}
|
|
9162
|
-
}
|
|
9163
|
-
catch {
|
|
9164
|
-
// No storage → prepareHandoffNavigation bails below; nothing to verify.
|
|
9165
|
-
}
|
|
9136
|
+
// With several hub sessions, login_hint names the account the interrupted
|
|
9137
|
+
// sign-in was addressing, and it is the whole wrong-account defence: /sso
|
|
9138
|
+
// mints silently ONLY for a hint that matched exactly one hub session's
|
|
9139
|
+
// verified identifiers — every unsatisfiable hint (a stranger's address, an
|
|
9140
|
+
// ambiguous match, an account not eligible here) comes back with no result
|
|
9141
|
+
// at all rather than a different account's.
|
|
9166
9142
|
if (loginHint) {
|
|
9167
9143
|
sso.searchParams.set('login_hint', loginHint);
|
|
9168
9144
|
}
|
|
@@ -9170,16 +9146,6 @@ class IdentityModule {
|
|
|
9170
9146
|
if (nav) {
|
|
9171
9147
|
window.location.assign(nav);
|
|
9172
9148
|
}
|
|
9173
|
-
else {
|
|
9174
|
-
// The bounce never left (no storage or WebCrypto) — retire the stash so
|
|
9175
|
-
// it cannot linger into an unrelated later return leg.
|
|
9176
|
-
try {
|
|
9177
|
-
sessionStorage.removeItem(RECOVERY_HINT_KEY);
|
|
9178
|
-
}
|
|
9179
|
-
catch {
|
|
9180
|
-
// Storage disabled: nothing was persisted, nothing to clear.
|
|
9181
|
-
}
|
|
9182
|
-
}
|
|
9183
9149
|
}
|
|
9184
9150
|
/**
|
|
9185
9151
|
* Explicit `flow: 'redirect'` — navigate this tab to the interactive sign-in
|
|
@@ -9279,12 +9245,11 @@ class IdentityModule {
|
|
|
9279
9245
|
window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
|
|
9280
9246
|
}
|
|
9281
9247
|
}
|
|
9282
|
-
/** Drop the one-shot PKCE state/verifier
|
|
9248
|
+
/** Drop the one-shot PKCE state/verifier a bounce staged. */
|
|
9283
9249
|
clearOneShotAuthState() {
|
|
9284
9250
|
try {
|
|
9285
9251
|
sessionStorage.removeItem('sv_oauth_state');
|
|
9286
9252
|
sessionStorage.removeItem('sv_pkce_verifier');
|
|
9287
|
-
sessionStorage.removeItem(RECOVERY_HINT_KEY);
|
|
9288
9253
|
}
|
|
9289
9254
|
catch {
|
|
9290
9255
|
// Storage disabled: nothing was persisted, nothing to clear.
|
|
@@ -9421,8 +9386,9 @@ class IdentityModule {
|
|
|
9421
9386
|
*
|
|
9422
9387
|
* The counterpart to `sv.notify`: where that module is session-scoped and reads
|
|
9423
9388
|
* only the signed-in person's OWN inbox, this one is the account-scoped product
|
|
9424
|
-
* surface a tenant's BACKEND drives — send, sender-side
|
|
9425
|
-
* send status, receipts, and the account's Notify config.
|
|
9389
|
+
* surface a tenant's BACKEND drives — send, send history, recall, sender-side
|
|
9390
|
+
* inbox reads and state, send status, receipts, and the account's Notify config.
|
|
9391
|
+
* Every method maps to
|
|
9426
9392
|
* `/v1/products/notify/*` and is authorized by the caller's account, so the
|
|
9427
9393
|
* recipient is supplied explicitly rather than derived from a session.
|
|
9428
9394
|
*
|
|
@@ -9474,15 +9440,22 @@ const NOTIFY_PRESETS = Object.freeze({
|
|
|
9474
9440
|
channels: ['in_app', 'push', 'web_push', 'email'],
|
|
9475
9441
|
policy: { verificationLevel: 'identifier', interaction: 'reply' },
|
|
9476
9442
|
},
|
|
9443
|
+
// `approval` and `signatureRequest` verify at `identifier`, not `passkey`: a
|
|
9444
|
+
// passkey-level grant is only satisfiable by a recipient who ALREADY has a
|
|
9445
|
+
// passkey registered with SparkVault, and the recipient ceremony cannot enrol
|
|
9446
|
+
// one mid-flight — a passkey default strands every first-time raw-email
|
|
9447
|
+
// recipient on a request they can never answer. Pass
|
|
9448
|
+
// `policy: { verificationLevel: 'passkey' }` explicitly when the audience is
|
|
9449
|
+
// known to be enrolled.
|
|
9477
9450
|
approval: {
|
|
9478
9451
|
category: 'approval',
|
|
9479
9452
|
channels: ['in_app', 'push', 'web_push', 'email'],
|
|
9480
|
-
policy: { verificationLevel: '
|
|
9453
|
+
policy: { verificationLevel: 'identifier', interaction: 'approve' },
|
|
9481
9454
|
},
|
|
9482
9455
|
signatureRequest: {
|
|
9483
9456
|
category: 'signature',
|
|
9484
9457
|
channels: ['in_app', 'push', 'web_push', 'email'],
|
|
9485
|
-
policy: { verificationLevel: '
|
|
9458
|
+
policy: { verificationLevel: 'identifier', interaction: 'sign' },
|
|
9486
9459
|
},
|
|
9487
9460
|
});
|
|
9488
9461
|
/**
|
|
@@ -9572,11 +9545,11 @@ class NotifyProductModule {
|
|
|
9572
9545
|
async sendConversation(options) {
|
|
9573
9546
|
return this.send(buildNotifyPresetSend('conversation', options));
|
|
9574
9547
|
}
|
|
9575
|
-
/** High-stakes approve/deny —
|
|
9548
|
+
/** High-stakes approve/deny — identifier-verified, with `action_hash` binding. */
|
|
9576
9549
|
async sendApproval(options) {
|
|
9577
9550
|
return this.send(buildNotifyPresetSend('approval', options));
|
|
9578
9551
|
}
|
|
9579
|
-
/** Signature-on-delivery —
|
|
9552
|
+
/** Signature-on-delivery — identifier-verified, with `action_hash` binding. */
|
|
9580
9553
|
async sendSignatureRequest(options) {
|
|
9581
9554
|
return this.send(buildNotifyPresetSend('signatureRequest', options));
|
|
9582
9555
|
}
|
|
@@ -9662,6 +9635,76 @@ class NotifyProductModule {
|
|
|
9662
9635
|
});
|
|
9663
9636
|
return response.data;
|
|
9664
9637
|
}
|
|
9638
|
+
// ── Send history & recall ───────────────────────────────────────────────────
|
|
9639
|
+
/**
|
|
9640
|
+
* The account's send history, newest first — what you sent, to how many, and
|
|
9641
|
+
* how it landed.
|
|
9642
|
+
*
|
|
9643
|
+
* Metadata only by construction: the history index does not project the
|
|
9644
|
+
* audience, so no recipient contact or SparkLink pointer can travel here. Take
|
|
9645
|
+
* `getSendStatus(sendId)` for the per-recipient detail.
|
|
9646
|
+
*
|
|
9647
|
+
* Real pagination: a null `cursor` means the end of the account's history.
|
|
9648
|
+
*
|
|
9649
|
+
* @example
|
|
9650
|
+
* let cursor: string | undefined;
|
|
9651
|
+
* do {
|
|
9652
|
+
* const page = await sv.products.notify.listSends({ cursor, limit: 50 });
|
|
9653
|
+
* for (const send of page.sends) {
|
|
9654
|
+
* console.log(send.created_at, send.title, send.state,
|
|
9655
|
+
* `${send.delivered_count ?? '?'} / ${send.recipient_count ?? '?'}`);
|
|
9656
|
+
* }
|
|
9657
|
+
* cursor = page.cursor ?? undefined;
|
|
9658
|
+
* } while (cursor);
|
|
9659
|
+
*/
|
|
9660
|
+
async listSends(options = {}) {
|
|
9661
|
+
const query = buildQuery$3({ limit: options.limit, cursor: options.cursor });
|
|
9662
|
+
const response = await this.http.get(`${BASE_PATH}/sends${query}`);
|
|
9663
|
+
return response.data;
|
|
9664
|
+
}
|
|
9665
|
+
/**
|
|
9666
|
+
* Recall a sealed send: revoke the single-use SparkLink grants it minted, so
|
|
9667
|
+
* the content can no longer be revealed.
|
|
9668
|
+
*
|
|
9669
|
+
* `mode: 'grant'` (the default) drops access and leaves the content intact.
|
|
9670
|
+
* `mode: 'content'` hard-burns the sealed spark so it is unreadable for
|
|
9671
|
+
* everyone — spark-backed sends only, since an ingot send merely references the
|
|
9672
|
+
* owner's durable vault content.
|
|
9673
|
+
*
|
|
9674
|
+
* Idempotent: a grant already revoked (or already consumed) counts as recalled,
|
|
9675
|
+
* so a repeated call converges rather than accumulating failures. One
|
|
9676
|
+
* recipient's failure never stops the rest — the response reports every one.
|
|
9677
|
+
*
|
|
9678
|
+
* PLAINTEXT SENDS CANNOT BE RECALLED (400): they delivered their body inline,
|
|
9679
|
+
* in the clear, and minted no grant. There is nothing to revoke, and saying
|
|
9680
|
+
* otherwise would be a lie about the one thing you are asking.
|
|
9681
|
+
*
|
|
9682
|
+
* @example
|
|
9683
|
+
* // Whole audience, access only
|
|
9684
|
+
* await sv.products.notify.recallSend(send.send_id);
|
|
9685
|
+
*
|
|
9686
|
+
* // One recipient, burn the content for everyone
|
|
9687
|
+
* const { recalled, failed } = await sv.products.notify.recallSend(send.send_id, {
|
|
9688
|
+
* recipientIds: [user.svid],
|
|
9689
|
+
* mode: 'content',
|
|
9690
|
+
* });
|
|
9691
|
+
*/
|
|
9692
|
+
async recallSend(sendId, options = {}) {
|
|
9693
|
+
requireSendId(sendId);
|
|
9694
|
+
if (options.recipientIds !== undefined) {
|
|
9695
|
+
if (!Array.isArray(options.recipientIds) || options.recipientIds.length === 0) {
|
|
9696
|
+
throw new ValidationError('recipientIds must be a non-empty array; omit it entirely to recall the whole audience', { field: 'recipientIds', received: options.recipientIds });
|
|
9697
|
+
}
|
|
9698
|
+
}
|
|
9699
|
+
if (options.mode !== undefined && options.mode !== 'grant' && options.mode !== 'content') {
|
|
9700
|
+
throw new ValidationError("mode must be 'grant' or 'content'", {
|
|
9701
|
+
field: 'mode',
|
|
9702
|
+
received: options.mode,
|
|
9703
|
+
});
|
|
9704
|
+
}
|
|
9705
|
+
const response = await this.http.post(`${BASE_PATH}/sends/${encodeURIComponent(sendId)}/recall`, { recipient_ids: options.recipientIds, mode: options.mode });
|
|
9706
|
+
return response.data;
|
|
9707
|
+
}
|
|
9665
9708
|
// ── Status & receipts ───────────────────────────────────────────────────────
|
|
9666
9709
|
/**
|
|
9667
9710
|
* The sender's per-recipient delivery rollup for one send: who it reached and
|
|
@@ -9679,13 +9722,14 @@ class NotifyProductModule {
|
|
|
9679
9722
|
* The account's verified-interaction receipts (portable, JWKS-verifiable
|
|
9680
9723
|
* proofs), newest first. Follow `cursor` to page.
|
|
9681
9724
|
*
|
|
9682
|
-
*
|
|
9683
|
-
*
|
|
9684
|
-
*
|
|
9685
|
-
*
|
|
9725
|
+
* `source` says which store answered. `receipt_index` is the normal path — a
|
|
9726
|
+
* bounded query with real pagination. `legacy_scan` appears only for an account
|
|
9727
|
+
* whose receipts all predate that index; it filters the account audit log, so
|
|
9728
|
+
* it can hand back EMPTY pages that are nowhere near the end. On EITHER source,
|
|
9729
|
+
* follow the cursor until it is null before concluding there are none.
|
|
9686
9730
|
*
|
|
9687
9731
|
* @example
|
|
9688
|
-
* const { receipts, cursor } = await sv.products.notify.listReceipts({ interaction: 'approve' });
|
|
9732
|
+
* const { receipts, cursor, source } = await sv.products.notify.listReceipts({ interaction: 'approve' });
|
|
9689
9733
|
*/
|
|
9690
9734
|
async listReceipts(options = {}) {
|
|
9691
9735
|
const query = buildQuery$3({
|
|
@@ -9738,12 +9782,21 @@ class NotifyProductModule {
|
|
|
9738
9782
|
* a seeded default from re-appearing on the next merge. The reserved `security`
|
|
9739
9783
|
* category can neither be removed nor made optional.
|
|
9740
9784
|
*
|
|
9785
|
+
* The `events` section configures the outbound event webhook: `webhook_url`
|
|
9786
|
+
* must be https on a public host, and `secret` (16-256 chars) signs every event
|
|
9787
|
+
* body as `X-SparkVault-Signature: hex(HMAC-SHA256(secret, rawBody))`. The
|
|
9788
|
+
* secret is WRITE-ONLY — reads report `events.secret_set`, never the value.
|
|
9789
|
+
*
|
|
9741
9790
|
* @example
|
|
9742
9791
|
* await sv.products.notify.updateConfig({
|
|
9743
9792
|
* categories: {
|
|
9744
9793
|
* weekly_newsletter: { label: 'Weekly newsletter', required: false },
|
|
9745
9794
|
* marketing: null, // tombstone — remove the seeded default
|
|
9746
9795
|
* },
|
|
9796
|
+
* events: {
|
|
9797
|
+
* webhook_url: 'https://api.example.com/hooks/sparkvault',
|
|
9798
|
+
* secret: process.env.SPARKVAULT_EVENT_SECRET,
|
|
9799
|
+
* },
|
|
9747
9800
|
* });
|
|
9748
9801
|
*/
|
|
9749
9802
|
async updateConfig(patch) {
|
|
@@ -14699,7 +14752,7 @@ class SparkVault {
|
|
|
14699
14752
|
}
|
|
14700
14753
|
/** Get the SDK version */
|
|
14701
14754
|
static get version() {
|
|
14702
|
-
return '
|
|
14755
|
+
return '9.0.1';
|
|
14703
14756
|
}
|
|
14704
14757
|
}
|
|
14705
14758
|
if (typeof window !== 'undefined') {
|
|
@@ -14710,4 +14763,4 @@ if (typeof window !== 'undefined') {
|
|
|
14710
14763
|
}
|
|
14711
14764
|
|
|
14712
14765
|
export { AuthenticationError, AuthorizationError, EntropyModule, FoldersModule, IdentityModule, IngotsModule, NOTIFY_PRESETS, NetworkError, NotifyModule, NotifyProductModule, NotifySubscriptionRequiredError, PlanRequiredError, PopupBlockedError, ProductsModule, QuotaExceededError, SparkVault, SparkVaultError, SparksModule, TimeoutError, UserCancelledError, ValidationError, VaultsModule, buildNotifyPresetSend, SparkVault as default, logger, setDebugMode };
|
|
14713
|
-
//# sourceMappingURL=
|
|
14766
|
+
//# sourceMappingURL=index.mjs.map
|