@sparkvault/sdk-js 12.0.5 → 13.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 +98 -733
- package/dist/errors.d.ts +41 -11
- package/dist/http.d.ts +8 -6
- package/dist/index.cjs +597 -216
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +758 -207
- package/dist/index.mjs +597 -217
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/index.d.ts +13 -4
- package/dist/ingots/types.d.ts +5 -2
- package/dist/notify/index.d.ts +50 -7
- package/dist/notify/types.d.ts +33 -9
- package/dist/products/identity/api.d.ts +25 -15
- package/dist/products/identity/index.d.ts +1 -1
- package/dist/products/identity/renderer.d.ts +12 -3
- package/dist/products/identity/state.d.ts +16 -1
- package/dist/products/identity/types.d.ts +26 -6
- package/dist/products/identity/views/error.d.ts +7 -0
- package/dist/products/index.d.ts +2 -2
- package/dist/products/notify/index.d.ts +154 -31
- package/dist/products/notify/types.d.ts +406 -121
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/index.d.ts +5 -2
- package/dist/vaults/types.d.ts +2 -8
- package/dist/vaults/upload/api.d.ts +7 -0
- package/dist/vaults/upload/types.d.ts +10 -7
- package/package.json +1 -1
- package/dist/products/identity/types.test-d.d.ts +0 -21
- package/dist/products/notify/types.test-d.d.ts +0 -35
package/dist/index.cjs
CHANGED
|
@@ -31,12 +31,13 @@ function isTransientHttpStatus(status) {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* The upload publication contract between Forge and Core's activation, and
|
|
34
|
-
* the facts of a transfer
|
|
35
|
-
* publication
|
|
36
|
-
* names),
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* too: the upload id its delete is
|
|
34
|
+
* the facts of a transfer both services spell: its token's shape and the
|
|
35
|
+
* publication the token is bound to (a content version, and the one an ingot
|
|
36
|
+
* row names), its charge's ledger reference and category, Core's revocation
|
|
37
|
+
* of an upload's token, and the refusals of Core's a transfer's answer names
|
|
38
|
+
* (the header, and the lock of a vault scheduled for deletion). Every client
|
|
39
|
+
* ends an upload it gives up by one rule here too: the upload id its delete is
|
|
40
|
+
* conditioned on (givenUpUploadId).
|
|
40
41
|
*
|
|
41
42
|
* Forge stamps UPLOAD_PUBLICATION_PROTOCOL on every upload session it creates
|
|
42
43
|
* and on the final state it hands Core's activation (POST
|
|
@@ -771,33 +772,47 @@ function resumeOffsetProblem(offset, { totalSize, chunkSize }) {
|
|
|
771
772
|
* SparkVault SDK Error Types
|
|
772
773
|
*/
|
|
773
774
|
class SparkVaultError extends Error {
|
|
774
|
-
constructor(message, code, statusCode, details, retryAfterMs = null) {
|
|
775
|
+
constructor(message, code, statusCode, details, retryAfterMs = null, serviceCode) {
|
|
775
776
|
super(message);
|
|
776
777
|
this.name = 'SparkVaultError';
|
|
777
778
|
this.code = code;
|
|
778
779
|
this.statusCode = statusCode;
|
|
779
780
|
this.details = details;
|
|
780
781
|
this.retryAfterMs = retryAfterMs;
|
|
782
|
+
this.serviceCode = serviceCode;
|
|
781
783
|
Object.setPrototypeOf(this, SparkVaultError.prototype);
|
|
782
784
|
}
|
|
783
785
|
}
|
|
784
786
|
class AuthenticationError extends SparkVaultError {
|
|
785
|
-
constructor(message, details, retryAfterMs = null) {
|
|
786
|
-
super(message, 'authentication_error', 401, details, retryAfterMs);
|
|
787
|
+
constructor(message, details, retryAfterMs = null, serviceCode) {
|
|
788
|
+
super(message, 'authentication_error', 401, details, retryAfterMs, serviceCode);
|
|
787
789
|
this.name = 'AuthenticationError';
|
|
788
790
|
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
789
791
|
}
|
|
790
792
|
}
|
|
793
|
+
/**
|
|
794
|
+
* A key the request presents was refused (401 UNAUTHORIZED): the DVAK an
|
|
795
|
+
* unseal names is invalid or revoked. The caller's own credential stood, so
|
|
796
|
+
* this is no ended session, and signing in again changes nothing: present a
|
|
797
|
+
* live key. Every other 401 is an {@link AuthenticationError}.
|
|
798
|
+
*/
|
|
799
|
+
class UnauthorizedError extends SparkVaultError {
|
|
800
|
+
constructor(message, details, retryAfterMs = null, serviceCode) {
|
|
801
|
+
super(message, 'UNAUTHORIZED', 401, details, retryAfterMs, serviceCode);
|
|
802
|
+
this.name = 'UnauthorizedError';
|
|
803
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
791
806
|
class AuthorizationError extends SparkVaultError {
|
|
792
|
-
constructor(message, details, retryAfterMs = null) {
|
|
793
|
-
super(message, 'authorization_error', 403, details, retryAfterMs);
|
|
807
|
+
constructor(message, details, retryAfterMs = null, serviceCode) {
|
|
808
|
+
super(message, 'authorization_error', 403, details, retryAfterMs, serviceCode);
|
|
794
809
|
this.name = 'AuthorizationError';
|
|
795
810
|
Object.setPrototypeOf(this, AuthorizationError.prototype);
|
|
796
811
|
}
|
|
797
812
|
}
|
|
798
813
|
class ValidationError extends SparkVaultError {
|
|
799
|
-
constructor(message, details, retryAfterMs = null) {
|
|
800
|
-
super(message, 'validation_error', 400, details, retryAfterMs);
|
|
814
|
+
constructor(message, details, retryAfterMs = null, serviceCode) {
|
|
815
|
+
super(message, 'validation_error', 400, details, retryAfterMs, serviceCode);
|
|
801
816
|
this.name = 'ValidationError';
|
|
802
817
|
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
803
818
|
}
|
|
@@ -808,8 +823,8 @@ class ValidationError extends SparkVaultError {
|
|
|
808
823
|
* to admins, or "ask your account admin" to members.
|
|
809
824
|
*/
|
|
810
825
|
class PlanRequiredError extends SparkVaultError {
|
|
811
|
-
constructor(message, details, retryAfterMs = null) {
|
|
812
|
-
super(message, 'PLAN_REQUIRED', 402, details, retryAfterMs);
|
|
826
|
+
constructor(message, details, retryAfterMs = null, serviceCode) {
|
|
827
|
+
super(message, 'PLAN_REQUIRED', 402, details, retryAfterMs, serviceCode);
|
|
813
828
|
this.name = 'PlanRequiredError';
|
|
814
829
|
Object.setPrototypeOf(this, PlanRequiredError.prototype);
|
|
815
830
|
}
|
|
@@ -820,8 +835,8 @@ class PlanRequiredError extends SparkVaultError {
|
|
|
820
835
|
* the right capacity block.
|
|
821
836
|
*/
|
|
822
837
|
class QuotaExceededError extends SparkVaultError {
|
|
823
|
-
constructor(message, details, retryAfterMs = null) {
|
|
824
|
-
super(message, 'QUOTA_EXCEEDED', 402, details, retryAfterMs);
|
|
838
|
+
constructor(message, details, retryAfterMs = null, serviceCode) {
|
|
839
|
+
super(message, 'QUOTA_EXCEEDED', 402, details, retryAfterMs, serviceCode);
|
|
825
840
|
this.name = 'QuotaExceededError';
|
|
826
841
|
const resource = details?.resource;
|
|
827
842
|
this.resource =
|
|
@@ -830,14 +845,17 @@ class QuotaExceededError extends SparkVaultError {
|
|
|
830
845
|
}
|
|
831
846
|
}
|
|
832
847
|
/**
|
|
833
|
-
* Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED) — the account
|
|
834
|
-
*
|
|
835
|
-
*
|
|
836
|
-
*
|
|
848
|
+
* Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED) — the account
|
|
849
|
+
* does not hold Notify and attempted a send that names no accepted send's
|
|
850
|
+
* `sendId` (a replay of an accepted send, the same request under its `sendId`,
|
|
851
|
+
* is answered with the stored send), or a config save that selects a new
|
|
852
|
+
* `email.sending_domain`. Distinct from a generic authorization failure: the
|
|
853
|
+
* credential is fine and re-authenticating changes nothing, so surface a
|
|
854
|
+
* subscribe CTA rather than a sign-in prompt.
|
|
837
855
|
*/
|
|
838
856
|
class NotifySubscriptionRequiredError extends SparkVaultError {
|
|
839
|
-
constructor(message, details, retryAfterMs = null) {
|
|
840
|
-
super(message, 'NOTIFY_SUBSCRIPTION_REQUIRED', 403, details, retryAfterMs);
|
|
857
|
+
constructor(message, details, retryAfterMs = null, serviceCode) {
|
|
858
|
+
super(message, 'NOTIFY_SUBSCRIPTION_REQUIRED', 403, details, retryAfterMs, serviceCode);
|
|
841
859
|
this.name = 'NotifySubscriptionRequiredError';
|
|
842
860
|
Object.setPrototypeOf(this, NotifySubscriptionRequiredError.prototype);
|
|
843
861
|
}
|
|
@@ -969,6 +987,9 @@ async function readApiFailure(response) {
|
|
|
969
987
|
*
|
|
970
988
|
* - `isResourceIdOf(kind, value)`: an id of that kind.
|
|
971
989
|
* - `isResourceId(value)`: an id of any kind, for a check that takes several.
|
|
990
|
+
* - `resourceIdPattern(kind)`: the same grammar as a regular-expression
|
|
991
|
+
* source, for a JSON Schema `pattern` beside `maxLength:
|
|
992
|
+
* RESOURCE_ID_MAX_LENGTH`, so a route schema and a check never disagree.
|
|
972
993
|
*
|
|
973
994
|
* Browser-safe and import-free: sdk-js bundles it, sdk-mobile mirrors it, and
|
|
974
995
|
* the apps, the console and the mobile app import it.
|
|
@@ -1001,7 +1022,30 @@ const RESOURCE_ID_PREFIXES = Object.freeze({
|
|
|
1001
1022
|
/** The longest id, prefix included. */
|
|
1002
1023
|
const RESOURCE_ID_MAX_LENGTH = 128;
|
|
1003
1024
|
|
|
1004
|
-
|
|
1025
|
+
/** The body every id carries after its prefix's underscore: the path-safe alphabet. */
|
|
1026
|
+
const ID_BODY_SOURCE = '[A-Za-z0-9_-]+';
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* The pattern an id of the given kind matches, as a regular-expression source
|
|
1030
|
+
* string: its prefix, '_' and a body of the path-safe alphabet. A JSON Schema
|
|
1031
|
+
* reads it as `pattern`, with `maxLength: RESOURCE_ID_MAX_LENGTH`.
|
|
1032
|
+
*
|
|
1033
|
+
* @param {string} kind - A key of RESOURCE_ID_PREFIXES
|
|
1034
|
+
* @returns {string}
|
|
1035
|
+
* @throws {TypeError} for a kind the grammar does not name: a misspelled kind
|
|
1036
|
+
* would otherwise refuse every id without saying why
|
|
1037
|
+
*/
|
|
1038
|
+
function resourceIdPattern(kind) {
|
|
1039
|
+
if (!Object.hasOwn(RESOURCE_ID_PREFIXES, kind)) {
|
|
1040
|
+
throw new TypeError(`No resource kind '${kind}'`);
|
|
1041
|
+
}
|
|
1042
|
+
return `^${RESOURCE_ID_PREFIXES[kind]}_${ID_BODY_SOURCE}$`;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/** Each kind's pattern, compiled once. */
|
|
1046
|
+
const ID_PATTERNS = Object.freeze(Object.fromEntries(
|
|
1047
|
+
Object.keys(RESOURCE_ID_PREFIXES).map((kind) => [kind, new RegExp(resourceIdPattern(kind))])
|
|
1048
|
+
));
|
|
1005
1049
|
|
|
1006
1050
|
/**
|
|
1007
1051
|
* Whether a value is an id of the given kind.
|
|
@@ -1016,11 +1060,9 @@ function isResourceIdOf(kind, value) {
|
|
|
1016
1060
|
if (!Object.hasOwn(RESOURCE_ID_PREFIXES, kind)) {
|
|
1017
1061
|
throw new TypeError(`No resource kind '${kind}'`);
|
|
1018
1062
|
}
|
|
1019
|
-
const prefix = `${RESOURCE_ID_PREFIXES[kind]}_`;
|
|
1020
1063
|
return typeof value === 'string'
|
|
1021
1064
|
&& value.length <= RESOURCE_ID_MAX_LENGTH
|
|
1022
|
-
&&
|
|
1023
|
-
&& ID_BODY.test(value.slice(prefix.length));
|
|
1065
|
+
&& ID_PATTERNS[kind].test(value);
|
|
1024
1066
|
}
|
|
1025
1067
|
|
|
1026
1068
|
const KINDS = Object.freeze(Object.keys(RESOURCE_ID_PREFIXES));
|
|
@@ -1041,7 +1083,7 @@ function isResourceId(value) {
|
|
|
1041
1083
|
* Keep platform domain decisions centralized: CSP, redirect safety, custom
|
|
1042
1084
|
* domain reservation, and Identity postMessage trust all read this registry.
|
|
1043
1085
|
* Trust follows the hosts the platform owns (isSparkVaultOwnedHostname);
|
|
1044
|
-
* reservation covers those and
|
|
1086
|
+
* reservation covers those and each product mail domain's subtree
|
|
1045
1087
|
* (isSparkVaultReservedDomain), whose hosts are SparkVault's to hand out but
|
|
1046
1088
|
* never trusted.
|
|
1047
1089
|
*/
|
|
@@ -1071,7 +1113,6 @@ const SPARKVAULT_PLATFORM_SV_HOSTS = Object.freeze([
|
|
|
1071
1113
|
SPARKVAULT_LINKS_HOST,
|
|
1072
1114
|
SPARKVAULT_FILES_HOST,
|
|
1073
1115
|
'file.sv',
|
|
1074
|
-
'send.sv',
|
|
1075
1116
|
'spark.sv',
|
|
1076
1117
|
'by.sv',
|
|
1077
1118
|
'at.sv',
|
|
@@ -1516,33 +1557,40 @@ class HttpClient {
|
|
|
1516
1557
|
throw new SparkVaultError(`Unexpected response format: expected JSON but received ${contentType ?? 'unknown content type'}`, 'invalid_response_format', response.status, { body: text.slice(0, 500) });
|
|
1517
1558
|
}
|
|
1518
1559
|
/**
|
|
1519
|
-
* The SDK error for a failed answer, typed by its status
|
|
1520
|
-
* page branches on get their own class,
|
|
1521
|
-
* error under the service's own code.
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1524
|
-
*
|
|
1560
|
+
* The SDK error for a failed answer, typed by its status (a 402's or a 403's
|
|
1561
|
+
* by its code too): the gates a host page branches on get their own class,
|
|
1562
|
+
* and every other answer is the base error under the service's own code.
|
|
1563
|
+
* Each carries the service's code (`serviceCode`), which tells apart two
|
|
1564
|
+
* refusals that share a typed class's `code`, and the answer's `Retry-After`
|
|
1565
|
+
* (`retryAfterMs`), the floor for whoever retries it — the SDK's own
|
|
1566
|
+
* transfers when the answer is a download link's mint, and the host page
|
|
1567
|
+
* otherwise.
|
|
1525
1568
|
*/
|
|
1526
1569
|
createErrorFromResponse({ status, message, code, details, retryAfterMs }) {
|
|
1527
1570
|
switch (status) {
|
|
1528
1571
|
case 400:
|
|
1529
|
-
return new ValidationError(message, details, retryAfterMs);
|
|
1572
|
+
return new ValidationError(message, details, retryAfterMs, code);
|
|
1530
1573
|
case 401:
|
|
1531
|
-
|
|
1574
|
+
// A refused key the request carries (an unseal's DVAK) is no ended
|
|
1575
|
+
// session: its own class, so a caller never signs out over it.
|
|
1576
|
+
if (code === 'UNAUTHORIZED')
|
|
1577
|
+
return new UnauthorizedError(message, details, retryAfterMs, code);
|
|
1578
|
+
return new AuthenticationError(message, details, retryAfterMs, code);
|
|
1532
1579
|
case 402:
|
|
1533
1580
|
if (code === 'QUOTA_EXCEEDED')
|
|
1534
|
-
return new QuotaExceededError(message, details, retryAfterMs);
|
|
1581
|
+
return new QuotaExceededError(message, details, retryAfterMs, code);
|
|
1535
1582
|
// PLAN_REQUIRED is the canonical 402 gate; treat any other 402 as one too.
|
|
1536
|
-
return new PlanRequiredError(message, details, retryAfterMs);
|
|
1583
|
+
return new PlanRequiredError(message, details, retryAfterMs, code);
|
|
1537
1584
|
case 403:
|
|
1538
|
-
// A Notify send
|
|
1539
|
-
//
|
|
1585
|
+
// A Notify send, or a config save selecting a new sending domain, refused
|
|
1586
|
+
// because the account does not hold Notify is a billing gate, not a
|
|
1587
|
+
// credential problem — give it its own catchable type.
|
|
1540
1588
|
if (code === 'NOTIFY_SUBSCRIPTION_REQUIRED') {
|
|
1541
|
-
return new NotifySubscriptionRequiredError(message, details, retryAfterMs);
|
|
1589
|
+
return new NotifySubscriptionRequiredError(message, details, retryAfterMs, code);
|
|
1542
1590
|
}
|
|
1543
|
-
return new AuthorizationError(message, details, retryAfterMs);
|
|
1591
|
+
return new AuthorizationError(message, details, retryAfterMs, code);
|
|
1544
1592
|
default:
|
|
1545
|
-
return new SparkVaultError(message, code, status, details, retryAfterMs);
|
|
1593
|
+
return new SparkVaultError(message, code, status, details, retryAfterMs, code);
|
|
1546
1594
|
}
|
|
1547
1595
|
}
|
|
1548
1596
|
unwrapApiResponse(data) {
|
|
@@ -2397,11 +2445,12 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2397
2445
|
}
|
|
2398
2446
|
/**
|
|
2399
2447
|
* Check whether the SVID resolved from an email or phone has registered
|
|
2400
|
-
* passkeys (`has_passkey`; cross-tenant — single global RP)
|
|
2448
|
+
* passkeys (`has_passkey`; cross-tenant — single global RP), for a
|
|
2449
|
+
* verification that admits passkeys.
|
|
2401
2450
|
*/
|
|
2402
|
-
async checkPasskey(identity, identityType = 'email') {
|
|
2403
|
-
const
|
|
2404
|
-
return this.request('POST', apiPath `/passkey/check`,
|
|
2451
|
+
async checkPasskey(identity, identityType = 'email', authContext) {
|
|
2452
|
+
const identityParam = identityType === 'phone' ? { phone: identity } : { email: identity };
|
|
2453
|
+
return this.request('POST', apiPath `/passkey/check`, { ...identityParam, ...verifySessionParam(authContext) });
|
|
2405
2454
|
}
|
|
2406
2455
|
/**
|
|
2407
2456
|
* Redeem a one-time sign-in code (with its PKCE verifier) for the sign-in
|
|
@@ -2417,28 +2466,15 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2417
2466
|
});
|
|
2418
2467
|
}
|
|
2419
2468
|
/**
|
|
2420
|
-
* The auth context a
|
|
2421
|
-
* `auth_request_id
|
|
2422
|
-
*
|
|
2423
|
-
*/
|
|
2424
|
-
buildAuthRequestParam(authContext) {
|
|
2425
|
-
return authContext?.authRequestId ? { auth_request_id: authContext.authRequestId } : {};
|
|
2426
|
-
}
|
|
2427
|
-
/**
|
|
2428
|
-
* Build auth context params for the completing requests (OIDC/simple mode).
|
|
2429
|
-
* Converts AuthContext to snake_case params expected by backend.
|
|
2469
|
+
* The auth context a send or a completion carries: its OIDC
|
|
2470
|
+
* `auth_request_id` (a send keeps the auth request alive as long as what it
|
|
2471
|
+
* sent), and the verify session it belongs to.
|
|
2430
2472
|
*/
|
|
2431
2473
|
buildAuthContextParams(authContext) {
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
failure_url: authContext.simpleMode.failureUrl,
|
|
2437
|
-
state: authContext.simpleMode.state,
|
|
2438
|
-
session_id: authContext.simpleMode.sessionId,
|
|
2439
|
-
};
|
|
2440
|
-
}
|
|
2441
|
-
return params;
|
|
2474
|
+
return {
|
|
2475
|
+
...(authContext?.authRequestId ? { auth_request_id: authContext.authRequestId } : {}),
|
|
2476
|
+
...verifySessionParam(authContext),
|
|
2477
|
+
};
|
|
2442
2478
|
}
|
|
2443
2479
|
/**
|
|
2444
2480
|
* Send OTP code to email or phone
|
|
@@ -2447,7 +2483,7 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2447
2483
|
return this.request('POST', apiPath `/otp/send`, {
|
|
2448
2484
|
recipient: params.recipient,
|
|
2449
2485
|
method: params.method,
|
|
2450
|
-
...this.
|
|
2486
|
+
...this.buildAuthContextParams(params.authContext),
|
|
2451
2487
|
});
|
|
2452
2488
|
}
|
|
2453
2489
|
/**
|
|
@@ -2474,16 +2510,17 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2474
2510
|
});
|
|
2475
2511
|
}
|
|
2476
2512
|
/**
|
|
2477
|
-
* Start passkey verification
|
|
2478
|
-
* that person's credentials
|
|
2479
|
-
* only the matching passkey;
|
|
2480
|
-
*
|
|
2513
|
+
* Start passkey verification, for a verification that admits passkeys. An
|
|
2514
|
+
* optional identifier scopes the ceremony to that person's credentials
|
|
2515
|
+
* (`allowCredentials`) so the authenticator offers only the matching passkey;
|
|
2516
|
+
* omit it for a discoverable ceremony. Completion always routes via the
|
|
2517
|
+
* credential userHandle, so scoping is purely a hint.
|
|
2481
2518
|
*/
|
|
2482
|
-
async startPasskeyVerify(identity, identityType = 'email') {
|
|
2519
|
+
async startPasskeyVerify(identity, identityType = 'email', authContext) {
|
|
2483
2520
|
const identityParam = identity ? { [identityType]: identity } : {};
|
|
2484
2521
|
// Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
|
|
2485
2522
|
// Extract and flatten to match PasskeyChallengeResponse
|
|
2486
|
-
const response = await this.request('POST', apiPath `/passkey/verify`, identityParam);
|
|
2523
|
+
const response = await this.request('POST', apiPath `/passkey/verify`, { ...identityParam, ...verifySessionParam(authContext) });
|
|
2487
2524
|
return {
|
|
2488
2525
|
challenge: response.options.challenge,
|
|
2489
2526
|
rpId: response.options.rpId,
|
|
@@ -2562,14 +2599,8 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2562
2599
|
if (authContext?.authRequestId) {
|
|
2563
2600
|
params.set('auth_request_id', authContext.authRequestId);
|
|
2564
2601
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
? { session_id: authContext.simpleMode.sessionId }
|
|
2568
|
-
: {
|
|
2569
|
-
success_url: authContext.simpleMode.successUrl,
|
|
2570
|
-
failure_url: authContext.simpleMode.failureUrl,
|
|
2571
|
-
state: authContext.simpleMode.state,
|
|
2572
|
-
};
|
|
2602
|
+
const { simple_mode: simpleMode } = verifySessionParam(authContext);
|
|
2603
|
+
if (simpleMode) {
|
|
2573
2604
|
params.set('simple_mode', JSON.stringify(simpleMode));
|
|
2574
2605
|
}
|
|
2575
2606
|
return `${this.baseUrl}/social/${provider}?${params}`;
|
|
@@ -2582,7 +2613,7 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2582
2613
|
return this.request('POST', apiPath `/sparklink/send`, {
|
|
2583
2614
|
email,
|
|
2584
2615
|
connection_id: connectionId,
|
|
2585
|
-
...this.
|
|
2616
|
+
...this.buildAuthContextParams(authContext),
|
|
2586
2617
|
});
|
|
2587
2618
|
}
|
|
2588
2619
|
/**
|
|
@@ -2598,6 +2629,17 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2598
2629
|
return parseSparkLinkEvent(data);
|
|
2599
2630
|
}
|
|
2600
2631
|
}
|
|
2632
|
+
/**
|
|
2633
|
+
* The verify session a request of a verification against one names, as
|
|
2634
|
+
* `simple_mode: { session_id }`: the one field of it the server reads, the
|
|
2635
|
+
* session's row holding the rest. Every request of the verification carries
|
|
2636
|
+
* it (its sends, its passkey check and start, its completion, in a body or a
|
|
2637
|
+
* popup's query), so the server holds each to what the session admits; a
|
|
2638
|
+
* request that named none would be judged as a sign-in to the account instead.
|
|
2639
|
+
*/
|
|
2640
|
+
function verifySessionParam(authContext) {
|
|
2641
|
+
return authContext?.simpleMode ? { simple_mode: { session_id: authContext.simpleMode.sessionId } } : {};
|
|
2642
|
+
}
|
|
2601
2643
|
/**
|
|
2602
2644
|
* Read a SparkLink result event. The WebSocket push and the kindling reclaim
|
|
2603
2645
|
* carry the same server-built event, so this is the one reader for both.
|
|
@@ -2794,6 +2836,42 @@ function formatPhoneDisplay(value) {
|
|
|
2794
2836
|
return `(${national.slice(0, 3)}) ${national.slice(3, 6)}-${national.slice(6, 10)}`;
|
|
2795
2837
|
}
|
|
2796
2838
|
|
|
2839
|
+
/**
|
|
2840
|
+
* What a recipient is told when the grant they opened asks a stronger
|
|
2841
|
+
* verification than they can give: its sender held it to the `passkey` level,
|
|
2842
|
+
* and the person holds no passkey registered with SparkVault, or proved
|
|
2843
|
+
* themselves by a lesser factor. No ceremony enrols a passkey on the way to a
|
|
2844
|
+
* grant, so nothing the recipient retries can clear it: only the sender can
|
|
2845
|
+
* resend at a level the person can clear, and the words say so.
|
|
2846
|
+
*
|
|
2847
|
+
* One wording for every surface that meets it, each naming what was opened:
|
|
2848
|
+
* x.sv's page for a proof weaker than its grant asks (apps/api
|
|
2849
|
+
* routes/public-domains.js renderStrongerVerificationPage) and the JSON refusal
|
|
2850
|
+
* of the same proof (apps/api sparklinks/public-denial.js
|
|
2851
|
+
* verificationChallenge), the files.sv viewer (apps/web
|
|
2852
|
+
* pages/PublicFileViewer.jsx), and the Identity sign-in renderer on a
|
|
2853
|
+
* recipient's proof that admits a passkey alone, for a person who holds none
|
|
2854
|
+
* (packages/sdk-js products/identity/renderer.ts).
|
|
2855
|
+
*
|
|
2856
|
+
* BROWSER-SAFE: no imports.
|
|
2857
|
+
*/
|
|
2858
|
+
|
|
2859
|
+
/** The heading of a page that says it. */
|
|
2860
|
+
const STRONGER_VERIFICATION_TITLE = 'This request needs your passkey';
|
|
2861
|
+
|
|
2862
|
+
/**
|
|
2863
|
+
* The words, naming what was opened and the organization that sent it.
|
|
2864
|
+
*
|
|
2865
|
+
* @param {'request'|'link'|'file'} subject - What the recipient opened
|
|
2866
|
+
* @param {string|null} [organizationName] - The sending organization's name,
|
|
2867
|
+
* when the surface knows it; the words name "the sender" otherwise
|
|
2868
|
+
* @returns {string}
|
|
2869
|
+
*/
|
|
2870
|
+
function strongerVerificationMessage(subject, organizationName) {
|
|
2871
|
+
return `This ${subject} requires a passkey already registered with SparkVault. `
|
|
2872
|
+
+ `Ask ${organizationName || 'the sender'} to resend it at a different verification level.`;
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2797
2875
|
/**
|
|
2798
2876
|
* Method Registry
|
|
2799
2877
|
*
|
|
@@ -2973,7 +3051,29 @@ class VerificationState {
|
|
|
2973
3051
|
this._recipient = recipient;
|
|
2974
3052
|
this._identityType = type;
|
|
2975
3053
|
}
|
|
3054
|
+
/**
|
|
3055
|
+
* The methods this verification may use: what its verify session admits,
|
|
3056
|
+
* as the hosted page names it, else the account's sign-in methods.
|
|
3057
|
+
*/
|
|
3058
|
+
get methodIds() {
|
|
3059
|
+
return this._authContext?.simpleMode?.methods ?? this._sdkConfig?.methods ?? [];
|
|
3060
|
+
}
|
|
3061
|
+
/**
|
|
3062
|
+
* Whether this verification proves a request its sender held to a passkey,
|
|
3063
|
+
* as its verify session's hosted page names it: the session admits the
|
|
3064
|
+
* passkey alone.
|
|
3065
|
+
*/
|
|
3066
|
+
get passkeyRequired() {
|
|
3067
|
+
return this._authContext?.simpleMode?.passkeyRequired === true;
|
|
3068
|
+
}
|
|
3069
|
+
/**
|
|
3070
|
+
* The identifier types this verification's methods deliver to: its verify
|
|
3071
|
+
* session's, else the account's.
|
|
3072
|
+
*/
|
|
2976
3073
|
getAllowedIdentityTypes() {
|
|
3074
|
+
const fromSession = this._authContext?.simpleMode?.allowedIdentityTypes;
|
|
3075
|
+
if (fromSession)
|
|
3076
|
+
return fromSession;
|
|
2977
3077
|
if (!this._sdkConfig)
|
|
2978
3078
|
return ['email'];
|
|
2979
3079
|
const allowed = this._sdkConfig.allowedIdentityTypes ?? ['email'];
|
|
@@ -3196,7 +3296,7 @@ class PasskeyHandler {
|
|
|
3196
3296
|
*/
|
|
3197
3297
|
async checkPasskey() {
|
|
3198
3298
|
try {
|
|
3199
|
-
const response = await this.api.checkPasskey(this.state.recipient, this.state.identityType);
|
|
3299
|
+
const response = await this.api.checkPasskey(this.state.recipient, this.state.identityType, this.state.authContext);
|
|
3200
3300
|
this.state.setPasskeyStatus(response.has_passkey);
|
|
3201
3301
|
}
|
|
3202
3302
|
catch (error) {
|
|
@@ -3267,7 +3367,7 @@ class PasskeyHandler {
|
|
|
3267
3367
|
// passkeys so the authenticator offers only the matching credential;
|
|
3268
3368
|
// without one it falls back to a discoverable ceremony.
|
|
3269
3369
|
const identityType = this.state.identityType === 'phone' ? 'phone' : 'email';
|
|
3270
|
-
const challenge = await this.api.startPasskeyVerify(this.state.recipient, identityType);
|
|
3370
|
+
const challenge = await this.api.startPasskeyVerify(this.state.recipient, identityType, this.state.authContext);
|
|
3271
3371
|
const credential = await navigator.credentials.get({
|
|
3272
3372
|
...(signal ? { signal } : {}),
|
|
3273
3373
|
publicKey: {
|
|
@@ -3371,18 +3471,15 @@ class PasskeyHandler {
|
|
|
3371
3471
|
const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
|
|
3372
3472
|
params.set(identityParam, this.state.recipient);
|
|
3373
3473
|
}
|
|
3374
|
-
//
|
|
3474
|
+
// The ceremony's auth context: an OIDC auth request, or the verify session
|
|
3475
|
+
// every request of the verification names.
|
|
3375
3476
|
const authContext = this.state.authContext;
|
|
3376
3477
|
if (authContext?.authRequestId) {
|
|
3377
3478
|
params.set('auth_request_id', authContext.authRequestId);
|
|
3378
3479
|
}
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
failure_url: authContext.simpleMode.failureUrl,
|
|
3383
|
-
state: authContext.simpleMode.state,
|
|
3384
|
-
session_id: authContext.simpleMode.sessionId,
|
|
3385
|
-
}));
|
|
3480
|
+
const { simple_mode: simpleMode } = verifySessionParam(authContext);
|
|
3481
|
+
if (simpleMode) {
|
|
3482
|
+
params.set('simple_mode', JSON.stringify(simpleMode));
|
|
3386
3483
|
}
|
|
3387
3484
|
const hash = mode === 'register' && registrationToken
|
|
3388
3485
|
? `#${new URLSearchParams({ registration_token: registrationToken }).toString()}`
|
|
@@ -5542,6 +5639,33 @@ const IDENTITY_BLOCKED_ERROR_CODES = [
|
|
|
5542
5639
|
function isBlockedCode(code) {
|
|
5543
5640
|
return IDENTITY_BLOCKED_ERROR_CODES.includes(code);
|
|
5544
5641
|
}
|
|
5642
|
+
/**
|
|
5643
|
+
* The code of a verification whose request its sender held to a passkey, for
|
|
5644
|
+
* a person who holds none: no ceremony here enrols one, so the person can do
|
|
5645
|
+
* nothing from this page, and only the sender can resend the request at a
|
|
5646
|
+
* level they can clear (the message says so).
|
|
5647
|
+
*/
|
|
5648
|
+
const STRONGER_VERIFICATION_REQUIRED_CODE = 'stronger_verification_required';
|
|
5649
|
+
/**
|
|
5650
|
+
* The heading of a state the person can do nothing about from here, by its
|
|
5651
|
+
* code, or null for a genuine error. Retrying cannot clear any of them, so the
|
|
5652
|
+
* view shows such a state with no debug code badge and no "Try Again", only
|
|
5653
|
+
* Close:
|
|
5654
|
+
* - a locked-down identity, which only managing it at auth.sv clears;
|
|
5655
|
+
* - a blocked Identity (trial exhausted or expired, or a paid capacity wall),
|
|
5656
|
+
* which only the site owner subscribing clears, shown as a friendly,
|
|
5657
|
+
* non-leaky interstitial;
|
|
5658
|
+
* - a request held to a passkey the person does not hold.
|
|
5659
|
+
*/
|
|
5660
|
+
function terminalTitle(code) {
|
|
5661
|
+
if (code === 'identity_locked')
|
|
5662
|
+
return 'This SparkVault Identity is locked';
|
|
5663
|
+
if (isBlockedCode(code))
|
|
5664
|
+
return 'Sign-in unavailable';
|
|
5665
|
+
if (code === STRONGER_VERIFICATION_REQUIRED_CODE)
|
|
5666
|
+
return STRONGER_VERIFICATION_TITLE;
|
|
5667
|
+
return null;
|
|
5668
|
+
}
|
|
5545
5669
|
class ErrorView {
|
|
5546
5670
|
constructor(props) {
|
|
5547
5671
|
this.retryButton = null;
|
|
@@ -5561,24 +5685,11 @@ class ErrorView {
|
|
|
5561
5685
|
// Content section
|
|
5562
5686
|
const contentSection = div();
|
|
5563
5687
|
contentSection.className = 'sv-error-content';
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
// login cannot clear a lockdown — only managing it at auth.sv can).
|
|
5567
|
-
const isLocked = this.props.code === 'identity_locked';
|
|
5568
|
-
// A blocked Identity (trial exhausted/expired, or paid capacity wall) is
|
|
5569
|
-
// likewise terminal for the end user: retrying cannot restore access, only
|
|
5570
|
-
// the site owner subscribing can. Show a friendly, non-leaky interstitial.
|
|
5571
|
-
const isBlocked = isBlockedCode(this.props.code);
|
|
5572
|
-
// Both states are terminal — suppress the debug code badge and the retry
|
|
5573
|
-
// button, leaving only Close.
|
|
5574
|
-
const isTerminal = isLocked || isBlocked;
|
|
5688
|
+
const terminal = terminalTitle(this.props.code);
|
|
5689
|
+
const isTerminal = terminal !== null;
|
|
5575
5690
|
const title = document.createElement('h3');
|
|
5576
5691
|
title.className = 'sv-error-title';
|
|
5577
|
-
title.textContent =
|
|
5578
|
-
? 'This SparkVault Identity is locked'
|
|
5579
|
-
: isBlocked
|
|
5580
|
-
? 'Sign-in unavailable'
|
|
5581
|
-
: 'Something went wrong';
|
|
5692
|
+
title.textContent = terminal ?? 'Something went wrong';
|
|
5582
5693
|
const message = document.createElement('p');
|
|
5583
5694
|
message.className = 'sv-error-message';
|
|
5584
5695
|
message.textContent = this.props.message;
|
|
@@ -6444,14 +6555,14 @@ class IdentityRenderer {
|
|
|
6444
6555
|
}
|
|
6445
6556
|
/**
|
|
6446
6557
|
* True when the discoverable ceremony may be started without a gesture and
|
|
6447
|
-
* this
|
|
6448
|
-
* origin, the browser carries the passkey hint, and `passkey` is
|
|
6449
|
-
*
|
|
6558
|
+
* this verification actually offers passkey login: the flow runs on the
|
|
6559
|
+
* Identity origin, the browser carries the passkey hint, and `passkey` is
|
|
6560
|
+
* among the verification's methods.
|
|
6450
6561
|
*/
|
|
6451
6562
|
canDiscoverableVerify() {
|
|
6452
6563
|
if (!this.passkeyHandler.canAutoVerify())
|
|
6453
6564
|
return false;
|
|
6454
|
-
const methods = enrichMethods(this.
|
|
6565
|
+
const methods = enrichMethods(this.verificationState.methodIds);
|
|
6455
6566
|
return methods.some((m) => m.type === 'passkey');
|
|
6456
6567
|
}
|
|
6457
6568
|
/**
|
|
@@ -6643,15 +6754,18 @@ class IdentityRenderer {
|
|
|
6643
6754
|
: state.mode === 'verify'
|
|
6644
6755
|
// Back returns to the picker with passkey still listed.
|
|
6645
6756
|
// autoRoute=false prevents the auto-jump from sending the
|
|
6646
|
-
// user straight back to this view.
|
|
6647
|
-
//
|
|
6757
|
+
// user straight back to this view. With no other method to
|
|
6758
|
+
// pick, it returns to the identifier the person typed; an
|
|
6759
|
+
// identity the flow fixed has no identifier step to return to.
|
|
6648
6760
|
? this.passkeyFallbackMethodsAvailable()
|
|
6649
6761
|
? () => this.showMethodSelect({ autoRoute: false })
|
|
6650
|
-
: this.recipient
|
|
6762
|
+
: this.recipient && !this.isIdentityFixed()
|
|
6651
6763
|
? () => this.showIdentityInput()
|
|
6652
6764
|
: undefined
|
|
6653
6765
|
: () => this.showMethodSelect(),
|
|
6654
|
-
|
|
6766
|
+
// A code is offered only where the verification admits another
|
|
6767
|
+
// method: a request held to a passkey admits the passkey alone.
|
|
6768
|
+
onFallback: passkey.hasPasskey && !passkey.isFallbackMode && this.passkeyFallbackMethodsAvailable()
|
|
6655
6769
|
? () => this.handlePasskeyFallback()
|
|
6656
6770
|
: undefined,
|
|
6657
6771
|
});
|
|
@@ -6739,8 +6853,10 @@ class IdentityRenderer {
|
|
|
6739
6853
|
const autoRoute = options.autoRoute !== false;
|
|
6740
6854
|
if (!this.sdkConfig)
|
|
6741
6855
|
return;
|
|
6742
|
-
//
|
|
6743
|
-
|
|
6856
|
+
// The verification's methods: what its verify session admits, else the
|
|
6857
|
+
// account's sign-in methods. An answer that names no list is a
|
|
6858
|
+
// configuration fault, shown as one.
|
|
6859
|
+
const methodIds = this.verificationState.methodIds;
|
|
6744
6860
|
if (!Array.isArray(methodIds)) {
|
|
6745
6861
|
this.setState({
|
|
6746
6862
|
view: 'error',
|
|
@@ -6781,11 +6897,7 @@ class IdentityRenderer {
|
|
|
6781
6897
|
methods = methods.filter((m) => m.type !== 'passkey');
|
|
6782
6898
|
}
|
|
6783
6899
|
if (methods.length === 0) {
|
|
6784
|
-
this.setState(
|
|
6785
|
-
view: 'error',
|
|
6786
|
-
message: 'No authentication methods available',
|
|
6787
|
-
code: 'no_methods',
|
|
6788
|
-
});
|
|
6900
|
+
this.setState(this.noMethodState());
|
|
6789
6901
|
return;
|
|
6790
6902
|
}
|
|
6791
6903
|
// When a passkey is already registered for this identifier, jump
|
|
@@ -6823,6 +6935,24 @@ class IdentityRenderer {
|
|
|
6823
6935
|
methods,
|
|
6824
6936
|
});
|
|
6825
6937
|
}
|
|
6938
|
+
/**
|
|
6939
|
+
* The state for a verification that leaves this person no method. A request
|
|
6940
|
+
* its sender held to a passkey admits the passkey alone, so a person the
|
|
6941
|
+
* check found holding none is told the request needs a passkey already
|
|
6942
|
+
* registered with SparkVault and that only the sender can resend it at a
|
|
6943
|
+
* level they can clear: no retry here changes that. Any other verification
|
|
6944
|
+
* with nothing to offer is a configuration fault, shown as one.
|
|
6945
|
+
*/
|
|
6946
|
+
noMethodState() {
|
|
6947
|
+
if (this.verificationState.passkeyRequired && this.verificationState.passkey.hasPasskey === false) {
|
|
6948
|
+
return {
|
|
6949
|
+
view: 'error',
|
|
6950
|
+
code: STRONGER_VERIFICATION_REQUIRED_CODE,
|
|
6951
|
+
message: strongerVerificationMessage('request', this.sdkConfig?.branding?.companyName),
|
|
6952
|
+
};
|
|
6953
|
+
}
|
|
6954
|
+
return { view: 'error', message: 'No authentication methods available', code: 'no_methods' };
|
|
6955
|
+
}
|
|
6826
6956
|
handleIdentitySubmit(result) {
|
|
6827
6957
|
this.verificationState.setIdentity(result.value, result.type);
|
|
6828
6958
|
// The person typed this identifier, so it is theirs to change — a no-hint
|
|
@@ -7173,7 +7303,7 @@ class IdentityRenderer {
|
|
|
7173
7303
|
passkeyFallbackMethodsAvailable() {
|
|
7174
7304
|
if (!this.sdkConfig)
|
|
7175
7305
|
return false;
|
|
7176
|
-
const methods = enrichMethods(this.
|
|
7306
|
+
const methods = enrichMethods(this.verificationState.methodIds);
|
|
7177
7307
|
if (!this.recipient) {
|
|
7178
7308
|
return methods.some((m) => m.type === 'social');
|
|
7179
7309
|
}
|
|
@@ -10333,7 +10463,7 @@ class IdentityModule {
|
|
|
10333
10463
|
* error.
|
|
10334
10464
|
*
|
|
10335
10465
|
* @example
|
|
10336
|
-
* const result =
|
|
10466
|
+
* const result = IdentityModule.isFedcmAvailable()
|
|
10337
10467
|
* ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.signIn())
|
|
10338
10468
|
* : await sv.products.identity.signIn();
|
|
10339
10469
|
*/
|
|
@@ -10999,8 +11129,10 @@ class IdentityModule {
|
|
|
10999
11129
|
/**
|
|
11000
11130
|
* The Notify API contract values more than one runtime reads: the Core API
|
|
11001
11131
|
* validates against them, the published API reference states them, and the JS
|
|
11002
|
-
* SDK checks and applies them client-side
|
|
11003
|
-
*
|
|
11132
|
+
* SDK checks and applies them client-side; and the field sets each read answers
|
|
11133
|
+
* with, which the Core API's and the JS SDK's suites both hold their code to.
|
|
11134
|
+
* One definition, so a change reaches every reader instead of leaving a
|
|
11135
|
+
* hand-kept copy behind.
|
|
11004
11136
|
*
|
|
11005
11137
|
* Browser-safe and dependency-free: the JS SDK bundles this module.
|
|
11006
11138
|
*/
|
|
@@ -11027,13 +11159,18 @@ const NOTIFY_INBOX_BULK_MARK_STATES = Object.freeze(['seen', 'read']);
|
|
|
11027
11159
|
* The five secure-by-default preset bundles, in the send API's vocabulary.
|
|
11028
11160
|
*
|
|
11029
11161
|
* A preset is a merge over the one send contract, never a separate path: the
|
|
11030
|
-
* caller's arguments win over its defaults, and `channels`
|
|
11031
|
-
* account config resolve the ladder per category.
|
|
11162
|
+
* caller's arguments win over its defaults (mergePresetSend), and `channels`
|
|
11163
|
+
* left unset lets the account config resolve the ladder per category.
|
|
11032
11164
|
*
|
|
11033
11165
|
* `alert` is the only plaintext preset: a non-confidential ping is read at a
|
|
11034
11166
|
* glance, delivered inline rather than behind a tap-to-view link, on the account's
|
|
11035
11167
|
* ladder narrowed to the channels that can render cleartext. The other four seal.
|
|
11036
11168
|
*
|
|
11169
|
+
* The ladders the sealed presets name are the channels every sender's recipients
|
|
11170
|
+
* are reached on: the sender's Notify inbox (`in_app`, which the sender's own app
|
|
11171
|
+
* reads) and email. `secureMessage` goes to the person's mailbox alone. The
|
|
11172
|
+
* device channels reach SparkVault's own devices only, so no preset names them.
|
|
11173
|
+
*
|
|
11037
11174
|
* `approval` and `signatureRequest` verify at `identifier`, not `passkey`: a
|
|
11038
11175
|
* passkey-level grant is satisfiable only by a recipient who ALREADY has a
|
|
11039
11176
|
* passkey registered, and the recipient ceremony cannot enrol one mid-flight, so
|
|
@@ -11049,34 +11186,86 @@ const NOTIFY_PRESETS$1 = Object.freeze({
|
|
|
11049
11186
|
}),
|
|
11050
11187
|
secureMessage: Object.freeze({
|
|
11051
11188
|
category: 'secure',
|
|
11052
|
-
channels: Object.freeze(['
|
|
11189
|
+
channels: Object.freeze(['email']),
|
|
11053
11190
|
policy: Object.freeze({ verification_level: 'identifier', interaction: 'view' })
|
|
11054
11191
|
}),
|
|
11055
11192
|
conversation: Object.freeze({
|
|
11056
11193
|
category: 'conversation',
|
|
11057
|
-
channels: Object.freeze(['in_app', '
|
|
11194
|
+
channels: Object.freeze(['in_app', 'email']),
|
|
11058
11195
|
policy: Object.freeze({ verification_level: 'identifier', interaction: 'reply' })
|
|
11059
11196
|
}),
|
|
11060
11197
|
approval: Object.freeze({
|
|
11061
11198
|
category: 'approval',
|
|
11062
|
-
channels: Object.freeze(['in_app', '
|
|
11199
|
+
channels: Object.freeze(['in_app', 'email']),
|
|
11063
11200
|
policy: Object.freeze({ verification_level: 'identifier', interaction: 'approve' })
|
|
11064
11201
|
}),
|
|
11065
11202
|
signatureRequest: Object.freeze({
|
|
11066
11203
|
category: 'signature',
|
|
11067
|
-
channels: Object.freeze(['in_app', '
|
|
11204
|
+
channels: Object.freeze(['in_app', 'email']),
|
|
11068
11205
|
policy: Object.freeze({ verification_level: 'identifier', interaction: 'sign' })
|
|
11069
11206
|
})
|
|
11070
11207
|
});
|
|
11071
11208
|
|
|
11209
|
+
/**
|
|
11210
|
+
* The categories the five presets stamp. Every account's config seeds them, and
|
|
11211
|
+
* the send API accepts them whatever the account's map holds: a preset is a
|
|
11212
|
+
* first-class API surface, so an account that deletes one of these categories
|
|
11213
|
+
* narrows what it derives (its place on the compliance floor, its toggle on the
|
|
11214
|
+
* recipient's settings), never what a preset send may be classified as.
|
|
11215
|
+
*/
|
|
11216
|
+
Object.freeze([
|
|
11217
|
+
...new Set(Object.values(NOTIFY_PRESETS$1).map((preset) => preset.category))
|
|
11218
|
+
]);
|
|
11219
|
+
|
|
11220
|
+
/**
|
|
11221
|
+
* A preset's bundle with the caller's send arguments over it: the one merge the
|
|
11222
|
+
* Core API's presets (`buildPresetSend`) and the JS SDK's
|
|
11223
|
+
* (`buildNotifyPresetSend`) both apply, each in its own vocabulary. The two
|
|
11224
|
+
* share every top-level field name, and the policy merge names no field.
|
|
11225
|
+
*
|
|
11226
|
+
* The caller's `category` wins when it names one, its `delivery` when it states
|
|
11227
|
+
* one (a sealed alert is allowed), and its `channels` when it names a ladder;
|
|
11228
|
+
* neither naming one leaves the ladder to the account config, per category. A
|
|
11229
|
+
* ladder the result carries is its own copy, never the preset's.
|
|
11230
|
+
*
|
|
11231
|
+
* The policy merges field by field, a caller field winning only where it states
|
|
11232
|
+
* a value. Neither undefined nor null states one: the send API types no policy
|
|
11233
|
+
* field as nullable, so either is a field the caller left unset
|
|
11234
|
+
* (`verificationLevel: enrolled ? 'passkey' : undefined` says nothing for an
|
|
11235
|
+
* audience that is not enrolled), and the preset's value stands. Reading it as
|
|
11236
|
+
* an erase would leave the send to fill the field (the account's default level),
|
|
11237
|
+
* never with the preset's value.
|
|
11238
|
+
*
|
|
11239
|
+
* @param {Object} preset - A NOTIFY_PRESETS bundle, in the caller's vocabulary; never modified
|
|
11240
|
+
* @param {Object} args - The caller's send arguments; never modified
|
|
11241
|
+
* @returns {Object} New send arguments
|
|
11242
|
+
*/
|
|
11243
|
+
function mergePresetSend(preset, args) {
|
|
11244
|
+
const merged = {
|
|
11245
|
+
...args,
|
|
11246
|
+
category: args.category || preset.category,
|
|
11247
|
+
delivery: args.delivery ?? preset.delivery,
|
|
11248
|
+
policy: { ...preset.policy }
|
|
11249
|
+
};
|
|
11250
|
+
for (const [field, value] of Object.entries(args.policy ?? {})) {
|
|
11251
|
+
if (value !== undefined && value !== null) merged.policy[field] = value;
|
|
11252
|
+
}
|
|
11253
|
+
const channels = args.channels || preset.channels;
|
|
11254
|
+
if (channels) merged.channels = [...channels];
|
|
11255
|
+
return merged;
|
|
11256
|
+
}
|
|
11257
|
+
|
|
11072
11258
|
/**
|
|
11073
11259
|
* Notify Product Module — the TENANT (sender) surface.
|
|
11074
11260
|
*
|
|
11075
|
-
* The counterpart to `sv.notify`: where that module is
|
|
11076
|
-
*
|
|
11077
|
-
*
|
|
11078
|
-
*
|
|
11079
|
-
*
|
|
11261
|
+
* The counterpart to `sv.notify`: where that module is SparkVault's own
|
|
11262
|
+
* first-party inbox, which a signed-in SparkVault user reads for the
|
|
11263
|
+
* notifications SparkVault delivered to them `in_app`, this one is the
|
|
11264
|
+
* account-scoped product surface a tenant's BACKEND drives — send, send
|
|
11265
|
+
* history, recall, sender-side inbox reads and state, send status, receipts,
|
|
11266
|
+
* the account's Notify config, and who its email is from.
|
|
11267
|
+
* A tenant reads its own recipients' feeds here (`getInbox`), never through
|
|
11268
|
+
* `sv.notify`. Every method maps to
|
|
11080
11269
|
* `/v1/products/notify/*` and is authorized by the caller's account, so the
|
|
11081
11270
|
* recipient is supplied explicitly rather than derived from a session.
|
|
11082
11271
|
*
|
|
@@ -11110,49 +11299,45 @@ const BULK_MARK_STATES$1 = NOTIFY_INBOX_BULK_MARK_STATES;
|
|
|
11110
11299
|
*
|
|
11111
11300
|
* There is no preset endpoint — presets are a merge over the one send contract,
|
|
11112
11301
|
* so they are applied client-side and produce an ordinary `send` request. Caller
|
|
11113
|
-
* arguments
|
|
11114
|
-
* account config resolve the ladder per category.
|
|
11302
|
+
* arguments win over a preset's defaults wherever they state a value;
|
|
11303
|
+
* `channels` left unset lets the account config resolve the ladder per category.
|
|
11115
11304
|
*
|
|
11116
11305
|
* `alert` is the only plaintext preset: a non-confidential ping is read at a
|
|
11117
|
-
* glance rather than behind a tap-to-view link
|
|
11306
|
+
* glance rather than behind a tap-to-view link, on the account's ladder. The
|
|
11307
|
+
* other four seal, on the channels every organization's recipients are reached
|
|
11308
|
+
* on: `secureMessage` by email alone, `conversation`, `approval` and
|
|
11309
|
+
* `signatureRequest` in your Notify inbox (`in_app`) and then by email.
|
|
11118
11310
|
* `approval` and `signatureRequest` verify at `identifier`: pass
|
|
11119
11311
|
* `policy: { verificationLevel: 'passkey' }` explicitly when the audience is
|
|
11120
11312
|
* known to be enrolled.
|
|
11313
|
+
*
|
|
11314
|
+
* Every send in the process reads this one table, so it is frozen all the way
|
|
11315
|
+
* down; `buildNotifyPresetSend` hands back options of the caller's own.
|
|
11121
11316
|
*/
|
|
11122
11317
|
const NOTIFY_PRESETS = Object.freeze(Object.fromEntries(Object.keys(NOTIFY_PRESETS$1).map((name) => {
|
|
11318
|
+
// The contract's ladders are frozen already, so the table can carry them as they are.
|
|
11123
11319
|
const { category, delivery, channels, policy } = NOTIFY_PRESETS$1[name];
|
|
11124
11320
|
const preset = {
|
|
11125
11321
|
category,
|
|
11126
11322
|
...(delivery ? { delivery } : {}),
|
|
11127
|
-
...(channels ? { channels
|
|
11128
|
-
policy: { verificationLevel: policy.verification_level, interaction: policy.interaction },
|
|
11323
|
+
...(channels ? { channels } : {}),
|
|
11324
|
+
policy: Object.freeze({ verificationLevel: policy.verification_level, interaction: policy.interaction }),
|
|
11129
11325
|
};
|
|
11130
11326
|
return [name, Object.freeze(preset)];
|
|
11131
11327
|
})));
|
|
11132
11328
|
/**
|
|
11133
11329
|
* Merge a preset's bundle UNDER the caller's arguments, yielding ordinary send
|
|
11134
|
-
* options
|
|
11135
|
-
*
|
|
11330
|
+
* options: the Core API's own merge (`mergePresetSend`), so a preset sends the
|
|
11331
|
+
* same through either. Exported so a caller can inspect (or further adjust)
|
|
11332
|
+
* what a preset would send before sending it: the options are the caller's own,
|
|
11333
|
+
* so adjusting them never reaches the preset table or any other send.
|
|
11136
11334
|
*/
|
|
11137
11335
|
function buildNotifyPresetSend(preset, options) {
|
|
11138
11336
|
const bundle = NOTIFY_PRESETS[preset];
|
|
11139
11337
|
if (!bundle) {
|
|
11140
11338
|
throw new ValidationError(`Unknown notify preset "${preset}" (valid: ${Object.keys(NOTIFY_PRESETS).join(', ')})`, { field: 'preset', received: preset });
|
|
11141
11339
|
}
|
|
11142
|
-
|
|
11143
|
-
...options,
|
|
11144
|
-
category: options.category || bundle.category,
|
|
11145
|
-
// A caller-supplied delivery wins (a sealed override of an alert is allowed);
|
|
11146
|
-
// otherwise the preset's mode, or the sealed default when it declares none.
|
|
11147
|
-
delivery: options.delivery ?? bundle.delivery,
|
|
11148
|
-
policy: { ...bundle.policy, ...(options.policy ?? {}) },
|
|
11149
|
-
};
|
|
11150
|
-
// Only set channels when the preset declares them and the caller did not
|
|
11151
|
-
// override — leaving it unset lets the account config resolve them per category.
|
|
11152
|
-
const channels = options.channels || bundle.channels;
|
|
11153
|
-
if (channels)
|
|
11154
|
-
merged.channels = channels;
|
|
11155
|
-
return merged;
|
|
11340
|
+
return mergePresetSend(bundle, options);
|
|
11156
11341
|
}
|
|
11157
11342
|
class NotifyProductModule {
|
|
11158
11343
|
constructor(http) {
|
|
@@ -11163,8 +11348,28 @@ class NotifyProductModule {
|
|
|
11163
11348
|
* Send a notification: seal the content, mint one single-use SparkLink per
|
|
11164
11349
|
* recipient, and enqueue delivery across the resolved channel ladder.
|
|
11165
11350
|
*
|
|
11166
|
-
* `sendId` is the idempotency key. Replaying an existing one
|
|
11167
|
-
* send unchanged — never re-sealed, never
|
|
11351
|
+
* `sendId` is the idempotency key. Replaying an existing one with the same
|
|
11352
|
+
* request returns the stored send unchanged — never re-sealed, never
|
|
11353
|
+
* re-delivered — flagged `idempotent`; another request under it is refused 400
|
|
11354
|
+
* (`sendId` on `CreateNotifySendOptions`).
|
|
11355
|
+
*
|
|
11356
|
+
* The send speaks in your organization's name, and one that would email
|
|
11357
|
+
* someone goes out from your organization's own sender (`getEmailSender`) and
|
|
11358
|
+
* is admitted against your hourly share of sending capacity. Each refusal is
|
|
11359
|
+
* a thrown `SparkVaultError` whose `serviceCode` names it, made before
|
|
11360
|
+
* anything is sealed, charged or stored:
|
|
11361
|
+
*
|
|
11362
|
+
* | Status | `serviceCode` | `details` | Next |
|
|
11363
|
+
* | --- | --- | --- | --- |
|
|
11364
|
+
* | 403 | `NOTIFY_CHANNEL_NOT_AVAILABLE` | `{ field, channels }` | Name only `in_app` and `email` |
|
|
11365
|
+
* | 409 | `NOTIFY_SENDER_NAME_REQUIRED` | — | Name the organization in Settings |
|
|
11366
|
+
* | 409 | `NOTIFY_SENDER_NAME_RESERVED` | `{ reason: 'reserved_name' }` | Rename the organization |
|
|
11367
|
+
* | 409 | `HANDLE_REQUIRED` | `{ product: 'notify' }` | Choose the organization's handle in Company Settings |
|
|
11368
|
+
* | 429 | `NOTIFY_EMAIL_ADMISSION_LIMIT` | `{ limit, window: 'hour', resets_at }` | Wait `retryAfterMs`, then send |
|
|
11369
|
+
* | 503 | `EMAIL_SETUP_BUSY` | — | Retry the same send after `retryAfterMs` |
|
|
11370
|
+
* | 503 | `NOTIFY_EMAIL_CAPACITY_UNAVAILABLE` | — | Retry the same send |
|
|
11371
|
+
*
|
|
11372
|
+
* A replay is answered from the stored send and meets none of them again.
|
|
11168
11373
|
*
|
|
11169
11374
|
* @example
|
|
11170
11375
|
* const send = await sv.products.notify.send({
|
|
@@ -11209,7 +11414,7 @@ class NotifyProductModule {
|
|
|
11209
11414
|
/**
|
|
11210
11415
|
* Frictionless informational ping — no verification, view-only, delivered
|
|
11211
11416
|
* INLINE (plaintext) so it is read at a glance. Channels resolve from the
|
|
11212
|
-
* account config
|
|
11417
|
+
* account config, narrowed to the ones that render cleartext.
|
|
11213
11418
|
*
|
|
11214
11419
|
* @example
|
|
11215
11420
|
* await sv.products.notify.sendAlert({
|
|
@@ -11229,18 +11434,58 @@ class NotifyProductModule {
|
|
|
11229
11434
|
async sendConversation(options) {
|
|
11230
11435
|
return this.send(buildNotifyPresetSend('conversation', options));
|
|
11231
11436
|
}
|
|
11232
|
-
/**
|
|
11437
|
+
/**
|
|
11438
|
+
* High-stakes approve/deny, identifier-verified. Pass `policy.actionHash`, the
|
|
11439
|
+
* SHA-256 of the thing being approved, so the signed receipt attests to THAT:
|
|
11440
|
+
* without it the receipt binds a digest of the grant, which no hash of your
|
|
11441
|
+
* own copy can match.
|
|
11442
|
+
*
|
|
11443
|
+
* @example
|
|
11444
|
+
* const actionHash = createHash('sha256').update(canonicalWire).digest('hex');
|
|
11445
|
+
* await sv.products.notify.sendApproval({
|
|
11446
|
+
* sendId: `wire-approval-${wire.id}`,
|
|
11447
|
+
* recipients: [{ id: approver.svid, email: approver.email }],
|
|
11448
|
+
* content: { payload: `Approve ${wire.amount} to ${wire.payee}?` },
|
|
11449
|
+
* policy: { actionHash },
|
|
11450
|
+
* });
|
|
11451
|
+
*/
|
|
11233
11452
|
async sendApproval(options) {
|
|
11234
11453
|
return this.send(buildNotifyPresetSend('approval', options));
|
|
11235
11454
|
}
|
|
11236
|
-
/**
|
|
11455
|
+
/**
|
|
11456
|
+
* Signature-on-delivery, identifier-verified. Pass `policy.actionHash`, the
|
|
11457
|
+
* SHA-256 of the document being signed, so the signed receipt attests to THAT
|
|
11458
|
+
* document.
|
|
11459
|
+
*
|
|
11460
|
+
* @example
|
|
11461
|
+
* await sv.products.notify.sendSignatureRequest({
|
|
11462
|
+
* sendId: `contract-${contract.id}`,
|
|
11463
|
+
* recipients: [{ email: signer.email }],
|
|
11464
|
+
* content: { payload: contractPdfBase64, contentType: 'application/pdf' },
|
|
11465
|
+
* policy: { actionHash: createHash('sha256').update(contractPdfBytes).digest('hex') },
|
|
11466
|
+
* });
|
|
11467
|
+
*/
|
|
11237
11468
|
async sendSignatureRequest(options) {
|
|
11238
11469
|
return this.send(buildNotifyPresetSend('signatureRequest', options));
|
|
11239
11470
|
}
|
|
11240
11471
|
// ── Inbox (sender-side) ─────────────────────────────────────────────────────
|
|
11241
11472
|
/**
|
|
11242
|
-
* Read one recipient's
|
|
11243
|
-
*
|
|
11473
|
+
* Read one recipient's feed in your Notify inbox, newest first: exactly the
|
|
11474
|
+
* notifications delivered to them `in_app`. The row IS the `in_app`
|
|
11475
|
+
* delivery: its ladder carries `in_app`, because the send named it or your
|
|
11476
|
+
* config resolved it and the recipient left In-app on for your site (a
|
|
11477
|
+
* `security` send crosses that switch), and it is listed when that step
|
|
11478
|
+
* runs: as the send fans out when `in_app` leads the ladder, and only when
|
|
11479
|
+
* the step comes due when it follows `email`. A notification whose ladder
|
|
11480
|
+
* carries no `in_app` (a send naming `email` alone, a recipient who switched
|
|
11481
|
+
* In-app off for your site on auth.sv on any send but a `security` one, one
|
|
11482
|
+
* their own preferences or block refused, one no channel reaches), one whose
|
|
11483
|
+
* `in_app` step has not delivered it (and never will once a stop ended its
|
|
11484
|
+
* ladder first), and the per-recipient ceiling's skip are status records
|
|
11485
|
+
* only: in no view, and a mark of one is refused as not found. A sealed row carries
|
|
11486
|
+
* the recipient's own pointer (`sparklink_code`, `pointer_url`) while its
|
|
11487
|
+
* grant still opens, never the content; a plaintext row carries its body.
|
|
11488
|
+
* Treat the answer as sensitive and keep it out of logs.
|
|
11244
11489
|
*
|
|
11245
11490
|
* A page can come back SHORT of `limit` yet still carry a non-null cursor —
|
|
11246
11491
|
* follow the cursor; never treat a short page as the end.
|
|
@@ -11265,8 +11510,9 @@ class NotifyProductModule {
|
|
|
11265
11510
|
}
|
|
11266
11511
|
/**
|
|
11267
11512
|
* Apply a terminal display state to one row (idempotent). `createdAt` MUST be
|
|
11268
|
-
* the row's own `created_at`, round-tripped from the feed
|
|
11269
|
-
*
|
|
11513
|
+
* the row's own `created_at`, round-tripped from the feed row — the id alone
|
|
11514
|
+
* cannot address the row. Any mark (seen, read or archived) marks the row seen,
|
|
11515
|
+
* which stops its escalation.
|
|
11270
11516
|
*
|
|
11271
11517
|
* @example
|
|
11272
11518
|
* await sv.products.notify.markInboxState(row.notification_id, {
|
|
@@ -11328,6 +11574,7 @@ class NotifyProductModule {
|
|
|
11328
11574
|
* `getSendStatus(sendId)` for the per-recipient detail.
|
|
11329
11575
|
*
|
|
11330
11576
|
* Real pagination: a null `cursor` means the end of the account's history.
|
|
11577
|
+
* A delivery counter is null until its first increment, so it reads 0 there.
|
|
11331
11578
|
*
|
|
11332
11579
|
* @example
|
|
11333
11580
|
* let cursor: string | undefined;
|
|
@@ -11335,7 +11582,7 @@ class NotifyProductModule {
|
|
|
11335
11582
|
* const page = await sv.products.notify.listSends({ cursor, limit: 50 });
|
|
11336
11583
|
* for (const send of page.sends) {
|
|
11337
11584
|
* console.log(send.created_at, send.title, send.state,
|
|
11338
|
-
* `${send.delivered_count ??
|
|
11585
|
+
* `${send.delivered_count ?? 0} / ${send.recipient_count ?? '?'}`);
|
|
11339
11586
|
* }
|
|
11340
11587
|
* cursor = page.cursor ?? undefined;
|
|
11341
11588
|
* } while (cursor);
|
|
@@ -11352,8 +11599,9 @@ class NotifyProductModule {
|
|
|
11352
11599
|
*
|
|
11353
11600
|
* `mode: 'grant'` (the default) drops access and leaves the content intact.
|
|
11354
11601
|
* `mode: 'content'` hard-burns the sealed spark so it is unreadable for
|
|
11355
|
-
* everyone — spark-backed sends only
|
|
11356
|
-
* owner's durable vault content
|
|
11602
|
+
* everyone — spark-backed sends only: an ingot send merely references the
|
|
11603
|
+
* owner's durable vault content, so a content recall of one is a 400, refused
|
|
11604
|
+
* before anything is revoked or stopped.
|
|
11357
11605
|
*
|
|
11358
11606
|
* Idempotent: a grant already revoked (or already consumed) counts as recalled,
|
|
11359
11607
|
* so a repeated call converges rather than accumulating failures. One
|
|
@@ -11392,7 +11640,8 @@ class NotifyProductModule {
|
|
|
11392
11640
|
// ── Status & receipts ───────────────────────────────────────────────────────
|
|
11393
11641
|
/**
|
|
11394
11642
|
* The sender's per-recipient delivery rollup for one send: who it reached and
|
|
11395
|
-
* how far each recipient got. Metadata only — never the pointer
|
|
11643
|
+
* how far each recipient got. Metadata only — never the pointer, and no contact
|
|
11644
|
+
* beyond the handle each recipient was addressed by (`recipient_id`).
|
|
11396
11645
|
*
|
|
11397
11646
|
* @example
|
|
11398
11647
|
* const { counts } = await sv.products.notify.getSendStatus(send.send_id);
|
|
@@ -11403,10 +11652,11 @@ class NotifyProductModule {
|
|
|
11403
11652
|
return response.data;
|
|
11404
11653
|
}
|
|
11405
11654
|
/**
|
|
11406
|
-
* The account's verified-interaction receipts (portable,
|
|
11407
|
-
*
|
|
11408
|
-
*
|
|
11409
|
-
* it is null before
|
|
11655
|
+
* The account's verified-interaction receipts (a ceremony's carries portable,
|
|
11656
|
+
* JWKS-verifiable proof; an open's is an unsigned access record), newest
|
|
11657
|
+
* first, with real pagination. An `interaction` filter can hand back a short
|
|
11658
|
+
* or empty page while more follow, so follow `cursor` until it is null before
|
|
11659
|
+
* concluding there are none.
|
|
11410
11660
|
*
|
|
11411
11661
|
* @example
|
|
11412
11662
|
* const { receipts, cursor } = await sv.products.notify.listReceipts({ interaction: 'approve' });
|
|
@@ -11423,9 +11673,9 @@ class NotifyProductModule {
|
|
|
11423
11673
|
}
|
|
11424
11674
|
/**
|
|
11425
11675
|
* Every receipt for one send, each attached to the recipient who produced it.
|
|
11426
|
-
* The
|
|
11427
|
-
*
|
|
11428
|
-
* to resume
|
|
11676
|
+
* The walk reads the account's receipts back to the send's creation, and no
|
|
11677
|
+
* further. One call is bounded: when `truncated` is true it stopped first —
|
|
11678
|
+
* pass the returned `cursor` back in to resume exactly where it stopped.
|
|
11429
11679
|
*
|
|
11430
11680
|
* @example
|
|
11431
11681
|
* const all: NotifySendReceipt[] = [];
|
|
@@ -11467,6 +11717,14 @@ class NotifyProductModule {
|
|
|
11467
11717
|
* body as `X-SparkVault-Signature: hex(HMAC-SHA256(secret, rawBody))`. The
|
|
11468
11718
|
* secret is WRITE-ONLY — reads report `events.secret_set`, never the value.
|
|
11469
11719
|
*
|
|
11720
|
+
* The `email` section selects a domain of your own for your Notify email to go
|
|
11721
|
+
* out from. `security`, `events` and `email` are an org admin's to change: a
|
|
11722
|
+
* patch from anyone else naming one is refused whole, 403 `FORBIDDEN`
|
|
11723
|
+
* (`details: { sections, required_role: 'admin' }`). A ladder naming a channel
|
|
11724
|
+
* other than `in_app` and `email` is refused 403 `NOTIFY_CHANNEL_NOT_AVAILABLE`
|
|
11725
|
+
* (`details: { field, channels }`); a save that overlapping saves kept
|
|
11726
|
+
* outracing is refused 409 `CONFLICT`: reload and patch again.
|
|
11727
|
+
*
|
|
11470
11728
|
* @example
|
|
11471
11729
|
* await sv.products.notify.updateConfig({
|
|
11472
11730
|
* categories: {
|
|
@@ -11486,6 +11744,35 @@ class NotifyProductModule {
|
|
|
11486
11744
|
const response = await this.http.put(apiPath `/v1/products/notify/config`, patch);
|
|
11487
11745
|
return response.data;
|
|
11488
11746
|
}
|
|
11747
|
+
/**
|
|
11748
|
+
* Who your organization's Notify email is from, as the API answers it
|
|
11749
|
+
* (verbatim snake_case): `"{organization name}" <from_address>`, with a
|
|
11750
|
+
* notice naming SparkVault Notify. A reply reaches no one when the email goes
|
|
11751
|
+
* out from the handle host, or from a domain of your own that is set up as a
|
|
11752
|
+
* help-desk web host or receives the help desk's email; from a domain that
|
|
11753
|
+
* only sends, a reply goes wherever that domain's own MX records route it.
|
|
11754
|
+
*
|
|
11755
|
+
* - `ready`: the email goes out from `from_address`, on `sending_host`: the
|
|
11756
|
+
* domain `email.sending_domain` selects while it serves sending (its
|
|
11757
|
+
* ownership verified and its sending ready), else the organization's handle
|
|
11758
|
+
* host under send.sv, `handle_host`, which it falls back to the moment the
|
|
11759
|
+
* domain stops serving.
|
|
11760
|
+
* - `handle_required`: the organization has not chosen its handle, so a send
|
|
11761
|
+
* that would email someone is refused 409 `HANDLE_REQUIRED` until it does.
|
|
11762
|
+
* - `platform_sender`: SparkVault's own account, whose Notify email is
|
|
11763
|
+
* platform mail.
|
|
11764
|
+
*
|
|
11765
|
+
* `domain_readiness` is the selected domain's readiness flags, null with no
|
|
11766
|
+
* selection or while the organization does not hold the domain's claim.
|
|
11767
|
+
*
|
|
11768
|
+
* @example
|
|
11769
|
+
* const sender = await sv.products.notify.getEmailSender();
|
|
11770
|
+
* if (sender.state === 'handle_required') promptForHandle();
|
|
11771
|
+
*/
|
|
11772
|
+
async getEmailSender() {
|
|
11773
|
+
const response = await this.http.get(apiPath `/v1/products/notify/email-sender`);
|
|
11774
|
+
return response.data;
|
|
11775
|
+
}
|
|
11489
11776
|
}
|
|
11490
11777
|
/**
|
|
11491
11778
|
* Map the camelCase option bag onto the send body. Undefined fields drop out at
|
|
@@ -11512,6 +11799,7 @@ function toSendBody(options) {
|
|
|
11512
11799
|
verification_level: options.policy.verificationLevel,
|
|
11513
11800
|
interaction: options.policy.interaction,
|
|
11514
11801
|
reveal_freshness_minutes: options.policy.revealFreshnessMinutes,
|
|
11802
|
+
action_hash: options.policy.actionHash,
|
|
11515
11803
|
}
|
|
11516
11804
|
: undefined,
|
|
11517
11805
|
channels: options.channels,
|
|
@@ -11958,7 +12246,12 @@ function stagingRefusalOf(error) {
|
|
|
11958
12246
|
function cancelledError() {
|
|
11959
12247
|
return new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
11960
12248
|
}
|
|
11961
|
-
/**
|
|
12249
|
+
/**
|
|
12250
|
+
* Refuse a transfer where the browser's XMLHttpRequest is missing (a server
|
|
12251
|
+
* process: Node has fetch and no XMLHttpRequest): a chunk's upload progress
|
|
12252
|
+
* needs it. A flow that stages its upload with Core first checks this before
|
|
12253
|
+
* the staging request, so a run that cannot transfer stages nothing.
|
|
12254
|
+
*/
|
|
11962
12255
|
function assertBrowserTransfer() {
|
|
11963
12256
|
if (typeof XMLHttpRequest === 'undefined') {
|
|
11964
12257
|
throw new UploadApiError('XMLHttpRequest is required for browser uploads', 'environment_unsupported', 0);
|
|
@@ -15346,7 +15639,8 @@ class VaultUploadModule {
|
|
|
15346
15639
|
});
|
|
15347
15640
|
}
|
|
15348
15641
|
catch {
|
|
15349
|
-
//
|
|
15642
|
+
// The host's onError or onCancel has already received the outcome;
|
|
15643
|
+
// a click handler has no caller to reject to.
|
|
15350
15644
|
}
|
|
15351
15645
|
};
|
|
15352
15646
|
return attachClickHandler(selector, handleClick);
|
|
@@ -15568,7 +15862,8 @@ class VaultsModule {
|
|
|
15568
15862
|
return mapVaultDetail(response.data);
|
|
15569
15863
|
}
|
|
15570
15864
|
/**
|
|
15571
|
-
* Get a vault's public-sharing configuration.
|
|
15865
|
+
* Get a vault's public-sharing configuration. Every sharing write below
|
|
15866
|
+
* answers the same configuration as that write left it.
|
|
15572
15867
|
*
|
|
15573
15868
|
* @example
|
|
15574
15869
|
* const sharing = await sv.vaults.getSharingConfig('vlt_abc');
|
|
@@ -15658,7 +15953,9 @@ class VaultsModule {
|
|
|
15658
15953
|
};
|
|
15659
15954
|
}
|
|
15660
15955
|
/**
|
|
15661
|
-
* Get a vault's upload-channel configuration.
|
|
15956
|
+
* Get a vault's upload-channel configuration. Every upload write below
|
|
15957
|
+
* answers the same configuration as that write left it: both channels, the
|
|
15958
|
+
* shared settings, and the portal's URL while the portal is on.
|
|
15662
15959
|
*
|
|
15663
15960
|
* @example
|
|
15664
15961
|
* const upload = await sv.vaults.getUploadConfig('vlt_abc');
|
|
@@ -15726,17 +16023,7 @@ class VaultsModule {
|
|
|
15726
16023
|
throw new ValidationError('VMK is required');
|
|
15727
16024
|
}
|
|
15728
16025
|
const response = await this.http.post(apiPath `/v1/vaults/${id}/upload/${channel}/${action}`, action === 'enable' ? { vmk } : undefined);
|
|
15729
|
-
|
|
15730
|
-
return {
|
|
15731
|
-
vaultId: d.vault_id,
|
|
15732
|
-
uploadPortalEnabled: d.upload_portal_enabled ?? (channel === 'portal' && action === 'enable'),
|
|
15733
|
-
uploadPortalEnabledAt: channel === 'portal' && action === 'enable' ? d.enabled_at ?? null : null,
|
|
15734
|
-
uploadWidgetEnabled: d.upload_widget_enabled ?? (channel === 'widget' && action === 'enable'),
|
|
15735
|
-
uploadWidgetEnabledAt: channel === 'widget' && action === 'enable' ? d.enabled_at ?? null : null,
|
|
15736
|
-
maxSizeBytes: null,
|
|
15737
|
-
notificationEmail: null,
|
|
15738
|
-
portalUrl: d.portal_url,
|
|
15739
|
-
};
|
|
16026
|
+
return mapUploadSettings(response.data);
|
|
15740
16027
|
}
|
|
15741
16028
|
validateCreateOptions(options) {
|
|
15742
16029
|
// A name's length is Core's to decide (it answers a ValidationError naming
|
|
@@ -16699,7 +16986,10 @@ class IngotsModule {
|
|
|
16699
16986
|
* `upload_received_publishing`: every byte is received, and the server
|
|
16700
16987
|
* finishes the publication on its own, so never upload the file again; a
|
|
16701
16988
|
* caller that kept the session (`onSessionCreated`) learns what became of
|
|
16702
|
-
* it with {@link resumeUpload}.
|
|
16989
|
+
* it with {@link resumeUpload}. A chunk's upload progress needs the
|
|
16990
|
+
* browser's XMLHttpRequest: where there is none (a Node server) it rejects
|
|
16991
|
+
* with code `environment_unsupported` before any request; a server sends
|
|
16992
|
+
* the bytes over tus to `uploadUrl` itself.
|
|
16703
16993
|
*
|
|
16704
16994
|
* @param options.signal - Cancels this transfer (it rejects with code
|
|
16705
16995
|
* `cancelled`); other transfers carry on.
|
|
@@ -16788,7 +17078,10 @@ class IngotsModule {
|
|
|
16788
17078
|
* any way but one the server received whole ({@link isReceivedUploadFailure}:
|
|
16789
17079
|
* the server publishes or ends that one on its own) is given up: the end of
|
|
16790
17080
|
* it with the file its create made ({@link endUpload}) starts as it
|
|
16791
|
-
* rejects, without holding up its own error.
|
|
17081
|
+
* rejects, without holding up its own error. It needs the browser's
|
|
17082
|
+
* XMLHttpRequest, as {@link sendUpload} does: in a server process it
|
|
17083
|
+
* rejects with code `environment_unsupported` before any request, so no
|
|
17084
|
+
* create stages an ingot it cannot send.
|
|
16792
17085
|
*
|
|
16793
17086
|
* @example
|
|
16794
17087
|
* const ingot = await sv.ingots.upload(unsealed, {
|
|
@@ -16801,6 +17094,7 @@ class IngotsModule {
|
|
|
16801
17094
|
throw new ValidationError('Provide folder or folderId, not both');
|
|
16802
17095
|
}
|
|
16803
17096
|
const name = options.name ?? getBlobName(options.file);
|
|
17097
|
+
assertBrowserTransfer();
|
|
16804
17098
|
const created = await this.requestUploadSession(vault, {
|
|
16805
17099
|
name,
|
|
16806
17100
|
content_type: sentContentType(options),
|
|
@@ -16837,7 +17131,8 @@ class IngotsModule {
|
|
|
16837
17131
|
/**
|
|
16838
17132
|
* Replace an existing ingot's content (high-level flow). Rejects as
|
|
16839
17133
|
* {@link upload} does, a replacement another upload of the same ingot
|
|
16840
|
-
* superseded included (`upload_refused`)
|
|
17134
|
+
* superseded included (`upload_refused`), and `environment_unsupported`
|
|
17135
|
+
* before the replacement is staged where there is no XMLHttpRequest.
|
|
16841
17136
|
*
|
|
16842
17137
|
* @example
|
|
16843
17138
|
* await sv.ingots.replace(unsealed, 'ing_abc', { file: updatedFile });
|
|
@@ -16848,6 +17143,7 @@ class IngotsModule {
|
|
|
16848
17143
|
const id = requireResourceId(ingotId, 'ingotId');
|
|
16849
17144
|
const name = options.name ?? getBlobName(options.file);
|
|
16850
17145
|
const contentType = sentContentType(options);
|
|
17146
|
+
assertBrowserTransfer();
|
|
16851
17147
|
const response = await this.http.put(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, {
|
|
16852
17148
|
name,
|
|
16853
17149
|
// Omitted, Core keeps the ingot's stored type (ReplaceIngotOptions.contentType).
|
|
@@ -16915,7 +17211,9 @@ class IngotsModule {
|
|
|
16915
17211
|
return mapIngot(response.data);
|
|
16916
17212
|
}
|
|
16917
17213
|
/**
|
|
16918
|
-
* List ingots in an unsealed vault
|
|
17214
|
+
* List ingots in an unsealed vault, one page at a time in the vault index's
|
|
17215
|
+
* order: follow `nextCursor`. `sortBy` orders only the page answered; for
|
|
17216
|
+
* one order across a vault, search or list a folder's contents.
|
|
16919
17217
|
*
|
|
16920
17218
|
* @example
|
|
16921
17219
|
* const { ingots } = await sv.ingots.list(unsealed);
|
|
@@ -17559,11 +17857,16 @@ function validateEntropyRequest(bytes, format) {
|
|
|
17559
17857
|
/**
|
|
17560
17858
|
* Notify Module
|
|
17561
17859
|
*
|
|
17562
|
-
*
|
|
17563
|
-
*
|
|
17564
|
-
*
|
|
17565
|
-
* to
|
|
17566
|
-
*
|
|
17860
|
+
* SparkVault's first-party Notify surface: the metadata-only inbox of a user
|
|
17861
|
+
* signed in to SparkVault itself (a Core session JWT; an API key or an
|
|
17862
|
+
* identity-only token is refused), holding the notifications SparkVault
|
|
17863
|
+
* delivered to them `in_app`, plus this browser's Web Push registration. It is
|
|
17864
|
+
* not a tenant's inbox for its own end users: a tenant reads its recipients'
|
|
17865
|
+
* feeds with `sv.products.notify.getInbox`. The recipient is ALWAYS derived
|
|
17866
|
+
* from the session on the server — no method takes a `recipient_id`, and any
|
|
17867
|
+
* account/recipient a caller might try to supply is ignored. This mirrors
|
|
17868
|
+
* `@sparkvault/sdk-mobile`'s notify client; device push registration is
|
|
17869
|
+
* intentionally omitted (Expo-only on mobile).
|
|
17567
17870
|
*/
|
|
17568
17871
|
const MARK_STATES = NOTIFY_INBOX_MARK_STATES;
|
|
17569
17872
|
const BULK_MARK_STATES = NOTIFY_INBOX_BULK_MARK_STATES;
|
|
@@ -17573,6 +17876,17 @@ const BULK_MARK_STATES = NOTIFY_INBOX_BULK_MARK_STATES;
|
|
|
17573
17876
|
* inbox deeper than the bound finishes on a second call (the drain is idempotent).
|
|
17574
17877
|
*/
|
|
17575
17878
|
const MARK_ALL_MAX_PAGES = 100;
|
|
17879
|
+
/**
|
|
17880
|
+
* Whether a browser subscription was made against `key`. One that reports no
|
|
17881
|
+
* key at all is treated as bound to another: nothing proves it can deliver.
|
|
17882
|
+
*/
|
|
17883
|
+
function isBoundToKey(subscription, key) {
|
|
17884
|
+
const bound = subscription.options?.applicationServerKey;
|
|
17885
|
+
if (!bound)
|
|
17886
|
+
return false;
|
|
17887
|
+
const bytes = new Uint8Array(bound);
|
|
17888
|
+
return bytes.length === key.length && bytes.every((byte, index) => byte === key[index]);
|
|
17889
|
+
}
|
|
17576
17890
|
/** Normalize a PushSubscription (or its JSON) to the server's wire shape. */
|
|
17577
17891
|
function toSubscriptionInput(subscription) {
|
|
17578
17892
|
const json = typeof subscription.toJSON === 'function'
|
|
@@ -17718,6 +18032,48 @@ class NotifyModule {
|
|
|
17718
18032
|
const response = await this.http.get(apiPath `/v1/me/notifications/web-push/key`);
|
|
17719
18033
|
return response.data;
|
|
17720
18034
|
}
|
|
18035
|
+
/**
|
|
18036
|
+
* The VAPID public key the server signs every push with, as the bytes a
|
|
18037
|
+
* browser subscription is bound to; null while no keypair is provisioned.
|
|
18038
|
+
*/
|
|
18039
|
+
async serverKey() {
|
|
18040
|
+
const key = await this.getWebPushKey();
|
|
18041
|
+
if (!key.configured || !key.vapid_public_key) {
|
|
18042
|
+
return null;
|
|
18043
|
+
}
|
|
18044
|
+
const bytes = base64urlToBytes(key.vapid_public_key);
|
|
18045
|
+
if (bytes === null) {
|
|
18046
|
+
throw new SparkVaultError('The server returned a Web Push key that is not base64url', 'invalid_response');
|
|
18047
|
+
}
|
|
18048
|
+
return bytes;
|
|
18049
|
+
}
|
|
18050
|
+
/**
|
|
18051
|
+
* This browser's Web Push state, read without prompting, subscribing or
|
|
18052
|
+
* registering anything: `subscribed` only when the browser holds a
|
|
18053
|
+
* subscription made for the key the server signs with now. One made for
|
|
18054
|
+
* another key reads `not_subscribed`: its push service refuses every push
|
|
18055
|
+
* signed with the current key, and `subscribeWebPush` replaces it. Read it to
|
|
18056
|
+
* show whether this browser's notifications are on.
|
|
18057
|
+
*
|
|
18058
|
+
* @example
|
|
18059
|
+
* const registration = await navigator.serviceWorker.getRegistration();
|
|
18060
|
+
* const { status } = await sv.notify.getWebPushStatus({ serviceWorkerRegistration: registration });
|
|
18061
|
+
*/
|
|
18062
|
+
async getWebPushStatus(options = {}) {
|
|
18063
|
+
if (!this.isWebPushSupported()) {
|
|
18064
|
+
return { status: 'not_supported' };
|
|
18065
|
+
}
|
|
18066
|
+
const key = await this.serverKey();
|
|
18067
|
+
if (key === null) {
|
|
18068
|
+
return { status: 'not_configured' };
|
|
18069
|
+
}
|
|
18070
|
+
const held = options.serviceWorkerRegistration
|
|
18071
|
+
? await options.serviceWorkerRegistration.pushManager.getSubscription()
|
|
18072
|
+
: null;
|
|
18073
|
+
return held && isBoundToKey(held, key)
|
|
18074
|
+
? { status: 'subscribed', subscription: held }
|
|
18075
|
+
: { status: 'not_subscribed' };
|
|
18076
|
+
}
|
|
17721
18077
|
/**
|
|
17722
18078
|
* Register (or refresh) a browser push subscription for the signed-in user.
|
|
17723
18079
|
* Accepts a live PushSubscription or its JSON shape.
|
|
@@ -17743,6 +18099,12 @@ class NotifyModule {
|
|
|
17743
18099
|
* permission denied) so a host can branch on the outcome. Call it from a user
|
|
17744
18100
|
* gesture (permission prompts require one).
|
|
17745
18101
|
*
|
|
18102
|
+
* A subscription the browser holds for the current key is kept
|
|
18103
|
+
* (`already_subscribed`); one made for a previous key can never deliver
|
|
18104
|
+
* again, so it is removed and replaced (`subscribed`). Enabling again is
|
|
18105
|
+
* therefore how a browser recovers after the platform's key changes, and
|
|
18106
|
+
* `getWebPushStatus` reads such a browser as `not_subscribed` until it does.
|
|
18107
|
+
*
|
|
17746
18108
|
* @example
|
|
17747
18109
|
* const reg = await navigator.serviceWorker.register('/sw.js');
|
|
17748
18110
|
* const { status } = await sv.notify.subscribeWebPush({ serviceWorkerRegistration: reg });
|
|
@@ -17755,15 +18117,11 @@ class NotifyModule {
|
|
|
17755
18117
|
if (!registration || typeof registration.pushManager?.subscribe !== 'function') {
|
|
17756
18118
|
throw new ValidationError('serviceWorkerRegistration with a pushManager is required');
|
|
17757
18119
|
}
|
|
17758
|
-
|
|
17759
|
-
if (!key.configured || !key.vapid_public_key) {
|
|
17760
|
-
return { status: 'not_configured' };
|
|
17761
|
-
}
|
|
17762
|
-
// Checked before the permission prompt: a key the browser cannot use must
|
|
18120
|
+
// Read before the permission prompt: a key the browser cannot use must
|
|
17763
18121
|
// never cost the user a prompt.
|
|
17764
|
-
const applicationServerKey =
|
|
18122
|
+
const applicationServerKey = await this.serverKey();
|
|
17765
18123
|
if (applicationServerKey === null) {
|
|
17766
|
-
|
|
18124
|
+
return { status: 'not_configured' };
|
|
17767
18125
|
}
|
|
17768
18126
|
if (Notification.permission === 'denied') {
|
|
17769
18127
|
return { status: 'permission_denied' };
|
|
@@ -17774,9 +18132,14 @@ class NotifyModule {
|
|
|
17774
18132
|
return { status: 'permission_denied' };
|
|
17775
18133
|
}
|
|
17776
18134
|
}
|
|
17777
|
-
//
|
|
17778
|
-
//
|
|
17779
|
-
|
|
18135
|
+
// A subscription made against the current key is reused: registering it
|
|
18136
|
+
// again refreshes its server TTL. One made against another key is dead — its
|
|
18137
|
+
// push service refuses every push signed with this one — so it is replaced.
|
|
18138
|
+
const held = await registration.pushManager.getSubscription();
|
|
18139
|
+
const existing = held && isBoundToKey(held, applicationServerKey) ? held : null;
|
|
18140
|
+
if (held && !existing) {
|
|
18141
|
+
await this.dropDeadSubscription(held);
|
|
18142
|
+
}
|
|
17780
18143
|
const subscription = existing ??
|
|
17781
18144
|
(await registration.pushManager.subscribe({
|
|
17782
18145
|
userVisibleOnly: true,
|
|
@@ -17785,6 +18148,23 @@ class NotifyModule {
|
|
|
17785
18148
|
await this.registerWebPushSubscription(subscription);
|
|
17786
18149
|
return { status: existing ? 'already_subscribed' : 'subscribed', subscription };
|
|
17787
18150
|
}
|
|
18151
|
+
/**
|
|
18152
|
+
* Retire a browser subscription bound to a key the server no longer signs
|
|
18153
|
+
* with: the server forgets its endpoint first (still authenticated, and the
|
|
18154
|
+
* push service would otherwise refuse that endpoint's every push without it
|
|
18155
|
+
* ever being pruned), then the browser drops it, which a subscribe against the
|
|
18156
|
+
* new key needs. A failure stops here with nothing half-done, so enabling
|
|
18157
|
+
* again starts from the same state.
|
|
18158
|
+
*
|
|
18159
|
+
* `unsubscribe()` resolves false only when the subscription is already gone
|
|
18160
|
+
* (another tab dropped it first), which leaves the browser as a subscribe
|
|
18161
|
+
* needs it; a browser that kept one refuses that subscribe outright
|
|
18162
|
+
* (InvalidStateError), so a kept subscription is never reused unseen.
|
|
18163
|
+
*/
|
|
18164
|
+
async dropDeadSubscription(subscription) {
|
|
18165
|
+
await this.unsubscribeWebPushEndpoint(subscription.endpoint);
|
|
18166
|
+
await subscription.unsubscribe();
|
|
18167
|
+
}
|
|
17788
18168
|
/**
|
|
17789
18169
|
* Disable Web Push on this device: unsubscribe the browser subscription and
|
|
17790
18170
|
* remove it server-side. Safe to call when not subscribed (returns false).
|
|
@@ -17938,7 +18318,7 @@ class SparkVault {
|
|
|
17938
18318
|
}
|
|
17939
18319
|
/** Get the SDK version */
|
|
17940
18320
|
static get version() {
|
|
17941
|
-
return '
|
|
18321
|
+
return '13.0.1';
|
|
17942
18322
|
}
|
|
17943
18323
|
}
|
|
17944
18324
|
if (typeof window !== 'undefined') {
|
|
@@ -17969,6 +18349,7 @@ exports.SparkVault = SparkVault;
|
|
|
17969
18349
|
exports.SparkVaultError = SparkVaultError;
|
|
17970
18350
|
exports.SparksModule = SparksModule;
|
|
17971
18351
|
exports.TimeoutError = TimeoutError;
|
|
18352
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
17972
18353
|
exports.UserCancelledError = UserCancelledError;
|
|
17973
18354
|
exports.ValidationError = ValidationError;
|
|
17974
18355
|
exports.VaultsModule = VaultsModule;
|