@djangocfg/nextjs 1.0.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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +449 -0
  3. package/package.json +133 -0
  4. package/src/components/HomePage.tsx +73 -0
  5. package/src/components/index.ts +7 -0
  6. package/src/config/base-next-config.ts +262 -0
  7. package/src/config/index.ts +6 -0
  8. package/src/contact/index.ts +13 -0
  9. package/src/contact/route.ts +102 -0
  10. package/src/contact/submit.ts +80 -0
  11. package/src/errors/ErrorLayout.tsx +228 -0
  12. package/src/errors/errorConfig.ts +118 -0
  13. package/src/errors/index.ts +10 -0
  14. package/src/health/index.ts +7 -0
  15. package/src/health/route.ts +65 -0
  16. package/src/health/types.ts +19 -0
  17. package/src/index.ts +36 -0
  18. package/src/legal/LegalPage.tsx +85 -0
  19. package/src/legal/configs.ts +131 -0
  20. package/src/legal/index.ts +24 -0
  21. package/src/legal/pages.tsx +58 -0
  22. package/src/legal/types.ts +15 -0
  23. package/src/navigation/index.ts +9 -0
  24. package/src/navigation/types.ts +68 -0
  25. package/src/navigation/utils.ts +181 -0
  26. package/src/og-image/README.md +66 -0
  27. package/src/og-image/components/DefaultTemplate.tsx +369 -0
  28. package/src/og-image/components/index.ts +9 -0
  29. package/src/og-image/index.ts +27 -0
  30. package/src/og-image/route.tsx +253 -0
  31. package/src/og-image/types.ts +46 -0
  32. package/src/og-image/utils/fonts.ts +150 -0
  33. package/src/og-image/utils/index.ts +28 -0
  34. package/src/og-image/utils/metadata.ts +235 -0
  35. package/src/og-image/utils/url.ts +327 -0
  36. package/src/sitemap/generator.ts +64 -0
  37. package/src/sitemap/index.ts +8 -0
  38. package/src/sitemap/route.ts +74 -0
  39. package/src/sitemap/types.ts +20 -0
  40. package/src/types.ts +35 -0
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Universal Error Configuration
3
+ *
4
+ * Provides standard error content for common HTTP status codes
5
+ * Use this to maintain consistency across error pages
6
+ *
7
+ * NOTE: Only returns primitives (title, description) - NO React components
8
+ * This ensures safe serialization during prerendering
9
+ */
10
+
11
+ export interface ErrorContent {
12
+ title: string;
13
+ description: string;
14
+ }
15
+
16
+ /**
17
+ * Get standardized error content based on status code
18
+ *
19
+ * @param statusCode - HTTP status code or custom error type
20
+ * @returns Error content configuration (title and description only)
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const { title, description } = getErrorContent(404);
25
+ * <ErrorLayout title={title} description={description} code={404} />
26
+ * ```
27
+ */
28
+ export function getErrorContent(statusCode?: number | string): ErrorContent {
29
+ const code = typeof statusCode === 'string' ? parseInt(statusCode, 10) : statusCode;
30
+
31
+ switch (code) {
32
+ // 400 Bad Request
33
+ case 400:
34
+ return {
35
+ title: 'Bad Request',
36
+ description: 'The request could not be understood. Please check your input and try again.',
37
+ };
38
+
39
+ // 401 Unauthorized
40
+ case 401:
41
+ return {
42
+ title: 'Authentication Required',
43
+ description: 'You need to sign in to access this page.',
44
+ };
45
+
46
+ // 403 Forbidden
47
+ case 403:
48
+ return {
49
+ title: 'Access Denied',
50
+ description: "You don't have permission to access this resource.",
51
+ };
52
+
53
+ // 404 Not Found
54
+ case 404:
55
+ return {
56
+ title: 'Page Not Found',
57
+ description: "The page you're looking for doesn't exist or has been moved.",
58
+ };
59
+
60
+ // 408 Request Timeout
61
+ case 408:
62
+ return {
63
+ title: 'Request Timeout',
64
+ description: 'The request took too long to process. Please try again.',
65
+ };
66
+
67
+ // 500 Internal Server Error
68
+ case 500:
69
+ return {
70
+ title: 'Server Error',
71
+ description: "Something went wrong on our end. We're working to fix it.",
72
+ };
73
+
74
+ // 502 Bad Gateway
75
+ case 502:
76
+ return {
77
+ title: 'Bad Gateway',
78
+ description: 'The server received an invalid response. Please try again later.',
79
+ };
80
+
81
+ // 503 Service Unavailable
82
+ case 503:
83
+ return {
84
+ title: 'Service Unavailable',
85
+ description: 'The service is temporarily unavailable. Please try again later.',
86
+ };
87
+
88
+ // 504 Gateway Timeout
89
+ case 504:
90
+ return {
91
+ title: 'Gateway Timeout',
92
+ description: 'The server took too long to respond. Please try again.',
93
+ };
94
+
95
+ // Default / Unknown Error
96
+ default:
97
+ return {
98
+ title: 'Something Went Wrong',
99
+ description: 'An unexpected error occurred. Please try again or contact support.',
100
+ };
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Common error codes as constants
106
+ */
107
+ export const ERROR_CODES = {
108
+ BAD_REQUEST: 400,
109
+ UNAUTHORIZED: 401,
110
+ FORBIDDEN: 403,
111
+ NOT_FOUND: 404,
112
+ TIMEOUT: 408,
113
+ SERVER_ERROR: 500,
114
+ BAD_GATEWAY: 502,
115
+ SERVICE_UNAVAILABLE: 503,
116
+ GATEWAY_TIMEOUT: 504,
117
+ } as const;
118
+
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Error pages exports
3
+ */
4
+
5
+ export { ErrorLayout } from './ErrorLayout';
6
+ export type { ErrorLayoutProps } from './ErrorLayout';
7
+
8
+ export { getErrorContent, ERROR_CODES } from './errorConfig';
9
+ export type { ErrorContent } from './errorConfig';
10
+
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Health exports
3
+ */
4
+
5
+ export { createHealthHandler } from './route';
6
+ export type { HealthConfig, HealthCheck, HealthResponse } from './types';
7
+
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Health Route Handler for Next.js App Router
3
+ *
4
+ * Usage:
5
+ * ```tsx
6
+ * // app/api/health/route.ts
7
+ * import { createHealthHandler } from '@djangocfg/nextjs/health';
8
+ *
9
+ * export const GET = createHealthHandler({
10
+ * version: process.env.NEXT_PUBLIC_APP_VERSION || '1.0.0',
11
+ * checks: [
12
+ * {
13
+ * name: 'database',
14
+ * check: async () => {
15
+ * // Check database connection
16
+ * return await checkDatabase();
17
+ * },
18
+ * },
19
+ * ],
20
+ * });
21
+ * ```
22
+ */
23
+
24
+ import { NextResponse } from 'next/server';
25
+ import type { HealthConfig, HealthResponse } from './types';
26
+
27
+ export function createHealthHandler(config: HealthConfig = {}) {
28
+ const { version, checks = [], customData = {} } = config;
29
+
30
+ return async function GET() {
31
+ const startTime = Date.now();
32
+ let status: 'ok' | 'error' = 'ok';
33
+ const checkResults: Record<string, boolean> = {};
34
+
35
+ // Run health checks
36
+ if (checks.length > 0) {
37
+ for (const check of checks) {
38
+ try {
39
+ const result = await check.check();
40
+ checkResults[check.name] = result;
41
+ if (!result) {
42
+ status = 'error';
43
+ }
44
+ } catch (error) {
45
+ checkResults[check.name] = false;
46
+ status = 'error';
47
+ }
48
+ }
49
+ }
50
+
51
+ const response: HealthResponse = {
52
+ status,
53
+ timestamp: new Date().toISOString(),
54
+ uptime: process.uptime(),
55
+ ...(version && { version }),
56
+ ...(Object.keys(checkResults).length > 0 && { checks: checkResults }),
57
+ ...customData,
58
+ };
59
+
60
+ const statusCode = status === 'ok' ? 200 : 503;
61
+
62
+ return NextResponse.json(response, { status: statusCode });
63
+ };
64
+ }
65
+
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Health check types
3
+ */
4
+
5
+ import type { HealthResponse } from '../types';
6
+
7
+ export interface HealthCheck {
8
+ name: string;
9
+ check: () => Promise<boolean> | boolean;
10
+ }
11
+
12
+ export interface HealthConfig {
13
+ version?: string;
14
+ checks?: HealthCheck[];
15
+ customData?: Record<string, unknown>;
16
+ }
17
+
18
+ export type { HealthResponse };
19
+
package/src/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @djangocfg/nextjs
3
+ *
4
+ * Next.js utilities and components: sitemap, health, OG images, legal pages, error pages
5
+ */
6
+
7
+ // Sitemap
8
+ export * from './sitemap';
9
+
10
+ // Health
11
+ export * from './health';
12
+
13
+ // OG Image
14
+ export * from './og-image';
15
+
16
+ // Legal pages
17
+ export * from './legal';
18
+
19
+ // Error pages
20
+ export * from './errors';
21
+
22
+ // Components
23
+ export * from './components';
24
+
25
+ // Contact form
26
+ export * from './contact';
27
+
28
+ // Navigation
29
+ export * from './navigation';
30
+
31
+ // Config
32
+ export * from './config';
33
+
34
+ // Types
35
+ export type * from './types';
36
+
@@ -0,0 +1,85 @@
1
+ /**
2
+ * LegalPage Component
3
+ *
4
+ * Reusable component for legal pages (Privacy, Terms, Cookies, Security)
5
+ * Accepts configuration for flexible content rendering
6
+ *
7
+ * Usage:
8
+ * ```tsx
9
+ * import { LegalPage } from '@djangocfg/nextjs/legal';
10
+ * import { privacyConfig } from './config';
11
+ *
12
+ * export default function PrivacyPage() {
13
+ * return <LegalPage config={privacyConfig} />;
14
+ * }
15
+ * ```
16
+ */
17
+
18
+ 'use client';
19
+
20
+ import React from 'react';
21
+ import {
22
+ Card,
23
+ CardHeader,
24
+ CardTitle,
25
+ CardContent,
26
+ } from '@djangocfg/ui/components';
27
+ import type { LegalPageConfig } from './types';
28
+
29
+ export interface LegalPageProps {
30
+ config: LegalPageConfig;
31
+ className?: string;
32
+ }
33
+
34
+ /**
35
+ * Format date for display
36
+ */
37
+ function formatDate(date: string | Date | undefined): string {
38
+ if (!date) return '';
39
+ if (typeof date === 'string') return date;
40
+ return date.toISOString().split('T')[0];
41
+ }
42
+
43
+ /**
44
+ * LegalPage Component
45
+ */
46
+ export function LegalPage({ config, className }: LegalPageProps) {
47
+ const { title, lastUpdated, sections } = config;
48
+
49
+ return (
50
+ <div className={`container mx-auto max-w-4xl py-16 px-4 ${className || ''}`}>
51
+ <div className="flex flex-col gap-8">
52
+ {/* Header */}
53
+ <div className="flex flex-col gap-4">
54
+ <h1 className="text-4xl font-bold">{title}</h1>
55
+ {lastUpdated && (
56
+ <p className="text-lg text-muted-foreground">
57
+ Last updated: {formatDate(lastUpdated)}
58
+ </p>
59
+ )}
60
+ </div>
61
+
62
+ {/* Sections */}
63
+ {sections.map((section, index) => (
64
+ <Card key={index}>
65
+ <CardHeader>
66
+ <CardTitle>{section.title}</CardTitle>
67
+ </CardHeader>
68
+ <CardContent className="text-muted-foreground">
69
+ {Array.isArray(section.content) ? (
70
+ <div className="flex flex-col gap-2">
71
+ {section.content.map((paragraph, pIndex) => (
72
+ <p key={pIndex}>{paragraph}</p>
73
+ ))}
74
+ </div>
75
+ ) : (
76
+ <p>{section.content}</p>
77
+ )}
78
+ </CardContent>
79
+ </Card>
80
+ ))}
81
+ </div>
82
+ </div>
83
+ );
84
+ }
85
+
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Default legal page configurations
3
+ *
4
+ * Pre-configured content for common legal pages
5
+ * Can be customized or extended as needed
6
+ */
7
+
8
+ import type { LegalPageConfig } from './types';
9
+
10
+ export const privacyConfig: LegalPageConfig = {
11
+ title: 'Privacy Policy',
12
+ sections: [
13
+ {
14
+ title: 'Information We Collect',
15
+ content: 'We collect information that you provide directly to us, including when you create an account, use our services, or communicate with us.',
16
+ },
17
+ {
18
+ title: 'How We Use Your Information',
19
+ content: [
20
+ 'We use the information we collect to:',
21
+ 'Provide, maintain, and improve our services',
22
+ 'Process transactions and send related information',
23
+ 'Send technical notices and support messages',
24
+ 'Respond to your comments and questions',
25
+ ],
26
+ },
27
+ {
28
+ title: 'Information Sharing',
29
+ content: 'We do not share your personal information with third parties except as described in this privacy policy or with your consent.',
30
+ },
31
+ {
32
+ title: 'Data Security',
33
+ content: 'We take reasonable measures to help protect your personal information from loss, theft, misuse, unauthorized access, disclosure, alteration, and destruction.',
34
+ },
35
+ {
36
+ title: 'Your Rights',
37
+ content: 'You have the right to access, update, or delete your personal information at any time. Contact us if you wish to exercise these rights.',
38
+ },
39
+ {
40
+ title: 'Changes to This Policy',
41
+ content: 'We may update this privacy policy from time to time. We will notify you of any changes by posting the new policy on this page.',
42
+ },
43
+ ],
44
+ };
45
+
46
+ export const termsConfig: LegalPageConfig = {
47
+ title: 'Terms of Service',
48
+ sections: [
49
+ {
50
+ title: '1. Acceptance of Terms',
51
+ content: 'By accessing and using this service, you accept and agree to be bound by the terms and provision of this agreement.',
52
+ },
53
+ {
54
+ title: '2. Use License',
55
+ content: 'Permission is granted to temporarily download one copy of the materials on our service for personal, non-commercial transitory viewing only.',
56
+ },
57
+ {
58
+ title: '3. Disclaimer',
59
+ content: 'The materials on our service are provided on an \'as is\' basis. We make no warranties, expressed or implied, and hereby disclaim and negate all other warranties including, without limitation, implied warranties or conditions of merchantability, fitness for a particular purpose, or non-infringement of intellectual property or other violation of rights.',
60
+ },
61
+ {
62
+ title: '4. Limitations',
63
+ content: 'In no event shall we or our suppliers be liable for any damages (including, without limitation, damages for loss of data or profit, or due to business interruption) arising out of the use or inability to use the materials on our service.',
64
+ },
65
+ {
66
+ title: '5. Revisions',
67
+ content: 'We may revise these terms of service at any time without notice. By using this service you are agreeing to be bound by the then current version of these terms of service.',
68
+ },
69
+ ],
70
+ };
71
+
72
+ export const cookiesConfig: LegalPageConfig = {
73
+ title: 'Cookie Policy',
74
+ sections: [
75
+ {
76
+ title: 'What Are Cookies?',
77
+ content: 'Cookies are small text files that are placed on your device when you visit our website. They help us provide you with a better experience by remembering your preferences and understanding how you use our site.',
78
+ },
79
+ {
80
+ title: 'Types of Cookies We Use',
81
+ content: [
82
+ 'Essential Cookies: These cookies are necessary for the website to function properly.',
83
+ 'Performance Cookies: These cookies help us understand how visitors interact with our website.',
84
+ 'Functionality Cookies: These cookies allow us to remember choices you make and provide enhanced features.',
85
+ ],
86
+ },
87
+ {
88
+ title: 'Managing Cookies',
89
+ content: 'Most web browsers allow you to control cookies through their settings. You can set your browser to refuse cookies or delete certain cookies. However, please note that if you disable cookies, some features of our website may not function properly.',
90
+ },
91
+ {
92
+ title: 'Third-Party Cookies',
93
+ content: 'We may use third-party services that also use cookies. These third parties have their own privacy policies, and we do not accept any responsibility or liability for their policies.',
94
+ },
95
+ {
96
+ title: 'Updates to This Policy',
97
+ content: 'We may update our Cookie Policy from time to time. Any changes will be posted on this page with an updated revision date.',
98
+ },
99
+ ],
100
+ };
101
+
102
+ export const securityConfig: LegalPageConfig = {
103
+ title: 'Security Policy',
104
+ sections: [
105
+ {
106
+ title: 'Our Commitment to Security',
107
+ content: 'We take the security of your data seriously. We implement industry-standard security measures to protect your personal information from unauthorized access, disclosure, alteration, and destruction.',
108
+ },
109
+ {
110
+ title: 'Data Encryption',
111
+ content: 'All data transmitted between your device and our servers is encrypted using industry-standard SSL/TLS protocols. Sensitive data stored in our databases is encrypted at rest using advanced encryption standards.',
112
+ },
113
+ {
114
+ title: 'Access Controls',
115
+ content: 'Access to user data is strictly limited to authorized personnel who require it to perform their job functions. We employ multi-factor authentication and regular access reviews to ensure that only authorized individuals can access sensitive information.',
116
+ },
117
+ {
118
+ title: 'Security Monitoring',
119
+ content: 'We continuously monitor our systems for potential security threats and vulnerabilities. Our security team actively tracks and responds to any suspicious activity or potential security incidents.',
120
+ },
121
+ {
122
+ title: 'Reporting Security Issues',
123
+ content: 'If you discover a security vulnerability or have concerns about our security practices, please report it to us immediately. We appreciate responsible disclosure and will work with you to address any legitimate security concerns.',
124
+ },
125
+ {
126
+ title: 'Regular Security Updates',
127
+ content: 'We regularly update our systems and software to ensure that known security vulnerabilities are patched promptly. Our infrastructure undergoes periodic security audits and penetration testing to identify and address potential weaknesses.',
128
+ },
129
+ ],
130
+ };
131
+
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Legal pages exports
3
+ */
4
+
5
+ export { LegalPage } from './LegalPage';
6
+ export type { LegalPageProps } from './LegalPage';
7
+
8
+ export {
9
+ PrivacyPage,
10
+ TermsPage,
11
+ CookiesPage,
12
+ SecurityPage,
13
+ } from './pages';
14
+ export type { LegalPageComponentProps } from './pages';
15
+
16
+ export {
17
+ privacyConfig,
18
+ termsConfig,
19
+ cookiesConfig,
20
+ securityConfig,
21
+ } from './configs';
22
+
23
+ export type { LegalPageConfig, LegalPageSection } from './types';
24
+
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Pre-built legal page components
3
+ *
4
+ * Ready-to-use page components with default configurations
5
+ * Can be customized by passing custom config
6
+ *
7
+ * Usage:
8
+ * ```tsx
9
+ * // app/legal/privacy/page.tsx
10
+ * import { PrivacyPage } from '@djangocfg/nextjs/legal';
11
+ *
12
+ * export default PrivacyPage;
13
+ * ```
14
+ */
15
+
16
+ 'use client';
17
+
18
+ import { LegalPage } from './LegalPage';
19
+ import {
20
+ privacyConfig,
21
+ termsConfig,
22
+ cookiesConfig,
23
+ securityConfig,
24
+ } from './configs';
25
+ import type { LegalPageConfig } from './types';
26
+
27
+ export interface LegalPageComponentProps {
28
+ config?: LegalPageConfig;
29
+ }
30
+
31
+ /**
32
+ * Privacy Policy Page
33
+ */
34
+ export function PrivacyPage({ config }: LegalPageComponentProps = {}) {
35
+ return <LegalPage config={config || privacyConfig} />;
36
+ }
37
+
38
+ /**
39
+ * Terms of Service Page
40
+ */
41
+ export function TermsPage({ config }: LegalPageComponentProps = {}) {
42
+ return <LegalPage config={config || termsConfig} />;
43
+ }
44
+
45
+ /**
46
+ * Cookie Policy Page
47
+ */
48
+ export function CookiesPage({ config }: LegalPageComponentProps = {}) {
49
+ return <LegalPage config={config || cookiesConfig} />;
50
+ }
51
+
52
+ /**
53
+ * Security Policy Page
54
+ */
55
+ export function SecurityPage({ config }: LegalPageComponentProps = {}) {
56
+ return <LegalPage config={config || securityConfig} />;
57
+ }
58
+
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Legal page types
3
+ */
4
+
5
+ export interface LegalPageSection {
6
+ title: string;
7
+ content: string | string[];
8
+ }
9
+
10
+ export interface LegalPageConfig {
11
+ title: string;
12
+ lastUpdated?: string | Date;
13
+ sections: LegalPageSection[];
14
+ }
15
+
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Navigation Module
3
+ *
4
+ * Common utilities and types for route definitions and navigation
5
+ */
6
+
7
+ export * from './types';
8
+ export * from './utils';
9
+
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Navigation Types
3
+ *
4
+ * Common types used for route definitions and navigation
5
+ */
6
+
7
+ import type { LucideIcon } from 'lucide-react';
8
+
9
+ // ─────────────────────────────────────────────────────────────────────────
10
+ // Route Types
11
+ // ─────────────────────────────────────────────────────────────────────────
12
+
13
+ export interface RouteMetadata {
14
+ label: string;
15
+ description?: string;
16
+ icon?: LucideIcon | string;
17
+ protected: boolean;
18
+ group?: string;
19
+ order?: number;
20
+ show?: boolean;
21
+ }
22
+
23
+ export interface RouteDefinition {
24
+ path: string;
25
+ metadata: RouteMetadata;
26
+ }
27
+
28
+ // ─────────────────────────────────────────────────────────────────────────
29
+ // Menu Types
30
+ // ─────────────────────────────────────────────────────────────────────────
31
+
32
+ export interface MenuItem {
33
+ path: string;
34
+ label: string;
35
+ icon: LucideIcon | string;
36
+ badge?: string | number;
37
+ }
38
+
39
+ export interface MenuGroup {
40
+ label: string;
41
+ order: number;
42
+ items: MenuItem[];
43
+ }
44
+
45
+ // ─────────────────────────────────────────────────────────────────────────
46
+ // Navigation Types
47
+ // ─────────────────────────────────────────────────────────────────────────
48
+
49
+ export interface NavigationItem {
50
+ label: string;
51
+ path: string;
52
+ }
53
+
54
+ export interface NavigationSection {
55
+ title: string;
56
+ items: NavigationItem[];
57
+ }
58
+
59
+ // ─────────────────────────────────────────────────────────────────────────
60
+ // Breadcrumb Types
61
+ // ─────────────────────────────────────────────────────────────────────────
62
+
63
+ export interface BreadcrumbItem {
64
+ label: string;
65
+ path: string;
66
+ isActive: boolean;
67
+ }
68
+