zyket 1.2.3 → 1.2.5

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/README.md CHANGED
@@ -6,7 +6,37 @@ Upon initial boot, Zyket automatically scaffolds a default project structure, in
6
6
 
7
7
  ## Getting Started
8
8
 
9
- To begin using Zyket, install it in your project:
9
+ ### Quick Start (Recommended)
10
+
11
+ The easiest way to get started with Zyket is to use the CLI initialization command:
12
+
13
+ ```bash
14
+ # Create a new directory for your project
15
+ mkdir my-zyket-app
16
+ cd my-zyket-app
17
+
18
+ # Install zyket
19
+ npm install zyket
20
+
21
+ # Initialize the project
22
+ npx zyket init
23
+
24
+ # Install dependencies (if not already done)
25
+ npm install
26
+
27
+ # Start your application
28
+ npm run dev
29
+ ```
30
+
31
+ The `init` command will:
32
+ - Create an `index.js` file with the kernel boilerplate
33
+ - Generate a `.env` file with sensible defaults
34
+ - Create a `package.json` if one doesn't exist
35
+ - Set up your project ready to run
36
+
37
+ ### Manual Setup (Alternative)
38
+
39
+ If you prefer to set up manually, install Zyket in your project:
10
40
 
11
41
  ```bash
12
42
  npm i zyket
package/bin/cli.js CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  const prompts = require('prompts');
3
+ const fs = require('fs');
4
+ const path = require('path');
3
5
  const TemplateManager = require('../src/services/template-manager');
6
+ const EnvManager = require('../src/utils/EnvManager');
4
7
  const templateManager = new TemplateManager();
5
8
 
6
9
  (async () => {
@@ -11,6 +14,7 @@ const templateManager = new TemplateManager();
11
14
  name: 'value',
12
15
  message: '[ZYKET] What do you want to do?',
13
16
  choices: [
17
+ { title: 'Initialize Project', value: 'init-project', description: 'Set up a new Zyket project', disabled: false },
14
18
  { title: 'Install Template', value: 'install-template', description: 'Install a new template', disabled: false },
15
19
  /*{ title: 'Remove Template', value: 'remove-template', description: 'Remove an existing template', disabled: false },*/
16
20
  ],
@@ -18,6 +22,71 @@ const templateManager = new TemplateManager();
18
22
  });
19
23
 
20
24
  const actions = {
25
+ 'init-project': async () => {
26
+ const indexPath = path.join(process.cwd(), 'index.js');
27
+ const envPath = path.join(process.cwd(), '.env');
28
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
29
+
30
+ // Check if index.js already exists
31
+ if (fs.existsSync(indexPath)) {
32
+ const overwrite = await prompts({
33
+ type: 'confirm',
34
+ name: 'value',
35
+ message: '[ZYKET] index.js already exists. Overwrite?',
36
+ initial: false
37
+ });
38
+ if (!overwrite.value) {
39
+ console.log('[ZYKET] Initialization cancelled.');
40
+ return;
41
+ }
42
+ }
43
+
44
+ // Create .env file
45
+ console.log('[ZYKET] Creating .env file...');
46
+ EnvManager.createEnvFile(envPath);
47
+
48
+ // Create index.js with boilerplate code
49
+ console.log('[ZYKET] Creating index.js...');
50
+ const indexContent = `const { Kernel } = require('zyket');
51
+
52
+ const kernel = new Kernel();
53
+
54
+ kernel.boot().then(() => {
55
+ console.log('Kernel booted successfully!');
56
+ }).catch((error) => {
57
+ console.error('Error booting kernel:', error);
58
+ });
59
+ `;
60
+ fs.writeFileSync(indexPath, indexContent);
61
+
62
+ // Create package.json if it doesn't exist
63
+ if (!fs.existsSync(packageJsonPath)) {
64
+ console.log('[ZYKET] Creating package.json...');
65
+ const packageJson = {
66
+ name: path.basename(process.cwd()),
67
+ version: "1.0.0",
68
+ description: "Zyket application",
69
+ main: "index.js",
70
+ scripts: {
71
+ dev: "node index.js"
72
+ },
73
+ keywords: [],
74
+ author: "",
75
+ license: "ISC",
76
+ dependencies: {
77
+ zyket: "^1.2.3"
78
+ }
79
+ };
80
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
81
+ }
82
+
83
+ console.log('\n[ZYKET] ✅ Project initialized successfully!');
84
+ console.log('\n[ZYKET] Next steps:');
85
+ console.log(' 1. Review and update your .env file');
86
+ console.log(' 2. Run: npm install (if you haven\'t already)');
87
+ console.log(' 3. Run: npm run dev');
88
+ console.log('\n[ZYKET] Happy coding! 🚀\n');
89
+ },
21
90
  'install-template': async () => {
22
91
  const templates = templateManager.getTemplates();
23
92
  const response = await prompts({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zyket",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -3,6 +3,7 @@ const { toNodeHandler } = require('better-auth/node');
3
3
  const { betterAuth } = require("better-auth");
4
4
  const { admin, bearer, organization } = require("better-auth/plugins");
5
5
  const { Pool } = require("pg");
6
+ const path = require("path");
6
7
 
7
8
  module.exports = class AuthService extends Service {
8
9
  #container;
@@ -14,12 +15,46 @@ module.exports = class AuthService extends Service {
14
15
  }
15
16
 
16
17
  async boot() {
17
- if(process.env.DATABASE_DIALECT !== 'postgresql') throw new Error("AuthService only supports PostgreSQL as database dialect");
18
+ if (!['postgresql', 'sqlite'].includes(process.env.DATABASE_DIALECT)) {
19
+ throw new Error("AuthService only supports PostgreSQL and SQLite as database dialects");
20
+ }
21
+ this.#addAuthEnvVariables();
18
22
  this.client = this.auth;
19
23
  const express = this.#container.get('express');
20
24
  express.regiterRawAllRoutes("/api/auth/*splat", toNodeHandler(this.auth));
21
25
  }
22
26
 
27
+ #addAuthEnvVariables() {
28
+ const EnvManager = require('../../utils/EnvManager');
29
+ const envPath = path.join(process.cwd(), '.env');
30
+
31
+ const secretAdded = EnvManager.addEnvVariable(envPath, 'AUTH_SECRET', 'change-this-secret-in-production');
32
+ if (secretAdded) {
33
+ this.#container.get('logger').info('Added AUTH_SECRET to .env file');
34
+ }
35
+
36
+ const originsAdded = EnvManager.addEnvVariable(envPath, 'TRUSTED_ORIGINS', 'http://localhost:5173,http://localhost:3000');
37
+ if (originsAdded) {
38
+ this.#container.get('logger').info('Added TRUSTED_ORIGINS to .env file');
39
+ }
40
+ }
41
+
42
+ #getDatabaseConnection() {
43
+ const dialect = process.env.DATABASE_DIALECT;
44
+
45
+ if (dialect === 'sqlite') {
46
+ const Database = require('better-sqlite3');
47
+ const dbPath = process.env.DATABASE_URL || path.join(process.cwd(), 'database.sqlite');
48
+ return new Database(dbPath);
49
+ } else if (dialect === 'postgresql') {
50
+ return new Pool({
51
+ connectionString: process.env.DATABASE_URL || null,
52
+ });
53
+ }
54
+
55
+ throw new Error(`Unsupported database dialect: ${dialect}`);
56
+ }
57
+
23
58
  get plugins() {
24
59
  return [];
25
60
  }
@@ -86,9 +121,7 @@ module.exports = class AuthService extends Service {
86
121
  ...this.plugins,
87
122
  ],
88
123
  socialProviders: this.socialProviders,
89
- database: new Pool({
90
- connectionString: process.env.DATABASE_URL || null,
91
- }),
124
+ database: this.#getDatabaseConnection(),
92
125
  advanced: {
93
126
  crossSubDomainCookies: {
94
127
  enabled: true,
@@ -20,8 +20,8 @@ module.exports = class EnvManager {
20
20
  DISABLE_EVENTS: true,
21
21
  DISABLE_BULLMQ: true,
22
22
  DISABLE_SCHEDULER: true,
23
- DATABASE_URL: '',
24
- DATABASE_DIALECT: 'mariadb',
23
+ DATABASE_URL: './database.sqlite',
24
+ DATABASE_DIALECT: 'sqlite',
25
25
  CACHE_URL: '',
26
26
  S3_ENDPOINT: '',
27
27
  S3_PORT: '',