@sparkvault/sdk-js 8.1.2 → 8.3.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.
@@ -149,7 +149,7 @@ const DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS = [
149
149
  /\.cloudfront\.net$/i,
150
150
  ];
151
151
  const API_URL = 'https://api.sparkvault.com';
152
- const IDENTITY_URL = 'https://api.sparkvault.com/v1/products/identity';
152
+ const IDENTITY_URL = 'https://auth.sparkvault.com';
153
153
  const PORTAL_URL = `https://${SPARKVAULT_AUTH_HOST}`;
154
154
  function normalizeApiBaseUrl(url) {
155
155
  const trimmed = url.replace(/\/+$/, '');
@@ -2019,6 +2019,38 @@ function getStyles(options) {
2019
2019
  : '0 8px 24px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04)',
2020
2020
  };
2021
2021
  return `
2022
+ /* ========================================
2023
+ MOTION SYSTEM — shared duration/easing tokens so every transition in
2024
+ the flow is consistent. Enters decelerate (ease-out-expo), exits
2025
+ accelerate, spring is reserved for the success moment.
2026
+ ======================================== */
2027
+ :root {
2028
+ --sv-dur-instant: 80ms;
2029
+ --sv-dur-fast: 140ms;
2030
+ --sv-dur-base: 220ms;
2031
+ --sv-dur-slow: 320ms;
2032
+ --sv-dur-slower: 480ms;
2033
+ --sv-ease-standard: cubic-bezier(0.2, 0, 0, 1);
2034
+ --sv-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
2035
+ --sv-ease-accelerate: cubic-bezier(0.3, 0, 1, 1);
2036
+ --sv-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
2037
+ }
2038
+
2039
+ /* Each mounted view enters with a calm fade + rise. Applied by the renderer
2040
+ on every step change; the brand lockup and footer never move. */
2041
+ @keyframes sv-step-in {
2042
+ from { opacity: 0; transform: translateY(8px); }
2043
+ to { opacity: 1; transform: none; }
2044
+ }
2045
+ .sv-step-enter { animation: sv-step-in var(--sv-dur-base) var(--sv-ease-out) both; }
2046
+
2047
+ /* The top progress bar itself is owned and styled by the sign-in page
2048
+ (login-popup.js); the renderer only drives it via window.__sparkvaultProgress. */
2049
+
2050
+ @media (prefers-reduced-motion: reduce) {
2051
+ .sv-step-enter { animation-duration: 1ms; }
2052
+ }
2053
+
2022
2054
  /* ========================================
2023
2055
  OVERLAY & MODAL CONTAINER
2024
2056
  ======================================== */
@@ -2139,11 +2171,11 @@ function getStyles(options) {
2139
2171
  ======================================== */
2140
2172
 
2141
2173
  .sv-title {
2142
- font-size: 18px;
2174
+ font-size: 21px;
2143
2175
  font-weight: 600;
2144
- letter-spacing: -0.02em;
2145
- line-height: 1.3;
2146
- margin: 0 0 6px 0;
2176
+ letter-spacing: -0.021em;
2177
+ line-height: 1.22;
2178
+ margin: 0 0 7px 0;
2147
2179
  text-align: center;
2148
2180
  color: ${tokens.textPrimary};
2149
2181
  }
@@ -2182,16 +2214,17 @@ function getStyles(options) {
2182
2214
 
2183
2215
  .sv-input {
2184
2216
  width: 100%;
2185
- padding: 10px 12px;
2217
+ padding: 13px 14px;
2186
2218
  font-size: 15px;
2187
2219
  font-weight: 400;
2188
2220
  line-height: 1.4;
2189
- border: 1px solid ${tokens.border};
2190
- border-radius: 8px;
2221
+ border: 1px solid ${tokens.borderHover};
2222
+ border-radius: 10px;
2191
2223
  background: ${tokens.bgInput};
2192
2224
  color: ${tokens.textPrimary};
2193
2225
  box-sizing: border-box;
2194
- transition: border-color 0.15s ease, box-shadow 0.15s ease;
2226
+ box-shadow: 0 1px 1px ${isDark ? 'rgba(0,0,0,0.3)' : 'rgba(10,10,10,0.04)'};
2227
+ transition: border-color var(--sv-dur-fast) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard);
2195
2228
  }
2196
2229
 
2197
2230
  .sv-input:hover:not(:focus):not(:disabled) {
@@ -2233,15 +2266,15 @@ function getStyles(options) {
2233
2266
  justify-content: center;
2234
2267
  gap: 8px;
2235
2268
  width: 100%;
2236
- padding: 10px 16px;
2237
- font-size: 14px;
2238
- font-weight: 500;
2239
- letter-spacing: -0.005em;
2240
- line-height: 1.4;
2269
+ padding: 14px 16px;
2270
+ font-size: 15px;
2271
+ font-weight: 600;
2272
+ letter-spacing: -0.006em;
2273
+ line-height: 1.35;
2241
2274
  border: none;
2242
- border-radius: 8px;
2275
+ border-radius: 10px;
2243
2276
  cursor: pointer;
2244
- transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
2277
+ transition: background var(--sv-dur-fast) var(--sv-ease-standard), transform var(--sv-dur-instant) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard);
2245
2278
  box-sizing: border-box;
2246
2279
  }
2247
2280
 
@@ -2284,14 +2317,17 @@ function getStyles(options) {
2284
2317
  border-color: ${tokens.borderHover};
2285
2318
  }
2286
2319
 
2287
- /* Method Button */
2320
+ /* Method Button — a full-width row that lifts on hover with a nudging
2321
+ chevron affordance (added via ::after so no DOM change is needed). */
2288
2322
  .sv-btn-method {
2323
+ position: relative;
2289
2324
  background: ${tokens.bg};
2290
- border: 1px solid ${tokens.border};
2325
+ border: 1px solid ${tokens.borderHover};
2326
+ border-radius: 12px;
2291
2327
  color: ${tokens.textPrimary};
2292
2328
  text-align: left;
2293
- padding: 12px 14px;
2294
- margin-bottom: 8px;
2329
+ padding: 15px 40px 15px 14px;
2330
+ margin-bottom: 9px;
2295
2331
  /* Inset 2px on either side so the focus outline (drawn outside the
2296
2332
  border-box) has room to render without clipping against the
2297
2333
  dialog's container edges. width:auto pairs with this to prevent
@@ -2299,6 +2335,25 @@ function getStyles(options) {
2299
2335
  margin-left: 2px;
2300
2336
  margin-right: 2px;
2301
2337
  width: calc(100% - 4px);
2338
+ transition: transform var(--sv-dur-base) var(--sv-ease-out), background var(--sv-dur-fast) var(--sv-ease-standard), border-color var(--sv-dur-fast) var(--sv-ease-standard);
2339
+ }
2340
+
2341
+ .sv-btn-method::after {
2342
+ content: "";
2343
+ position: absolute;
2344
+ right: 16px;
2345
+ top: 50%;
2346
+ width: 8px;
2347
+ height: 8px;
2348
+ border-right: 1.6px solid ${tokens.textMuted};
2349
+ border-top: 1.6px solid ${tokens.textMuted};
2350
+ transform: translateY(-50%) rotate(45deg);
2351
+ transition: transform var(--sv-dur-base) var(--sv-ease-out), border-color var(--sv-dur-fast) var(--sv-ease-standard);
2352
+ }
2353
+
2354
+ .sv-btn-method:hover:not(:disabled)::after {
2355
+ transform: translateY(-50%) translateX(3px) rotate(45deg);
2356
+ border-color: ${tokens.textSecondary};
2302
2357
  }
2303
2358
 
2304
2359
  /* The shared .sv-btn focus rule sets outline-offset:2px which sits
@@ -2311,7 +2366,8 @@ function getStyles(options) {
2311
2366
 
2312
2367
  .sv-btn-method:hover:not(:disabled) {
2313
2368
  background: ${tokens.bgSubtle};
2314
- border-color: ${tokens.borderHover};
2369
+ border-color: ${tokens.border};
2370
+ transform: translateY(-2px);
2315
2371
  }
2316
2372
 
2317
2373
  .sv-btn-method:last-child {
@@ -2352,18 +2408,25 @@ function getStyles(options) {
2352
2408
  }
2353
2409
 
2354
2410
  .sv-method-icon {
2355
- width: 20px;
2356
- height: 20px;
2411
+ width: 36px;
2412
+ height: 36px;
2357
2413
  flex-shrink: 0;
2358
2414
  display: flex;
2359
2415
  align-items: center;
2360
2416
  justify-content: center;
2417
+ border-radius: 9px;
2418
+ background: ${tokens.bgSubtle};
2361
2419
  color: ${tokens.textSecondary};
2420
+ transition: background var(--sv-dur-fast) var(--sv-ease-standard);
2421
+ }
2422
+
2423
+ .sv-btn-method:hover:not(:disabled) .sv-method-icon {
2424
+ background: ${tokens.bg};
2362
2425
  }
2363
2426
 
2364
2427
  .sv-method-icon svg {
2365
- width: 20px;
2366
- height: 20px;
2428
+ width: 19px;
2429
+ height: 19px;
2367
2430
  }
2368
2431
 
2369
2432
  .sv-method-text {
@@ -2395,18 +2458,20 @@ function getStyles(options) {
2395
2458
  }
2396
2459
 
2397
2460
  .sv-otp-digit {
2398
- width: 44px;
2399
- height: 52px;
2461
+ width: 46px;
2462
+ height: 56px;
2400
2463
  text-align: center;
2401
- font-size: 20px;
2464
+ font-size: 22px;
2402
2465
  font-weight: 600;
2403
2466
  letter-spacing: 0;
2404
- border: 1px solid ${tokens.border};
2405
- border-radius: 8px;
2467
+ font-variant-numeric: tabular-nums;
2468
+ caret-color: transparent;
2469
+ border: 1px solid ${tokens.borderHover};
2470
+ border-radius: 11px;
2406
2471
  background: ${tokens.bgInput};
2407
2472
  color: ${tokens.textPrimary};
2408
2473
  box-sizing: border-box;
2409
- transition: border-color 0.15s ease, box-shadow 0.15s ease;
2474
+ transition: border-color var(--sv-dur-fast) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard), transform var(--sv-dur-fast) var(--sv-ease-spring);
2410
2475
  }
2411
2476
 
2412
2477
  .sv-otp-digit:hover:not(:focus):not(:disabled) {
@@ -2417,6 +2482,7 @@ function getStyles(options) {
2417
2482
  outline: none;
2418
2483
  border-color: ${tokens.borderFocus};
2419
2484
  box-shadow: 0 0 0 3px ${tokens.primaryLight};
2485
+ transform: translateY(-2px);
2420
2486
  }
2421
2487
 
2422
2488
  .sv-otp-digit:disabled {
@@ -5934,6 +6000,14 @@ class OriginNotAllowedView {
5934
6000
  * Orchestrates view state and rendering for identity verification flows.
5935
6001
  * Uses extracted handlers for OTP and Passkey operations.
5936
6002
  */
6003
+ function progressHook() {
6004
+ if (typeof window === 'undefined')
6005
+ return null;
6006
+ const hook = window.__sparkvaultProgress;
6007
+ return hook && typeof hook.start === 'function' ? hook : null;
6008
+ }
6009
+ function progressStart() { progressHook()?.start(); }
6010
+ function progressDone() { progressHook()?.done(); }
5937
6011
  /**
5938
6012
  * End-user copy for a blocked Identity. Intentionally non-leaky — it never names
5939
6013
  * the trial, billing, usage, or any owner-facing internal. When the site's
@@ -6211,7 +6285,24 @@ class IdentityRenderer {
6211
6285
  const view = this.createViewForState(this.viewState);
6212
6286
  this.currentView = view;
6213
6287
  clearChildren(body);
6214
- body.appendChild(view.render());
6288
+ const rendered = view.render();
6289
+ // Each step enters with a calm fade + rise (see .sv-step-enter). The brand
6290
+ // lockup and footer live outside `body`, so only the flow content moves.
6291
+ if (rendered instanceof HTMLElement) {
6292
+ rendered.classList.add('sv-step-enter');
6293
+ }
6294
+ body.appendChild(rendered);
6295
+ // Drive the top progress bar (owned by login-popup.js as
6296
+ // `window.__sparkvaultProgress`) off the view: a transient `loading` view
6297
+ // means a network step is in flight, so keep the bar trickling; any real
6298
+ // view completes it. The controller is idempotent, so overlapping calls are
6299
+ // safe, and it is a no-op when the hook is absent (any non-popup host).
6300
+ if (this.viewState.view === 'loading') {
6301
+ progressStart();
6302
+ }
6303
+ else {
6304
+ progressDone();
6305
+ }
6215
6306
  // Auto-focus: prefer inputs first, then primary/method buttons (skip back links)
6216
6307
  const focusable = body.querySelector('input:not([disabled]), ' +
6217
6308
  'button.sv-btn-primary:not([disabled]), ' +
@@ -6593,6 +6684,7 @@ class IdentityRenderer {
6593
6684
  if (this.viewState.view !== 'otp-verify')
6594
6685
  return;
6595
6686
  const currentMethod = this.verificationState.otp.method ?? 'email';
6687
+ progressStart();
6596
6688
  const result = await this.otpHandler.verify(code);
6597
6689
  if (result.secondFactor) {
6598
6690
  this.setState({
@@ -7966,17 +8058,14 @@ function attachClickHandler(selector, onClick) {
7966
8058
  /**
7967
8059
  * Identity Module
7968
8060
  *
7969
- * Provides identity verification through dialog or inline UI.
8061
+ * Passwordless sign-in through the first-party SparkVault popup.
7970
8062
  * Supports passkey, OTP, SparkLink, and social authentication.
7971
8063
  *
7972
- * @example Dialog mode (immediate)
7973
- * const result = await sv.products.identity.verify();
8064
+ * @example Programmatic
8065
+ * const result = await sv.products.identity.signIn();
7974
8066
  *
7975
- * @example Dialog mode (attached to clicks)
8067
+ * @example Attached to clicks
7976
8068
  * sv.products.identity.attach('.login-btn');
7977
- *
7978
- * @example Inline mode
7979
- * const result = await sv.products.identity.verify({ target: '#auth-container' });
7980
8069
  */
7981
8070
  const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
7982
8071
  function isTokenClaims(payload) {
@@ -8048,7 +8137,7 @@ class IdentityModule {
8048
8137
  * the browser surfaces a "Continue as …" prompt with no popup, redirect, or
8049
8138
  * typing. Requires a registered `clientId` in the SDK config and a browser
8050
8139
  * with FedCM support — callers should feature-detect with
8051
- * `IdentityModule.isFedcmAvailable()` and fall back to `verify()` otherwise.
8140
+ * `IdentityModule.isFedcmAvailable()` and fall back to `signIn()` otherwise.
8052
8141
  *
8053
8142
  * @returns the verified result, or `null` when the browser has no FedCM
8054
8143
  * support (so the caller can fall back). Throws `UserCancelledError` when the
@@ -8056,8 +8145,8 @@ class IdentityModule {
8056
8145
  *
8057
8146
  * @example
8058
8147
  * const result = (await sv.products.identity.isFedcmAvailable())
8059
- * ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.verify())
8060
- * : await sv.products.identity.verify();
8148
+ * ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.signIn())
8149
+ * : await sv.products.identity.signIn();
8061
8150
  */
8062
8151
  async signInWithFedcm(options = {}) {
8063
8152
  if (!IdentityModule.isFedcmAvailable()) {
@@ -8110,22 +8199,26 @@ class IdentityModule {
8110
8199
  typeof navigator.credentials.get === 'function');
8111
8200
  }
8112
8201
  /**
8113
- * Verify user identity.
8202
+ * Open the SparkVault sign-in popup and resolve with the verified identity.
8114
8203
  *
8115
- * - Without `target`: Opens a dialog (modal)
8116
- * - With `target`: Renders inline into the specified element
8204
+ * This is the single programmatic entry point; `attach()` binds it to element
8205
+ * clicks. There is no inline/in-page mode — sign-in always runs in the
8206
+ * first-party popup on the Identity origin, so login's `__Host-` hub cookie is
8207
+ * a first-party write and cross-domain SSO works.
8117
8208
  *
8118
- * @example Dialog mode
8119
- * const result = await sv.products.identity.verify();
8209
+ * @example
8210
+ * const result = await sv.products.identity.signIn();
8120
8211
  * console.log(result.token, result.identity);
8121
- *
8122
- * @example Inline mode
8123
- * const result = await sv.products.identity.verify({
8124
- * target: '#auth-container',
8125
- * email: 'user@example.com'
8126
- * });
8127
8212
  */
8128
- async verify(options = {}) {
8213
+ async signIn(options = {}) {
8214
+ return this.runFlow(options);
8215
+ }
8216
+ /**
8217
+ * Core flow runner. Dialog mode (no `target`) opens the popup; local mode
8218
+ * (`renderMode: 'local'` / `target`) renders into the current document and
8219
+ * powers the SparkVault-hosted sign-in surfaces (see the internal `render`).
8220
+ */
8221
+ async runFlow(options = {}) {
8129
8222
  const redirectResult = await this.consumeRedirectResult();
8130
8223
  if (redirectResult) {
8131
8224
  options.onSuccess?.(redirectResult);
@@ -8223,7 +8316,7 @@ class IdentityModule {
8223
8316
  const handleClick = async (event) => {
8224
8317
  event.preventDefault();
8225
8318
  try {
8226
- await this.verify({
8319
+ await this.signIn({
8227
8320
  email: options.email,
8228
8321
  phone: options.phone,
8229
8322
  authContext: options.authContext,
@@ -8262,7 +8355,7 @@ class IdentityModule {
8262
8355
  *
8263
8356
  * To trust a token (e.g. before keying records by `claims.svid`), verify the
8264
8357
  * Ed25519 signature server-side against the Identity JWKS endpoint
8265
- * (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
8358
+ * (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
8266
8359
  */
8267
8360
  decodeToken(token) {
8268
8361
  if (!token || typeof token !== 'string') {
@@ -8319,8 +8412,8 @@ class IdentityModule {
8319
8412
  }
8320
8413
  // Once a token is present it must be consumed exactly once: the hash and
8321
8414
  // one-shot OAuth state are cleared whether validation succeeds or fails.
8322
- // A failing token left in the URL would make every subsequent verify()
8323
- // re-consume and re-reject it before the dialog could ever open — login
8415
+ // A failing token left in the URL would make every subsequent signIn()
8416
+ // re-consume and re-reject it before the dialog could ever open, so login
8324
8417
  // would stay wedged until the user manually edited the URL.
8325
8418
  try {
8326
8419
  let expectedState = null;
@@ -8424,22 +8517,15 @@ class IdentityModule {
8424
8517
  // container's own surface and the SparkVault footer.
8425
8518
  return new InlineContainer(element, bare ? { bare: true, showFooter: false } : {});
8426
8519
  }
8427
- // Public-API aliases. The documented method names in the customer-facing
8428
- // SDK README and the API docs are pop() and render(); verify() is the
8429
- // underlying primitive. Both remain canonical entry points.
8430
8520
  /**
8431
- * Open the identity verification modal as a popup. Equivalent to
8432
- * `verify(options)`.
8433
- */
8434
- async pop(options = {}) {
8435
- return this.verify(options);
8436
- }
8437
- /**
8438
- * Render the identity verification UI inline into a target element.
8439
- * Equivalent to `verify({ ...options, target })`.
8521
+ * Render the flow into a page element instead of a popup.
8522
+ *
8523
+ * @internal Used only by the SparkVault-hosted sign-in popup and hosted login
8524
+ * page (which own their chrome and pass `renderMode: 'local'`). Customer
8525
+ * integrations have no inline mode — use `signIn()` / `attach()`.
8440
8526
  */
8441
8527
  async render(options) {
8442
- return this.verify(options);
8528
+ return this.runFlow(options);
8443
8529
  }
8444
8530
  }
8445
8531
 
@@ -12934,7 +13020,7 @@ function autoInit(SparkVaultClass) {
12934
13020
  *
12935
13021
  * const sv = SparkVault.init({ accountId: 'acc_your_account' });
12936
13022
  *
12937
- * const result = await sv.products.identity.verify();
13023
+ * const result = await sv.products.identity.signIn();
12938
13024
  * console.log(result.identity, result.identityType);
12939
13025
  * ```
12940
13026
  */