@proveanything/smartlinks 1.14.4 → 1.14.6

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/api/auth.js CHANGED
@@ -1,4 +1,4 @@
1
- import { post, request, setBearerToken, getApiHeaders, hasAuthCredentials, isProxyEnabled } from "../http";
1
+ import { post, request, setBearerToken, getApiHeaders, hasAuthCredentials, isProxyEnabled, invalidateCache } from "../http";
2
2
  import { SmartlinksApiError } from "../types/error";
3
3
  const DEFAULT_AUTH_LOCATION_CACHE_KEY = 'smartlinks.auth.location';
4
4
  const DEFAULT_AUTH_LOCATION_TTL_MS = 30 * 60 * 1000;
@@ -80,6 +80,7 @@ export var auth;
80
80
  async function login(email, password) {
81
81
  const res = await post("/public/auth/login", { email, password });
82
82
  setBearerToken(res.bearerToken);
83
+ invalidateCache();
83
84
  return res;
84
85
  }
85
86
  auth.login = login;
@@ -88,6 +89,7 @@ export var auth;
88
89
  */
89
90
  function logout() {
90
91
  setBearerToken(undefined);
92
+ invalidateCache();
91
93
  }
92
94
  auth.logout = logout;
93
95
  /**
@@ -103,6 +105,7 @@ export var auth;
103
105
  const result = await post("/public/auth/verify", {}, headers);
104
106
  if (token && result.valid) {
105
107
  setBearerToken(token);
108
+ invalidateCache();
106
109
  }
107
110
  return result;
108
111
  }
@@ -131,8 +134,10 @@ export var auth;
131
134
  async function registerUser(user) {
132
135
  // Use the provided token, or the one from getApiHeaders
133
136
  const res = await post("/public/auth/register", user);
134
- if (res.bearerToken)
137
+ if (res.bearerToken) {
135
138
  setBearerToken(res.bearerToken);
139
+ invalidateCache();
140
+ }
136
141
  return res;
137
142
  }
138
143
  auth.registerUser = registerUser;
@@ -1,4 +1,4 @@
1
- import { request, post, put, del, setBearerToken } from "../http";
1
+ import { request, post, put, del, setBearerToken, invalidateCache } from "../http";
2
2
  /**
3
3
  * Namespace containing helper functions for the new AuthKit API.
4
4
  * Legacy collection-based authKit helpers retained (marked as *Legacy*).
@@ -11,8 +11,10 @@ export var authKit;
11
11
  /** Login with email + password (public). */
12
12
  async function login(clientId, email, password) {
13
13
  const res = await post(`/authkit/${encodeURIComponent(clientId)}/auth/login`, { email, password });
14
- if (res.token)
14
+ if (res.token) {
15
15
  setBearerToken(res.token);
16
+ invalidateCache();
17
+ }
16
18
  return res;
17
19
  }
18
20
  authKit.login = login;
@@ -24,16 +26,20 @@ export var authKit;
24
26
  /** Google OAuth login via ID token (public). */
25
27
  async function googleLogin(clientId, idToken) {
26
28
  const res = await post(`/authkit/${encodeURIComponent(clientId)}/auth/google`, { idToken });
27
- if (res.token)
29
+ if (res.token) {
28
30
  setBearerToken(res.token);
31
+ invalidateCache();
32
+ }
29
33
  return res;
30
34
  }
31
35
  authKit.googleLogin = googleLogin;
32
36
  /** Google OAuth login via server-side authorization code (public). */
33
37
  async function googleCodeLogin(clientId, code, redirectUri) {
34
38
  const res = await post(`/authkit/${encodeURIComponent(clientId)}/auth/google-code`, { code, redirectUri });
35
- if (res.token)
39
+ if (res.token) {
36
40
  setBearerToken(res.token);
41
+ invalidateCache();
42
+ }
37
43
  return res;
38
44
  }
39
45
  authKit.googleCodeLogin = googleCodeLogin;
@@ -45,8 +51,10 @@ export var authKit;
45
51
  /** Verify a magic link token and authenticate/create the user (public). */
46
52
  async function verifyMagicLink(clientId, token) {
47
53
  const res = await post(`/authkit/${encodeURIComponent(clientId)}/auth/magic-link/verify`, { token });
48
- if (res.token)
54
+ if (res.token) {
49
55
  setBearerToken(res.token);
56
+ invalidateCache();
57
+ }
50
58
  return res;
51
59
  }
52
60
  authKit.verifyMagicLink = verifyMagicLink;
@@ -59,6 +67,7 @@ export var authKit;
59
67
  async function verifyPhoneCode(clientId, phoneNumber, code) {
60
68
  const res = await post(`/authkit/${encodeURIComponent(clientId)}/auth/phone/verify`, { phoneNumber, code });
61
69
  setBearerToken(res.token);
70
+ invalidateCache();
62
71
  return res;
63
72
  }
64
73
  authKit.verifyPhoneCode = verifyPhoneCode;
@@ -82,6 +91,7 @@ export var authKit;
82
91
  async function exchangeWhatsAppSession(clientId, token, sessionKey) {
83
92
  const res = await post(`/authkit/${encodeURIComponent(clientId)}/auth/whatsapp/exchange-session`, { token, sessionKey });
84
93
  setBearerToken(res.token);
94
+ invalidateCache();
85
95
  return res;
86
96
  }
87
97
  authKit.exchangeWhatsAppSession = exchangeWhatsAppSession;
@@ -143,8 +153,10 @@ export var authKit;
143
153
  /** Update the authenticated user's profile and replace the bearer token when refreshed claims are returned. */
144
154
  async function updateProfile(clientId, data) {
145
155
  const res = await post(`/authkit/${encodeURIComponent(clientId)}/account/update-profile`, data);
146
- if (res.token)
156
+ if (res.token) {
147
157
  setBearerToken(res.token);
158
+ invalidateCache();
159
+ }
148
160
  return res;
149
161
  }
150
162
  authKit.updateProfile = updateProfile;
@@ -158,8 +170,10 @@ export var authKit;
158
170
  authKit.changeEmail = changeEmail;
159
171
  async function verifyEmailChange(clientId, token) {
160
172
  const res = await post(`/authkit/${encodeURIComponent(clientId)}/account/verify-email-change`, { token });
161
- if (res.token)
173
+ if (res.token) {
162
174
  setBearerToken(res.token);
175
+ invalidateCache();
176
+ }
163
177
  return res;
164
178
  }
165
179
  authKit.verifyEmailChange = verifyEmailChange;
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.14.4 | Generated: 2026-05-16T11:56:46.429Z
3
+ Version: 1.14.6 | Generated: 2026-05-16T13:22:01.199Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -150,9 +150,9 @@ Return whether proxy mode is currently enabled.
150
150
  iframeAutoResize?: boolean // default true when in iframe
151
151
  logger?: Logger // optional console-like or function to enable verbose logging
152
152
  /**
153
- * When true, bypasses the idempotency guard and forces a full re-initialization.
154
- * Use only when you intentionally need to reset all SDK state (e.g. in tests or
155
- * when switching accounts) → `void`
153
+ * When true, the bearer token is automatically saved to localStorage after login
154
+ * and restored on the next page load. Eliminates the need to manually persist
155
+ * the token across refreshes. Clear it by calling setBearerToken(undefined) → `void`
156
156
  Call this once (e.g. at app startup) to configure baseURL/auth.
157
157
 
158
158
  **setNgrokSkipBrowserWarning**(flag: boolean) → `void`
package/dist/http.d.ts CHANGED
@@ -16,6 +16,12 @@ export declare function initializeApi(options: {
16
16
  extraHeaders?: Record<string, string>;
17
17
  iframeAutoResize?: boolean;
18
18
  logger?: Logger;
19
+ /**
20
+ * When true, the bearer token is automatically saved to localStorage after login
21
+ * and restored on the next page load. Eliminates the need to manually persist
22
+ * the token across refreshes. Clear it by calling setBearerToken(undefined) or logout().
23
+ */
24
+ persistToken?: boolean;
19
25
  /**
20
26
  * When true, bypasses the idempotency guard and forces a full re-initialization.
21
27
  * Use only when you intentionally need to reset all SDK state (e.g. in tests or
package/dist/http.js CHANGED
@@ -48,13 +48,16 @@ function getSourceDomain() {
48
48
  const httpCache = new Map();
49
49
  let cacheEnabled = true;
50
50
  /** Default TTL used when no per-resource rule matches (milliseconds). */
51
- let cacheDefaultTtlMs = 60000; // 60 seconds
51
+ let cacheDefaultTtlMs = 15000; // 15 seconds
52
52
  /** Maximum number of entries before the oldest (LRU) entry is evicted. */
53
53
  let cacheMaxEntries = 200;
54
54
  /** Persistence backend for the L2 cache. 'none' (default) disables IndexedDB persistence. */
55
55
  let cachePersistence = 'none';
56
56
  /** When true (default), clear in-memory and sessionStorage caches on page load/refresh. */
57
57
  let cacheClearOnPageLoad = true;
58
+ /** When true, the bearer token is saved to localStorage and restored automatically on init. */
59
+ let tokenPersistenceEnabled = true;
60
+ const TOKEN_STORAGE_KEY = 'sl:token';
58
61
  /**
59
62
  * How long L2 (IndexedDB) entries are considered valid as an offline stale fallback,
60
63
  * measured from the original network fetch time (default: 7 days).
@@ -137,6 +140,11 @@ function clearSessionCachesOnPageLoad() {
137
140
  // Auto-clear session caches on page load (browser only)
138
141
  if (typeof window !== 'undefined' && cacheClearOnPageLoad) {
139
142
  clearSessionCachesOnPageLoad();
143
+ // Also clear on bfcache restoration (mobile browsers restore JS context without reloading)
144
+ window.addEventListener('pageshow', (e) => {
145
+ if (e.persisted)
146
+ clearSessionCachesOnPageLoad();
147
+ });
140
148
  }
141
149
  /**
142
150
  * Return cached data for a key if it exists and is within TTL.
@@ -339,6 +347,7 @@ function normalizeErrorResponse(responseBody, statusCode) {
339
347
  */
340
348
  import { iframe } from './iframe';
341
349
  export function initializeApi(options) {
350
+ var _a;
342
351
  // Normalize baseURL by removing trailing slashes.
343
352
  const normalizedBaseURL = options.baseURL.replace(/\/+$/g, "");
344
353
  // ------------------------------------------------------------------
@@ -355,6 +364,9 @@ export function initializeApi(options) {
355
364
  }
356
365
  baseURL = normalizedBaseURL;
357
366
  apiKey = options.apiKey;
367
+ // Enable token persistence before restoring the token.
368
+ if (options.persistToken !== undefined)
369
+ tokenPersistenceEnabled = options.persistToken;
358
370
  // Only overwrite bearerToken when the caller explicitly supplies one,
359
371
  // OR when this is the very first initialization (start with a clean slate).
360
372
  // Re-initialization calls that omit bearerToken must NOT clear a token that
@@ -363,7 +375,13 @@ export function initializeApi(options) {
363
375
  bearerToken = options.bearerToken;
364
376
  }
365
377
  else if (!initialized) {
366
- bearerToken = undefined;
378
+ // On first init with no explicit token, restore from localStorage if persistence is on.
379
+ if (tokenPersistenceEnabled && typeof localStorage !== 'undefined') {
380
+ bearerToken = (_a = localStorage.getItem(TOKEN_STORAGE_KEY)) !== null && _a !== void 0 ? _a : undefined;
381
+ }
382
+ else {
383
+ bearerToken = undefined;
384
+ }
367
385
  }
368
386
  // else: preserve the existing runtime bearerToken.
369
387
  proxyMode = !!options.proxyMode;
@@ -413,6 +431,21 @@ export function setBearerToken(token) {
413
431
  if (token === bearerToken)
414
432
  return;
415
433
  bearerToken = token;
434
+ // Persist or clear from localStorage when token persistence is enabled.
435
+ if (tokenPersistenceEnabled && typeof localStorage !== 'undefined') {
436
+ if (token) {
437
+ try {
438
+ localStorage.setItem(TOKEN_STORAGE_KEY, token);
439
+ }
440
+ catch (_a) { }
441
+ }
442
+ else {
443
+ try {
444
+ localStorage.removeItem(TOKEN_STORAGE_KEY);
445
+ }
446
+ catch (_b) { }
447
+ }
448
+ }
416
449
  httpCache.clear();
417
450
  if (cachePersistence !== 'none')
418
451
  idbClear().catch(() => { });
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.14.4 | Generated: 2026-05-16T11:56:46.429Z
3
+ Version: 1.14.6 | Generated: 2026-05-16T13:22:01.199Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -150,9 +150,9 @@ Return whether proxy mode is currently enabled.
150
150
  iframeAutoResize?: boolean // default true when in iframe
151
151
  logger?: Logger // optional console-like or function to enable verbose logging
152
152
  /**
153
- * When true, bypasses the idempotency guard and forces a full re-initialization.
154
- * Use only when you intentionally need to reset all SDK state (e.g. in tests or
155
- * when switching accounts) → `void`
153
+ * When true, the bearer token is automatically saved to localStorage after login
154
+ * and restored on the next page load. Eliminates the need to manually persist
155
+ * the token across refreshes. Clear it by calling setBearerToken(undefined) → `void`
156
156
  Call this once (e.g. at app startup) to configure baseURL/auth.
157
157
 
158
158
  **setNgrokSkipBrowserWarning**(flag: boolean) → `void`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.14.4",
3
+ "version": "1.14.6",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",