zyket 1.2.6 → 1.2.8

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/bin/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  const prompts = require('prompts');
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const { spawn } = require('child_process');
5
6
  const TemplateManager = require('../src/services/template-manager');
6
7
  const EnvManager = require('../src/utils/EnvManager');
7
8
  const templateManager = new TemplateManager();
@@ -63,11 +64,44 @@ const templateManager = new TemplateManager();
63
64
  console.log('[ZYKET] Creating .env file...');
64
65
  EnvManager.createEnvFile(envPath);
65
66
 
67
+ // Install default backend template files (src and config)
68
+ console.log('[ZYKET] Installing default backend template files...');
69
+ const defaultTemplate = templateManager.getTemplate('default');
70
+ const backendFiles = defaultTemplate.filter(file => {
71
+ const route = file.route;
72
+ // Only install src and config files, not frontend
73
+ // Skip guards and handlers folders since socket is disabled by default
74
+ return (route.startsWith('default/src/') || route.startsWith('default/config/'))
75
+ && !route.startsWith('default/src/guards/')
76
+ && !route.startsWith('default/src/handlers/');
77
+ });
78
+
79
+ for (const file of backendFiles) {
80
+ const fileName = file.route.split('/').slice(1).join('/');
81
+ const fileLocation = path.join(process.cwd(), fileName);
82
+ const folderLocation = path.dirname(fileLocation);
83
+
84
+ // Create directory if it doesn't exist
85
+ if (!fs.existsSync(folderLocation)) {
86
+ fs.mkdirSync(folderLocation, { recursive: true });
87
+ }
88
+
89
+ // Write file if it doesn't exist
90
+ if (!fs.existsSync(fileLocation)) {
91
+ fs.writeFileSync(fileLocation, file.content);
92
+ }
93
+ }
94
+ console.log('[ZYKET] ✅ Backend template files installed');
95
+
66
96
  // Create index.js with boilerplate code
67
97
  console.log('[ZYKET] Creating index.js...');
68
98
  const indexContent = `const { Kernel } = require('zyket');
69
99
 
70
- const kernel = new Kernel();
100
+ const kernel = new Kernel({
101
+ services: [
102
+ ['auth', require('./src/services/auth'), ["@service_container"]],
103
+ ]
104
+ });
71
105
 
72
106
  kernel.boot().then(() => {
73
107
  console.log('Kernel booted successfully!');
@@ -99,11 +133,41 @@ kernel.boot().then(() => {
99
133
  }
100
134
 
101
135
  console.log('\n[ZYKET] ✅ Project initialized successfully!');
102
- console.log('\n[ZYKET] Next steps:');
103
- console.log(' 1. Review and update your .env file');
104
- console.log(' 2. Run: npm install (if you haven\'t already)');
105
- console.log(' 3. Run: npm run dev');
106
- console.log('\n[ZYKET] Happy coding! 🚀\n');
136
+
137
+ // Install dependencies automatically
138
+ console.log('\n[ZYKET] Installing dependencies...');
139
+ await new Promise((resolve, reject) => {
140
+ const npmInstall = spawn('npm', ['install'], {
141
+ cwd: process.cwd(),
142
+ stdio: 'inherit',
143
+ shell: true
144
+ });
145
+
146
+ npmInstall.on('close', (code) => {
147
+ if (code === 0) {
148
+ console.log('\n[ZYKET] ✅ Dependencies installed successfully!');
149
+ resolve();
150
+ } else {
151
+ reject(new Error(`npm install exited with code ${code}`));
152
+ }
153
+ });
154
+
155
+ npmInstall.on('error', (error) => {
156
+ reject(error);
157
+ });
158
+ });
159
+
160
+ // Start the project automatically
161
+ console.log('\n[ZYKET] Starting project...\n');
162
+ const nodeStart = spawn('node', ['index.js'], {
163
+ cwd: process.cwd(),
164
+ stdio: 'inherit',
165
+ shell: true
166
+ });
167
+
168
+ nodeStart.on('error', (error) => {
169
+ console.error('[ZYKET] Error starting project:', error);
170
+ });
107
171
  },
108
172
  'install-template': async () => {
109
173
  const templates = templateManager.getTemplates();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zyket",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -3,36 +3,93 @@ const { createClient } = require("redis");
3
3
 
4
4
  module.exports = class Cache extends Service {
5
5
  #container;
6
- client;
6
+ #client;
7
+ #useRedis;
8
+ #memoryCache;
9
+ #expirations;
7
10
 
8
11
  constructor(container, url) {
9
12
  super("cache");
10
13
  this.#container = container;
11
- this.client = createClient({ url });
14
+ this.#useRedis = !!url && url !== '';
15
+
16
+ if (this.#useRedis) {
17
+ this.#client = createClient({ url });
18
+ } else {
19
+ // Use in-memory cache
20
+ this.#memoryCache = new Map();
21
+ this.#expirations = new Map();
22
+ }
12
23
  }
13
24
 
14
25
  async boot() {
15
- await this.client.connect();
26
+ if (this.#useRedis) {
27
+ await this.#client.connect();
28
+ this.#container.get('logger').info('Cache service using Redis');
29
+ } else {
30
+ this.#container.get('logger').info('Cache service using in-memory cache');
31
+ }
16
32
  }
17
33
 
18
34
  async set(key, value) {
19
- return await this.client.set(key, value);
20
-
35
+ if (this.#useRedis) {
36
+ return await this.#client.set(key, value);
37
+ } else {
38
+ this.#memoryCache.set(key, value);
39
+ return 'OK';
40
+ }
21
41
  }
22
42
 
23
43
  async get(key) {
24
- return await this.client.get(key);
44
+ if (this.#useRedis) {
45
+ return await this.#client.get(key);
46
+ } else {
47
+ // Check if the key has expired
48
+ if (this.#expirations.has(key)) {
49
+ const expireTime = this.#expirations.get(key);
50
+ if (Date.now() > expireTime) {
51
+ this.#memoryCache.delete(key);
52
+ this.#expirations.delete(key);
53
+ return null;
54
+ }
55
+ }
56
+ return this.#memoryCache.get(key) || null;
57
+ }
25
58
  }
26
59
 
27
60
  async del(key) {
28
- return await this.client.del(key);
61
+ if (this.#useRedis) {
62
+ return await this.#client.del(key);
63
+ } else {
64
+ this.#expirations.delete(key);
65
+ return this.#memoryCache.delete(key) ? 1 : 0;
66
+ }
29
67
  }
30
68
 
31
69
  async keys(pattern) {
32
- return await this.client.keys(pattern);
70
+ if (this.#useRedis) {
71
+ return await this.#client.keys(pattern);
72
+ } else {
73
+ // Simple pattern matching for memory cache
74
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
75
+ return Array.from(this.#memoryCache.keys()).filter(key => regex.test(key));
76
+ }
33
77
  }
34
78
 
35
79
  async expire(key, seconds) {
36
- return await this.client.expire(key, seconds);
80
+ if (this.#useRedis) {
81
+ return await this.#client.expire(key, seconds);
82
+ } else {
83
+ if (this.#memoryCache.has(key)) {
84
+ const expireTime = Date.now() + (seconds * 1000);
85
+ this.#expirations.set(key, expireTime);
86
+ return 1;
87
+ }
88
+ return 0;
89
+ }
90
+ }
91
+
92
+ get client() {
93
+ return this.#useRedis ? this.#client : null;
37
94
  }
38
95
  }
@@ -0,0 +1,8 @@
1
+ const AuthService = require('./index.js');
2
+
3
+ const auth = new AuthService({
4
+ get: (serviceName) => {
5
+ }
6
+ });
7
+
8
+ module.exports = auth.auth;
@@ -0,0 +1,33 @@
1
+ const { AuthService } = require('zyket');
2
+
3
+ module.exports = class CustomAuthService extends AuthService {
4
+ #container;
5
+ client;
6
+
7
+ constructor(container) {
8
+ super(container);
9
+ this.#container = container;
10
+ }
11
+
12
+ get userAdditionalFields() {
13
+ }
14
+
15
+ get organizationAdditionalFields() {
16
+ }
17
+
18
+ async sendResetPasswordEmail({ user, url, token }, request) {
19
+ throw new Error("sendResetPasswordEmail method not implemented");
20
+ }
21
+
22
+ async sendVerificationEmail({ user, url, token }, request) {
23
+ throw new Error("sendVerificationEmail method not implemented");
24
+ }
25
+
26
+ async sendInvitationEmail(data) {
27
+ throw new Error("sendInvitationEmail method not implemented");
28
+ }
29
+
30
+ async allowUserToCreateOrganization(user) {
31
+ throw new Error("allowUserToCreateOrganization method not implemented");
32
+ }
33
+ }
@@ -12,6 +12,10 @@ module.exports = class EnvManager {
12
12
  }
13
13
 
14
14
  static getDefaultSecrets() {
15
+ const header = `# Zyket Environment Configuration
16
+ # Leave CACHE_URL empty to use in-memory cache, or set to redis://localhost:6379 for Redis
17
+
18
+ `;
15
19
  const envsToCreate = {
16
20
  DEBUG: true,
17
21
  PORT: 3000,
@@ -35,7 +39,7 @@ module.exports = class EnvManager {
35
39
  DISABLE_VITE: true,
36
40
  }
37
41
 
38
- return Object.entries(envsToCreate).reduce((acc, [key, value]) => {
42
+ return header + Object.entries(envsToCreate).reduce((acc, [key, value]) => {
39
43
  return `${acc}${key}=${value}\n`;
40
44
  }, "");
41
45
  }