rkk-next 1.0.0 โ†’ 1.1.1

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/README.md CHANGED
@@ -1,218 +1,487 @@
1
- # ๐Ÿš€ rkk-next
1
+ <div align="center">
2
2
 
3
- > **SEO, Performance & Routing SDK for Next.js**
3
+ <img src="./assets/logo.svg" alt="rkk-next logo" width="120" height="120" />
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/rkk-next.svg)](https://www.npmjs.com/package/rkk-next)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
7
- [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
5
+ # rkk-next
8
6
 
9
- rkk-next is an opinionated Next.js SDK that helps you build **SEO-optimized**, **blazing fast**, and **scalable** applications with better routing, caching, and performance defaults.
7
+ **Production-ready SEO, Performance & Routing SDK for Next.js**
10
8
 
11
- โœจ **Built for Next.js Pages Router & App Router**
12
- ๐ŸŽฏ **Ideal for:** Startups, Landing Pages, Web3 Dashboards, SaaS, Hackathons
9
+ [![npm version](https://img.shields.io/npm/v/rkk-next.svg?style=flat-square)](https://www.npmjs.com/package/rkk-next)
10
+ [![npm downloads](https://img.shields.io/npm/dm/rkk-next.svg?style=flat-square)](https://www.npmjs.com/package/rkk-next)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](./LICENSE)
12
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-3178c6.svg?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
13
+ [![Tests](https://img.shields.io/badge/Tests-97%20Passing-success.svg?style=flat-square)](https://github.com/ROHIT8759/rkk-next)
14
+ [![Coverage](https://img.shields.io/badge/Coverage-85%25-green.svg?style=flat-square)](https://github.com/ROHIT8759/rkk-next)
13
15
 
14
- ## โœจ Features
16
+ **Enterprise-grade toolkit for building SEO-optimized, lightning-fast Next.js applications**
15
17
 
16
- ### ๐Ÿ” SEO Optimization
17
- - โœ… Centralized meta management (OpenGraph, Twitter Cards)
18
- - โœ… JSON-LD structured data (Schema.org)
19
- - โœ… Canonical URL handling
20
- - โœ… SEO-safe defaults & best practices
18
+ [Get Started](#-quick-start) ยท [Project Structure](./docs/PROJECT_STRUCTURE.md) ยท [Backend Docs](./docs/BACKEND.md) ยท [Examples](./examples/) ยท [Report Bug](https://github.com/ROHIT8759/rkk-next/issues)
21
19
 
22
- ### โšก Routing Optimization
23
- - โœ… Intelligent route prefetching (hover-based)
24
- - โœ… Network-aware prefetching
25
- - โœ… Route change observer with performance metrics
26
- - โœ… Analytics-ready routing events
20
+ </div>
27
21
 
28
- ### ๐Ÿš€ Performance Boost
29
- - โœ… Lazy loading for heavy components
30
- - โœ… Optimized image wrapper (SEO + performance)
31
- - โœ… Cache & CDN header presets
32
- - โœ… Edge-friendly caching strategies
33
- - โœ… Security headers included
22
+ ---
34
23
 
35
- ### ๐Ÿ“Š Analytics
36
- - โœ… Web Vitals tracking (LCP, FID, CLS, etc.)
37
- - โœ… Route navigation analytics
38
- - โœ… Performance monitoring
24
+ ## ๐ŸŽฏ Why rkk-next?
39
25
 
40
- ๐Ÿ“ฆ Installation
41
- npm install rkk-next
26
+ Building performant, SEO-optimized Next.js applications requires juggling multiple concerns: meta tags, structured data, route prefetching, image optimization, and caching strategies. **rkk-next** provides production-tested solutions out of the box.
27
+
28
+ **Perfect for:**
29
+
30
+ - ๐Ÿš€ Startups needing rapid development
31
+ - ๐Ÿ’ผ Enterprise applications requiring SEO excellence
32
+ - ๐ŸŽจ Marketing websites and landing pages
33
+ - ๐ŸŒ Web3 dashboards and SaaS platforms
34
+ - โšก Performance-critical applications
35
+
36
+ ## โœจ Key Features
37
+
38
+ <table>
39
+ <tr>
40
+ <td width="50%">
41
+
42
+ ### ๐Ÿ” **SEO Excellence**
43
+
44
+ - Comprehensive meta tag management
45
+ - OpenGraph & Twitter Cards
46
+ - JSON-LD structured data (Schema.org)
47
+ - Automatic canonical URLs
48
+ - Server-side rendering optimized
49
+
50
+ </td>
51
+ <td width="50%">
52
+
53
+ ### โšก **Performance First**
54
+
55
+ - Intelligent route prefetching
56
+ - Network-aware optimizations
57
+ - Lazy loading for heavy components
58
+ - CDN & edge caching strategies
59
+ - Built-in security headers
60
+
61
+ </td>
62
+ </tr>
63
+ <tr>
64
+ <td width="50%">
65
+
66
+ ### ๐Ÿ“Š **Analytics Ready**
67
+
68
+ - Core Web Vitals tracking
69
+ - Route navigation metrics
70
+ - Performance monitoring
71
+ - Custom event tracking
72
+ - Production-ready insights
73
+
74
+ </td>
75
+ <td width="50%">
76
+
77
+ ### โšก **Backend Utilities**
78
+
79
+ - Express-like middleware
80
+ - API route optimization
81
+ - Rate limiting & CORS
82
+ - Response caching
83
+ - Request validation
84
+
85
+ </td>
86
+ </tr>
87
+ <tr>
88
+ <td width="50%">
89
+
90
+ ### ๐ŸŽจ **Developer Experience**
91
+
92
+ - Full TypeScript support
93
+ - Zero configuration needed
94
+ - Pages Router & App Router
95
+ - Comprehensive documentation
96
+ - Active maintenance
97
+
98
+ </td>
99
+ </tr>
100
+ </table>
101
+
102
+ ---
103
+
104
+ ## ๐Ÿš€ Quick Start
105
+
106
+ ### Create New Project (Recommended)
42
107
 
108
+ Get started instantly with our CLI tool:
43
109
 
44
- or
110
+ ```bash
111
+ npx create-next-rkk@latest my-app
112
+ cd my-app
113
+ npm run dev
114
+ ```
45
115
 
116
+ ### Add to Existing Project
117
+
118
+ Install into your existing Next.js application:
119
+
120
+ ```bash
121
+ npm install rkk-next
122
+ # or
46
123
  yarn add rkk-next
124
+ # or
125
+ pnpm add rkk-next
126
+ ```
127
+
128
+ ---
129
+
130
+ ## ๐Ÿ“– Usage Examples
131
+
132
+ ### SEO Meta Management
47
133
 
48
- ๐Ÿง  Basic Usage
49
- 1๏ธโƒฃ SEO Meta Manager
134
+ Centralize your SEO configuration with type-safe components:
135
+
136
+ ```tsx
50
137
  import { MetaManager } from "rkk-next";
51
138
 
52
- export default function Home() {
139
+ export default function HomePage() {
53
140
  return (
54
141
  <>
55
142
  <MetaManager
56
143
  title="Home | My App"
57
- description="SEO optimized Next.js app using rkk-next"
58
- keywords="Next.js, SEO, Performance"
59
- image="/og.png"
144
+ description="Production-ready Next.js application with enterprise SEO"
145
+ keywords="Next.js, React, SEO, Performance"
146
+ image="https://myapp.com/og-image.png"
60
147
  siteName="My App"
148
+ twitterHandle="myhandle"
61
149
  />
62
150
 
63
- <h1>Hello World</h1>
151
+ <main>{/* Your content */}</main>
64
152
  </>
65
153
  );
66
154
  }
155
+ ```
67
156
 
68
- 2๏ธโƒฃ JSON-LD (Schema.org)
69
- import { JsonLd } from "rkk-next";
157
+ ### Structured Data (JSON-LD)
70
158
 
71
- <JsonLd
72
- type="WebSite"
73
- data={{
74
- name: "My App",
75
- url: "https://myapp.com",
76
- }}
77
- />
159
+ Improve search engine understanding with structured data:
78
160
 
79
- ๐Ÿ”— Smart Routing
80
- SmartLink (Enhanced next/link)
81
- import { SmartLink } from "rkk-next";
161
+ ```tsx
162
+ import { JsonLd } from "rkk-next";
82
163
 
83
- <SmartLink href="/dashboard">
84
- Go to Dashboard
85
- </SmartLink>
164
+ export default function ArticlePage() {
165
+ return (
166
+ <>
167
+ <JsonLd
168
+ type="Article"
169
+ data={{
170
+ headline: "Advanced Next.js SEO Techniques",
171
+ image: "https://myapp.com/article.jpg",
172
+ datePublished: "2025-12-18T08:00:00.000Z",
173
+ author: {
174
+ "@type": "Person",
175
+ name: "John Doe",
176
+ },
177
+ }}
178
+ />
86
179
 
180
+ <article>{/* Article content */}</article>
181
+ </>
182
+ );
183
+ }
184
+ ```
87
185
 
88
- โœ” Prefetch on hover
89
- โœ” Network-aware
90
- โœ” SEO-safe <a> tag
186
+ ### Smart Routing & Prefetching
91
187
 
92
- Route Observer
93
- import { observeRoutes } from "rkk-next";
188
+ Enhance navigation performance with intelligent prefetching:
94
189
 
95
- observeRoutes((event) => {
96
- console.log(event.url, event.duration);
97
- });
190
+ ```tsx
191
+ import { SmartLink, observeRoutes } from "rkk-next";
192
+ import { useEffect } from "react";
98
193
 
99
- ๐Ÿ–ผ๏ธ Image Optimization
100
- import { OptimizedImage } from "rkk-next";
194
+ export default function Navigation() {
195
+ useEffect(() => {
196
+ // Track route changes for analytics
197
+ const unsubscribe = observeRoutes((event) => {
198
+ analytics.track("page_view", {
199
+ url: event.url,
200
+ duration: event.duration,
201
+ });
202
+ });
101
203
 
102
- <OptimizedImage
103
- src="/hero.png"
104
- alt="Landing page hero image"
105
- width={1200}
106
- height={630}
107
- priority
108
- />
204
+ return unsubscribe;
205
+ }, []);
109
206
 
207
+ return (
208
+ <nav>
209
+ <SmartLink href="/products" prefetchOnHover>
210
+ Products
211
+ </SmartLink>
212
+ </nav>
213
+ );
214
+ }
215
+ ```
110
216
 
111
- โœ” SEO-safe alt enforcement
112
- โœ” Responsive sizes
113
- โœ” LCP optimized
217
+ ### Optimized Images
114
218
 
115
- ๐Ÿ’ค Lazy Loading
116
- import { lazyImport } from "rkk-next";
219
+ Ensure SEO-compliant and performant images:
117
220
 
118
- const Chart = lazyImport(() => import("./Chart"));
221
+ ```tsx
222
+ import { OptimizedImage } from "rkk-next";
119
223
 
120
- export default function Dashboard() {
121
- return <Chart />;
224
+ export default function Hero() {
225
+ return (
226
+ <OptimizedImage
227
+ src="/hero-banner.jpg"
228
+ alt="Professional hero banner showcasing our product"
229
+ width={1920}
230
+ height={1080}
231
+ priority // For above-the-fold images
232
+ quality={85}
233
+ />
234
+ );
122
235
  }
236
+ ```
123
237
 
124
- ๐Ÿง  Intelligent Prefetching
125
- import { prefetchRoute, isFastConnection } from "rkk-next";
238
+ ### Code Splitting & Lazy Loading
126
239
 
127
- prefetchRoute("/dashboard", {
128
- condition: isFastConnection,
240
+ Reduce initial bundle size with intelligent lazy loading:
241
+
242
+ ```tsx
243
+ import { lazyImport, DefaultLoader } from "rkk-next";
244
+
245
+ // Heavy component loaded on-demand
246
+ const AnalyticsDashboard = lazyImport(() => import("./AnalyticsDashboard"), {
247
+ loading: DefaultLoader,
248
+ ssr: false,
249
+ delay: 100,
129
250
  });
130
251
 
131
- ๐Ÿ—„๏ธ Cache Headers
252
+ export default function Dashboard() {
253
+ return (
254
+ <main>
255
+ <h1>Dashboard</h1>
256
+ <AnalyticsDashboard />
257
+ </main>
258
+ );
259
+ }
260
+ ```
261
+
262
+ ### Performance-Optimized Caching
132
263
 
133
- Use directly inside next.config.js:
264
+ Configure production-grade caching in `next.config.js`:
134
265
 
266
+ ```javascript
135
267
  const {
136
268
  LONG_TERM_CACHE,
137
269
  EDGE_CACHE,
138
270
  NO_CACHE,
271
+ SECURITY_HEADERS,
139
272
  applyCache,
140
- } = require("rkk-next");
273
+ } = require("rkk-next/performance/cacheHeaders");
141
274
 
142
275
  module.exports = {
143
276
  async headers() {
144
277
  return [
278
+ // Static assets: aggressive caching
145
279
  applyCache("/_next/static/:path*", LONG_TERM_CACHE),
280
+ applyCache("/images/:path*", LONG_TERM_CACHE),
281
+
282
+ // API routes: edge caching
146
283
  applyCache("/api/public/:path*", EDGE_CACHE),
284
+
285
+ // User-specific pages: no cache
147
286
  applyCache("/dashboard/:path*", NO_CACHE),
287
+
288
+ // Security headers for all routes
289
+ {
290
+ source: "/:path*",
291
+ headers: SECURITY_HEADERS,
292
+ },
148
293
  ];
149
294
  },
150
295
  };
296
+ ```
297
+
298
+ ### Backend API Utilities
299
+
300
+ Build robust Next.js API routes with Express-like middleware:
301
+
302
+ ```typescript
303
+ // pages/api/users/[id].ts
304
+ import { NextApiRequest, NextApiResponse } from "next";
305
+ import {
306
+ composeMiddleware,
307
+ cors,
308
+ rateLimit,
309
+ validateRequest,
310
+ logger,
311
+ errorHandler,
312
+ cacheResponse,
313
+ jsonResponse,
314
+ allowMethods,
315
+ } from "rkk-next";
316
+
317
+ // Compose middleware chain
318
+ const handler = composeMiddleware(
319
+ cors({ origin: "https://yourdomain.com" }),
320
+ rateLimit({ maxRequests: 100, windowMs: 60000 }),
321
+ logger(),
322
+ allowMethods(["GET", "PUT", "DELETE"]),
323
+ cacheResponse({ ttl: 300 }), // Cache for 5 minutes
324
+ validateRequest((req) => {
325
+ if (req.method === "PUT" && !req.body.name) {
326
+ return "Name is required";
327
+ }
328
+ }),
329
+ errorHandler()
330
+ )(async (req: NextApiRequest, res: NextApiResponse) => {
331
+ const { id } = req.query;
332
+
333
+ // Your API logic
334
+ const user = await getUserById(id as string);
335
+
336
+ return jsonResponse(res, {
337
+ success: true,
338
+ data: user,
339
+ });
340
+ });
151
341
 
152
- ## ๐Ÿงฉ Supported Next.js Versions
342
+ export default handler;
343
+ ```
153
344
 
154
- | Feature | Pages Router | App Router |
155
- |-------------------|--------------|------------|
156
- | MetaManager | โœ… | โœ… (via generateAppMetadata) |
157
- | JsonLd | โœ… | โœ… |
158
- | SmartLink | โœ… | โš ๏ธ (use for internal links only) |
159
- | Routing Observer | โœ… | โš ๏ธ (Pages Router recommended) |
160
- | OptimizedImage | โœ… | โœ… |
161
- | Lazy Loading | โœ… | โœ… |
162
- | Cache Headers | โœ… | โœ… |
163
- | Web Vitals | โœ… | โœ… |
345
+ **Server-side caching with automatic TTL:**
164
346
 
165
- **Minimum Requirements:**
166
- - Next.js >= 12.0.0
167
- - React >= 17.0.0
168
- - TypeScript >= 4.5.0 (optional but recommended)
169
- ๐Ÿ› ๏ธ Best Practices
347
+ ```typescript
348
+ import { cache, memoize } from "rkk-next";
170
349
 
171
- Use MetaManager on every page
350
+ // Cache expensive operations
351
+ const expensiveQuery = memoize(
352
+ async (userId: string) => {
353
+ return await database.query(/* ... */);
354
+ },
355
+ { ttl: 600 } // 10 minutes
356
+ );
172
357
 
173
- Avoid lazy loading LCP elements
358
+ // Manual cache control
359
+ cache.set("user:123", userData, 300);
360
+ const cachedUser = cache.get("user:123");
361
+ ```
174
362
 
175
- Use SmartLink for internal navigation
363
+ See [Backend Utilities Documentation](docs/BACKEND.md) for complete API reference.
176
364
 
177
- Enable cache headers for static assets
365
+ ---
178
366
 
179
- Always provide alt text for images
367
+ ## ๐Ÿงฉ Compatibility Matrix
180
368
 
181
- ## ๐Ÿง‘โ€๐Ÿ’ป Author
369
+ | Feature | Pages Router | App Router | Notes |
370
+ | -------------- | :----------: | :--------: | ------------------------------------- |
371
+ | MetaManager | โœ… | โœ… | App Router uses `generateAppMetadata` |
372
+ | JsonLd | โœ… | โœ… | Works with both routers |
373
+ | SmartLink | โœ… | โš ๏ธ | Recommended for Pages Router |
374
+ | RouteObserver | โœ… | โš ๏ธ | Pages Router only |
375
+ | OptimizedImage | โœ… | โœ… | Full support both routers |
376
+ | Lazy Loading | โœ… | โœ… | Dynamic imports supported |
377
+ | Cache Headers | โœ… | โœ… | Universal support |
378
+ | Web Vitals | โœ… | โœ… | Analytics integration |
379
+ | Backend Utils | โœ… | โœ… | API routes middleware |
182
380
 
183
- **Rohit Kumar Kundu**
184
- ๐ŸŽ“ B.Tech CSE | Web3 & Next.js Developer
185
- ๐Ÿ”— [GitHub](https://github.com/ROHIT8759) | [LinkedIn](https://linkedin.com/in/rohit-kumar-kundu)
381
+ **System Requirements:**
382
+
383
+ - Next.js `>= 12.0.0`
384
+ - React `>= 17.0.0`
385
+ - Node.js `>= 16.0.0`
386
+ - TypeScript `>= 4.5.0` (optional but recommended)
387
+
388
+ ---
389
+
390
+ ## ๐ŸŽ“ Learn More
186
391
 
187
- ## ๐Ÿ“š Documentation
392
+ ### ๐Ÿ“š Documentation
188
393
 
189
- - ๐Ÿ“– [Full Documentation](./docs/DOCS.md)
190
- - ๐Ÿš€ [Quick Start Guide](./docs/QUICKSTART.md)
191
- - ๐Ÿ“ [API Reference](./docs/DOCS.md#api-reference)
192
- - ๐Ÿ’ก [Examples](./examples/)
394
+ - [Complete Documentation](./docs/DOCS.md) - Comprehensive API reference
395
+ - [Quick Start Guide](./docs/QUICKSTART.md) - Get running in 5 minutes
396
+ - [Migration Guide](./docs/DOCS.md) - Upgrade from other solutions
397
+ - [Best Practices](./docs/DOCS.md#best-practices) - Production tips
193
398
 
194
399
  ## ๐Ÿค Contributing
195
400
 
196
- We welcome contributions! See [CONTRIBUTING.md](./docs/CONTRIBUTING.md) for guidelines.
401
+ We welcome contributions from the community! Whether it's:
402
+
403
+ - ๐Ÿ› Bug reports and fixes
404
+ - โœจ New features and enhancements
405
+ - ๐Ÿ“– Documentation improvements
406
+ - ๐Ÿ’ก Feature suggestions
407
+
408
+ **Getting Started:**
197
409
 
198
410
  1. Fork the repository
199
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
200
- 3. Commit your changes (`git commit -m 'Add amazing feature'`)
201
- 4. Push to the branch (`git push origin feature/amazing-feature`)
202
- 5. Open a Pull Request
411
+ 2. Create a feature branch: `git checkout -b feature/amazing-feature`
412
+ 3. Make your changes with clear commit messages
413
+ 4. Write or update tests as needed
414
+ 5. Submit a pull request
415
+
416
+ See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for detailed guidelines.
417
+
418
+ ---
419
+
420
+ ## ๐Ÿ“ Project Structure
203
421
 
204
- ## ๐Ÿš€ Next Steps
422
+ ```
423
+ rkk-next/
424
+ โ”œโ”€โ”€ src/ # Source code
425
+ โ”‚ โ”œโ”€โ”€ seo/ # SEO utilities
426
+ โ”‚ โ”œโ”€โ”€ routing/ # Routing optimization
427
+ โ”‚ โ”œโ”€โ”€ performance/ # Performance tools
428
+ โ”‚ โ”œโ”€โ”€ analytics/ # Web Vitals tracking
429
+ โ”‚ โ””โ”€โ”€ backend/ # API utilities
430
+ โ”œโ”€โ”€ __tests__/ # Test suites (97 tests)
431
+ โ”œโ”€โ”€ docs/ # Documentation
432
+ โ”œโ”€โ”€ examples/ # Usage examples
433
+ โ””โ”€โ”€ cli/ # CLI tool (create-next-rkk)
434
+ ```
205
435
 
206
- - [ ] Add App Router `generateMetadata` helper
207
- - [ ] Expand Web Vitals analytics integration
208
- - [ ] Create demo app showcase
209
- - [ ] Add Lighthouse CI integration
210
- - [ ] Video tutorials & guides
436
+ ๐Ÿ“– See [Project Structure Documentation](./docs/PROJECT_STRUCTURE.md) for complete details.
437
+
438
+ ---
211
439
 
212
440
  ## ๐Ÿ“„ License
213
441
 
214
442
  MIT License ยฉ 2025 [Rohit Kumar Kundu](https://github.com/ROHIT8759)
215
443
 
444
+ Free for commercial and personal use. See [LICENSE](./LICENSE) for details.
445
+
446
+ ---
447
+
448
+ ## ๐Ÿ™ Support & Community
449
+
450
+ ### Get Help
451
+
452
+ - ๐Ÿ“– [Documentation](./docs/DOCS.md)
453
+ - ๐Ÿ’ฌ [GitHub Discussions](https://github.com/ROHIT8759/rkk-next/discussions)
454
+ - ๐Ÿ› [Issue Tracker](https://github.com/ROHIT8759/rkk-next/issues)
455
+
456
+ ### Show Your Support
457
+
458
+ If rkk-next helps your project:
459
+
460
+ - โญ Star the repository
461
+ - ๐Ÿฆ Share on social media
462
+ - ๐Ÿ“ Write about your experience
463
+ - ๐Ÿค Contribute back to the project
464
+
465
+ ---
466
+
467
+ ## ๐Ÿง‘โ€๐Ÿ’ป Author
468
+
469
+ **Rohit Kumar Kundu**
470
+ Full-Stack Developer | Next.js & Web3 Specialist
471
+
472
+ ๐Ÿ”— [GitHub](https://github.com/ROHIT8759) ยท [LinkedIn](https://linkedin.com/in/rohit-kumar-kundu) ยท [Portfolio](https://rohitkundu.dev)
473
+
474
+ ---
475
+
476
+ <div align="center">
477
+
478
+ **Built with โค๏ธ for the Next.js community**
479
+
480
+ [Get Started](./docs/QUICKSTART.md) ยท [Documentation](./docs/DOCS.md) ยท [Examples](./examples/) ยท [Changelog](./CHANGELOG.md)
481
+
482
+ </div>
483
+ MIT License ยฉ 2025 [Rohit Kumar Kundu](https://github.com/ROHIT8759)
484
+
216
485
  Free to use, modify, and distribute. See [LICENSE](./LICENSE) for details.
217
486
 
218
487
  ## โญ Support the Project
@@ -245,4 +514,4 @@ If you want, I can now:
245
514
 
246
515
  โœ” Final SDK audit before release
247
516
 
248
- Just tell me ๐Ÿ‘
517
+ Just tell me ๐Ÿ‘
@@ -0,0 +1,49 @@
1
+ import { NextApiRequest, NextApiResponse } from 'next';
2
+ export interface CacheOptions {
3
+ /** Time to live in seconds */
4
+ ttl?: number;
5
+ /** Cache key generator function */
6
+ keyGenerator?: (req: NextApiRequest) => string;
7
+ /** Conditional caching based on request */
8
+ shouldCache?: (req: NextApiRequest) => boolean;
9
+ }
10
+ /**
11
+ * In-memory cache store for API responses
12
+ */
13
+ declare class MemoryCache {
14
+ private cache;
15
+ set<T = any>(key: string, data: T, ttl: number): void;
16
+ get<T = any>(key: string): T | null;
17
+ has(key: string): boolean;
18
+ delete(key: string): void;
19
+ clear(): void;
20
+ size(): number;
21
+ /**
22
+ * Clean up expired entries
23
+ */
24
+ cleanup(): void;
25
+ }
26
+ export declare const cache: MemoryCache;
27
+ /**
28
+ * Cache API response middleware
29
+ */
30
+ export declare function cacheResponse(options?: CacheOptions): (req: NextApiRequest, res: NextApiResponse, next: () => void | Promise<void>) => Promise<void>;
31
+ /**
32
+ * Invalidate cache by pattern or specific key
33
+ */
34
+ export declare function invalidateCache(pattern?: string | RegExp): void;
35
+ /**
36
+ * Get cache statistics
37
+ */
38
+ export declare function getCacheStats(): {
39
+ size: number;
40
+ timestamp: string;
41
+ };
42
+ /**
43
+ * Memoize function results with TTL
44
+ */
45
+ export declare function memoize<T extends (...args: any[]) => any>(fn: T, options?: {
46
+ ttl?: number;
47
+ keyGenerator?: (...args: Parameters<T>) => string;
48
+ }): T;
49
+ export {};