admin-lib-cms 1.1.9 → 1.2.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/dist/auth.d.mts CHANGED
@@ -6,6 +6,8 @@ declare function createAuthHandler({ adapter, jwtSecret }: {
6
6
  jwtSecret?: string;
7
7
  }): (request: Request) => Promise<NextResponse<{
8
8
  hasUsers: boolean;
9
+ authenticated: boolean;
10
+ user: any;
9
11
  }> | NextResponse<{
10
12
  ok: boolean;
11
13
  }> | NextResponse<{
package/dist/auth.d.ts CHANGED
@@ -6,6 +6,8 @@ declare function createAuthHandler({ adapter, jwtSecret }: {
6
6
  jwtSecret?: string;
7
7
  }): (request: Request) => Promise<NextResponse<{
8
8
  hasUsers: boolean;
9
+ authenticated: boolean;
10
+ user: any;
9
11
  }> | NextResponse<{
10
12
  ok: boolean;
11
13
  }> | NextResponse<{
package/dist/auth.js CHANGED
@@ -44,7 +44,24 @@ function createAuthHandler({ adapter, jwtSecret }) {
44
44
  const action = url.searchParams.get("action");
45
45
  if (request.method === "GET") {
46
46
  const users = await adapter.listEntries("usersAdmin");
47
- return import_server.NextResponse.json({ hasUsers: users && users.length > 0 });
47
+ let authenticated = false;
48
+ let user = null;
49
+ const cookieHeader = request.headers.get("cookie") || "";
50
+ const match = cookieHeader.match(/admin_token=([^;]+)/);
51
+ const token = match ? match[1] : null;
52
+ if (token) {
53
+ try {
54
+ const { payload } = await (0, import_jose.jwtVerify)(token, secret);
55
+ authenticated = true;
56
+ user = { email: payload.email, id: payload.id };
57
+ } catch {
58
+ }
59
+ }
60
+ return import_server.NextResponse.json({
61
+ hasUsers: users && users.length > 0,
62
+ authenticated,
63
+ user
64
+ });
48
65
  }
49
66
  if (request.method === "POST") {
50
67
  let body = {};
package/dist/auth.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/auth.ts
2
2
  import { NextResponse } from "next/server";
3
3
  import bcrypt from "bcryptjs";
4
- import { SignJWT } from "jose";
4
+ import { SignJWT, jwtVerify } from "jose";
5
5
  function createAuthHandler({ adapter, jwtSecret }) {
6
6
  const secret = new TextEncoder().encode(jwtSecret || "fallback_secret_for_development_only");
7
7
  return async function handler(request) {
@@ -10,7 +10,24 @@ function createAuthHandler({ adapter, jwtSecret }) {
10
10
  const action = url.searchParams.get("action");
11
11
  if (request.method === "GET") {
12
12
  const users = await adapter.listEntries("usersAdmin");
13
- return NextResponse.json({ hasUsers: users && users.length > 0 });
13
+ let authenticated = false;
14
+ let user = null;
15
+ const cookieHeader = request.headers.get("cookie") || "";
16
+ const match = cookieHeader.match(/admin_token=([^;]+)/);
17
+ const token = match ? match[1] : null;
18
+ if (token) {
19
+ try {
20
+ const { payload } = await jwtVerify(token, secret);
21
+ authenticated = true;
22
+ user = { email: payload.email, id: payload.id };
23
+ } catch {
24
+ }
25
+ }
26
+ return NextResponse.json({
27
+ hasUsers: users && users.length > 0,
28
+ authenticated,
29
+ user
30
+ });
14
31
  }
15
32
  if (request.method === "POST") {
16
33
  let body = {};
@@ -0,0 +1,153 @@
1
+ // src/emails/templates/default.ts
2
+ function generateDefaultTemplate(data, title, description, companyName = "Admin CMS") {
3
+ const items = Object.entries(data).filter(([_, value]) => value !== void 0 && value !== null && value !== "").map(([key, value]) => {
4
+ const label = key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => str.toUpperCase());
5
+ const displayValue = Array.isArray(value) ? value.join(", ") : String(value);
6
+ return `
7
+ <div class="detail-item">
8
+ <span class="detail-label">${label}</span>
9
+ <span class="detail-value">${displayValue}</span>
10
+ </div>
11
+ `;
12
+ }).join("");
13
+ return `
14
+ <!DOCTYPE html>
15
+ <html lang="en">
16
+ <head>
17
+ <meta charset="UTF-8">
18
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
19
+ <title>${title}</title>
20
+ <style>
21
+ * { margin: 0; padding: 0; box-sizing: border-box; }
22
+ body {
23
+ background-color: #f4f4f5;
24
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
25
+ color: #18181b;
26
+ line-height: 1.5;
27
+ }
28
+ .wrapper { width: 100%; padding: 40px 20px; }
29
+ .container { max-width: 600px; margin: 0 auto; }
30
+ .card {
31
+ background: #ffffff;
32
+ border-radius: 12px;
33
+ overflow: hidden;
34
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
35
+ border: 1px solid #e4e4e7;
36
+ }
37
+ .header {
38
+ background: #1a2d42;
39
+ padding: 40px 32px;
40
+ text-align: center;
41
+ border-bottom: 4px solid #d4af37;
42
+ }
43
+ .header h1 {
44
+ color: #ffffff;
45
+ font-size: 24px;
46
+ font-weight: 700;
47
+ margin-bottom: 8px;
48
+ text-transform: uppercase;
49
+ letter-spacing: 0.05em;
50
+ }
51
+ .header p {
52
+ color: rgba(255, 255, 255, 0.9);
53
+ font-size: 14px;
54
+ }
55
+ .content { padding: 32px; }
56
+ .details-grid {
57
+ display: grid;
58
+ gap: 12px;
59
+ margin-bottom: 24px;
60
+ }
61
+ .detail-item {
62
+ background: #fafafa;
63
+ padding: 12px 16px;
64
+ border-radius: 8px;
65
+ border: 1px solid #f1f1f4;
66
+ }
67
+ .detail-label {
68
+ font-size: 11px;
69
+ font-weight: 700;
70
+ color: #71717a;
71
+ text-transform: uppercase;
72
+ letter-spacing: 0.05em;
73
+ display: block;
74
+ margin-bottom: 4px;
75
+ }
76
+ .detail-value {
77
+ font-size: 14px;
78
+ font-weight: 500;
79
+ color: #18181b;
80
+ word-break: break-word;
81
+ }
82
+ .footer {
83
+ padding: 24px 32px;
84
+ background: #f8fafc;
85
+ border-top: 1px solid #e2e8f0;
86
+ text-align: center;
87
+ }
88
+ .footer-text {
89
+ font-size: 12px;
90
+ color: #64748b;
91
+ }
92
+ </style>
93
+ </head>
94
+ <body>
95
+ <div class="wrapper">
96
+ <div class="container">
97
+ <div class="card">
98
+ <div class="header">
99
+ <h1>${title}</h1>
100
+ <p>${description}</p>
101
+ </div>
102
+ <div class="content">
103
+ <div class="details-grid">
104
+ ${items}
105
+ </div>
106
+ </div>
107
+ <div class="footer">
108
+ <p class="footer-text">\xA9 ${(/* @__PURE__ */ new Date()).getFullYear()} ${companyName}. This is an automated notification.</p>
109
+ </div>
110
+ </div>
111
+ </div>
112
+ </div>
113
+ </body>
114
+ </html>
115
+ `;
116
+ }
117
+
118
+ // src/emails/index.ts
119
+ async function sendEmailNotification(content, apiUrl) {
120
+ try {
121
+ const url = apiUrl || process.env.API_URL || process.env.NEXT_PUBLIC_API_URL || "";
122
+ const response = await fetch(`${url}/api/send-email`, {
123
+ method: "POST",
124
+ headers: {
125
+ "Content-Type": "application/json"
126
+ },
127
+ body: JSON.stringify({
128
+ content: {
129
+ ...content,
130
+ from: content.from || "Admin CMS <notifications@admincms.com>"
131
+ }
132
+ })
133
+ });
134
+ if (response.ok) {
135
+ const result = await response.json();
136
+ if (!result.success) {
137
+ console.error("Failed to send email:", result.error);
138
+ }
139
+ return result;
140
+ } else {
141
+ const errText = await response.text().catch(() => "");
142
+ console.warn("Email API endpoint error:", response.status, errText);
143
+ }
144
+ } catch (error) {
145
+ console.error("Error sending email:", error);
146
+ }
147
+ return null;
148
+ }
149
+
150
+ export {
151
+ generateDefaultTemplate,
152
+ sendEmailNotification
153
+ };
@@ -165,7 +165,8 @@ async function sendEmailNotification(content, apiUrl) {
165
165
  }
166
166
  return result;
167
167
  } else {
168
- console.warn("Email API endpoint error:", response.status);
168
+ const errText = await response.text().catch(() => "");
169
+ console.warn("Email API endpoint error:", response.status, errText);
169
170
  }
170
171
  } catch (error) {
171
172
  console.error("Error sending email:", error);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generateDefaultTemplate,
3
3
  sendEmailNotification
4
- } from "../chunk-ZG5XBIW7.mjs";
4
+ } from "../chunk-4KJKAYIC.mjs";
5
5
  export {
6
6
  generateDefaultTemplate,
7
7
  sendEmailNotification
package/dist/index.d.mts CHANGED
@@ -86,15 +86,16 @@ interface EditableListProps<T = any> extends BaseProps {
86
86
  renderList?: (items: T[]) => React.ReactNode;
87
87
  itemSchema?: {
88
88
  key: string;
89
- type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
89
+ type: "text" | "textarea" | "boolean" | "icon" | "image" | "file" | "number" | "select";
90
90
  label?: string;
91
91
  options?: string[];
92
92
  }[];
93
93
  fixedLength?: boolean;
94
94
  className?: string;
95
95
  listClassName?: string;
96
+ search?: boolean;
96
97
  }
97
- declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, }: EditableListProps<T>): react.JSX.Element;
98
+ declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, }: EditableListProps<T>): react.JSX.Element;
98
99
 
99
100
  declare function AdminApp({ apiUrl, projectId, email }: {
100
101
  apiUrl?: string;
package/dist/index.d.ts CHANGED
@@ -86,15 +86,16 @@ interface EditableListProps<T = any> extends BaseProps {
86
86
  renderList?: (items: T[]) => React.ReactNode;
87
87
  itemSchema?: {
88
88
  key: string;
89
- type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
89
+ type: "text" | "textarea" | "boolean" | "icon" | "image" | "file" | "number" | "select";
90
90
  label?: string;
91
91
  options?: string[];
92
92
  }[];
93
93
  fixedLength?: boolean;
94
94
  className?: string;
95
95
  listClassName?: string;
96
+ search?: boolean;
96
97
  }
97
- declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, }: EditableListProps<T>): react.JSX.Element;
98
+ declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, }: EditableListProps<T>): react.JSX.Element;
98
99
 
99
100
  declare function AdminApp({ apiUrl, projectId, email }: {
100
101
  apiUrl?: string;