@proveanything/smartlinks 1.14.5 → 1.14.7
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/docs/API_SUMMARY.md +4 -4
- package/dist/http.d.ts +6 -0
- package/dist/http.js +35 -2
- package/docs/API_SUMMARY.md +4 -4
- package/package.json +1 -1
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.14.
|
|
3
|
+
Version: 1.14.7 | Generated: 2026-05-16T13:30:13.413Z
|
|
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,
|
|
154
|
-
*
|
|
155
|
-
*
|
|
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 =
|
|
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 = false;
|
|
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
|
-
|
|
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(() => { });
|
package/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.14.
|
|
3
|
+
Version: 1.14.7 | Generated: 2026-05-16T13:30:13.413Z
|
|
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,
|
|
154
|
-
*
|
|
155
|
-
*
|
|
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`
|