admin-lib-cms 1.1.9 → 1.2.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/dist/auth.d.mts +2 -0
- package/dist/auth.d.ts +2 -0
- package/dist/auth.js +18 -1
- package/dist/auth.mjs +19 -2
- package/dist/chunk-4KJKAYIC.mjs +153 -0
- package/dist/emails/index.js +2 -1
- package/dist/emails/index.mjs +1 -1
- package/dist/index.js +26 -1
- package/dist/index.mjs +25 -1
- package/package.json +1 -1
package/dist/auth.d.mts
CHANGED
package/dist/auth.d.ts
CHANGED
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
|
-
|
|
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
|
-
|
|
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
|
+
};
|
package/dist/emails/index.js
CHANGED
|
@@ -165,7 +165,8 @@ async function sendEmailNotification(content, apiUrl) {
|
|
|
165
165
|
}
|
|
166
166
|
return result;
|
|
167
167
|
} else {
|
|
168
|
-
|
|
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);
|
package/dist/emails/index.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -681,7 +681,22 @@ function AdminApp({ apiUrl, projectId, email }) {
|
|
|
681
681
|
}
|
|
682
682
|
function AdminAppContent() {
|
|
683
683
|
const [section, setSection] = (0, import_react5.useState)("pages");
|
|
684
|
+
const [authChecking, setAuthChecking] = (0, import_react5.useState)(true);
|
|
685
|
+
const [authenticated, setAuthenticated] = (0, import_react5.useState)(false);
|
|
684
686
|
const ctx = useCmsContext();
|
|
687
|
+
(0, import_react5.useEffect)(() => {
|
|
688
|
+
fetch("/api/admin/auth").then((res) => res.json()).then((data) => {
|
|
689
|
+
if (data && data.authenticated) {
|
|
690
|
+
setAuthenticated(true);
|
|
691
|
+
} else {
|
|
692
|
+
window.location.href = "/admin/login";
|
|
693
|
+
}
|
|
694
|
+
}).catch(() => {
|
|
695
|
+
window.location.href = "/admin/login";
|
|
696
|
+
}).finally(() => {
|
|
697
|
+
setAuthChecking(false);
|
|
698
|
+
});
|
|
699
|
+
}, []);
|
|
685
700
|
let subscriptionCtx = null;
|
|
686
701
|
try {
|
|
687
702
|
subscriptionCtx = useSubscription();
|
|
@@ -689,6 +704,15 @@ function AdminAppContent() {
|
|
|
689
704
|
}
|
|
690
705
|
const isSubscriptionActive = subscriptionCtx?.isSubscriptionActive ?? true;
|
|
691
706
|
const daysOverdue = subscriptionCtx?.daysOverdue ?? 0;
|
|
707
|
+
if (authChecking) {
|
|
708
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex h-screen w-full items-center justify-center bg-slate-50", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-3 text-slate-500 font-medium text-sm", children: [
|
|
709
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "w-5 h-5 border-2 border-indigo-600 border-t-transparent rounded-full animate-spin" }),
|
|
710
|
+
"Authenticating Admin..."
|
|
711
|
+
] }) });
|
|
712
|
+
}
|
|
713
|
+
if (!authenticated) {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
692
716
|
if (!isSubscriptionActive) {
|
|
693
717
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-col lg:flex-row h-screen w-full overflow-hidden bg-slate-50 text-slate-900 font-sans selection:bg-indigo-100 selection:text-indigo-900", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubscriptionPage, {}) });
|
|
694
718
|
}
|
|
@@ -2776,7 +2800,8 @@ async function sendEmailNotification(content, apiUrl) {
|
|
|
2776
2800
|
}
|
|
2777
2801
|
return result;
|
|
2778
2802
|
} else {
|
|
2779
|
-
|
|
2803
|
+
const errText = await response.text().catch(() => "");
|
|
2804
|
+
console.warn("Email API endpoint error:", response.status, errText);
|
|
2780
2805
|
}
|
|
2781
2806
|
} catch (error) {
|
|
2782
2807
|
console.error("Error sending email:", error);
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import "./chunk-WBQAMGXK.mjs";
|
|
|
3
3
|
import {
|
|
4
4
|
generateDefaultTemplate,
|
|
5
5
|
sendEmailNotification
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4KJKAYIC.mjs";
|
|
7
7
|
|
|
8
8
|
// src/provider.tsx
|
|
9
9
|
import {
|
|
@@ -680,7 +680,22 @@ function AdminApp({ apiUrl, projectId, email }) {
|
|
|
680
680
|
}
|
|
681
681
|
function AdminAppContent() {
|
|
682
682
|
const [section, setSection] = useState4("pages");
|
|
683
|
+
const [authChecking, setAuthChecking] = useState4(true);
|
|
684
|
+
const [authenticated, setAuthenticated] = useState4(false);
|
|
683
685
|
const ctx = useCmsContext();
|
|
686
|
+
useEffect4(() => {
|
|
687
|
+
fetch("/api/admin/auth").then((res) => res.json()).then((data) => {
|
|
688
|
+
if (data && data.authenticated) {
|
|
689
|
+
setAuthenticated(true);
|
|
690
|
+
} else {
|
|
691
|
+
window.location.href = "/admin/login";
|
|
692
|
+
}
|
|
693
|
+
}).catch(() => {
|
|
694
|
+
window.location.href = "/admin/login";
|
|
695
|
+
}).finally(() => {
|
|
696
|
+
setAuthChecking(false);
|
|
697
|
+
});
|
|
698
|
+
}, []);
|
|
684
699
|
let subscriptionCtx = null;
|
|
685
700
|
try {
|
|
686
701
|
subscriptionCtx = useSubscription();
|
|
@@ -688,6 +703,15 @@ function AdminAppContent() {
|
|
|
688
703
|
}
|
|
689
704
|
const isSubscriptionActive = subscriptionCtx?.isSubscriptionActive ?? true;
|
|
690
705
|
const daysOverdue = subscriptionCtx?.daysOverdue ?? 0;
|
|
706
|
+
if (authChecking) {
|
|
707
|
+
return /* @__PURE__ */ jsx5("div", { className: "flex h-screen w-full items-center justify-center bg-slate-50", children: /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-3 text-slate-500 font-medium text-sm", children: [
|
|
708
|
+
/* @__PURE__ */ jsx5("div", { className: "w-5 h-5 border-2 border-indigo-600 border-t-transparent rounded-full animate-spin" }),
|
|
709
|
+
"Authenticating Admin..."
|
|
710
|
+
] }) });
|
|
711
|
+
}
|
|
712
|
+
if (!authenticated) {
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
691
715
|
if (!isSubscriptionActive) {
|
|
692
716
|
return /* @__PURE__ */ jsx5("div", { className: "flex flex-col lg:flex-row h-screen w-full overflow-hidden bg-slate-50 text-slate-900 font-sans selection:bg-indigo-100 selection:text-indigo-900", children: /* @__PURE__ */ jsx5(SubscriptionPage, {}) });
|
|
693
717
|
}
|