@sparkvault/sdk-js 6.0.0 → 7.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/dist/index.d.ts +15 -7
- package/dist/products/identity/handlers/passkey-handler.d.ts +6 -1
- package/dist/products/identity/handlers/sparklink-handler.d.ts +3 -0
- package/dist/products/identity/handlers/totp-handler.d.ts +7 -0
- package/dist/products/identity/index.d.ts +15 -7
- package/dist/products/identity/renderer.d.ts +8 -0
- package/dist/products/identity/views/error.d.ts +9 -0
- package/dist/sparkvault.cjs.js +108 -12
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +108 -12
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/sparkvault.esm.js
CHANGED
|
@@ -1711,9 +1711,11 @@ class TotpHandler {
|
|
|
1711
1711
|
}
|
|
1712
1712
|
catch (error) {
|
|
1713
1713
|
const message = error instanceof Error ? error.message : 'Failed to send code';
|
|
1714
|
+
const errorCode = error instanceof SparkVaultError ? error.code : undefined;
|
|
1714
1715
|
return {
|
|
1715
1716
|
success: false,
|
|
1716
1717
|
error: message,
|
|
1718
|
+
errorCode,
|
|
1717
1719
|
};
|
|
1718
1720
|
}
|
|
1719
1721
|
}
|
|
@@ -1744,9 +1746,11 @@ class TotpHandler {
|
|
|
1744
1746
|
}
|
|
1745
1747
|
catch (error) {
|
|
1746
1748
|
const message = error instanceof Error ? error.message : 'Failed to resend code';
|
|
1749
|
+
const errorCode = error instanceof SparkVaultError ? error.code : undefined;
|
|
1747
1750
|
return {
|
|
1748
1751
|
success: false,
|
|
1749
1752
|
error: `Failed to resend: ${message}`,
|
|
1753
|
+
errorCode,
|
|
1750
1754
|
};
|
|
1751
1755
|
}
|
|
1752
1756
|
}
|
|
@@ -1848,6 +1852,7 @@ class SparkLinkHandler {
|
|
|
1848
1852
|
return {
|
|
1849
1853
|
success: false,
|
|
1850
1854
|
error: message,
|
|
1855
|
+
errorCode: error instanceof SparkVaultError ? error.code : undefined,
|
|
1851
1856
|
};
|
|
1852
1857
|
}
|
|
1853
1858
|
}
|
|
@@ -5177,6 +5182,22 @@ class SparkLinkWaitingView {
|
|
|
5177
5182
|
*
|
|
5178
5183
|
* Professional enterprise-quality error display with clear visual hierarchy.
|
|
5179
5184
|
*/
|
|
5185
|
+
/**
|
|
5186
|
+
* Error codes that mean the site owner's Identity access is blocked — the
|
|
5187
|
+
* free trial was exhausted or expired, or a paid plan hit its capacity wall.
|
|
5188
|
+
* The end user can do nothing about these, so the ErrorView renders a friendly,
|
|
5189
|
+
* non-leaky interstitial (no "Try Again", no debug code badge) exactly like
|
|
5190
|
+
* `identity_locked`. The owner is nudged to subscribe through their own
|
|
5191
|
+
* dashboard, never through this end-user surface.
|
|
5192
|
+
*/
|
|
5193
|
+
const IDENTITY_BLOCKED_ERROR_CODES = [
|
|
5194
|
+
'identity_trial_exhausted',
|
|
5195
|
+
'identity_trial_expired',
|
|
5196
|
+
'identity_capacity_blocked',
|
|
5197
|
+
];
|
|
5198
|
+
function isBlockedCode(code) {
|
|
5199
|
+
return IDENTITY_BLOCKED_ERROR_CODES.includes(code);
|
|
5200
|
+
}
|
|
5180
5201
|
class ErrorView {
|
|
5181
5202
|
constructor(props) {
|
|
5182
5203
|
this.retryButton = null;
|
|
@@ -5200,15 +5221,26 @@ class ErrorView {
|
|
|
5200
5221
|
// title, no debug error-code badge, and no "Try Again" (retrying the
|
|
5201
5222
|
// login cannot clear a lockdown — only managing it at auth.sv can).
|
|
5202
5223
|
const isLocked = this.props.code === 'identity_locked';
|
|
5224
|
+
// A blocked Identity (trial exhausted/expired, or paid capacity wall) is
|
|
5225
|
+
// likewise terminal for the end user: retrying cannot restore access, only
|
|
5226
|
+
// the site owner subscribing can. Show a friendly, non-leaky interstitial.
|
|
5227
|
+
const isBlocked = isBlockedCode(this.props.code);
|
|
5228
|
+
// Both states are terminal — suppress the debug code badge and the retry
|
|
5229
|
+
// button, leaving only Close.
|
|
5230
|
+
const isTerminal = isLocked || isBlocked;
|
|
5203
5231
|
const title = document.createElement('h3');
|
|
5204
5232
|
title.className = 'sv-error-title';
|
|
5205
|
-
title.textContent = isLocked
|
|
5233
|
+
title.textContent = isLocked
|
|
5234
|
+
? 'This SparkVault Identity is locked'
|
|
5235
|
+
: isBlocked
|
|
5236
|
+
? 'Sign-in unavailable'
|
|
5237
|
+
: 'Something went wrong';
|
|
5206
5238
|
const message = document.createElement('p');
|
|
5207
5239
|
message.className = 'sv-error-message';
|
|
5208
5240
|
message.textContent = this.props.message;
|
|
5209
5241
|
contentSection.appendChild(title);
|
|
5210
5242
|
contentSection.appendChild(message);
|
|
5211
|
-
if (!
|
|
5243
|
+
if (!isTerminal) {
|
|
5212
5244
|
// Error code badge — useful for debugging genuine errors only.
|
|
5213
5245
|
const codeBadge = document.createElement('div');
|
|
5214
5246
|
codeBadge.className = 'sv-error-code-badge';
|
|
@@ -5225,7 +5257,7 @@ class ErrorView {
|
|
|
5225
5257
|
// Action buttons with proper styling
|
|
5226
5258
|
const buttonContainer = div();
|
|
5227
5259
|
buttonContainer.className = 'sv-error-actions';
|
|
5228
|
-
if (!
|
|
5260
|
+
if (!isTerminal) {
|
|
5229
5261
|
this.retryButton = document.createElement('button');
|
|
5230
5262
|
this.retryButton.className = 'sv-btn sv-btn-error-primary';
|
|
5231
5263
|
this.retryButton.textContent = 'Try Again';
|
|
@@ -5692,6 +5724,13 @@ class OriginNotAllowedView {
|
|
|
5692
5724
|
* Orchestrates view state and rendering for identity verification flows.
|
|
5693
5725
|
* Uses extracted handlers for TOTP and Passkey operations.
|
|
5694
5726
|
*/
|
|
5727
|
+
/**
|
|
5728
|
+
* End-user copy for a blocked Identity. Intentionally generic — it never names
|
|
5729
|
+
* the trial, billing, usage, or any owner-facing internal. The site owner is
|
|
5730
|
+
* nudged to subscribe through their own dashboard and emails, not here.
|
|
5731
|
+
*/
|
|
5732
|
+
const IDENTITY_BLOCKED_END_USER_MESSAGE = "This app's sign-in is temporarily unavailable. Please contact the site owner.";
|
|
5733
|
+
const BLOCKED_ERROR_CODES = new Set(IDENTITY_BLOCKED_ERROR_CODES);
|
|
5695
5734
|
const SPARKLINK_CSP_BLOCKED_ERROR = {
|
|
5696
5735
|
message: [
|
|
5697
5736
|
'Connection blocked by security policy.',
|
|
@@ -6225,6 +6264,8 @@ class IdentityRenderer {
|
|
|
6225
6264
|
this.setState({ view: 'loading' });
|
|
6226
6265
|
const result = await this.totpHandler.send(totpMethod);
|
|
6227
6266
|
if (!result.success) {
|
|
6267
|
+
if (this.renderBlockedInterstitial(result.errorCode))
|
|
6268
|
+
return;
|
|
6228
6269
|
this.setState({
|
|
6229
6270
|
view: 'error',
|
|
6230
6271
|
message: result.error ?? 'Failed to send code',
|
|
@@ -6283,6 +6324,12 @@ class IdentityRenderer {
|
|
|
6283
6324
|
const result = await this.sparkLinkHandler.send(wsResult.connectionId);
|
|
6284
6325
|
if (!result.success) {
|
|
6285
6326
|
this.cleanupSparkLink();
|
|
6327
|
+
// A blocked Identity (trial exhausted/expired, paid capacity) is
|
|
6328
|
+
// terminal — show the "sign-in unavailable" interstitial, not a
|
|
6329
|
+
// retryable "Try Again" that invites retrying a permanently-blocked
|
|
6330
|
+
// login. Mirrors the totp send path.
|
|
6331
|
+
if (this.renderBlockedInterstitial(result.errorCode))
|
|
6332
|
+
return;
|
|
6286
6333
|
this.setState({
|
|
6287
6334
|
view: 'error',
|
|
6288
6335
|
message: result.error ?? 'Failed to send SparkLink',
|
|
@@ -6320,6 +6367,24 @@ class IdentityRenderer {
|
|
|
6320
6367
|
this.handleErrorWithRecovery(error, 'unknown');
|
|
6321
6368
|
}
|
|
6322
6369
|
}
|
|
6370
|
+
/**
|
|
6371
|
+
* If the error code means the site owner's Identity access is blocked
|
|
6372
|
+
* (trial exhausted/expired, or paid capacity wall), render the dedicated
|
|
6373
|
+
* end-user interstitial and return true. The message is intentionally
|
|
6374
|
+
* generic so no billing internals leak to the end user. Returns false for
|
|
6375
|
+
* any other code so the caller falls through to its normal handling.
|
|
6376
|
+
*/
|
|
6377
|
+
renderBlockedInterstitial(code) {
|
|
6378
|
+
if (!code || !BLOCKED_ERROR_CODES.has(code)) {
|
|
6379
|
+
return false;
|
|
6380
|
+
}
|
|
6381
|
+
this.setState({
|
|
6382
|
+
view: 'error',
|
|
6383
|
+
code,
|
|
6384
|
+
message: IDENTITY_BLOCKED_END_USER_MESSAGE,
|
|
6385
|
+
});
|
|
6386
|
+
return true;
|
|
6387
|
+
}
|
|
6323
6388
|
async handleTotpSubmit(code) {
|
|
6324
6389
|
if (this.viewState.view !== 'totp-verify')
|
|
6325
6390
|
return;
|
|
@@ -6336,6 +6401,7 @@ class IdentityRenderer {
|
|
|
6336
6401
|
if (result.success && result.result) {
|
|
6337
6402
|
this.runPostLogin(result.result);
|
|
6338
6403
|
}
|
|
6404
|
+
else if (this.renderBlockedInterstitial(result.errorCode)) ;
|
|
6339
6405
|
else if (result.errorCode === 'identity_locked') {
|
|
6340
6406
|
// The identity is locked down — a dedicated, actionable state, not a
|
|
6341
6407
|
// generic "invalid code" retry. The person must manage it at auth.sv.
|
|
@@ -6416,6 +6482,8 @@ class IdentityRenderer {
|
|
|
6416
6482
|
const currentMethod = this.verificationState.totp.method ?? 'email';
|
|
6417
6483
|
const result = await this.totpHandler.resend();
|
|
6418
6484
|
if (!result.success) {
|
|
6485
|
+
if (this.renderBlockedInterstitial(result.errorCode))
|
|
6486
|
+
return;
|
|
6419
6487
|
this.setState({
|
|
6420
6488
|
view: 'totp-verify',
|
|
6421
6489
|
email: this.recipient,
|
|
@@ -6458,6 +6526,7 @@ class IdentityRenderer {
|
|
|
6458
6526
|
navigateWith(this.options, result.result.redirect);
|
|
6459
6527
|
}
|
|
6460
6528
|
}
|
|
6529
|
+
else if (this.renderBlockedInterstitial(result.errorCode)) ;
|
|
6461
6530
|
else if (result.errorCode === 'identity_locked') {
|
|
6462
6531
|
// Dedicated state — retrying cannot unlock the identity.
|
|
6463
6532
|
this.setState({
|
|
@@ -7097,6 +7166,8 @@ class IdentityRenderer {
|
|
|
7097
7166
|
this.setState({ view: 'loading' });
|
|
7098
7167
|
const result = await this.totpHandler.send('email');
|
|
7099
7168
|
if (!result.success) {
|
|
7169
|
+
if (this.renderBlockedInterstitial(result.errorCode))
|
|
7170
|
+
return;
|
|
7100
7171
|
this.setState({
|
|
7101
7172
|
view: 'error',
|
|
7102
7173
|
message: result.error ?? 'Failed to send code',
|
|
@@ -7930,13 +8001,19 @@ class IdentityModule {
|
|
|
7930
8001
|
return cleanup;
|
|
7931
8002
|
}
|
|
7932
8003
|
/**
|
|
7933
|
-
*
|
|
7934
|
-
*
|
|
8004
|
+
* Decode an identity token's claims WITHOUT verifying its signature.
|
|
8005
|
+
*
|
|
8006
|
+
* This is an UNVERIFIED, client-side decode: it parses the JWT payload and
|
|
8007
|
+
* sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
|
|
8008
|
+
* `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
|
|
8009
|
+
* cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
|
|
8010
|
+
* result MUST NOT be trusted for any authorization decision.
|
|
7935
8011
|
*
|
|
7936
|
-
*
|
|
7937
|
-
*
|
|
8012
|
+
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
8013
|
+
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
8014
|
+
* (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
7938
8015
|
*/
|
|
7939
|
-
|
|
8016
|
+
decodeToken(token) {
|
|
7940
8017
|
if (!token || typeof token !== 'string') {
|
|
7941
8018
|
throw new ValidationError('Token is required');
|
|
7942
8019
|
}
|
|
@@ -7944,7 +8021,17 @@ class IdentityModule {
|
|
|
7944
8021
|
if (parts.length !== 3) {
|
|
7945
8022
|
throw new ValidationError('Invalid token format');
|
|
7946
8023
|
}
|
|
7947
|
-
const [, payloadB64] = parts;
|
|
8024
|
+
const [headerB64, payloadB64] = parts;
|
|
8025
|
+
const header = JSON.parse(base64urlToString(headerB64));
|
|
8026
|
+
if (typeof header !== 'object' || header === null) {
|
|
8027
|
+
throw new ValidationError('Invalid token header');
|
|
8028
|
+
}
|
|
8029
|
+
// Reject alg:none (unsigned) and any algorithm other than EdDSA. Identity
|
|
8030
|
+
// tokens are Ed25519-signed; anything else is an unsigned or algorithm-
|
|
8031
|
+
// confused token that could never pass server-side JWKS verification.
|
|
8032
|
+
if (header.alg !== 'EdDSA') {
|
|
8033
|
+
throw new ValidationError('Unsupported token algorithm');
|
|
8034
|
+
}
|
|
7948
8035
|
const payload = JSON.parse(base64urlToString(payloadB64));
|
|
7949
8036
|
if (!isTokenClaims(payload)) {
|
|
7950
8037
|
throw new ValidationError('Invalid token payload structure');
|
|
@@ -7957,13 +8044,18 @@ class IdentityModule {
|
|
|
7957
8044
|
if (payload.iss !== expectedIssuer) {
|
|
7958
8045
|
throw new ValidationError('Invalid token issuer');
|
|
7959
8046
|
}
|
|
8047
|
+
if (payload.aud !== this.config.accountId) {
|
|
8048
|
+
throw new ValidationError('Invalid token audience');
|
|
8049
|
+
}
|
|
7960
8050
|
return payload;
|
|
7961
8051
|
}
|
|
7962
8052
|
/**
|
|
7963
8053
|
* Complete full-page redirect results produced by social-login flows.
|
|
7964
8054
|
* The Identity Product redirects back with `#token=...` so the token does
|
|
7965
|
-
* not hit server logs. Consume it once,
|
|
7966
|
-
*
|
|
8055
|
+
* not hit server logs. Consume it once, run the unverified client-side decode
|
|
8056
|
+
* (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
|
|
8057
|
+
* remove it from the URL bar. The host must still verify the token server-side
|
|
8058
|
+
* via the Identity JWKS before trusting any claim.
|
|
7967
8059
|
*/
|
|
7968
8060
|
async consumeRedirectResult() {
|
|
7969
8061
|
if (typeof window === 'undefined' || !window.location.hash) {
|
|
@@ -7990,7 +8082,11 @@ class IdentityModule {
|
|
|
7990
8082
|
if (expectedState && params.get('state') !== expectedState) {
|
|
7991
8083
|
throw new ValidationError('Invalid OAuth state');
|
|
7992
8084
|
}
|
|
7993
|
-
|
|
8085
|
+
// Unverified client-side decode — surfaces the claims for the result
|
|
8086
|
+
// shape and rejects an obviously-bad token (expiry/issuer/audience/alg).
|
|
8087
|
+
// The host MUST still verify result.token server-side via the Identity
|
|
8088
|
+
// JWKS before trusting any claim for an authorization decision.
|
|
8089
|
+
const claims = this.decodeToken(token);
|
|
7994
8090
|
return {
|
|
7995
8091
|
token,
|
|
7996
8092
|
identity: claims.identity,
|