@sparkvault/sdk-js 1.25.1 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/config.d.ts +1 -1
- package/dist/identity/api.d.ts +2 -5
- package/dist/identity/handlers/passkey-handler.d.ts +3 -1
- package/dist/identity/handlers/totp-handler.d.ts +2 -0
- package/dist/identity/renderer.d.ts +8 -2
- package/dist/identity/types.d.ts +1 -1
- package/dist/identity/views/index.d.ts +1 -1
- package/dist/identity/views/{app-not-activated.d.ts → product-not-configured.d.ts} +6 -6
- package/dist/index.d.ts +12 -1
- package/dist/sparkvault.cjs.js +135 -108
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +135 -108
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/upload/types.d.ts +11 -0
- package/package.json +2 -2
package/dist/sparkvault.esm.js
CHANGED
|
@@ -73,7 +73,7 @@ const DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS = [
|
|
|
73
73
|
/\.cloudfront\.net$/i,
|
|
74
74
|
];
|
|
75
75
|
const API_URL = 'https://api.sparkvault.com';
|
|
76
|
-
const IDENTITY_URL = 'https://api.sparkvault.com/v1/
|
|
76
|
+
const IDENTITY_URL = 'https://api.sparkvault.com/v1/products/identity';
|
|
77
77
|
function normalizeApiBaseUrl(url) {
|
|
78
78
|
const trimmed = url.replace(/\/+$/, '');
|
|
79
79
|
return trimmed.endsWith('/v1') ? trimmed.slice(0, -3) : trimmed;
|
|
@@ -148,6 +148,14 @@ function defaultIsRetryable(error) {
|
|
|
148
148
|
}
|
|
149
149
|
return false;
|
|
150
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Return a random unit interval value using Web Crypto.
|
|
153
|
+
*/
|
|
154
|
+
function randomUnit() {
|
|
155
|
+
const value = new Uint32Array(1);
|
|
156
|
+
crypto.getRandomValues(value);
|
|
157
|
+
return value[0] / 0x100000000;
|
|
158
|
+
}
|
|
151
159
|
/**
|
|
152
160
|
* Calculate delay with exponential backoff and jitter
|
|
153
161
|
*/
|
|
@@ -156,7 +164,7 @@ function calculateDelay(attempt, baseDelayMs, maxDelayMs, jitterFactor) {
|
|
|
156
164
|
const exponentialDelay = baseDelayMs * Math.pow(2, attempt);
|
|
157
165
|
const cappedDelay = Math.min(exponentialDelay, maxDelayMs);
|
|
158
166
|
// Add jitter: random value within jitter range
|
|
159
|
-
const jitter = cappedDelay * jitterFactor *
|
|
167
|
+
const jitter = cappedDelay * jitterFactor * randomUnit();
|
|
160
168
|
return cappedDelay + jitter;
|
|
161
169
|
}
|
|
162
170
|
/**
|
|
@@ -890,7 +898,7 @@ function generateState() {
|
|
|
890
898
|
/**
|
|
891
899
|
* Identity API Client
|
|
892
900
|
*
|
|
893
|
-
* Handles all HTTP communication with the Identity
|
|
901
|
+
* Handles all HTTP communication with the Identity Product endpoints.
|
|
894
902
|
* Single responsibility: API calls only.
|
|
895
903
|
*/
|
|
896
904
|
class IdentityApi extends SparkVaultApi {
|
|
@@ -966,8 +974,6 @@ class IdentityApi extends SparkVaultApi {
|
|
|
966
974
|
* (email: MX lookup; phone: E.164 format)
|
|
967
975
|
* - has_passkey: whether any passkeys are registered for this identity
|
|
968
976
|
* (cross-tenant — single global RP)
|
|
969
|
-
* - email_valid: legacy alias for identity_valid, present for backward
|
|
970
|
-
* compatibility with older SDK versions
|
|
971
977
|
*/
|
|
972
978
|
async checkPasskey(identity, identityType = 'email') {
|
|
973
979
|
const body = identityType === 'phone' ? { phone: identity } : { email: identity };
|
|
@@ -1018,8 +1024,10 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1018
1024
|
/**
|
|
1019
1025
|
* Start passkey registration for an identity (email or phone).
|
|
1020
1026
|
*/
|
|
1021
|
-
async startPasskeyRegister(identity, identityType = 'email') {
|
|
1022
|
-
const body = identityType === 'phone'
|
|
1027
|
+
async startPasskeyRegister(identity, identityType = 'email', registrationToken) {
|
|
1028
|
+
const body = identityType === 'phone'
|
|
1029
|
+
? { phone: identity, registration_token: registrationToken }
|
|
1030
|
+
: { email: identity, registration_token: registrationToken };
|
|
1023
1031
|
// Backend returns { options: PublicKeyCredentialCreationOptions, session: {...} }
|
|
1024
1032
|
// Extract and flatten to match PasskeyChallengeResponse
|
|
1025
1033
|
const response = await this.request('POST', '/passkey/register', body);
|
|
@@ -1467,10 +1475,8 @@ class PasskeyHandler {
|
|
|
1467
1475
|
try {
|
|
1468
1476
|
const response = await this.api.checkPasskey(this.state.recipient, this.state.identityType);
|
|
1469
1477
|
this.state.setPasskeyStatus(response.has_passkey);
|
|
1470
|
-
// Prefer identity_valid; fall back to email_valid for older backends.
|
|
1471
|
-
const valid = response.identity_valid ?? response.email_valid;
|
|
1472
1478
|
return {
|
|
1473
|
-
emailValid:
|
|
1479
|
+
emailValid: response.identity_valid,
|
|
1474
1480
|
hasPasskey: response.has_passkey,
|
|
1475
1481
|
};
|
|
1476
1482
|
}
|
|
@@ -1483,8 +1489,8 @@ class PasskeyHandler {
|
|
|
1483
1489
|
/**
|
|
1484
1490
|
* Register a new passkey for the user via popup
|
|
1485
1491
|
*/
|
|
1486
|
-
async register() {
|
|
1487
|
-
const result = await this.openPasskeyPopup('register');
|
|
1492
|
+
async register(registrationToken) {
|
|
1493
|
+
const result = await this.openPasskeyPopup('register', registrationToken);
|
|
1488
1494
|
if (result.success) {
|
|
1489
1495
|
// Update state - user now has a passkey
|
|
1490
1496
|
this.state.setPasskeyStatus(true);
|
|
@@ -1500,7 +1506,7 @@ class PasskeyHandler {
|
|
|
1500
1506
|
/**
|
|
1501
1507
|
* Open passkey popup and wait for result
|
|
1502
1508
|
*/
|
|
1503
|
-
async openPasskeyPopup(mode) {
|
|
1509
|
+
async openPasskeyPopup(mode, registrationToken) {
|
|
1504
1510
|
return new Promise((resolve) => {
|
|
1505
1511
|
// Build popup URL. Pass identity as `email` or `phone` (mutually
|
|
1506
1512
|
// exclusive) so the popup can render and POST the correct field.
|
|
@@ -1523,7 +1529,10 @@ class PasskeyHandler {
|
|
|
1523
1529
|
session_id: authContext.simpleMode.sessionId,
|
|
1524
1530
|
}));
|
|
1525
1531
|
}
|
|
1526
|
-
const
|
|
1532
|
+
const hash = mode === 'register' && registrationToken
|
|
1533
|
+
? `#${new URLSearchParams({ registration_token: registrationToken }).toString()}`
|
|
1534
|
+
: '';
|
|
1535
|
+
const popupUrl = `${this.baseUrl}/${this.accountId}/passkey/popup?${params}${hash}`;
|
|
1527
1536
|
// Calculate popup position (centered)
|
|
1528
1537
|
const left = Math.round((window.screen.width - POPUP_WIDTH) / 2);
|
|
1529
1538
|
const top = Math.round((window.screen.height - POPUP_HEIGHT) / 2);
|
|
@@ -1568,7 +1577,7 @@ class PasskeyHandler {
|
|
|
1568
1577
|
});
|
|
1569
1578
|
}
|
|
1570
1579
|
else {
|
|
1571
|
-
resolve(this.handlePopupError(data.error, data.message));
|
|
1580
|
+
resolve(this.handlePopupError(data.error, data.message, data.errorCode));
|
|
1572
1581
|
}
|
|
1573
1582
|
};
|
|
1574
1583
|
window.addEventListener('message', handleMessage);
|
|
@@ -1619,7 +1628,7 @@ class PasskeyHandler {
|
|
|
1619
1628
|
/**
|
|
1620
1629
|
* Handle popup error response
|
|
1621
1630
|
*/
|
|
1622
|
-
handlePopupError(error, message) {
|
|
1631
|
+
handlePopupError(error, message, errorCode) {
|
|
1623
1632
|
if (error === 'cancelled') {
|
|
1624
1633
|
return {
|
|
1625
1634
|
success: false,
|
|
@@ -1627,6 +1636,14 @@ class PasskeyHandler {
|
|
|
1627
1636
|
errorType: 'cancelled',
|
|
1628
1637
|
};
|
|
1629
1638
|
}
|
|
1639
|
+
if (errorCode === 'identity_locked' || error === 'identity_locked') {
|
|
1640
|
+
return {
|
|
1641
|
+
success: false,
|
|
1642
|
+
error: message || 'This SparkVault Identity is locked. Visit auth.sv to manage it.',
|
|
1643
|
+
errorType: 'unknown',
|
|
1644
|
+
errorCode: 'identity_locked',
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1630
1647
|
if (message?.includes('No passkey') || message?.includes('not found')) {
|
|
1631
1648
|
return {
|
|
1632
1649
|
success: false,
|
|
@@ -1638,6 +1655,7 @@ class PasskeyHandler {
|
|
|
1638
1655
|
success: false,
|
|
1639
1656
|
error: message || error || 'Passkey authentication failed',
|
|
1640
1657
|
errorType: 'unknown',
|
|
1658
|
+
errorCode,
|
|
1641
1659
|
};
|
|
1642
1660
|
}
|
|
1643
1661
|
}
|
|
@@ -1759,9 +1777,11 @@ class TotpHandler {
|
|
|
1759
1777
|
}
|
|
1760
1778
|
catch (error) {
|
|
1761
1779
|
const message = error instanceof Error ? error.message : 'Verification failed';
|
|
1780
|
+
const errorCode = (error instanceof SparkVaultError) ? error.code : undefined;
|
|
1762
1781
|
return {
|
|
1763
1782
|
success: false,
|
|
1764
1783
|
error: message,
|
|
1784
|
+
errorCode,
|
|
1765
1785
|
};
|
|
1766
1786
|
}
|
|
1767
1787
|
}
|
|
@@ -4859,38 +4879,46 @@ class ErrorView {
|
|
|
4859
4879
|
// Content section
|
|
4860
4880
|
const contentSection = div();
|
|
4861
4881
|
contentSection.className = 'sv-error-content';
|
|
4882
|
+
// A locked-down identity is a dedicated, non-error state: a specific
|
|
4883
|
+
// title, no debug error-code badge, and no "Try Again" (retrying the
|
|
4884
|
+
// login cannot clear a lockdown — only managing it at auth.sv can).
|
|
4885
|
+
const isLocked = this.props.code === 'identity_locked';
|
|
4862
4886
|
const title = document.createElement('h3');
|
|
4863
4887
|
title.className = 'sv-error-title';
|
|
4864
|
-
title.textContent = 'Something went wrong';
|
|
4888
|
+
title.textContent = isLocked ? 'This SparkVault Identity is locked' : 'Something went wrong';
|
|
4865
4889
|
const message = document.createElement('p');
|
|
4866
4890
|
message.className = 'sv-error-message';
|
|
4867
4891
|
message.textContent = this.props.message;
|
|
4868
|
-
// Error code badge
|
|
4869
|
-
const codeBadge = document.createElement('div');
|
|
4870
|
-
codeBadge.className = 'sv-error-code-badge';
|
|
4871
|
-
const codeLabel = document.createElement('span');
|
|
4872
|
-
codeLabel.className = 'sv-error-code-label';
|
|
4873
|
-
codeLabel.textContent = 'Error code';
|
|
4874
|
-
const codeValue = document.createElement('code');
|
|
4875
|
-
codeValue.className = 'sv-error-code-value';
|
|
4876
|
-
codeValue.textContent = this.props.code;
|
|
4877
|
-
codeBadge.appendChild(codeLabel);
|
|
4878
|
-
codeBadge.appendChild(codeValue);
|
|
4879
4892
|
contentSection.appendChild(title);
|
|
4880
4893
|
contentSection.appendChild(message);
|
|
4881
|
-
|
|
4894
|
+
if (!isLocked) {
|
|
4895
|
+
// Error code badge — useful for debugging genuine errors only.
|
|
4896
|
+
const codeBadge = document.createElement('div');
|
|
4897
|
+
codeBadge.className = 'sv-error-code-badge';
|
|
4898
|
+
const codeLabel = document.createElement('span');
|
|
4899
|
+
codeLabel.className = 'sv-error-code-label';
|
|
4900
|
+
codeLabel.textContent = 'Error code';
|
|
4901
|
+
const codeValue = document.createElement('code');
|
|
4902
|
+
codeValue.className = 'sv-error-code-value';
|
|
4903
|
+
codeValue.textContent = this.props.code;
|
|
4904
|
+
codeBadge.appendChild(codeLabel);
|
|
4905
|
+
codeBadge.appendChild(codeValue);
|
|
4906
|
+
contentSection.appendChild(codeBadge);
|
|
4907
|
+
}
|
|
4882
4908
|
// Action buttons with proper styling
|
|
4883
4909
|
const buttonContainer = div();
|
|
4884
4910
|
buttonContainer.className = 'sv-error-actions';
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4911
|
+
if (!isLocked) {
|
|
4912
|
+
this.retryButton = document.createElement('button');
|
|
4913
|
+
this.retryButton.className = 'sv-btn sv-btn-error-primary';
|
|
4914
|
+
this.retryButton.textContent = 'Try Again';
|
|
4915
|
+
this.retryButton.addEventListener('click', this.boundHandleRetry);
|
|
4916
|
+
buttonContainer.appendChild(this.retryButton);
|
|
4917
|
+
}
|
|
4889
4918
|
this.closeButton = document.createElement('button');
|
|
4890
4919
|
this.closeButton.className = 'sv-btn sv-btn-error-secondary';
|
|
4891
4920
|
this.closeButton.textContent = 'Close';
|
|
4892
4921
|
this.closeButton.addEventListener('click', this.boundHandleClose);
|
|
4893
|
-
buttonContainer.appendChild(this.retryButton);
|
|
4894
4922
|
buttonContainer.appendChild(this.closeButton);
|
|
4895
4923
|
container.appendChild(iconContainer);
|
|
4896
4924
|
container.appendChild(contentSection);
|
|
@@ -5009,15 +5037,15 @@ class ServiceUnavailableView {
|
|
|
5009
5037
|
}
|
|
5010
5038
|
|
|
5011
5039
|
/**
|
|
5012
|
-
*
|
|
5040
|
+
* Product Not Configured View
|
|
5013
5041
|
*
|
|
5014
|
-
* Full-dialog terminal screen shown when the SparkVault Identity
|
|
5015
|
-
* been
|
|
5042
|
+
* Full-dialog terminal screen shown when the SparkVault Identity Product has
|
|
5043
|
+
* not been configured for the account that the JS SDK is configured against. The
|
|
5016
5044
|
* audience is the website owner / developer — this is a misconfiguration
|
|
5017
5045
|
* surface, not an end-user error — so the dialog drops customer branding and
|
|
5018
5046
|
* presents itself as an unmistakable SparkVault notice.
|
|
5019
5047
|
*/
|
|
5020
|
-
const ACTIVATION_URL = 'https://app.sparkvault.com/
|
|
5048
|
+
const ACTIVATION_URL = 'https://app.sparkvault.com/products/identity';
|
|
5021
5049
|
function createBadge() {
|
|
5022
5050
|
const badge = div('sv-not-activated-badge');
|
|
5023
5051
|
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
@@ -5092,7 +5120,7 @@ function createSparkVaultMark() {
|
|
|
5092
5120
|
mark.appendChild(label);
|
|
5093
5121
|
return mark;
|
|
5094
5122
|
}
|
|
5095
|
-
class
|
|
5123
|
+
class ProductNotConfiguredView {
|
|
5096
5124
|
constructor(props) {
|
|
5097
5125
|
this.dismissButton = null;
|
|
5098
5126
|
this.props = props;
|
|
@@ -5116,12 +5144,12 @@ class AppNotActivatedView {
|
|
|
5116
5144
|
const title = document.createElement('h2');
|
|
5117
5145
|
title.className = 'sv-not-activated-title';
|
|
5118
5146
|
title.id = 'sv-modal-title';
|
|
5119
|
-
title.textContent = 'Identity
|
|
5147
|
+
title.textContent = 'Identity Product not configured';
|
|
5120
5148
|
container.appendChild(title);
|
|
5121
5149
|
const message = document.createElement('p');
|
|
5122
5150
|
message.className = 'sv-not-activated-message';
|
|
5123
5151
|
message.textContent =
|
|
5124
|
-
'Sign-in is unavailable because the site owner
|
|
5152
|
+
'Sign-in is unavailable because the site owner has not configured SparkVault Identity for this account.';
|
|
5125
5153
|
container.appendChild(message);
|
|
5126
5154
|
const ownerCard = div('sv-not-activated-owner');
|
|
5127
5155
|
const ownerLabel = document.createElement('span');
|
|
@@ -5130,7 +5158,7 @@ class AppNotActivatedView {
|
|
|
5130
5158
|
const ownerHint = document.createElement('span');
|
|
5131
5159
|
ownerHint.className = 'sv-not-activated-owner-hint';
|
|
5132
5160
|
ownerHint.textContent =
|
|
5133
|
-
'Sign in to
|
|
5161
|
+
'Sign in to SparkVault and configure the Identity Product to start accepting sign-ins.';
|
|
5134
5162
|
ownerCard.appendChild(ownerLabel);
|
|
5135
5163
|
ownerCard.appendChild(ownerHint);
|
|
5136
5164
|
container.appendChild(ownerCard);
|
|
@@ -5141,7 +5169,7 @@ class AppNotActivatedView {
|
|
|
5141
5169
|
cta.target = '_blank';
|
|
5142
5170
|
cta.rel = 'noopener noreferrer';
|
|
5143
5171
|
const ctaLabel = document.createElement('span');
|
|
5144
|
-
ctaLabel.textContent = '
|
|
5172
|
+
ctaLabel.textContent = 'Configure in SparkVault';
|
|
5145
5173
|
cta.appendChild(ctaLabel);
|
|
5146
5174
|
cta.appendChild(createExternalLinkIcon());
|
|
5147
5175
|
actions.appendChild(cta);
|
|
@@ -5196,6 +5224,20 @@ class IdentityRenderer {
|
|
|
5196
5224
|
this.verificationState.setAuthContext(options.authContext);
|
|
5197
5225
|
}
|
|
5198
5226
|
}
|
|
5227
|
+
/**
|
|
5228
|
+
* Fire the host's onSuccess callback, swallowing any exception so a
|
|
5229
|
+
* misbehaving host handler can't block the post-success redirect the
|
|
5230
|
+
* caller is depending on. The verify flow continues regardless.
|
|
5231
|
+
*/
|
|
5232
|
+
safeOnSuccess(result) {
|
|
5233
|
+
try {
|
|
5234
|
+
this.callbacks.onSuccess(result);
|
|
5235
|
+
}
|
|
5236
|
+
catch (err) {
|
|
5237
|
+
// eslint-disable-next-line no-console
|
|
5238
|
+
console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
|
|
5239
|
+
}
|
|
5240
|
+
}
|
|
5199
5241
|
// Convenience accessors for state
|
|
5200
5242
|
get recipient() {
|
|
5201
5243
|
return this.verificationState.recipient;
|
|
@@ -5218,7 +5260,7 @@ class IdentityRenderer {
|
|
|
5218
5260
|
if (this.api.isConfigPreloaded()) {
|
|
5219
5261
|
// Config fetch already started - race it against a 50ms timeout
|
|
5220
5262
|
// If config is ready (or almost ready), we skip the loading flash.
|
|
5221
|
-
// A rejected preload (e.g.
|
|
5263
|
+
// A rejected preload (e.g. product_not_configured) must not abort start() —
|
|
5222
5264
|
// swallow here and let the in-modal try/catch below route to the
|
|
5223
5265
|
// correct error view.
|
|
5224
5266
|
const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(null), 50));
|
|
@@ -5272,13 +5314,13 @@ class IdentityRenderer {
|
|
|
5272
5314
|
}
|
|
5273
5315
|
/**
|
|
5274
5316
|
* Map a config-fetch error to the appropriate terminal view.
|
|
5275
|
-
* `
|
|
5276
|
-
* Identity
|
|
5317
|
+
* `product_not_configured` is a misconfiguration (the account has not
|
|
5318
|
+
* configured Identity) — show a developer-targeted terminal screen with a
|
|
5277
5319
|
* link to SparkVault.com instead of the generic service-unavailable view.
|
|
5278
5320
|
*/
|
|
5279
5321
|
viewStateForConfigError(error) {
|
|
5280
|
-
if (error instanceof IdentityApiError && error.code === '
|
|
5281
|
-
return { view: '
|
|
5322
|
+
if (error instanceof IdentityApiError && error.code === 'product_not_configured') {
|
|
5323
|
+
return { view: 'product-not-configured' };
|
|
5282
5324
|
}
|
|
5283
5325
|
return { view: 'service-unavailable' };
|
|
5284
5326
|
}
|
|
@@ -5366,7 +5408,7 @@ class IdentityRenderer {
|
|
|
5366
5408
|
// Full-dialog terminal screens own the entire modal; toggle the container
|
|
5367
5409
|
// chrome accordingly so the customer header doesn't bleed into a
|
|
5368
5410
|
// SparkVault-owned message.
|
|
5369
|
-
this.container.setMinimalChrome(this.viewState.view === '
|
|
5411
|
+
this.container.setMinimalChrome(this.viewState.view === 'product-not-configured');
|
|
5370
5412
|
const view = this.createViewForState(this.viewState);
|
|
5371
5413
|
this.currentView = view;
|
|
5372
5414
|
clearChildren(body);
|
|
@@ -5468,8 +5510,8 @@ class IdentityRenderer {
|
|
|
5468
5510
|
onRetry: () => this.retryConfigLoad(),
|
|
5469
5511
|
onClose: () => this.handleClose(),
|
|
5470
5512
|
});
|
|
5471
|
-
case '
|
|
5472
|
-
return new
|
|
5513
|
+
case 'product-not-configured':
|
|
5514
|
+
return new ProductNotConfiguredView({
|
|
5473
5515
|
onClose: () => this.handleClose(),
|
|
5474
5516
|
});
|
|
5475
5517
|
}
|
|
@@ -5666,17 +5708,20 @@ class IdentityRenderer {
|
|
|
5666
5708
|
this.close();
|
|
5667
5709
|
// Hand the full result (including redirect) to the host first so the
|
|
5668
5710
|
// page-level handler can act before we navigate away.
|
|
5669
|
-
|
|
5670
|
-
this.callbacks.onSuccess(result.result);
|
|
5671
|
-
}
|
|
5672
|
-
catch (err) {
|
|
5673
|
-
// eslint-disable-next-line no-console
|
|
5674
|
-
console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
|
|
5675
|
-
}
|
|
5711
|
+
this.safeOnSuccess(result.result);
|
|
5676
5712
|
if (typeof result.result.redirect === 'string' && result.result.redirect) {
|
|
5677
5713
|
window.location.href = result.result.redirect;
|
|
5678
5714
|
}
|
|
5679
5715
|
}
|
|
5716
|
+
else if (result.errorCode === 'identity_locked') {
|
|
5717
|
+
// The identity is locked down — a dedicated, actionable state, not a
|
|
5718
|
+
// generic "invalid code" retry. The person must manage it at auth.sv.
|
|
5719
|
+
this.setState({
|
|
5720
|
+
view: 'error',
|
|
5721
|
+
code: 'identity_locked',
|
|
5722
|
+
message: 'This SparkVault Identity is locked. Visit auth.sv to manage it.',
|
|
5723
|
+
});
|
|
5724
|
+
}
|
|
5680
5725
|
else {
|
|
5681
5726
|
// Check if error is expiry - auto-resend if so
|
|
5682
5727
|
const errorMsg = result.error?.toLowerCase() ?? '';
|
|
@@ -5739,17 +5784,19 @@ class IdentityRenderer {
|
|
|
5739
5784
|
: await this.passkeyHandler.verify();
|
|
5740
5785
|
if (result.success && result.result) {
|
|
5741
5786
|
this.close();
|
|
5742
|
-
|
|
5743
|
-
this.callbacks.onSuccess(result.result);
|
|
5744
|
-
}
|
|
5745
|
-
catch (err) {
|
|
5746
|
-
// eslint-disable-next-line no-console
|
|
5747
|
-
console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
|
|
5748
|
-
}
|
|
5787
|
+
this.safeOnSuccess(result.result);
|
|
5749
5788
|
if (typeof result.result.redirect === 'string' && result.result.redirect) {
|
|
5750
5789
|
window.location.href = result.result.redirect;
|
|
5751
5790
|
}
|
|
5752
5791
|
}
|
|
5792
|
+
else if (result.errorCode === 'identity_locked') {
|
|
5793
|
+
// Dedicated state — retrying cannot unlock the identity.
|
|
5794
|
+
this.setState({
|
|
5795
|
+
view: 'error',
|
|
5796
|
+
code: 'identity_locked',
|
|
5797
|
+
message: 'This SparkVault Identity is locked. Visit auth.sv to manage it.',
|
|
5798
|
+
});
|
|
5799
|
+
}
|
|
5753
5800
|
else {
|
|
5754
5801
|
// Handle different error types
|
|
5755
5802
|
if (result.errorType === 'not_found') {
|
|
@@ -5787,13 +5834,7 @@ class IdentityRenderer {
|
|
|
5787
5834
|
if (pendingResult) {
|
|
5788
5835
|
this.verificationState.setPendingResult(null);
|
|
5789
5836
|
this.close();
|
|
5790
|
-
|
|
5791
|
-
this.callbacks.onSuccess(pendingResult);
|
|
5792
|
-
}
|
|
5793
|
-
catch (err) {
|
|
5794
|
-
// eslint-disable-next-line no-console
|
|
5795
|
-
console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
|
|
5796
|
-
}
|
|
5837
|
+
this.safeOnSuccess(pendingResult);
|
|
5797
5838
|
if (typeof pendingResult.redirect === 'string' && pendingResult.redirect) {
|
|
5798
5839
|
window.location.href = pendingResult.redirect;
|
|
5799
5840
|
}
|
|
@@ -5876,17 +5917,11 @@ class IdentityRenderer {
|
|
|
5876
5917
|
// Show loading while browser passkey dialog is active
|
|
5877
5918
|
this.setState({ view: 'loading' });
|
|
5878
5919
|
// Directly trigger passkey registration
|
|
5879
|
-
const result = await this.passkeyHandler.register();
|
|
5920
|
+
const result = await this.passkeyHandler.register(pendingResult.token);
|
|
5880
5921
|
if (result.success && result.result) {
|
|
5881
5922
|
// Passkey created successfully - use the new token
|
|
5882
5923
|
this.close();
|
|
5883
|
-
|
|
5884
|
-
this.callbacks.onSuccess(result.result);
|
|
5885
|
-
}
|
|
5886
|
-
catch (err) {
|
|
5887
|
-
// eslint-disable-next-line no-console
|
|
5888
|
-
console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
|
|
5889
|
-
}
|
|
5924
|
+
this.safeOnSuccess(result.result);
|
|
5890
5925
|
if (typeof result.result.redirect === 'string' && result.result.redirect) {
|
|
5891
5926
|
window.location.href = result.result.redirect;
|
|
5892
5927
|
}
|
|
@@ -5918,13 +5953,7 @@ class IdentityRenderer {
|
|
|
5918
5953
|
this.verificationState.dismissPasskeyPrompt();
|
|
5919
5954
|
// Complete the verification
|
|
5920
5955
|
this.close();
|
|
5921
|
-
|
|
5922
|
-
this.callbacks.onSuccess(pendingResult);
|
|
5923
|
-
}
|
|
5924
|
-
catch (err) {
|
|
5925
|
-
// eslint-disable-next-line no-console
|
|
5926
|
-
console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
|
|
5927
|
-
}
|
|
5956
|
+
this.safeOnSuccess(pendingResult);
|
|
5928
5957
|
if (typeof pendingResult.redirect === 'string' && pendingResult.redirect) {
|
|
5929
5958
|
window.location.href = pendingResult.redirect;
|
|
5930
5959
|
}
|
|
@@ -6029,19 +6058,6 @@ class IdentityRenderer {
|
|
|
6029
6058
|
catch {
|
|
6030
6059
|
return;
|
|
6031
6060
|
}
|
|
6032
|
-
// Diagnostic: dump the parsed message so we can see on the client
|
|
6033
|
-
// EXACTLY what arrives. Keys + redirect prefix tell us whether the
|
|
6034
|
-
// field made it across API Gateway. Remove once we've confirmed.
|
|
6035
|
-
// eslint-disable-next-line no-console
|
|
6036
|
-
console.info('[SparkVault SDK] sparklink WS message', {
|
|
6037
|
-
type: data.type,
|
|
6038
|
-
keys: Object.keys(data),
|
|
6039
|
-
hasRedirect: typeof data.redirect === 'string',
|
|
6040
|
-
redirectPrefix: typeof data.redirect === 'string'
|
|
6041
|
-
? data.redirect.slice(0, 80)
|
|
6042
|
-
: null,
|
|
6043
|
-
rawLength: event.data.length,
|
|
6044
|
-
});
|
|
6045
6061
|
switch (data.type) {
|
|
6046
6062
|
case 'sparklink_verified':
|
|
6047
6063
|
this.handleSparkLinkVerified({
|
|
@@ -6103,13 +6119,7 @@ class IdentityRenderer {
|
|
|
6103
6119
|
// Hand the full result (including redirect) to the host first so the
|
|
6104
6120
|
// page-level handler can do app-specific work (logging, navigation,
|
|
6105
6121
|
// etc.) before we steal the browsing context with a navigation.
|
|
6106
|
-
|
|
6107
|
-
this.callbacks.onSuccess(result);
|
|
6108
|
-
}
|
|
6109
|
-
catch (err) {
|
|
6110
|
-
// eslint-disable-next-line no-console
|
|
6111
|
-
console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
|
|
6112
|
-
}
|
|
6122
|
+
this.safeOnSuccess(result);
|
|
6113
6123
|
// SDK-side fallback navigation. If the host already navigated this is
|
|
6114
6124
|
// a no-op (the document is already unloading); if not, this rescues
|
|
6115
6125
|
// simple-mode flows whose host forgot to act on result.redirect.
|
|
@@ -8624,7 +8634,9 @@ function hexToBase64url(hex) {
|
|
|
8624
8634
|
*/
|
|
8625
8635
|
function generateRequestId() {
|
|
8626
8636
|
const timestamp = Date.now().toString(16);
|
|
8627
|
-
const
|
|
8637
|
+
const randomBytes = new Uint8Array(4);
|
|
8638
|
+
crypto.getRandomValues(randomBytes);
|
|
8639
|
+
const random = Array.from(randomBytes, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
8628
8640
|
return `${timestamp}${random}`;
|
|
8629
8641
|
}
|
|
8630
8642
|
/**
|
|
@@ -8674,6 +8686,14 @@ class UploadRenderer {
|
|
|
8674
8686
|
this.config = config;
|
|
8675
8687
|
// Update branding
|
|
8676
8688
|
this.container.updateBranding(config.branding);
|
|
8689
|
+
// Programmatic mode: a File was supplied, so skip the drop-zone form
|
|
8690
|
+
// and upload it straight away. Lets a host site own file selection
|
|
8691
|
+
// (its own button, picker, or drop target) and hand the File to the SDK.
|
|
8692
|
+
if (this.options.file) {
|
|
8693
|
+
this.selectedFile = this.options.file;
|
|
8694
|
+
await this.startUpload(config);
|
|
8695
|
+
return;
|
|
8696
|
+
}
|
|
8677
8697
|
// Show form
|
|
8678
8698
|
this.setState({ view: 'form', config });
|
|
8679
8699
|
}
|
|
@@ -9233,6 +9253,13 @@ class UploadRenderer {
|
|
|
9233
9253
|
percentage: 100,
|
|
9234
9254
|
phase: 'complete',
|
|
9235
9255
|
});
|
|
9256
|
+
// Silent mode: skip the success screen — fire onSuccess and close so
|
|
9257
|
+
// the host site can render its own post-upload UI.
|
|
9258
|
+
if (this.options.hideSuccessScreen) {
|
|
9259
|
+
this.callbacks.onSuccess(result);
|
|
9260
|
+
this.close();
|
|
9261
|
+
return;
|
|
9262
|
+
}
|
|
9236
9263
|
this.setState({ view: 'complete', result, config });
|
|
9237
9264
|
// Notify success
|
|
9238
9265
|
this.callbacks.onSuccess(result);
|