@proveanything/smartlinks 1.3.8 → 1.3.9

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.
@@ -0,0 +1,32 @@
1
+ export interface CacheOptions {
2
+ /** TTL in milliseconds (default: 5 minutes) */
3
+ ttl?: number;
4
+ /** Storage backend */
5
+ storage?: 'memory' | 'session' | 'local';
6
+ }
7
+ /**
8
+ * Get cached value or fetch fresh.
9
+ *
10
+ * @param key - Cache key
11
+ * @param fetcher - Async function to fetch fresh data
12
+ * @param options - Cache options
13
+ * @returns Cached or fresh value
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const apps = await cache.getOrFetch(
18
+ * `apps:${collectionId}`,
19
+ * () => collection.getApps(collectionId),
20
+ * { ttl: 5 * 60 * 1000, storage: 'session' }
21
+ * );
22
+ * ```
23
+ */
24
+ export declare function getOrFetch<T>(key: string, fetcher: () => Promise<T>, options?: CacheOptions): Promise<T>;
25
+ /**
26
+ * Invalidate a cached key.
27
+ */
28
+ export declare function invalidate(key: string): void;
29
+ /**
30
+ * Clear all cached data.
31
+ */
32
+ export declare function clear(): void;
package/dist/cache.js ADDED
@@ -0,0 +1,125 @@
1
+ // =============================================================================
2
+ // Cache Utilities - TTL-based caching for browser and Node environments
3
+ // =============================================================================
4
+ // In-memory cache store
5
+ const memoryCache = new Map();
6
+ /**
7
+ * Get cached value or fetch fresh.
8
+ *
9
+ * @param key - Cache key
10
+ * @param fetcher - Async function to fetch fresh data
11
+ * @param options - Cache options
12
+ * @returns Cached or fresh value
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const apps = await cache.getOrFetch(
17
+ * `apps:${collectionId}`,
18
+ * () => collection.getApps(collectionId),
19
+ * { ttl: 5 * 60 * 1000, storage: 'session' }
20
+ * );
21
+ * ```
22
+ */
23
+ export async function getOrFetch(key, fetcher, options = {}) {
24
+ const { ttl = 5 * 60 * 1000, storage = 'memory' } = options;
25
+ const now = Date.now();
26
+ // Try to get from cache
27
+ const cached = getFromStorage(key, storage);
28
+ if (cached && cached.expiresAt > now) {
29
+ return cached.value;
30
+ }
31
+ // Fetch fresh data
32
+ const value = await fetcher();
33
+ // Store in cache
34
+ const entry = {
35
+ value,
36
+ expiresAt: now + ttl,
37
+ };
38
+ setToStorage(key, entry, storage);
39
+ return value;
40
+ }
41
+ /**
42
+ * Invalidate a cached key.
43
+ */
44
+ export function invalidate(key) {
45
+ // Remove from all storage backends
46
+ memoryCache.delete(key);
47
+ try {
48
+ if (typeof sessionStorage !== 'undefined') {
49
+ sessionStorage.removeItem(`smartlinks:cache:${key}`);
50
+ }
51
+ if (typeof localStorage !== 'undefined') {
52
+ localStorage.removeItem(`smartlinks:cache:${key}`);
53
+ }
54
+ }
55
+ catch (_a) {
56
+ // Storage may not be available
57
+ }
58
+ }
59
+ /**
60
+ * Clear all cached data.
61
+ */
62
+ export function clear() {
63
+ memoryCache.clear();
64
+ try {
65
+ if (typeof sessionStorage !== 'undefined') {
66
+ // Clear only smartlinks cache keys
67
+ const sessionKeys = Object.keys(sessionStorage).filter(k => k.startsWith('smartlinks:cache:'));
68
+ sessionKeys.forEach(k => sessionStorage.removeItem(k));
69
+ }
70
+ if (typeof localStorage !== 'undefined') {
71
+ const localKeys = Object.keys(localStorage).filter(k => k.startsWith('smartlinks:cache:'));
72
+ localKeys.forEach(k => localStorage.removeItem(k));
73
+ }
74
+ }
75
+ catch (_a) {
76
+ // Storage may not be available
77
+ }
78
+ }
79
+ // =============================================================================
80
+ // Internal Helpers
81
+ // =============================================================================
82
+ function getFromStorage(key, storage) {
83
+ try {
84
+ if (storage === 'memory') {
85
+ return memoryCache.get(key) || null;
86
+ }
87
+ const storageKey = `smartlinks:cache:${key}`;
88
+ let stored = null;
89
+ if (storage === 'session' && typeof sessionStorage !== 'undefined') {
90
+ stored = sessionStorage.getItem(storageKey);
91
+ }
92
+ else if (storage === 'local' && typeof localStorage !== 'undefined') {
93
+ stored = localStorage.getItem(storageKey);
94
+ }
95
+ if (stored) {
96
+ return JSON.parse(stored);
97
+ }
98
+ }
99
+ catch (_a) {
100
+ // Storage errors - return null
101
+ }
102
+ return null;
103
+ }
104
+ function setToStorage(key, entry, storage) {
105
+ try {
106
+ if (storage === 'memory') {
107
+ memoryCache.set(key, entry);
108
+ return;
109
+ }
110
+ const storageKey = `smartlinks:cache:${key}`;
111
+ const serialized = JSON.stringify(entry);
112
+ if (storage === 'session' && typeof sessionStorage !== 'undefined') {
113
+ sessionStorage.setItem(storageKey, serialized);
114
+ }
115
+ else if (storage === 'local' && typeof localStorage !== 'undefined') {
116
+ localStorage.setItem(storageKey, serialized);
117
+ }
118
+ // Also keep in memory for faster access
119
+ memoryCache.set(key, entry);
120
+ }
121
+ catch (_a) {
122
+ // Storage quota exceeded or not available - keep in memory only
123
+ memoryCache.set(key, entry);
124
+ }
125
+ }
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.3.8 | Generated: 2026-02-05T19:14:34.871Z
3
+ Version: 1.3.9 | Generated: 2026-02-05T20:01:56.914Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -1489,6 +1489,165 @@ interface ErrorResponse {
1489
1489
  }
1490
1490
  ```
1491
1491
 
1492
+ ### iframeResponder
1493
+
1494
+ **CachedData** (interface)
1495
+ ```typescript
1496
+ interface CachedData {
1497
+ collection?: Record<string, any>;
1498
+ product?: Record<string, any>;
1499
+ proof?: Record<string, any>;
1500
+ user?: {
1501
+ uid: string;
1502
+ email?: string;
1503
+ displayName?: string;
1504
+ accountData?: Record<string, any>;
1505
+ } | null;
1506
+ apps?: AppConfig[];
1507
+ }
1508
+ ```
1509
+
1510
+ **IframeResponderOptions** (interface)
1511
+ ```typescript
1512
+ interface IframeResponderOptions {
1513
+ collectionId: string;
1514
+ appId: string;
1515
+ productId?: string;
1516
+ proofId?: string;
1517
+ version?: string;
1518
+ appUrl?: string;
1519
+ initialPath?: string;
1520
+ isAdmin?: boolean;
1521
+ cache?: CachedData;
1522
+ onAuthLogin?: (
1523
+ token: string,
1524
+ user: any,
1525
+ accountData?: Record<string, any>
1526
+ ) => Promise<void>;
1527
+ onAuthLogout?: () => Promise<void>;
1528
+ onRouteChange?: (path: string, state: Record<string, string>) => void;
1529
+ onResize?: (height: number) => void;
1530
+ onError?: (error: Error) => void;
1531
+ onReady?: () => void;
1532
+ }
1533
+ ```
1534
+
1535
+ **RouteChangeMessage** (interface)
1536
+ ```typescript
1537
+ interface RouteChangeMessage {
1538
+ type: 'smartlinks-route-change';
1539
+ path: string;
1540
+ context: Record<string, string>;
1541
+ state: Record<string, string>;
1542
+ appId?: string;
1543
+ }
1544
+ ```
1545
+
1546
+ **SmartlinksIframeMessage** (interface)
1547
+ ```typescript
1548
+ interface SmartlinksIframeMessage {
1549
+ _smartlinksIframeMessage: true;
1550
+ type:
1551
+ | 'smartlinks:resize'
1552
+ | 'smartlinks:redirect'
1553
+ | 'smartlinks:authkit:login'
1554
+ | 'smartlinks:authkit:logout'
1555
+ | 'smartlinks:authkit:redirect';
1556
+ payload: Record<string, any>;
1557
+ messageId?: string;
1558
+ }
1559
+ ```
1560
+
1561
+ **ProxyRequest** (interface)
1562
+ ```typescript
1563
+ interface ProxyRequest {
1564
+ _smartlinksProxyRequest: true;
1565
+ id: string;
1566
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
1567
+ path: string;
1568
+ body?: any;
1569
+ headers?: Record<string, string>;
1570
+ }
1571
+ ```
1572
+
1573
+ **CustomProxyRequest** (interface)
1574
+ ```typescript
1575
+ interface CustomProxyRequest {
1576
+ _smartlinksProxyRequest: true;
1577
+ _smartlinksCustomProxyRequest: true;
1578
+ id: string;
1579
+ request: 'REDIRECT' | string;
1580
+ params: Record<string, any>;
1581
+ }
1582
+ ```
1583
+
1584
+ **ProxyResponse** (interface)
1585
+ ```typescript
1586
+ interface ProxyResponse {
1587
+ _smartlinksProxyResponse: true;
1588
+ id: string;
1589
+ data?: any;
1590
+ error?: string;
1591
+ }
1592
+ ```
1593
+
1594
+ **UploadStartMessage** (interface)
1595
+ ```typescript
1596
+ interface UploadStartMessage {
1597
+ _smartlinksProxyUpload: true;
1598
+ phase: 'start';
1599
+ id: string;
1600
+ fields: [string, string][];
1601
+ fileInfo: { type?: string; name?: string; key?: string };
1602
+ path: string;
1603
+ headers?: Record<string, string>;
1604
+ }
1605
+ ```
1606
+
1607
+ **UploadChunkMessage** (interface)
1608
+ ```typescript
1609
+ interface UploadChunkMessage {
1610
+ _smartlinksProxyUpload: true;
1611
+ phase: 'chunk';
1612
+ id: string;
1613
+ seq: number;
1614
+ chunk: ArrayBuffer;
1615
+ }
1616
+ ```
1617
+
1618
+ **UploadEndMessage** (interface)
1619
+ ```typescript
1620
+ interface UploadEndMessage {
1621
+ _smartlinksProxyUpload: true;
1622
+ phase: 'end';
1623
+ id: string;
1624
+ }
1625
+ ```
1626
+
1627
+ **UploadAckMessage** (interface)
1628
+ ```typescript
1629
+ interface UploadAckMessage {
1630
+ _smartlinksProxyUpload: true;
1631
+ phase: 'ack';
1632
+ id: string;
1633
+ seq: number;
1634
+ }
1635
+ ```
1636
+
1637
+ **UploadDoneMessage** (interface)
1638
+ ```typescript
1639
+ interface UploadDoneMessage {
1640
+ _smartlinksProxyUpload: true;
1641
+ phase: 'done';
1642
+ id: string;
1643
+ ok: boolean;
1644
+ data?: any;
1645
+ error?: string;
1646
+ }
1647
+ ```
1648
+
1649
+ **UploadMessage** = ``
1650
+
1492
1651
  ### interaction
1493
1652
 
1494
1653
  **AdminInteractionsQueryRequest** (interface)