create-astratra-app 1.10.0 → 1.11.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/package.json +1 -1
- package/src/bricks.js +1 -1
- package/src/createProject.js +43 -19
package/package.json
CHANGED
package/src/bricks.js
CHANGED
|
@@ -220,7 +220,7 @@ export const erasure = createErasureWorkflow({
|
|
|
220
220
|
|
|
221
221
|
resilience: {
|
|
222
222
|
package: '@astratra/resilience',
|
|
223
|
-
version: '^1.
|
|
223
|
+
version: '^1.1.0',
|
|
224
224
|
summary: 'disjoncteur, cache TTL, relance avec brouillage',
|
|
225
225
|
file: 'api/bricks/resilience.js',
|
|
226
226
|
contents: () => `import { createCache, createCircuitBreaker, retry } from '@astratra/resilience';
|
package/src/createProject.js
CHANGED
|
@@ -68,10 +68,10 @@ function assertCanCreate(targetDir, force) {
|
|
|
68
68
|
|
|
69
69
|
function packageJson(projectName, template, bricks = []) {
|
|
70
70
|
const dependencies = {
|
|
71
|
-
'@astratra/ai': '^1.
|
|
71
|
+
'@astratra/ai': '^1.10.0',
|
|
72
72
|
'@astratra/core': '^1.1.0',
|
|
73
|
-
'@astratra/saas-kit': '^
|
|
74
|
-
'@astratra/security': '^1.
|
|
73
|
+
'@astratra/saas-kit': '^2.0.0',
|
|
74
|
+
'@astratra/security': '^1.12.1'
|
|
75
75
|
};
|
|
76
76
|
// Scaffolded (api/stores/mongo.js, api/db/mongo.js) but not wired into
|
|
77
77
|
// api/server.js by default — the project starts on the in-memory store.
|
|
@@ -85,7 +85,7 @@ function packageJson(projectName, template, bricks = []) {
|
|
|
85
85
|
const devDependencies = {};
|
|
86
86
|
|
|
87
87
|
if (template === 'fullstack') {
|
|
88
|
-
dependencies['@astratra/saas-kit-ui'] = '^1.
|
|
88
|
+
dependencies['@astratra/saas-kit-ui'] = '^1.4.0';
|
|
89
89
|
dependencies.react = '^19.0.0';
|
|
90
90
|
dependencies['react-dom'] = '^19.0.0';
|
|
91
91
|
devDependencies['@vitejs/plugin-react'] = '^4.3.4';
|
|
@@ -118,6 +118,7 @@ function apiServer() {
|
|
|
118
118
|
return `import fs from 'node:fs';
|
|
119
119
|
import path from 'node:path';
|
|
120
120
|
import saasKit from '@astratra/saas-kit';
|
|
121
|
+
import security from '@astratra/security';
|
|
121
122
|
import { env } from './config/env.js';
|
|
122
123
|
import { createAuthSecurity } from './security/auth.js';
|
|
123
124
|
import { createRateLimitSecurity } from './security/rateLimit.js';
|
|
@@ -128,9 +129,10 @@ import { createNotificationModule } from './modules/notifications.js';
|
|
|
128
129
|
import { createAiTools } from './ai/tools.js';
|
|
129
130
|
|
|
130
131
|
const { createSaasApp } = saasKit;
|
|
132
|
+
const { verifyPasswordHash } = security;
|
|
131
133
|
const preferredPort = env.port;
|
|
132
134
|
const host = env.host;
|
|
133
|
-
const stores = createMemoryStores();
|
|
135
|
+
const stores = await createMemoryStores();
|
|
134
136
|
const notifications = createNotificationModule();
|
|
135
137
|
const aiTools = createAiTools();
|
|
136
138
|
|
|
@@ -146,7 +148,9 @@ const app = createSaasApp({
|
|
|
146
148
|
usersStore: stores.usersStore,
|
|
147
149
|
settingsStore: stores.settingsStore,
|
|
148
150
|
publicUserFields: userPublicFields(),
|
|
149
|
-
|
|
151
|
+
// Passwords are only ever stored as scrypt hashes (hashPassword) and checked
|
|
152
|
+
// in constant time — never compared in clear.
|
|
153
|
+
verifyPassword: async (user, password) => verifyPasswordHash(password, user.passwordHash),
|
|
150
154
|
notify: notifications.notify,
|
|
151
155
|
// This is where YOUR routes go — not app.use()'d after createSaasApp()
|
|
152
156
|
// returns. createSaasApp() ends its own middleware stack with a
|
|
@@ -180,8 +184,8 @@ function listen(port, attemptsLeft = 20) {
|
|
|
180
184
|
const selectedPort = typeof address === 'object' && address ? address.port : port;
|
|
181
185
|
writeApiRuntimeConfig(selectedPort);
|
|
182
186
|
console.log(\`Astratra API listening on http://\${host}:\${selectedPort}\`);
|
|
183
|
-
|
|
184
|
-
console.log(
|
|
187
|
+
// Development only: a random password drawn at each start (or DEMO_PASSWORD), never a fixed one.
|
|
188
|
+
console.log(\`Demo accounts (development only): owner@example.test and member@example.test, password: \${stores.demoPassword}\`);
|
|
185
189
|
});
|
|
186
190
|
|
|
187
191
|
server.on('error', (error) => {
|
|
@@ -280,14 +284,33 @@ function securityWaf() {
|
|
|
280
284
|
}
|
|
281
285
|
|
|
282
286
|
function memoryStores() {
|
|
283
|
-
return `import
|
|
287
|
+
return `import crypto from 'node:crypto';
|
|
288
|
+
import saasKit from '@astratra/saas-kit';
|
|
289
|
+
import security from '@astratra/security';
|
|
284
290
|
import { defaultSettings } from '../modules/settings.js';
|
|
285
291
|
|
|
286
292
|
const { createMemorySettingsStore, createMemoryUsersStore } = saasKit;
|
|
287
|
-
|
|
288
|
-
|
|
293
|
+
const { hashPassword } = security;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* In-memory stores for local development. The two demo accounts get a random
|
|
297
|
+
* password at each start (or DEMO_PASSWORD from .env), stored only as a scrypt
|
|
298
|
+
* hash. Refused in production: plug real stores before going live.
|
|
299
|
+
*/
|
|
300
|
+
export async function createMemoryStores() {
|
|
301
|
+
if (process.env.NODE_ENV === 'production') {
|
|
302
|
+
throw new Error('In-memory stores and demo accounts are for development only: plug real stores in production.');
|
|
303
|
+
}
|
|
304
|
+
const demoPassword = process.env.DEMO_PASSWORD || crypto.randomBytes(9).toString('base64url') /* 12 characters */;
|
|
305
|
+
const passwordHash = await hashPassword(demoPassword);
|
|
289
306
|
return {
|
|
290
|
-
|
|
307
|
+
demoPassword,
|
|
308
|
+
usersStore: createMemoryUsersStore({
|
|
309
|
+
users: [
|
|
310
|
+
{ id: 'user-owner', email: 'owner@example.test', role: 'owner', passwordHash },
|
|
311
|
+
{ id: 'user-member', email: 'member@example.test', role: 'member', passwordHash }
|
|
312
|
+
]
|
|
313
|
+
}),
|
|
291
314
|
settingsStore: createMemorySettingsStore(defaultSettings)
|
|
292
315
|
};
|
|
293
316
|
}
|
|
@@ -626,13 +649,14 @@ plus \`127.0.0.1\`/\`localhost\` autorisés automatiquement hors production).
|
|
|
626
649
|
- \`api/modules/users.js\`, \`api/modules/settings.js\` et
|
|
627
650
|
\`api/modules/notifications.js\` isolent la logique métier de départ.
|
|
628
651
|
|
|
629
|
-
Comptes de test
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
652
|
+
Comptes de démonstration (développement seulement) : \`owner@example.test\` et
|
|
653
|
+
\`member@example.test\`. Leur mot de passe est tiré au hasard à chaque démarrage
|
|
654
|
+
et affiché dans la console de l'API (ou fixé par \`DEMO_PASSWORD\` dans
|
|
655
|
+
\`.env\`). Il n'est gardé que sous forme d'empreinte scrypt (\`hashPassword\`),
|
|
656
|
+
et la connexion le vérifie avec \`verifyPasswordHash\`, jamais en clair.
|
|
633
657
|
|
|
634
|
-
Avant la production, remplace \`JWT_SECRET
|
|
635
|
-
|
|
658
|
+
Avant la production, remplace \`JWT_SECRET\` et branche de vrais stores : les
|
|
659
|
+
stores en mémoire refusent de démarrer avec \`NODE_ENV=production\`. Définis aussi \`JWT_ISSUER\` et
|
|
636
660
|
\`JWT_AUDIENCE\` quand l'API sort du développement local.
|
|
637
661
|
`;
|
|
638
662
|
}
|
|
@@ -725,7 +749,7 @@ export function createProject({ targetDir, template = 'fullstack', force = false
|
|
|
725
749
|
writeFile(absoluteTarget, 'api/modules/settings.js', settingsModule());
|
|
726
750
|
writeFile(absoluteTarget, 'api/modules/notifications.js', notificationsModule());
|
|
727
751
|
writeFile(absoluteTarget, '.gitignore', 'node_modules\n.env\n.astratra\n');
|
|
728
|
-
writeFile(absoluteTarget, '.env.example', 'PORT=\nHOST=127.0.0.1\nJWT_SECRET=change-me\nLEGACY_JWT_SECRET=\nJWT_ISSUER=\nJWT_AUDIENCE=\nCORS_ORIGIN=\nMONGO_URI=\nREDIS_URL=\n');
|
|
752
|
+
writeFile(absoluteTarget, '.env.example', 'PORT=\nHOST=127.0.0.1\nJWT_SECRET=change-me\nLEGACY_JWT_SECRET=\nJWT_ISSUER=\nJWT_AUDIENCE=\nCORS_ORIGIN=\nMONGO_URI=\nREDIS_URL=\n# Développement seulement : mot de passe des comptes de démonstration (vide = tiré au hasard à chaque démarrage).\nDEMO_PASSWORD=\n');
|
|
729
753
|
writeFile(absoluteTarget, 'README.md', readme(projectName, template));
|
|
730
754
|
|
|
731
755
|
if (template === 'fullstack') {
|