@frozencrow/create-api 0.1.0 → 0.1.3

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/create-api.js CHANGED
@@ -81,15 +81,25 @@ async function main() {
81
81
  pkg.name = pkgName
82
82
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 4) + '\n')
83
83
 
84
- // 2. Generate a strong secret and a real .env from the example.
84
+ // 2. Personalize config/default.json (app name + database name).
85
+ const defaultConfigPath = path.join(targetDir, 'config', 'default.json')
86
+ if (fs.existsSync(defaultConfigPath)) {
87
+ const cfg = JSON.parse(fs.readFileSync(defaultConfigPath, 'utf8'))
88
+ cfg.appName = pkgName
89
+ cfg.mongodb = `mongodb://localhost:27017/${pkgName}`
90
+ fs.writeFileSync(defaultConfigPath, JSON.stringify(cfg, null, 4) + '\n')
91
+ }
92
+
93
+ // 3. Generate a strong secret into config/local.json (git-ignored). The config
94
+ // module (config/*.json) loads local.json last, so this overrides the default
95
+ // placeholder secret without committing it. In production, set AUTH_SECRET —
96
+ // it is mapped in config/custom-environment-variables.json.
85
97
  const secret = crypto.randomBytes(48).toString('base64url')
86
- const envExamplePath = path.join(targetDir, '.env.example')
87
- let env = fs.readFileSync(envExamplePath, 'utf8')
88
- env = env
89
- .replace(/^APP_NAME=.*$/m, `APP_NAME=${pkgName}`)
90
- .replace(/^AUTH_SECRET=.*$/m, `AUTH_SECRET=${secret}`)
91
- .replace(/mongodb:\/\/localhost:27017\/my-api/g, `mongodb://localhost:27017/${pkgName}`)
92
- fs.writeFileSync(path.join(targetDir, '.env'), env)
98
+ const localConfig = { authentication: { secret } }
99
+ fs.writeFileSync(
100
+ path.join(targetDir, 'config', 'local.json'),
101
+ JSON.stringify(localConfig, null, 4) + '\n'
102
+ )
93
103
 
94
104
  console.log(`
95
105
  Done! Next steps:
@@ -98,9 +108,9 @@ Done! Next steps:
98
108
  npm install
99
109
  npm run dev
100
110
 
101
- A strong AUTH_SECRET has been generated in .env. Point MONGODB_URI at your
102
- database, then add your own services under src/services (see src/services/widgets
103
- for the pattern).
111
+ A strong secret was written to config/local.json (git-ignored). Configure the
112
+ rest in config/default.json, then add your own services under src/services
113
+ (see src/services/widgets for the pattern, or run \`npx frozencrow g service\`).
104
114
  `)
105
115
  }
106
116
 
package/package.json CHANGED
@@ -1,9 +1,18 @@
1
1
  {
2
2
  "name": "@frozencrow/create-api",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Scaffold a new API project powered by @frozencrow/api-core",
5
5
  "license": "MIT",
6
6
  "author": "Eric Uldall",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Frozen-Crow/api-boilerplate.git",
10
+ "directory": "packages/create-api"
11
+ },
12
+ "homepage": "https://github.com/Frozen-Crow/api-boilerplate#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/Frozen-Crow/api-boilerplate/issues"
15
+ },
7
16
  "keywords": [
8
17
  "feathers",
9
18
  "scaffold",
@@ -2,3 +2,4 @@ node_modules
2
2
  lib
3
3
  .git
4
4
  .env
5
+ config/local.json
@@ -19,6 +19,7 @@ RUN npm ci --omit=dev
19
19
 
20
20
  COPY --from=builder /app/lib ./lib
21
21
  COPY --from=builder /app/public ./public
22
+ COPY --from=builder /app/config ./config
22
23
 
23
24
  EXPOSE 3030
24
25
 
@@ -7,20 +7,47 @@ authentication, RBAC, and multitenant (organization) access control out of the b
7
7
 
8
8
  ```bash
9
9
  npm install
10
- cp .env.example .env # then set a strong AUTH_SECRET
11
10
  npm run dev
12
11
  ```
13
12
 
14
13
  Requires a MongoDB instance (see `docker-compose.yml` for a local stack with
15
14
  MongoDB + smtp4dev).
16
15
 
16
+ ## Configuration
17
+
18
+ Configuration uses the Feathers config module (no `.env` files):
19
+
20
+ - `config/default.json` — app settings (name, port, origins, mongodb, auth, …).
21
+ - `config/local.json` — machine-local overrides, **git-ignored**. Your project
22
+ was scaffolded with a strong `authentication.secret` here.
23
+ - `config/test.json` — used when `NODE_ENV=test`.
24
+ - `config/custom-environment-variables.json` — maps env vars (`AUTH_SECRET`,
25
+ `MONGODB_URI`, `PORT`, …) onto config for production.
26
+
27
+ Generate a fresh secret any time with `npm run secret -- --write` (updates
28
+ `config/local.json`), or set `AUTH_SECRET` in the environment for production.
29
+
17
30
  ## Where things live
18
31
 
19
- - `src/app.ts` — builds the app with `createApp(...)` from `@frozencrow/api-core`
20
- and registers your own services.
32
+ - `src/app.ts` — builds the app with `createConfiguredApp()` from
33
+ `@frozencrow/api-core` and registers your own services.
21
34
  - `src/services/widgets/` — an example multitenant service. Copy this folder as
22
35
  the pattern for new resources: a `.schema.ts`, a `.class.ts`, and a registration
23
- file that calls `generateDefaultHooks({ schema })`.
36
+ file that calls `generateDefaultHooks({ schema })` — or run
37
+ `npx frozencrow g service <name>`.
38
+
39
+ ## Generate services with the CLI
40
+
41
+ The `frozencrow` CLI ships with `@frozencrow/api-core`, so you can scaffold that
42
+ pattern instead of writing it by hand:
43
+
44
+ ```bash
45
+ npx frozencrow generate service invoices --fields "amount:number,paid?:boolean" --wire
46
+ # shortcuts: npm run generate -- service invoices ... npm run secret
47
+ ```
48
+
49
+ See the [@frozencrow/api-core CLI docs](https://www.npmjs.com/package/@frozencrow/api-core#cli)
50
+ for all commands and options.
24
51
 
25
52
  ## What you get from the core
26
53
 
@@ -0,0 +1,15 @@
1
+ {
2
+ "port": "PORT",
3
+ "mongodb": "MONGODB_URI",
4
+ "clientHost": "CLIENT_HOST",
5
+ "authentication": {
6
+ "secret": "AUTH_SECRET"
7
+ },
8
+ "mail": {
9
+ "host": "MAIL_HOST",
10
+ "port": {
11
+ "__name": "MAIL_PORT",
12
+ "__format": "number"
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "appName": "My API",
3
+ "host": "localhost",
4
+ "port": 3030,
5
+ "public": "./public",
6
+ "clientHost": "http://localhost:5173",
7
+ "origins": ["http://localhost:5173"],
8
+ "seed": true,
9
+ "paginate": {
10
+ "default": 10,
11
+ "max": 50
12
+ },
13
+ "mongodb": "mongodb://localhost:27017/my-api",
14
+ "authentication": {
15
+ "entity": "user",
16
+ "service": "users",
17
+ "secret": "CHANGE_ME_IN_PRODUCTION",
18
+ "authStrategies": ["jwt", "local"],
19
+ "jwtOptions": {
20
+ "header": { "typ": "access" },
21
+ "audience": "https://example.com",
22
+ "algorithm": "HS256",
23
+ "expiresIn": "1d"
24
+ },
25
+ "local": {
26
+ "usernameField": "email",
27
+ "passwordField": "password"
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "appName": "My API (test)",
3
+ "port": 8998,
4
+ "origins": ["http://localhost:5173"],
5
+ "mongodb": "mongodb://localhost:27017/my-api-test"
6
+ }
@@ -1,4 +1,4 @@
1
1
  node_modules/
2
2
  lib/
3
- .env
3
+ config/local.json
4
4
  *.log
@@ -10,16 +10,21 @@
10
10
  "dev": "nodemon -x ts-node src/index.ts",
11
11
  "compile": "shx rm -rf lib/ && tsc",
12
12
  "start": "node lib/",
13
- "mocha": "cross-env NODE_ENV=test PORT=8998 ORIGINS=http://localhost:5173 MONGODB_URI=mongodb://localhost:27017/my-api-test AUTH_SECRET=test-secret-least-32-characters-long!! mocha test/ --require ts-node/register --recursive --extension .ts --exit",
13
+ "generate": "frozencrow generate",
14
+ "secret": "frozencrow secret",
15
+ "mocha": "cross-env NODE_ENV=test mocha test/ --require ts-node/register --recursive --extension .ts --exit",
14
16
  "test": "npm run mocha"
15
17
  },
18
+ "overrides": {
19
+ "config": "3.3.9"
20
+ },
16
21
  "dependencies": {
17
- "@frozencrow/api-core": "^0.1.0",
22
+ "@frozencrow/api-core": "^0.1.3",
23
+ "@feathersjs/configuration": "^5.0.37",
18
24
  "@feathersjs/feathers": "^5.0.37",
19
25
  "@feathersjs/mongodb": "^5.0.37",
20
26
  "@feathersjs/schema": "^5.0.37",
21
- "@feathersjs/typebox": "^5.0.37",
22
- "dotenv": "^16.4.5"
27
+ "@feathersjs/typebox": "^5.0.37"
23
28
  },
24
29
  "devDependencies": {
25
30
  "@feathersjs/rest-client": "^5.0.37",
@@ -1,23 +1,15 @@
1
- import 'dotenv/config'
2
- import { join } from 'path'
3
- import { createApp } from '@frozencrow/api-core'
1
+ import { createConfiguredApp } from '@frozencrow/api-core'
4
2
 
5
3
  import { widgets } from './services/widgets/widgets'
6
4
 
7
- // Build a fully-configured API from the core. Everything (auth, RBAC,
8
- // multitenancy, users/organizations/roles/invites/verifications) comes from
9
- // @frozencrow/api-core; you extend it with your own services below.
10
- export const app = createApp({
11
- appName: process.env.APP_NAME || 'My API',
12
- host: process.env.HOST || 'localhost',
13
- port: Number(process.env.PORT) || 3030,
14
- public: join(__dirname, '..', 'public'),
15
- mongodb: process.env.MONGODB_URI || 'mongodb://localhost:27017/my-api',
16
- authSecret: process.env.AUTH_SECRET || 'dev-only-secret-change-me-32-chars!!',
17
- clientHost: process.env.CLIENT_HOST || 'http://localhost:5173',
18
- origins: (process.env.ORIGINS || 'http://localhost:5173').split(',').filter(Boolean),
19
- seed: true
20
- })
5
+ // Build a fully-configured API from the core. Configuration is loaded from the
6
+ // Feathers config module (config/*.json, config/local.json for secrets, and env
7
+ // vars mapped in config/custom-environment-variables.json) — no .env files.
8
+ //
9
+ // Everything (auth, RBAC, multitenancy, users/organizations/roles/invites/
10
+ // verifications) comes from @frozencrow/api-core; extend it with your own
11
+ // services below.
12
+ export const app = createConfiguredApp()
21
13
 
22
14
  // --- Register your own services on top of the core ---
23
15
  app.configure(widgets)
@@ -1,14 +0,0 @@
1
- # Copy to .env and adjust. `npm create @frozencrow/api` generates a real AUTH_SECRET for you.
2
- APP_NAME=My API
3
- HOST=localhost
4
- PORT=3030
5
-
6
- # MongoDB connection string
7
- MONGODB_URI=mongodb://localhost:27017/my-api
8
-
9
- # JWT signing secret. MUST be a strong random value (>= 32 chars) in production.
10
- AUTH_SECRET=please-change-me-to-a-random-32-plus-character-string
11
-
12
- # Frontend URL (used in emails) and allowed CORS origins (comma-separated)
13
- CLIENT_HOST=http://localhost:5173
14
- ORIGINS=http://localhost:5173