@revealui/cache 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 RevealUI Studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,111 @@
1
+ RevealUI Commercial License
2
+ Version 1.0, February 2026
3
+
4
+ Copyright (c) 2025-2026 RevealUI Studio (founder@revealui.com)
5
+
6
+ TERMS AND CONDITIONS
7
+
8
+ 1. DEFINITIONS
9
+
10
+ "Software" means the RevealUI source code, documentation, and associated
11
+ files contained in directories and packages designated as commercial,
12
+ including but not limited to: packages/ai, packages/harnesses, and any
13
+ directory named "ee" within the repository.
14
+
15
+ "License Key" means a valid RevealUI license key obtained through an active
16
+ paid subscription at https://revealui.com.
17
+
18
+ "Licensee" means the individual or organization that holds a valid License
19
+ Key through an active subscription.
20
+
21
+ "Production Use" means any use of the Software beyond local development and
22
+ evaluation, including but not limited to: deploying the Software to serve
23
+ end users, integrating the Software into a product or service, or using the
24
+ Software in a revenue-generating capacity.
25
+
26
+ 2. GRANT OF RIGHTS
27
+
28
+ Subject to the terms of this License and a valid License Key, the Licensee
29
+ is granted a non-exclusive, non-transferable, revocable license to:
30
+
31
+ (a) Use the Software for internal development and Production Use.
32
+ (b) Modify the Software for internal use.
33
+ (c) Deploy the Software on infrastructure controlled by the Licensee.
34
+
35
+ Enterprise License holders are additionally granted the right to:
36
+
37
+ (d) Deploy the Software in a self-hosted environment.
38
+ (e) Remove or replace RevealUI branding (white-label).
39
+ (f) Use the Software for multiple tenants within the Licensee's
40
+ organization or customer base.
41
+
42
+ 3. RESTRICTIONS
43
+
44
+ The Licensee SHALL NOT:
45
+
46
+ (a) Provide the Software, or any portion of it, to third parties as a
47
+ hosted or managed service that competes with RevealUI.
48
+ (b) Redistribute, sublicense, sell, or otherwise transfer the Software
49
+ or any portion of it to third parties.
50
+ (c) Remove, alter, or circumvent the license key verification
51
+ functionality of the Software.
52
+ (d) Use the Software in Production without a valid License Key.
53
+ (e) Share, publish, or make the License Key available to unauthorized
54
+ parties.
55
+
56
+ 4. EVALUATION
57
+
58
+ The Software may be used for evaluation and local development purposes
59
+ without a License Key. Evaluation use does not grant any rights to
60
+ Production Use.
61
+
62
+ 5. SUBSCRIPTION AND PAYMENT
63
+
64
+ This License is valid only during the term of an active paid subscription.
65
+ Upon cancellation or expiration of the subscription:
66
+
67
+ (a) The License terminates automatically.
68
+ (b) A grace period of fourteen (14) days is provided for the Licensee
69
+ to transition away from Production Use.
70
+ (c) After the grace period, the Licensee must cease all Production Use
71
+ of the Software.
72
+
73
+ 6. INTELLECTUAL PROPERTY
74
+
75
+ The Software is and remains the intellectual property of RevealUI Studio.
76
+ This License does not grant any ownership rights. Contributions to
77
+ commercial portions of the Software require a Contributor License Agreement.
78
+
79
+ 7. OPEN SOURCE COMPONENTS
80
+
81
+ This License applies only to files and directories designated as commercial.
82
+ Files under the MIT License (as indicated in the root LICENSE file) are not
83
+ subject to this commercial license and may be used freely under MIT terms.
84
+
85
+ 8. DISCLAIMER OF WARRANTY
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
89
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
90
+
91
+ 9. LIMITATION OF LIABILITY
92
+
93
+ IN NO EVENT SHALL REVEALUI STUDIO BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
94
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
95
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
96
+ DEALINGS IN THE SOFTWARE, EXCEEDING THE AMOUNT PAID BY THE LICENSEE IN
97
+ THE TWELVE (12) MONTHS PRECEDING THE CLAIM.
98
+
99
+ 10. GOVERNING LAW
100
+
101
+ This License shall be governed by the laws of the State of California,
102
+ United States of America, without regard to its conflict of law provisions.
103
+
104
+ 11. ENTIRE AGREEMENT
105
+
106
+ This License constitutes the entire agreement between the parties with
107
+ respect to the commercial portions of the Software and supersedes all
108
+ prior agreements, understandings, and communications.
109
+
110
+ For licensing inquiries: founder@revealui.com
111
+ For pricing and subscriptions: https://revealui.com/pricing
@@ -0,0 +1,366 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+
3
+ /**
4
+ * CDN Configuration and Cache Management
5
+ *
6
+ * Utilities for CDN caching, edge caching, and cache invalidation
7
+ */
8
+ /**
9
+ * CDN Cache Configuration
10
+ */
11
+ interface CDNCacheConfig {
12
+ provider?: 'cloudflare' | 'vercel' | 'fastly' | 'custom';
13
+ zones?: string[];
14
+ ttl?: number;
15
+ staleWhileRevalidate?: number;
16
+ staleIfError?: number;
17
+ bypassCache?: boolean;
18
+ cacheKey?: string[];
19
+ varyHeaders?: string[];
20
+ }
21
+ declare const DEFAULT_CDN_CONFIG: CDNCacheConfig;
22
+ /**
23
+ * Generate Cache-Control header
24
+ */
25
+ declare function generateCacheControl(config: {
26
+ maxAge?: number;
27
+ sMaxAge?: number;
28
+ staleWhileRevalidate?: number;
29
+ staleIfError?: number;
30
+ public?: boolean;
31
+ private?: boolean;
32
+ immutable?: boolean;
33
+ noCache?: boolean;
34
+ noStore?: boolean;
35
+ }): string;
36
+ /**
37
+ * Cache presets for different asset types
38
+ */
39
+ declare const CDN_CACHE_PRESETS: {
40
+ readonly immutable: {
41
+ readonly maxAge: 31536000;
42
+ readonly sMaxAge: 31536000;
43
+ readonly public: true;
44
+ readonly immutable: true;
45
+ };
46
+ readonly static: {
47
+ readonly maxAge: 2592000;
48
+ readonly sMaxAge: 31536000;
49
+ readonly staleWhileRevalidate: 86400;
50
+ readonly public: true;
51
+ };
52
+ readonly api: {
53
+ readonly maxAge: 0;
54
+ readonly sMaxAge: 60;
55
+ readonly staleWhileRevalidate: 30;
56
+ readonly public: true;
57
+ };
58
+ readonly page: {
59
+ readonly maxAge: 0;
60
+ readonly sMaxAge: 300;
61
+ readonly staleWhileRevalidate: 60;
62
+ readonly public: true;
63
+ };
64
+ readonly private: {
65
+ readonly maxAge: 300;
66
+ readonly private: true;
67
+ readonly staleWhileRevalidate: 60;
68
+ };
69
+ readonly noCache: {
70
+ readonly noStore: true;
71
+ };
72
+ readonly revalidate: {
73
+ readonly maxAge: 0;
74
+ readonly sMaxAge: 0;
75
+ readonly noCache: true;
76
+ };
77
+ };
78
+ /**
79
+ * CDN Purge Configuration
80
+ */
81
+ interface CDNPurgeConfig {
82
+ provider: 'cloudflare' | 'vercel' | 'fastly';
83
+ apiKey?: string;
84
+ apiSecret?: string;
85
+ zoneId?: string;
86
+ distributionId?: string;
87
+ }
88
+ /**
89
+ * Purge CDN cache
90
+ */
91
+ declare function purgeCDNCache(urls: string[], config: CDNPurgeConfig): Promise<{
92
+ success: boolean;
93
+ purged: number;
94
+ errors?: string[];
95
+ }>;
96
+ /**
97
+ * Purge by cache tag
98
+ */
99
+ declare function purgeCacheByTag(tags: string[], config: CDNPurgeConfig): Promise<{
100
+ success: boolean;
101
+ purged: number;
102
+ errors?: string[];
103
+ }>;
104
+ /**
105
+ * Purge everything
106
+ */
107
+ declare function purgeAllCache(config: CDNPurgeConfig): Promise<{
108
+ success: boolean;
109
+ errors?: string[];
110
+ }>;
111
+ /**
112
+ * CDN cache warming
113
+ */
114
+ declare function warmCDNCache(urls: string[], options?: {
115
+ concurrency?: number;
116
+ headers?: Record<string, string>;
117
+ }): Promise<{
118
+ warmed: number;
119
+ failed: number;
120
+ errors: string[];
121
+ }>;
122
+ /**
123
+ * Generate cache tags
124
+ */
125
+ declare function generateCacheTags(resource: {
126
+ type: string;
127
+ id?: string | number;
128
+ related?: string[];
129
+ }): string[];
130
+ /**
131
+ * Edge cache configuration for Vercel
132
+ */
133
+ declare function generateVercelCacheConfig(preset: keyof typeof CDN_CACHE_PRESETS): {
134
+ headers: {
135
+ 'Cache-Control': string;
136
+ 'CDN-Cache-Control': string;
137
+ 'Vercel-CDN-Cache-Control': string;
138
+ };
139
+ };
140
+ /**
141
+ * Edge cache configuration for Cloudflare
142
+ */
143
+ declare function generateCloudflareConfig(preset: keyof typeof CDN_CACHE_PRESETS, options?: {
144
+ cacheTags?: string[];
145
+ bypassOnCookie?: string;
146
+ }): {
147
+ headers: Record<string, string>;
148
+ };
149
+ /**
150
+ * Check if response should be cached
151
+ */
152
+ declare function shouldCacheResponse(status: number, headers: Headers): boolean;
153
+ /**
154
+ * Calculate cache TTL from headers
155
+ */
156
+ declare function getCacheTTL(headers: Headers): number;
157
+
158
+ /**
159
+ * Edge Caching and ISR (Incremental Static Regeneration)
160
+ *
161
+ * Utilities for Next.js edge caching, ISR, and on-demand revalidation
162
+ */
163
+
164
+ /**
165
+ * Next.js extends the standard RequestInit with a `next` property
166
+ * for ISR revalidation and cache tags.
167
+ */
168
+ interface NextFetchRequestInit extends RequestInit {
169
+ next?: {
170
+ revalidate?: number | false;
171
+ tags?: string[];
172
+ };
173
+ }
174
+ /**
175
+ * ISR Configuration
176
+ */
177
+ interface ISRConfig {
178
+ revalidate?: number | false;
179
+ tags?: string[];
180
+ dynamicParams?: boolean;
181
+ }
182
+ declare const ISR_PRESETS: {
183
+ readonly always: {
184
+ readonly revalidate: 0;
185
+ };
186
+ readonly minute: {
187
+ readonly revalidate: 60;
188
+ };
189
+ readonly fiveMinutes: {
190
+ readonly revalidate: 300;
191
+ };
192
+ readonly hourly: {
193
+ readonly revalidate: 3600;
194
+ };
195
+ readonly daily: {
196
+ readonly revalidate: 86400;
197
+ };
198
+ readonly never: {
199
+ readonly revalidate: false;
200
+ };
201
+ };
202
+ /**
203
+ * Generate static params for ISR
204
+ */
205
+ declare function generateStaticParams<T>(fetchFn: () => Promise<T[]>, mapFn: (item: T) => Record<string, string>): Promise<Array<Record<string, string>>>;
206
+ /**
207
+ * Revalidate tag
208
+ */
209
+ declare function revalidateTag(tag: string, secret?: string): Promise<{
210
+ revalidated: boolean;
211
+ error?: string;
212
+ }>;
213
+ /**
214
+ * Revalidate path
215
+ */
216
+ declare function revalidatePath(path: string, secret?: string): Promise<{
217
+ revalidated: boolean;
218
+ error?: string;
219
+ }>;
220
+ /**
221
+ * Revalidate multiple paths
222
+ */
223
+ declare function revalidatePaths(paths: string[], secret?: string): Promise<{
224
+ revalidated: number;
225
+ failed: number;
226
+ errors: Array<{
227
+ path: string;
228
+ error: string;
229
+ }>;
230
+ }>;
231
+ /**
232
+ * Revalidate multiple tags
233
+ */
234
+ declare function revalidateTags(tags: string[], secret?: string): Promise<{
235
+ revalidated: number;
236
+ failed: number;
237
+ errors: Array<{
238
+ tag: string;
239
+ error: string;
240
+ }>;
241
+ }>;
242
+ /**
243
+ * Edge middleware cache configuration
244
+ */
245
+ interface EdgeCacheConfig {
246
+ cache?: 'force-cache' | 'no-cache' | 'no-store' | 'only-if-cached';
247
+ next?: {
248
+ revalidate?: number | false;
249
+ tags?: string[];
250
+ };
251
+ }
252
+ /**
253
+ * Create edge cached fetch
254
+ */
255
+ declare function createEdgeCachedFetch(config?: EdgeCacheConfig): <T>(url: string, options?: NextFetchRequestInit) => Promise<T>;
256
+ /**
257
+ * Unstable cache wrapper (Next.js 14+)
258
+ */
259
+ declare function createCachedFunction<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => Promise<TReturn>, options?: {
260
+ tags?: string[];
261
+ revalidate?: number | false;
262
+ }): (...args: TArgs) => Promise<TReturn>;
263
+ /**
264
+ * Edge rate limiting with cache
265
+ */
266
+ interface EdgeRateLimitConfig {
267
+ limit: number;
268
+ window: number;
269
+ key?: (request: NextRequest) => string;
270
+ }
271
+ declare class EdgeRateLimiter {
272
+ private config;
273
+ private cache;
274
+ constructor(config: EdgeRateLimitConfig);
275
+ /**
276
+ * Check rate limit
277
+ */
278
+ check(request: NextRequest): {
279
+ allowed: boolean;
280
+ limit: number;
281
+ remaining: number;
282
+ reset: number;
283
+ };
284
+ /**
285
+ * Clean up expired entries
286
+ */
287
+ cleanup(): void;
288
+ }
289
+ /**
290
+ * Edge geolocation caching
291
+ */
292
+ interface GeoLocation {
293
+ country?: string;
294
+ region?: string;
295
+ city?: string;
296
+ latitude?: number;
297
+ longitude?: number;
298
+ }
299
+ declare function getGeoLocation(request: NextRequest): GeoLocation | null;
300
+ /**
301
+ * Edge A/B testing with cache
302
+ */
303
+ declare function getABTestVariant(request: NextRequest, testName: string, variants: string[]): string;
304
+ /**
305
+ * Edge personalization cache
306
+ */
307
+ interface PersonalizationConfig {
308
+ userId?: string;
309
+ preferences?: Record<string, unknown>;
310
+ location?: GeoLocation;
311
+ device?: 'mobile' | 'tablet' | 'desktop';
312
+ variant?: string;
313
+ }
314
+ declare function getPersonalizationConfig(request: NextRequest): PersonalizationConfig;
315
+ /**
316
+ * Edge cache headers helper
317
+ */
318
+ declare function setEdgeCacheHeaders(response: NextResponse, config: {
319
+ maxAge?: number;
320
+ sMaxAge?: number;
321
+ staleWhileRevalidate?: number;
322
+ tags?: string[];
323
+ }): NextResponse;
324
+ /**
325
+ * Preload links for critical resources
326
+ */
327
+ declare function addPreloadLinks(response: NextResponse, resources: Array<{
328
+ href: string;
329
+ as: string;
330
+ type?: string;
331
+ crossorigin?: boolean;
332
+ }>): NextResponse;
333
+ /**
334
+ * Cache warming for ISR pages
335
+ */
336
+ declare function warmISRCache(paths: string[], baseURL?: string): Promise<{
337
+ warmed: number;
338
+ failed: number;
339
+ errors: Array<{
340
+ path: string;
341
+ error: string;
342
+ }>;
343
+ }>;
344
+
345
+ /**
346
+ * Internal logger for @revealui/cache.
347
+ *
348
+ * Defaults to `console`. Consumers should call `configureCacheLogger()`
349
+ * to supply a structured logger (e.g. from `@revealui/utils/logger`).
350
+ */
351
+ interface CacheLogger {
352
+ warn(message: string, ...args: unknown[]): void;
353
+ error(message: string, ...args: unknown[]): void;
354
+ info(message: string, ...args: unknown[]): void;
355
+ debug(message: string, ...args: unknown[]): void;
356
+ }
357
+ /**
358
+ * Replace the default console logger with a structured logger.
359
+ */
360
+ declare function configureCacheLogger(logger: CacheLogger): void;
361
+ /**
362
+ * Get the current cache logger instance.
363
+ */
364
+ declare function getCacheLogger(): CacheLogger;
365
+
366
+ export { type CDNCacheConfig, type CDNPurgeConfig, CDN_CACHE_PRESETS, type CacheLogger, DEFAULT_CDN_CONFIG, type EdgeCacheConfig, type EdgeRateLimitConfig, EdgeRateLimiter, type GeoLocation, type ISRConfig, ISR_PRESETS, type PersonalizationConfig, addPreloadLinks, configureCacheLogger, createCachedFunction, createEdgeCachedFetch, generateCacheControl, generateCacheTags, generateCloudflareConfig, generateStaticParams, generateVercelCacheConfig, getABTestVariant, getCacheLogger, getCacheTTL, getGeoLocation, getPersonalizationConfig, purgeAllCache, purgeCDNCache, purgeCacheByTag, revalidatePath, revalidatePaths, revalidateTag, revalidateTags, setEdgeCacheHeaders, shouldCacheResponse, warmCDNCache, warmISRCache };