@adminforge/core 0.3.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 (86) hide show
  1. package/.turbo/turbo-build.log +56 -0
  2. package/CHANGELOG.md +32 -0
  3. package/LICENSE +21 -0
  4. package/bin/adminforge.js +317 -0
  5. package/dist/auth-client.cjs +45 -0
  6. package/dist/auth-client.cjs.map +1 -0
  7. package/dist/auth-client.d.cts +17 -0
  8. package/dist/auth-client.d.ts +17 -0
  9. package/dist/auth-client.js +20 -0
  10. package/dist/auth-client.js.map +1 -0
  11. package/dist/auth.cjs +65 -0
  12. package/dist/auth.cjs.map +1 -0
  13. package/dist/auth.d.cts +21 -0
  14. package/dist/auth.d.ts +21 -0
  15. package/dist/auth.js +36 -0
  16. package/dist/auth.js.map +1 -0
  17. package/dist/client-D0cjJVsn.d.ts +20 -0
  18. package/dist/client-sRnmZ-Y9.d.cts +20 -0
  19. package/dist/index-CyzxaE7n.d.cts +124 -0
  20. package/dist/index-CyzxaE7n.d.ts +124 -0
  21. package/dist/index.cjs +453 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.cts +65 -0
  24. package/dist/index.d.ts +65 -0
  25. package/dist/index.js +410 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/next.cjs +839 -0
  28. package/dist/next.cjs.map +1 -0
  29. package/dist/next.d.cts +84 -0
  30. package/dist/next.d.ts +84 -0
  31. package/dist/next.js +800 -0
  32. package/dist/next.js.map +1 -0
  33. package/dist/styles.css +763 -0
  34. package/dist/styles.css.map +1 -0
  35. package/dist/styles.d.cts +2 -0
  36. package/dist/styles.d.ts +2 -0
  37. package/dist/ui.cjs +2500 -0
  38. package/dist/ui.cjs.map +1 -0
  39. package/dist/ui.d.cts +119 -0
  40. package/dist/ui.d.ts +119 -0
  41. package/dist/ui.js +2448 -0
  42. package/dist/ui.js.map +1 -0
  43. package/eslint.config.js +35 -0
  44. package/package.json +99 -0
  45. package/src/api/controller.ts +234 -0
  46. package/src/api/index.ts +4 -0
  47. package/src/api/next.ts +281 -0
  48. package/src/api/security/agent-auth.ts +134 -0
  49. package/src/auth/config.ts +20 -0
  50. package/src/auth/index.ts +3 -0
  51. package/src/auth/middleware.ts +15 -0
  52. package/src/auth/provider.tsx +28 -0
  53. package/src/core/fields/index.ts +119 -0
  54. package/src/core/hooks/index.ts +60 -0
  55. package/src/core/index.ts +43 -0
  56. package/src/core/registry/index.ts +22 -0
  57. package/src/core/schema/collection.ts +12 -0
  58. package/src/core/schema/config.ts +11 -0
  59. package/src/core/schema/normalize.ts +32 -0
  60. package/src/core/types/index.ts +114 -0
  61. package/src/db/client.ts +146 -0
  62. package/src/db/index.ts +3 -0
  63. package/src/db/schema-generator.ts +104 -0
  64. package/src/fields/index.ts +1 -0
  65. package/src/index.ts +4 -0
  66. package/src/next.ts +3 -0
  67. package/src/styles/adminforge.css +840 -0
  68. package/src/ui/AdminDashboard.tsx +176 -0
  69. package/src/ui/AdminForgeContext.tsx +64 -0
  70. package/src/ui/components/AdminLayout.tsx +107 -0
  71. package/src/ui/form-engine/FormEngine.tsx +250 -0
  72. package/src/ui/form-engine/ImageUpload.tsx +68 -0
  73. package/src/ui/form-engine/RelationInput.tsx +215 -0
  74. package/src/ui/form-engine/RichTextEditor.tsx +708 -0
  75. package/src/ui/index.ts +18 -0
  76. package/src/ui/screens/AdminPage.tsx +162 -0
  77. package/src/ui/screens/AgentTokenPage.tsx +232 -0
  78. package/src/ui/screens/CollectionFormPage.tsx +135 -0
  79. package/src/ui/screens/CollectionListPage.tsx +170 -0
  80. package/src/ui/screens/CollectionSchemaPage.tsx +180 -0
  81. package/src/ui/screens/RoleDetailPage.tsx +147 -0
  82. package/src/ui/screens/RolesListPage.tsx +57 -0
  83. package/src/ui/table-engine/TableEngine.tsx +157 -0
  84. package/src/ui.ts +3 -0
  85. package/tsconfig.json +10 -0
  86. package/tsup.config.ts +54 -0
@@ -0,0 +1,56 @@
1
+
2
+ > @adminforge/core@0.3.1 build /home/runner/work/AdminForge/AdminForge/packages/adminforge
3
+ > tsup
4
+
5
+ CLI Building entry: {"index":"src/index.ts","ui":"src/ui.ts","next":"src/next.ts","auth":"src/auth/index.ts","auth-client":"src/auth/provider.tsx","styles":"src/styles/adminforge.css"}
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /home/runner/work/AdminForge/AdminForge/packages/adminforge/tsup.config.ts
9
+ CLI Target: es2022
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ CJS dist/ui.cjs 131.63 KB
14
+ CJS dist/next.cjs 28.86 KB
15
+ CJS dist/index.cjs 15.90 KB
16
+ CJS dist/auth-client.cjs 1.57 KB
17
+ CJS dist/auth.cjs 1.84 KB
18
+ CJS dist/styles.css 16.40 KB
19
+ CJS dist/ui.cjs.map 182.97 KB
20
+ CJS dist/index.cjs.map 29.76 KB
21
+ CJS dist/next.cjs.map 52.83 KB
22
+ CJS dist/auth-client.cjs.map 973.00 B
23
+ CJS dist/auth.cjs.map 1.69 KB
24
+ CJS dist/styles.css.map 27.16 KB
25
+ CJS ⚡️ Build success in 104ms
26
+ ESM dist/index.js 14.04 KB
27
+ ESM dist/next.js 26.79 KB
28
+ ESM dist/auth.js 778.00 B
29
+ ESM dist/auth-client.js 480.00 B
30
+ ESM dist/ui.js 115.58 KB
31
+ ESM dist/styles.css 16.40 KB
32
+ ESM dist/next.js.map 52.59 KB
33
+ ESM dist/auth.js.map 1.50 KB
34
+ ESM dist/auth-client.js.map 933.00 B
35
+ ESM dist/styles.css.map 27.16 KB
36
+ ESM dist/index.js.map 29.52 KB
37
+ ESM dist/ui.js.map 185.51 KB
38
+ ESM ⚡️ Build success in 105ms
39
+ DTS Build start
40
+ DTS ⚡️ Build success in 6145ms
41
+ DTS dist/styles.d.ts 13.00 B
42
+ DTS dist/auth-client.d.ts 451.00 B
43
+ DTS dist/next.d.ts 2.87 KB
44
+ DTS dist/index.d.ts 3.57 KB
45
+ DTS dist/ui.d.ts 4.06 KB
46
+ DTS dist/auth.d.ts 589.00 B
47
+ DTS dist/client-D0cjJVsn.d.ts 842.00 B
48
+ DTS dist/index-CyzxaE7n.d.ts 3.30 KB
49
+ DTS dist/styles.d.cts 13.00 B
50
+ DTS dist/auth-client.d.cts 451.00 B
51
+ DTS dist/next.d.cts 2.87 KB
52
+ DTS dist/index.d.cts 3.58 KB
53
+ DTS dist/ui.d.cts 4.06 KB
54
+ DTS dist/auth.d.cts 589.00 B
55
+ DTS dist/client-sRnmZ-Y9.d.cts 843.00 B
56
+ DTS dist/index-CyzxaE7n.d.cts 3.30 KB
package/CHANGELOG.md ADDED
@@ -0,0 +1,32 @@
1
+ # @adminforge/core
2
+
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 4a217a9: Fix build-time crash: defer ADMINFORGE_SECRET validation to runtime instead of module load time. This allows Next.js builds to complete without requiring the env var during static page generation.
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Refined Developer Experience (DX) for Zero-Config projects:
14
+ - Added `serializeConfig` utility for Next.js Server Components.
15
+ - Automatic route parameter detection (`admin`, `slug`, etc.).
16
+ - Default SQLite database provisioning when `DATABASE_URL` is missing.
17
+ - Fixed AI CLI executable permissions and dependencies.
18
+
19
+ ## 0.2.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 473b0a5: Added high-level helpers, CLI migrate command, and media upload support.
24
+ - 9ddaafa: Initial public release of the AdminForge ecosystem. Includes unified core framework and AI orchestration layer.
25
+
26
+ ### Patch Changes
27
+
28
+ - Critical DX refinements:
29
+ - Added `serializeConfig` to handle Zod schema serialization in Next.js.
30
+ - Improved API route flexibility by auto-detecting catch-all param names.
31
+ - Optimized Zero-Config setup by defaulting to local SQLite if DATABASE_URL is missing.
32
+ - Fixed AI CLI executable permissions and internal import paths.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AdminForge Contributors
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.
@@ -0,0 +1,317 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync } from "child_process";
4
+ import fs from "fs";
5
+ import path from "path";
6
+ import crypto from "crypto";
7
+
8
+ const args = process.argv.slice(2);
9
+ const command = args[0];
10
+
11
+ function resolvePrisma() {
12
+ const candidates = [
13
+ "node_modules/@adminforge/core/node_modules/.bin/prisma",
14
+ "node_modules/.bin/prisma",
15
+ ];
16
+ for (const c of candidates) {
17
+ const full = path.resolve(process.cwd(), c);
18
+ if (fs.existsSync(full)) return full;
19
+ }
20
+ return "npx prisma";
21
+ }
22
+
23
+ function generateSecret() {
24
+ return crypto.randomBytes(32).toString("hex");
25
+ }
26
+
27
+ function writeFile(dest, content) {
28
+ const fullPath = path.resolve(process.cwd(), dest);
29
+ if (fs.existsSync(fullPath)) {
30
+ console.log(` ${dest} — already exists, skipped`);
31
+ return false;
32
+ }
33
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
34
+ fs.writeFileSync(fullPath, content.trimStart() + "\n");
35
+ console.log(` ✓ ${dest}`);
36
+ return true;
37
+ }
38
+
39
+ if (!command) {
40
+ console.log("Usage: adminforge <command>");
41
+ console.log("Commands: init, makemigrations, migrate");
42
+ process.exit(1);
43
+ }
44
+
45
+ if (command === "init") {
46
+ console.log("\nScaffolding AdminForge project...\n");
47
+
48
+ writeFile("adminforge.ts", `
49
+ import { defineConfig, collection, fields } from "@adminforge/core";
50
+
51
+ export const config = defineConfig({
52
+ auth: {
53
+ enabled: true,
54
+ },
55
+ collections: [
56
+ collection({
57
+ name: "posts",
58
+ label: "Posts",
59
+ fields: {
60
+ title: fields.text({ required: true }),
61
+ content: fields.richText(),
62
+ },
63
+ }),
64
+ ],
65
+ });
66
+ `);
67
+
68
+ writeFile("auth.ts", `
69
+ import NextAuth from "next-auth";
70
+ import Credentials from "next-auth/providers/credentials";
71
+
72
+ /**
73
+ * ⚠ Replace these demo credentials before production deployment.
74
+ * Use environment variables or a real database for user storage.
75
+ */
76
+
77
+ export const { handlers, auth, signIn, signOut } = NextAuth({
78
+ providers: [
79
+ Credentials({
80
+ name: "Credentials",
81
+ credentials: {
82
+ email: { label: "Email", type: "email" },
83
+ password: { label: "Password", type: "password" },
84
+ },
85
+ async authorize(credentials) {
86
+ if (
87
+ credentials?.email === "admin@adminforge.com" &&
88
+ credentials?.password === "admin"
89
+ ) {
90
+ return { id: "1", name: "Admin", email: "admin@adminforge.com", role: "admin" };
91
+ }
92
+ if (
93
+ credentials?.email === "editor@adminforge.com" &&
94
+ credentials?.password === "editor"
95
+ ) {
96
+ return { id: "2", name: "Editor", email: "editor@adminforge.com", role: "editor" };
97
+ }
98
+ return null;
99
+ },
100
+ }),
101
+ ],
102
+ callbacks: {
103
+ jwt({ token, user }) {
104
+ if (user) token.role = (user).role;
105
+ return token;
106
+ },
107
+ session({ session, token }) {
108
+ if (session.user) session.role = token.role;
109
+ return session;
110
+ },
111
+ },
112
+ trustHost: true,
113
+ });
114
+ `);
115
+
116
+ writeFile("lib/db.ts", `
117
+ import { PrismaClient } from "@prisma/client";
118
+
119
+ const globalForPrisma = globalThis as unknown as {
120
+ prisma: PrismaClient | undefined;
121
+ };
122
+
123
+ export const db = globalForPrisma.prisma ?? new PrismaClient();
124
+
125
+ if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = db;
126
+ `);
127
+
128
+ writeFile("app/api/auth/[...nextauth]/route.ts", `
129
+ import { handlers } from "../../../../auth";
130
+
131
+ export const GET = handlers.GET;
132
+ export const POST = handlers.POST;
133
+ `);
134
+
135
+ writeFile("app/api/adminforge/[...slug]/route.ts", `
136
+ import { createAdminForgeApi } from "@adminforge/core/next";
137
+ import { config } from "../../../../adminforge";
138
+ import { db } from "../../../../lib/db";
139
+ import { auth } from "../../../../auth";
140
+
141
+ const handler = createAdminForgeApi({ config, db, auth });
142
+
143
+ export const GET = handler.GET;
144
+ export const POST = handler.POST;
145
+ export const PATCH = handler.PATCH;
146
+ export const DELETE = handler.DELETE;
147
+ `);
148
+
149
+ writeFile("app/admin/layout.tsx", `
150
+ import { AuthProvider } from "@adminforge/core/auth-client";
151
+ import { auth } from "../../auth";
152
+ import "@adminforge/core/styles.css";
153
+
154
+ export default async function AdminLayout({ children }: { children: React.ReactNode }) {
155
+ let session = null;
156
+ try {
157
+ session = await auth();
158
+ } catch (e) {
159
+ console.error("[AdminForge] Session retrieval failed:", e);
160
+ }
161
+
162
+ return (
163
+ <AuthProvider session={session}>
164
+ {children}
165
+ </AuthProvider>
166
+ );
167
+ }
168
+ `);
169
+
170
+ writeFile("app/admin/[[...admin]]/page.tsx", `
171
+ import { AdminDashboard } from "@adminforge/core/ui";
172
+
173
+ export default function AdminPage() {
174
+ return (
175
+ <main style={{ height: "100vh" }}>
176
+ <AdminDashboard />
177
+ </main>
178
+ );
179
+ }
180
+ `);
181
+
182
+ // .env: append only missing keys
183
+ const envPath = path.resolve(process.cwd(), ".env");
184
+ let envContent = "";
185
+ if (fs.existsSync(envPath)) {
186
+ envContent = fs.readFileSync(envPath, "utf-8");
187
+ }
188
+
189
+ const envUpdates = [];
190
+ if (!envContent.includes("AUTH_SECRET=")) {
191
+ envUpdates.push(`AUTH_SECRET="${generateSecret()}"`);
192
+ }
193
+ if (!envContent.includes("DATABASE_URL=")) {
194
+ envUpdates.push('DATABASE_URL="file:./dev.db"');
195
+ }
196
+
197
+ if (envUpdates.length > 0) {
198
+ const addendum = "\n" + envUpdates.join("\n") + "\n";
199
+ fs.appendFileSync(envPath, addendum);
200
+ for (const key of envUpdates) {
201
+ console.log(` ✓ .env — added ${key.split("=")[0]}`);
202
+ }
203
+ } else {
204
+ console.log(" .env — already configured, skipped");
205
+ }
206
+
207
+ console.log(`
208
+ Done. Next steps:
209
+
210
+ 1. Install dependencies (if not already done)
211
+ npm install @adminforge/core
212
+
213
+ 2. Generate schema and sync database
214
+ npx adminforge migrate
215
+
216
+ 3. Start dev server
217
+ npm run dev
218
+
219
+ 4. Visit
220
+ http://localhost:3000/admin
221
+ `);
222
+ process.exit(0);
223
+ }
224
+
225
+ // Find config file (for migrate/makemigrations commands)
226
+ const possiblePaths = [
227
+ "adminforge.ts",
228
+ "admin.config.ts",
229
+ "src/admin.config.ts",
230
+ "src/config/adminforge.ts"
231
+ ];
232
+
233
+ let configPath = null;
234
+ for (const p of possiblePaths) {
235
+ if (fs.existsSync(path.resolve(process.cwd(), p))) {
236
+ configPath = p;
237
+ break;
238
+ }
239
+ }
240
+
241
+ if (!configPath) {
242
+ console.error("Could not find adminforge config. Looked for:", possiblePaths.join(", "));
243
+ process.exit(1);
244
+ }
245
+
246
+ const isMakemigrations = command === "makemigrations";
247
+ const isMigrate = command === "migrate";
248
+
249
+ // Provide default DATABASE_URL if missing for SQLite Zero-Config
250
+ if (!process.env.DATABASE_URL) {
251
+ process.env.DATABASE_URL = "file:./dev.db";
252
+ }
253
+
254
+ if (isMakemigrations || isMigrate) {
255
+ // We need to generate the Prisma schema first.
256
+ const tempScriptPath = path.resolve(process.cwd(), ".adminforge-runner.ts");
257
+
258
+ const runnerContent = `
259
+ import { generatePrismaSchema } from "@adminforge/core";
260
+ import { config } from "./${configPath.replace(".ts", "")}";
261
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
262
+ import { resolve } from "path";
263
+
264
+ const schemaPath = resolve(process.cwd(), "prisma/schema.prisma");
265
+
266
+ let provider = "sqlite";
267
+ if (existsSync(schemaPath)) {
268
+ const existing = readFileSync(schemaPath, "utf-8");
269
+ const datasourceMatch = existing.match(/datasource db \\{[^}]*provider\\s*=\\s*"(.*)"/);
270
+ if (datasourceMatch) {
271
+ provider = datasourceMatch[1];
272
+ }
273
+ }
274
+
275
+ const schema = generatePrismaSchema(config, { provider });
276
+ const prismaDir = resolve(process.cwd(), "prisma");
277
+ if (!existsSync(prismaDir)) {
278
+ mkdirSync(prismaDir);
279
+ }
280
+ writeFileSync(schemaPath, schema);
281
+ console.log("Generated Prisma schema at prisma/schema.prisma (provider: " + provider + ")");
282
+ `;
283
+
284
+ fs.writeFileSync(tempScriptPath, runnerContent);
285
+
286
+ try {
287
+ // Generate schema
288
+ execSync(`npx tsx ${tempScriptPath}`, { stdio: "inherit" });
289
+
290
+ // Now run prisma command
291
+ const prismaBin = resolvePrisma();
292
+ if (isMakemigrations) {
293
+ const nameIndex = args.indexOf("--name");
294
+ const name = nameIndex !== -1 ? args[nameIndex + 1] : "auto";
295
+ execSync(`${prismaBin} migrate dev --name "${name}" --create-only`, { stdio: "inherit" });
296
+ console.log(`Created migration: ${name}`);
297
+ } else if (isMigrate) {
298
+ if (args.includes("--push")) {
299
+ execSync(`${prismaBin} db push`, { stdio: "inherit" });
300
+ } else if (args.includes("--deploy")) {
301
+ execSync(`${prismaBin} migrate deploy`, { stdio: "inherit" });
302
+ } else {
303
+ execSync(`${prismaBin} migrate dev`, { stdio: "inherit" });
304
+ }
305
+ execSync(`${prismaBin} generate`, { stdio: "inherit" });
306
+ console.log("Applied changes and generated client.");
307
+ }
308
+ } catch (error) {
309
+ console.error("Error executing command", error);
310
+ } finally {
311
+ if (fs.existsSync(tempScriptPath)) {
312
+ fs.unlinkSync(tempScriptPath);
313
+ }
314
+ }
315
+ } else {
316
+ console.log(`Unknown command: ${command}`);
317
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/auth/provider.tsx
22
+ var provider_exports = {};
23
+ __export(provider_exports, {
24
+ AuthProvider: () => AuthProvider,
25
+ useAdminSession: () => useAdminSession
26
+ });
27
+ module.exports = __toCommonJS(provider_exports);
28
+ var import_react = require("react");
29
+ var import_jsx_runtime = require("react/jsx-runtime");
30
+ var AdminSessionContext = (0, import_react.createContext)(null);
31
+ function AuthProvider({
32
+ children,
33
+ session
34
+ }) {
35
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdminSessionContext.Provider, { value: session, children });
36
+ }
37
+ function useAdminSession() {
38
+ return (0, import_react.useContext)(AdminSessionContext);
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ AuthProvider,
43
+ useAdminSession
44
+ });
45
+ //# sourceMappingURL=auth-client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth/provider.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext } from \"react\";\n\ninterface AdminSession {\n user: { id: string; email: string; role?: string } | null;\n role?: string;\n}\n\nconst AdminSessionContext = createContext<AdminSession | null>(null);\n\nexport function AuthProvider({\n children,\n session,\n}: {\n children: React.ReactNode;\n session: AdminSession | null;\n}) {\n return (\n <AdminSessionContext.Provider value={session}>\n {children}\n </AdminSessionContext.Provider>\n );\n}\n\nexport function useAdminSession(): AdminSession | null {\n return useContext(AdminSessionContext);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0C;AAiBtC;AAVJ,IAAM,0BAAsB,4BAAmC,IAAI;AAE5D,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,SACE,4CAAC,oBAAoB,UAApB,EAA6B,OAAO,SAClC,UACH;AAEJ;AAEO,SAAS,kBAAuC;AACrD,aAAO,yBAAW,mBAAmB;AACvC;","names":[]}
@@ -0,0 +1,17 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface AdminSession {
4
+ user: {
5
+ id: string;
6
+ email: string;
7
+ role?: string;
8
+ } | null;
9
+ role?: string;
10
+ }
11
+ declare function AuthProvider({ children, session, }: {
12
+ children: React.ReactNode;
13
+ session: AdminSession | null;
14
+ }): react_jsx_runtime.JSX.Element;
15
+ declare function useAdminSession(): AdminSession | null;
16
+
17
+ export { AuthProvider, useAdminSession };
@@ -0,0 +1,17 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface AdminSession {
4
+ user: {
5
+ id: string;
6
+ email: string;
7
+ role?: string;
8
+ } | null;
9
+ role?: string;
10
+ }
11
+ declare function AuthProvider({ children, session, }: {
12
+ children: React.ReactNode;
13
+ session: AdminSession | null;
14
+ }): react_jsx_runtime.JSX.Element;
15
+ declare function useAdminSession(): AdminSession | null;
16
+
17
+ export { AuthProvider, useAdminSession };
@@ -0,0 +1,20 @@
1
+ "use client";
2
+
3
+ // src/auth/provider.tsx
4
+ import { createContext, useContext } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ var AdminSessionContext = createContext(null);
7
+ function AuthProvider({
8
+ children,
9
+ session
10
+ }) {
11
+ return /* @__PURE__ */ jsx(AdminSessionContext.Provider, { value: session, children });
12
+ }
13
+ function useAdminSession() {
14
+ return useContext(AdminSessionContext);
15
+ }
16
+ export {
17
+ AuthProvider,
18
+ useAdminSession
19
+ };
20
+ //# sourceMappingURL=auth-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth/provider.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext } from \"react\";\n\ninterface AdminSession {\n user: { id: string; email: string; role?: string } | null;\n role?: string;\n}\n\nconst AdminSessionContext = createContext<AdminSession | null>(null);\n\nexport function AuthProvider({\n children,\n session,\n}: {\n children: React.ReactNode;\n session: AdminSession | null;\n}) {\n return (\n <AdminSessionContext.Provider value={session}>\n {children}\n </AdminSessionContext.Provider>\n );\n}\n\nexport function useAdminSession(): AdminSession | null {\n return useContext(AdminSessionContext);\n}\n"],"mappings":";;;AAEA,SAAS,eAAe,kBAAkB;AAiBtC;AAVJ,IAAM,sBAAsB,cAAmC,IAAI;AAE5D,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,SAClC,UACH;AAEJ;AAEO,SAAS,kBAAuC;AACrD,SAAO,WAAW,mBAAmB;AACvC;","names":[]}
package/dist/auth.cjs ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/auth/index.ts
21
+ var auth_exports = {};
22
+ __export(auth_exports, {
23
+ adminMiddleware: () => adminMiddleware,
24
+ auth: () => auth,
25
+ createAuthConfig: () => createAuthConfig
26
+ });
27
+ module.exports = __toCommonJS(auth_exports);
28
+
29
+ // src/auth/config.ts
30
+ function createAuthConfig(options) {
31
+ return {
32
+ ...options,
33
+ providers: ["credentials"]
34
+ };
35
+ }
36
+ var auth = {
37
+ providers: {
38
+ credentials: {
39
+ id: "credentials",
40
+ name: "Credentials"
41
+ }
42
+ }
43
+ };
44
+
45
+ // src/auth/middleware.ts
46
+ function adminMiddleware(handler) {
47
+ return async (request) => {
48
+ const sessionCookie = request.headers.get("cookie") ?? "";
49
+ const hasSession = sessionCookie.includes("next-auth.session-token");
50
+ if (!hasSession) {
51
+ return new Response(JSON.stringify({ error: "Unauthorized" }), {
52
+ status: 401,
53
+ headers: { "Content-Type": "application/json" }
54
+ });
55
+ }
56
+ return handler(request);
57
+ };
58
+ }
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ adminMiddleware,
62
+ auth,
63
+ createAuthConfig
64
+ });
65
+ //# sourceMappingURL=auth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth/index.ts","../src/auth/config.ts","../src/auth/middleware.ts"],"sourcesContent":["export { createAuthConfig, auth } from \"./config.js\";\nexport { adminMiddleware } from \"./middleware.js\";\n\n","interface AuthConfigOptions {\n enabled: boolean;\n secret?: string;\n}\n\nexport function createAuthConfig(options: AuthConfigOptions) {\n return {\n ...options,\n providers: [\"credentials\"] as const,\n };\n}\n\nexport const auth = {\n providers: {\n credentials: {\n id: \"credentials\",\n name: \"Credentials\",\n },\n },\n} as const;\n","export function adminMiddleware(handler: (request: Request) => Promise<Response>) {\n return async (request: Request): Promise<Response> => {\n const sessionCookie = request.headers.get(\"cookie\") ?? \"\";\n const hasSession = sessionCookie.includes(\"next-auth.session-token\");\n\n if (!hasSession) {\n return new Response(JSON.stringify({ error: \"Unauthorized\" }), {\n status: 401,\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n\n return handler(request);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,SAAS,iBAAiB,SAA4B;AAC3D,SAAO;AAAA,IACL,GAAG;AAAA,IACH,WAAW,CAAC,aAAa;AAAA,EAC3B;AACF;AAEO,IAAM,OAAO;AAAA,EAClB,WAAW;AAAA,IACT,aAAa;AAAA,MACX,IAAI;AAAA,MACJ,MAAM;AAAA,IACR;AAAA,EACF;AACF;;;ACnBO,SAAS,gBAAgB,SAAkD;AAChF,SAAO,OAAO,YAAwC;AACpD,UAAM,gBAAgB,QAAQ,QAAQ,IAAI,QAAQ,KAAK;AACvD,UAAM,aAAa,cAAc,SAAS,yBAAyB;AAEnE,QAAI,CAAC,YAAY;AACf,aAAO,IAAI,SAAS,KAAK,UAAU,EAAE,OAAO,eAAe,CAAC,GAAG;AAAA,QAC7D,QAAQ;AAAA,QACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAChD,CAAC;AAAA,IACH;AAEA,WAAO,QAAQ,OAAO;AAAA,EACxB;AACF;","names":[]}
@@ -0,0 +1,21 @@
1
+ interface AuthConfigOptions {
2
+ enabled: boolean;
3
+ secret?: string;
4
+ }
5
+ declare function createAuthConfig(options: AuthConfigOptions): {
6
+ providers: readonly ["credentials"];
7
+ enabled: boolean;
8
+ secret?: string;
9
+ };
10
+ declare const auth: {
11
+ readonly providers: {
12
+ readonly credentials: {
13
+ readonly id: "credentials";
14
+ readonly name: "Credentials";
15
+ };
16
+ };
17
+ };
18
+
19
+ declare function adminMiddleware(handler: (request: Request) => Promise<Response>): (request: Request) => Promise<Response>;
20
+
21
+ export { adminMiddleware, auth, createAuthConfig };
package/dist/auth.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ interface AuthConfigOptions {
2
+ enabled: boolean;
3
+ secret?: string;
4
+ }
5
+ declare function createAuthConfig(options: AuthConfigOptions): {
6
+ providers: readonly ["credentials"];
7
+ enabled: boolean;
8
+ secret?: string;
9
+ };
10
+ declare const auth: {
11
+ readonly providers: {
12
+ readonly credentials: {
13
+ readonly id: "credentials";
14
+ readonly name: "Credentials";
15
+ };
16
+ };
17
+ };
18
+
19
+ declare function adminMiddleware(handler: (request: Request) => Promise<Response>): (request: Request) => Promise<Response>;
20
+
21
+ export { adminMiddleware, auth, createAuthConfig };