nextjs-cms-kit 0.5.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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +232 -0
  3. package/dist/commands/db-config.d.ts +3 -0
  4. package/dist/commands/db-config.d.ts.map +1 -0
  5. package/dist/commands/db-config.js +20 -0
  6. package/dist/commands/fix-master-admin.d.ts +3 -0
  7. package/dist/commands/fix-master-admin.d.ts.map +1 -0
  8. package/dist/commands/fix-master-admin.js +19 -0
  9. package/dist/commands/set-master-admin.d.ts +3 -0
  10. package/dist/commands/set-master-admin.d.ts.map +1 -0
  11. package/dist/commands/set-master-admin.js +29 -0
  12. package/dist/commands/setup.d.ts +3 -0
  13. package/dist/commands/setup.d.ts.map +1 -0
  14. package/dist/commands/setup.js +61 -0
  15. package/dist/commands/update-sections.d.ts +3 -0
  16. package/dist/commands/update-sections.d.ts.map +1 -0
  17. package/dist/commands/update-sections.js +33 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +38 -0
  21. package/dist/lib/actions.d.ts +7 -0
  22. package/dist/lib/actions.d.ts.map +1 -0
  23. package/dist/lib/actions.js +62 -0
  24. package/dist/lib/add-table-keys.d.ts +32 -0
  25. package/dist/lib/add-table-keys.d.ts.map +1 -0
  26. package/dist/lib/add-table-keys.js +168 -0
  27. package/dist/lib/db-config-setup.d.ts +4 -0
  28. package/dist/lib/db-config-setup.d.ts.map +1 -0
  29. package/dist/lib/db-config-setup.js +216 -0
  30. package/dist/lib/fix-master-admin.d.ts +2 -0
  31. package/dist/lib/fix-master-admin.d.ts.map +1 -0
  32. package/dist/lib/fix-master-admin.js +7 -0
  33. package/dist/lib/reload-env.d.ts +16 -0
  34. package/dist/lib/reload-env.d.ts.map +1 -0
  35. package/dist/lib/reload-env.js +42 -0
  36. package/dist/lib/schema-generator.d.ts +10 -0
  37. package/dist/lib/schema-generator.d.ts.map +1 -0
  38. package/dist/lib/schema-generator.js +168 -0
  39. package/dist/lib/set-master-admin.d.ts +2 -0
  40. package/dist/lib/set-master-admin.d.ts.map +1 -0
  41. package/dist/lib/set-master-admin.js +53 -0
  42. package/dist/lib/update-sections.d.ts +2 -0
  43. package/dist/lib/update-sections.d.ts.map +1 -0
  44. package/dist/lib/update-sections.js +898 -0
  45. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 nextjs-cms-kit
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.
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # nextjs-cms-kit
2
+
3
+ A CLI toolkit for managing and maintaining your NextJS CMS application. Provides commands for database setup, schema generation, admin management, and section updates.
4
+
5
+ ## Installation
6
+
7
+ Install globally or use via npx:
8
+
9
+ ```bash
10
+ # Global installation
11
+ npm install -g nextjs-cms-kit
12
+ # or
13
+ pnpm add -g nextjs-cms-kit
14
+ # or
15
+ yarn global add nextjs-cms-kit
16
+ # or
17
+ bun add -g nextjs-cms-kit
18
+
19
+ # Or use via npx (no installation needed)
20
+ npx nextjs-cms-kit <command>
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ nextjs-cms-kit [command] [options]
27
+ ```
28
+
29
+ ### Global Options
30
+
31
+ - `-d, --dev` - Use development environment file (`.env.development` instead of `.env`)
32
+
33
+ ## Commands
34
+
35
+ ### `setup`
36
+
37
+ Complete LZCMS setup wizard. This is the recommended way to set up a new CMS project.
38
+
39
+ ```bash
40
+ nextjs-cms-kit setup
41
+ nextjs-cms-kit setup --dev # Use development environment
42
+ ```
43
+
44
+ **What it does:**
45
+ 1. Configures database connection
46
+ 2. Generates database schema using Drizzle Kit
47
+ 3. Sets up master admin account
48
+ 4. Updates database tables based on sections
49
+
50
+ **Use this when:**
51
+ - Setting up a new CMS project
52
+ - First-time installation
53
+ - After cloning a project
54
+
55
+ ### `db-config`
56
+
57
+ Initialize or update LZCMS database configuration.
58
+
59
+ ```bash
60
+ nextjs-cms-kit db-config
61
+ nextjs-cms-kit db-config --dev
62
+ ```
63
+
64
+ **What it does:**
65
+ - Prompts for database connection details
66
+ - Creates or updates `.env` file with database configuration
67
+ - Validates database connection
68
+
69
+ **Use this when:**
70
+ - Setting up database connection for the first time
71
+ - Changing database credentials
72
+ - Moving to a different database server
73
+
74
+ ### `set-master-admin`
75
+
76
+ Set or update the master admin password.
77
+
78
+ ```bash
79
+ nextjs-cms-kit set-master-admin
80
+ nextjs-cms-kit set-master-admin --dev
81
+ ```
82
+
83
+ **What it does:**
84
+ - Prompts for new master admin password
85
+ - Updates the master admin user in the database
86
+ - Ensures master admin has proper privileges
87
+
88
+ **Use this when:**
89
+ - First-time admin setup
90
+ - Resetting forgotten admin password
91
+ - Changing admin password
92
+
93
+ ### `fix-master-admin`
94
+
95
+ Fix master admin privileges for all sections.
96
+
97
+ ```bash
98
+ nextjs-cms-kit fix-master-admin
99
+ nextjs-cms-kit fix-master-admin --dev
100
+ ```
101
+
102
+ **What it does:**
103
+ - Ensures master admin has full access to all sections
104
+ - Updates section permissions in the database
105
+ - Fixes any permission inconsistencies
106
+
107
+ **Use this when:**
108
+ - Master admin lost access to sections
109
+ - After restoring from backup
110
+ - After section structure changes
111
+
112
+ ### `update-sections`
113
+
114
+ Update database tables based on current section definitions and fix master admin privileges.
115
+
116
+ ```bash
117
+ nextjs-cms-kit update-sections
118
+ nextjs-cms-kit update-sections --dev
119
+ ```
120
+
121
+ **What it does:**
122
+ 1. Scans your sections folder
123
+ 2. Generates/updates database schema to match section definitions
124
+ 3. Adds new fields and tables as needed
125
+ 4. Updates master admin privileges
126
+
127
+ **Use this when:**
128
+ - After adding new sections
129
+ - After modifying section fields
130
+ - After pulling changes that include section updates
131
+ - When database schema is out of sync with sections
132
+
133
+ ## Environment Files
134
+
135
+ The toolkit supports different environment files:
136
+
137
+ - **Production (default)**: Uses `.env` file
138
+ - **Development**: Use `--dev` flag to use `.env.development` file
139
+
140
+ Example:
141
+ ```bash
142
+ # Uses .env
143
+ nextjs-cms-kit setup
144
+
145
+ # Uses .env.development
146
+ nextjs-cms-kit setup --dev
147
+ ```
148
+
149
+ ## Prerequisites
150
+
151
+ Before using the toolkit, ensure you have:
152
+
153
+ 1. **Database configured** - MySQL/MariaDB database server running
154
+ 2. **Environment file** - `.env` or `.env.development` with database connection details
155
+ 3. **Sections folder** - Your CMS sections defined in the configured sections folder
156
+ 4. **Drizzle config** - `drizzle.config.ts` file in your project root
157
+
158
+ ## Common Workflows
159
+
160
+ ### Initial Setup
161
+
162
+ ```bash
163
+ # 1. Configure database
164
+ nextjs-cms-kit db-config
165
+
166
+ # 2. Complete setup
167
+ nextjs-cms-kit setup
168
+
169
+ # 3. Set master admin password
170
+ nextjs-cms-kit set-master-admin
171
+ ```
172
+
173
+ ### After Adding New Sections
174
+
175
+ ```bash
176
+ # Update database to match new sections
177
+ nextjs-cms-kit update-sections
178
+ ```
179
+
180
+ ### After Pulling Changes
181
+
182
+ ```bash
183
+ # Update database schema and permissions
184
+ nextjs-cms-kit update-sections
185
+ ```
186
+
187
+ ### Resetting Admin Access
188
+
189
+ ```bash
190
+ # Fix admin privileges
191
+ nextjs-cms-kit fix-master-admin
192
+
193
+ # Or reset password
194
+ nextjs-cms-kit set-master-admin
195
+ ```
196
+
197
+ ## Configuration
198
+
199
+ The toolkit reads configuration from:
200
+
201
+ - **CMS Config**: `cms.config.ts` in your project root
202
+ - **Environment**: `.env` or `.env.development` files
203
+ - **Drizzle Config**: `drizzle.config.ts` for database migrations
204
+
205
+ Make sure these files are properly configured before running commands.
206
+
207
+ ## Troubleshooting
208
+
209
+ ### Database Connection Errors
210
+
211
+ If you see database connection errors:
212
+ 1. Verify database server is running
213
+ 2. Check `.env` file has correct credentials
214
+ 3. Run `nextjs-cms-kit db-config` to reconfigure
215
+
216
+ ### Schema Generation Fails
217
+
218
+ If schema generation fails:
219
+ 1. Check `drizzle.config.ts` is properly configured
220
+ 2. Ensure database connection is working
221
+ 3. Verify sections are valid (no syntax errors)
222
+
223
+ ### Permission Errors
224
+
225
+ If you encounter permission errors:
226
+ 1. Run `nextjs-cms-kit fix-master-admin` to restore permissions
227
+ 2. Verify master admin user exists in database
228
+ 3. Check section definitions are valid
229
+
230
+ ## License
231
+
232
+ MIT License - see LICENSE file for details.
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const dbConfigCommand: Command;
3
+ //# sourceMappingURL=db-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-config.d.ts","sourceRoot":"","sources":["../../src/commands/db-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,eAAO,MAAM,eAAe,SAYtB,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { Command } from 'commander';
2
+ // import { intro, outro } from '@clack/prompts'
3
+ import { dbConfigSetup } from '../lib/db-config-setup';
4
+ import chalk from 'chalk';
5
+ import { dbConnectionClose } from 'nextjs-cms/db/client';
6
+ export const dbConfigCommand = new Command('db-config')
7
+ .description('Initialize LZCMS database configuration')
8
+ .action(async () => {
9
+ try {
10
+ await dbConfigSetup({ dev: dbConfigCommand.parent?.opts().dev ? true : false });
11
+ }
12
+ catch (error) {
13
+ console.error(chalk.red('Error during initialization:'), error);
14
+ process.exit(1);
15
+ }
16
+ finally {
17
+ await dbConnectionClose();
18
+ process.exit(0);
19
+ }
20
+ });
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const fixMasterAdminCommand: Command;
3
+ //# sourceMappingURL=fix-master-admin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-master-admin.d.ts","sourceRoot":"","sources":["../../src/commands/fix-master-admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKnC,eAAO,MAAM,qBAAqB,SAY5B,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { Command } from 'commander';
2
+ import { fixMasterAdmin } from '../lib/fix-master-admin';
3
+ import { dbConnectionClose } from 'nextjs-cms/db/client';
4
+ import chalk from 'chalk';
5
+ export const fixMasterAdminCommand = new Command('fix-master-admin')
6
+ .description('Fix master admin privileges for all sections')
7
+ .action(async () => {
8
+ try {
9
+ await fixMasterAdmin();
10
+ }
11
+ catch (error) {
12
+ console.error(chalk.red('Error fixing master admin privileges:'), error);
13
+ process.exit(1);
14
+ }
15
+ finally {
16
+ await dbConnectionClose();
17
+ process.exit(0);
18
+ }
19
+ });
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const setMasterAdminCommand: Command;
3
+ //# sourceMappingURL=set-master-admin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-master-admin.d.ts","sourceRoot":"","sources":["../../src/commands/set-master-admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKnC,eAAO,MAAM,qBAAqB,SA0B5B,CAAA"}
@@ -0,0 +1,29 @@
1
+ import { Command } from 'commander';
2
+ import { setMasterAdmin } from '../lib/set-master-admin';
3
+ import { dbConnectionClose } from 'nextjs-cms/db/client';
4
+ import chalk from 'chalk';
5
+ export const setMasterAdminCommand = new Command('set-master-admin')
6
+ .description('Set or update master admin password')
7
+ .action(async () => {
8
+ try {
9
+ console.log(chalk.hex('#E8DCFF').bold(setMasterAdminCommand.parent?.name()));
10
+ console.log(setMasterAdminCommand.parent?.version());
11
+ console.log(setMasterAdminCommand.parent?.description());
12
+ console.log(chalk.gray('--------------------------'));
13
+ console.log(chalk.hex('#E8DCFF').bold(setMasterAdminCommand.name()));
14
+ console.log(setMasterAdminCommand.description());
15
+ console.log(chalk.gray('--------------------------'));
16
+ console.log(chalk.yellow(`Running in ${setMasterAdminCommand.parent?.opts().dev ? 'development' : 'production'} mode`));
17
+ console.log(chalk.gray('--------------------------'));
18
+ console.log(chalk.gray(`.......................................................`));
19
+ await setMasterAdmin();
20
+ }
21
+ catch (error) {
22
+ console.error(chalk.red('Error resetting master admin:'), error);
23
+ process.exit(1);
24
+ }
25
+ finally {
26
+ await dbConnectionClose();
27
+ process.exit(0);
28
+ }
29
+ });
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const setupCommand: Command;
3
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQnC,eAAO,MAAM,YAAY,SAyDvB,CAAA"}
@@ -0,0 +1,61 @@
1
+ import { Command } from 'commander';
2
+ import { note, intro, outro, spinner } from '@clack/prompts';
3
+ import { spawn } from 'child_process';
4
+ import { setMasterAdmin } from '../lib/set-master-admin';
5
+ import { dbConnectionClose } from 'nextjs-cms/db/client';
6
+ import chalk from 'chalk';
7
+ import { dbConfigSetup } from '../lib/db-config-setup';
8
+ export const setupCommand = new Command('setup').description('Complete LZCMS setup').action(async () => {
9
+ const s = spinner();
10
+ console.log(chalk.hex('#E8DCFF').bold(setupCommand.parent?.name()));
11
+ console.log(setupCommand.parent?.version());
12
+ console.log(setupCommand.parent?.description());
13
+ console.log(chalk.gray('--------------------------'));
14
+ console.log(chalk.hex('#E8DCFF').bold(setupCommand.name()));
15
+ console.log(setupCommand.description());
16
+ console.log(chalk.gray('--------------------------'));
17
+ console.log(chalk.yellow(`Running in ${setupCommand.parent?.opts().dev ? 'development' : 'production'} mode`));
18
+ console.log(chalk.gray('--------------------------'));
19
+ console.log(chalk.gray(`.......................................................`));
20
+ console.log();
21
+ intro('Setting up LZCMS... 🚀');
22
+ try {
23
+ note('Configuring database...');
24
+ await dbConfigSetup({ dev: setupCommand.parent?.opts().dev ? true : false });
25
+ note('Generating database schema...');
26
+ // Use spawn to properly handle streams and prevent hanging
27
+ await new Promise((resolve, reject) => {
28
+ const child = spawn('pnpm', ['drizzle-kit', 'push --force', '--config=drizzle.config.ts'], {
29
+ cwd: process.cwd(),
30
+ env: { ...process.env },
31
+ stdio: 'inherit', // Inherit stdio to prevent hanging and show output directly
32
+ shell: true,
33
+ });
34
+ child.on('close', (code) => {
35
+ if (code === 0) {
36
+ resolve();
37
+ }
38
+ else {
39
+ reject(new Error(`drizzle-kit push exited with code ${code}`));
40
+ }
41
+ });
42
+ child.on('error', (error) => {
43
+ reject(error);
44
+ });
45
+ });
46
+ s.message('Database schema generated');
47
+ note('Setting up master admin...');
48
+ await setMasterAdmin();
49
+ note('Master admin configured');
50
+ outro('LZCMS setup completed successfully! 🎉');
51
+ }
52
+ catch (error) {
53
+ s.stop('Setup failed');
54
+ console.error(chalk.red('Error during setup:'), error);
55
+ process.exit(1);
56
+ }
57
+ finally {
58
+ await dbConnectionClose();
59
+ process.exit(0);
60
+ }
61
+ });
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const updateSectionsCommand: Command;
3
+ //# sourceMappingURL=update-sections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../src/commands/update-sections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,eAAO,MAAM,qBAAqB,SA6B5B,CAAA"}
@@ -0,0 +1,33 @@
1
+ import { Command } from 'commander';
2
+ import { updateSections } from '../lib/update-sections';
3
+ import { fixMasterAdminPrivileges } from '../lib/actions';
4
+ import chalk from 'chalk';
5
+ import { dbConnectionClose } from 'nextjs-cms/db/client';
6
+ export const updateSectionsCommand = new Command('update-sections')
7
+ .description('Update database tables based on current sections and update master admin privileges')
8
+ .action(async (options) => {
9
+ try {
10
+ console.log(chalk.hex('#E8DCFF').bold(updateSectionsCommand.parent?.name()));
11
+ console.log(updateSectionsCommand.parent?.version());
12
+ console.log(updateSectionsCommand.parent?.description());
13
+ console.log(chalk.gray('--------------------------'));
14
+ console.log(chalk.hex('#E8DCFF').bold(updateSectionsCommand.name()));
15
+ console.log(updateSectionsCommand.description());
16
+ console.log(chalk.gray('--------------------------'));
17
+ console.log(chalk.yellow(`Running in ${updateSectionsCommand.parent?.opts().dev ? 'development' : 'production'} mode`));
18
+ console.log(chalk.gray('--------------------------'));
19
+ console.log(chalk.gray(`.......................................................`));
20
+ await updateSections(options.dev);
21
+ console.log(chalk.blue('Modifying master admin privileges...'));
22
+ await fixMasterAdminPrivileges();
23
+ console.log(chalk.green('Master admin privileges fixed.'));
24
+ }
25
+ catch (error) {
26
+ console.error(chalk.red('Error updating sections:'), error);
27
+ process.exit(1);
28
+ }
29
+ finally {
30
+ await dbConnectionClose();
31
+ process.exit(0);
32
+ }
33
+ });
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ declare const program: Command;
4
+ export default program;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAWnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAgC7B,eAAe,OAAO,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import chalk from 'chalk';
4
+ // import { intro, outro } from '@clack/prompts'
5
+ // Import command modules
6
+ import { dbConfigCommand } from './commands/db-config';
7
+ import { setupCommand } from './commands/setup';
8
+ import { setMasterAdminCommand } from './commands/set-master-admin';
9
+ import { fixMasterAdminCommand } from './commands/fix-master-admin';
10
+ import { updateSectionsCommand } from './commands/update-sections';
11
+ const program = new Command();
12
+ program
13
+ .name('lzcms-kit')
14
+ .description(chalk.green('LZCMS CLI toolkit for managing your LZCMS application'))
15
+ .version('0.4.0')
16
+ .option('-d, --dev', 'Use development environment file')
17
+ .action(() => {
18
+ console.log(chalk.hex('#E8DCFF').bold(program.name()));
19
+ console.log(program.version());
20
+ console.log(program.description());
21
+ console.log(chalk.gray('--------------------------'));
22
+ console.log(chalk.yellow(`Running in ${process.env.NODE_ENV} mode`));
23
+ console.log(chalk.gray('--------------------------'));
24
+ });
25
+ program.addCommand(setupCommand);
26
+ program.addCommand(dbConfigCommand);
27
+ program.addCommand(setMasterAdminCommand);
28
+ program.addCommand(fixMasterAdminCommand);
29
+ program.addCommand(updateSectionsCommand);
30
+ // Handle unknown commands
31
+ program.on('command:*', (operands) => {
32
+ console.error(chalk.red(`Unknown command: ${operands[0]}`));
33
+ console.log(chalk.gray('Run lzcms-kit --help to see available commands'));
34
+ process.exit(1);
35
+ });
36
+ // Parse arguments
37
+ // program.parse()
38
+ export default program;
@@ -0,0 +1,7 @@
1
+ export declare function fixMasterAdminPrivileges(): Promise<void>;
2
+ export declare function getMasterAdmin(): Promise<{
3
+ id: string;
4
+ user: string;
5
+ } | null | undefined>;
6
+ export declare function setMaterAdmin(password: string): Promise<void>;
7
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/lib/actions.ts"],"names":[],"mappings":"AAMA,wBAAsB,wBAAwB,kBAyB7C;AAED,wBAAsB,cAAc;;;sBAWnC;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,iBAoBnD"}
@@ -0,0 +1,62 @@
1
+ import { SectionFactory } from 'nextjs-cms/core/factories';
2
+ import { db } from 'nextjs-cms/db/client';
3
+ import { AdminPrivilegesTable, AdminsTable } from 'nextjs-cms/db/schema';
4
+ import { eq, and } from 'drizzle-orm';
5
+ import bcrypt from 'bcrypt';
6
+ export async function fixMasterAdminPrivileges() {
7
+ // Let's also add privileges for all the sections to the master admin
8
+ // Loop through the sections to get the section ids for the insertion into the admin_privileges table
9
+ const sections = await SectionFactory.getSections();
10
+ const rows = sections.map((section) => ({
11
+ adminId: '1',
12
+ sectionName: section.name,
13
+ operations: 'CUD',
14
+ publisher: '1',
15
+ }));
16
+ if (rows.length === 0)
17
+ return;
18
+ await db
19
+ .insert(AdminPrivilegesTable)
20
+ .values(rows)
21
+ .onDuplicateKeyUpdate({
22
+ set: {
23
+ operations: 'CUD',
24
+ publisher: true,
25
+ },
26
+ });
27
+ console.log('Master admin privileges are set');
28
+ return;
29
+ }
30
+ export async function getMasterAdmin() {
31
+ const masterAdmin = await db
32
+ .select({
33
+ id: AdminsTable.id,
34
+ user: AdminsTable.user,
35
+ })
36
+ .from(AdminsTable)
37
+ .where(and(eq(AdminsTable.id, '1'), eq(AdminsTable.user, 'Master')));
38
+ if (masterAdmin.length === 0)
39
+ return null;
40
+ return masterAdmin[0];
41
+ }
42
+ export async function setMaterAdmin(password) {
43
+ try {
44
+ const hashedPassword = await bcrypt.hash(password, 10);
45
+ await db
46
+ .insert(AdminsTable)
47
+ .values({
48
+ id: '1', // Master admin id is always 1
49
+ pass: hashedPassword,
50
+ user: 'Master',
51
+ })
52
+ .onDuplicateKeyUpdate({
53
+ set: {
54
+ pass: hashedPassword,
55
+ },
56
+ });
57
+ return;
58
+ }
59
+ catch (err) {
60
+ console.log('Error creating master admin', err);
61
+ }
62
+ }
@@ -0,0 +1,32 @@
1
+ import type { FieldConfig } from 'nextjs-cms/core/fields';
2
+ export declare function addTableKeys(table: {
3
+ name: string;
4
+ primaryKey: FieldConfig[];
5
+ index?: {
6
+ name?: string;
7
+ columns: FieldConfig[];
8
+ }[];
9
+ unique?: {
10
+ name?: string;
11
+ columns: FieldConfig[];
12
+ }[];
13
+ fulltext?: {
14
+ name?: string;
15
+ columns: FieldConfig[];
16
+ }[];
17
+ }, existingKeys?: {
18
+ primaryKeys: string[];
19
+ uniqueKeys: {
20
+ name: string;
21
+ columns: string[];
22
+ }[];
23
+ indexKeys: {
24
+ name: string;
25
+ columns: string[];
26
+ }[];
27
+ fullTextKeys: {
28
+ name: string;
29
+ columns: string[];
30
+ }[];
31
+ }): Promise<number>;
32
+ //# sourceMappingURL=add-table-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-table-keys.d.ts","sourceRoot":"","sources":["../../src/lib/add-table-keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAIzD,wBAAsB,YAAY,CAC9B,KAAK,EAAE;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,WAAW,EAAE,CAAA;IACzB,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,EAAE,CAAA;KAAE,EAAE,CAAA;IACnD,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,EAAE,CAAA;KAAE,EAAE,CAAA;IACpD,QAAQ,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,EAAE,CAAA;KAAE,EAAE,CAAA;CACzD,EACD,YAAY,CAAC,EAAE;IACX,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IACjD,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IAChD,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;CACtD,mBA6OJ"}