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