@friggframework/devtools 2.0.0--canary.639.4058469.0 → 2.0.0--canary.666.81647c4.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.
Files changed (58) hide show
  1. package/frigg-cli/README.md +68 -78
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  3. package/frigg-cli/__tests__/unit/commands/deploy.test.js +3 -0
  4. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
  5. package/frigg-cli/__tests__/unit/commands/install.test.js +341 -594
  6. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  7. package/frigg-cli/build-command/index.js +6 -0
  8. package/frigg-cli/deploy-command/index.js +6 -0
  9. package/frigg-cli/generate-command/index.js +0 -1
  10. package/frigg-cli/generate-iam-command.js +0 -1
  11. package/frigg-cli/index.js +17 -10
  12. package/frigg-cli/init-command/backend-first-handler.js +531 -395
  13. package/frigg-cli/init-command/index.js +35 -82
  14. package/frigg-cli/install-command/commit-changes.js +8 -40
  15. package/frigg-cli/install-command/environment-variables.js +0 -15
  16. package/frigg-cli/install-command/index.js +21 -96
  17. package/frigg-cli/install-command/install-package.js +4 -77
  18. package/frigg-cli/install-command/integration-file.js +11 -20
  19. package/frigg-cli/install-command/template.js +75 -102
  20. package/frigg-cli/install-command/validate-package.js +4 -36
  21. package/frigg-cli/package.json +1 -1
  22. package/frigg-cli/start-command/index.js +4 -0
  23. package/frigg-cli/start-command/start-command.test.js +3 -0
  24. package/frigg-cli/test/init-command.test.js +2 -9
  25. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  26. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  27. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +326 -0
  28. package/frigg-cli/validate-command/__tests__/validate-command.test.js +241 -0
  29. package/frigg-cli/validate-command/checks/config.js +468 -0
  30. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  31. package/frigg-cli/validate-command/format-report.js +58 -0
  32. package/frigg-cli/validate-command/index.js +107 -0
  33. package/frigg-cli/validate-command/load-app-definition.js +93 -0
  34. package/frigg-cli/validate-command/schema-issues.js +154 -0
  35. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  36. package/infrastructure/app-definition-schema-contract.test.js +607 -0
  37. package/infrastructure/create-frigg-infrastructure.js +4 -1
  38. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  39. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +60 -118
  40. package/infrastructure/domains/database/aurora-builder.js +2 -13
  41. package/infrastructure/domains/database/aurora-builder.test.js +0 -22
  42. package/infrastructure/domains/security/iam-generator.js +5 -112
  43. package/infrastructure/domains/security/iam-generator.test.js +0 -94
  44. package/infrastructure/domains/shared/utilities/base-definition-factory.js +2 -7
  45. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +0 -21
  46. package/package.json +8 -10
  47. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
  48. package/frigg-cli/init-command/deployment-modes.js +0 -7
  49. package/frigg-cli/init-command/safe-path.js +0 -58
  50. package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
  51. package/frigg-cli/install-command/app-definition.js +0 -174
  52. package/frigg-cli/install-command/resolve-module.js +0 -69
  53. package/frigg-cli/templates/backend/README.md +0 -267
  54. package/frigg-cli/templates/backend/env.example +0 -20
  55. package/frigg-cli/templates/backend/gitignore +0 -10
  56. package/frigg-cli/templates/backend/index.js +0 -114
  57. package/frigg-cli/templates/backend/infrastructure.js +0 -20
  58. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
@@ -10,68 +10,29 @@ The Frigg CLI provides tools for building, deploying, and managing serverless in
10
10
 
11
11
  ### Core Commands
12
12
 
13
- #### `frigg init [projectName] [options]`
13
+ #### `frigg init [options]`
14
14
 
15
- Scaffold a new Frigg backend application that installs and runs out of the box.
15
+ **Status:** To be documented (command may not be merged yet)
16
16
 
17
- **Usage:**
17
+ Initialize a new Frigg application with scaffolding and configuration.
18
18
 
19
+ **Usage:**
19
20
  ```bash
20
- frigg init my-app # interactive (when stdin is a TTY)
21
- frigg init my-app --yes # accept every default, no prompts
22
- frigg init my-app --yes --mode standalone --no-install --no-git
23
- frigg init my-app --mode embedded # add to an existing project (./frigg-integration)
24
- npx @friggframework/devtools init my-app --yes # without a global install
21
+ frigg init
22
+ frigg init my-app
23
+ frigg init --template typescript
25
24
  ```
26
25
 
27
26
  **What it does:**
28
-
29
- 1. Validates the project name and `--mode`, and checks that the target directory is
30
- empty (only `.git`, `.gitignore`, `README.md` and `.DS_Store` may exist) before asking anything else
31
- 2. Copies the backend template: `index.js` (app definition, named after the project),
32
- `infrastructure.js`, `README.md`, `.gitignore`, `.env.example` (also seeded into `.env`)
33
- 3. Writes `package.json` with:
34
- - scripts: `start` (`frigg start`), `build` (`frigg build`), `deploy` (`frigg deploy`),
35
- `db:setup` (`frigg db:setup`), `test` (`jest --passWithNoTests`)
36
- - dependencies: `@friggframework/core`, `@prisma/client`, `prisma`
37
- - devDependencies: `@friggframework/devtools`, `@friggframework/serverless-plugin`,
38
- `osls`, and the serverless plugins the composed definition loads
39
- - Frigg package versions match the devtools that ran `init` (a prerelease is pinned exactly)
40
- 4. Validates the generated app definition against the app-definition schema (problems
41
- are printed as warnings; `frigg start`, `build` and `deploy` do not validate)
42
- 5. Optionally initializes git and runs `npm install`
43
- 6. Prints next steps. API modules picked in the interactive prompt are not wired in
44
- automatically; the next steps list a `frigg install <module>` command for each
45
-
46
- In `embedded` mode the backend is written to `./frigg-integration` inside the target
47
- directory, which may already contain your application. Git is not initialized.
27
+ - TBD - Full documentation pending implementation merge
48
28
 
49
29
  **Options:**
30
+ - TBD
50
31
 
51
- - `-n, --name <name>` - Project name (alternative to the positional argument)
52
- - `-m, --mode <mode>` - `standalone` (default) or `embedded`
53
- - `-y, --yes` - Accept the default for every prompt. Implied when stdin is not a TTY
54
- - `--no-install` - Skip `npm install`
55
- - `--no-git` - Skip `git init` and the initial commit
56
- - `-f, --force` - Scaffold into a non-empty directory and overwrite an existing `README.md`/`.gitignore`
57
- - `-v, --verbose` - Verbose output
58
-
59
- **Next steps after `init`:**
60
-
61
- ```bash
62
- cd my-app
63
- docker run --name frigg-postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:16
64
- npm run db:setup
65
- npm start
66
- ```
32
+ **Example Output:**
33
+ - TBD
67
34
 
68
- The scaffolded app deploys nothing that bills by the hour, so it costs near $0 while
69
- idle: no VPC, NAT gateway or database cluster (`vpc: { enable: false }`,
70
- `database.postgres.management: 'external'`), field-level encryption with a per-stage
71
- KMS key ($1/month, about $3/month after its first two yearly rotations), 14-day log
72
- retention, and the app connecting to a PostgreSQL you host through `DATABASE_URL`.
73
- `frigg deploy` reads `DATABASE_URL` from the shell that runs it, not from `.env`. The
74
- generated `README.md` lists every resource, the security model and the other options.
35
+ > **Note**: This command may be part of an upcoming release. Documentation will be updated once the implementation is merged to the main branch.
75
36
 
76
37
  ---
77
38
 
@@ -86,36 +47,28 @@ frigg install salesforce
86
47
  frigg install stripe
87
48
  ```
88
49
 
89
- Run it in the app directory (the one with `package.json` and `index.js`).
90
-
91
50
  **What it does:**
92
- - Searches npm for `@friggframework/api-module-<name>` and lets you pick the
93
- packages to install (with no terminal to prompt on, it takes the exact match)
94
- - Runs `npm install` in the app directory. An app on a Frigg 2.x prerelease
95
- (what `frigg init` scaffolds today) gets the module's `@next` release, because
96
- most modules' `latest` is still a 1.x release built for Frigg 1.x
97
- - Resolves the installed module from the app directory and writes
98
- `src/integrations/<Label>Integration.js`: an `IntegrationBase` subclass whose
99
- `Definition.modules` wraps the module (an existing file is kept)
100
- - Registers the class in your app definition: in `index.js` it adds the
101
- `require` and the first entry of the `integrations` array. When it cannot do
102
- that safely (no single `integrations: [...]` array literal, or the file does not
103
- parse) it changes nothing and prints the two lines to add by hand. Older apps
104
- with a `backend.js` are updated there instead
105
- - Commits the files it changed (`git commit -- <files>`, so nothing else you have
106
- staged is included) when the app is in a git repository; otherwise leaves them
107
- in the working tree
108
- - Lists the environment variables the module reads (from its `definition.js`)
109
- that are not in `.env`, and offers to add them when run in a terminal
51
+ - Searches the api-module-library for the specified integration
52
+ - Installs the npm package (@friggframework/api-module-{name})
53
+ - Adds integration to your app definition
54
+ - Configures OAuth flows and webhooks if applicable
55
+ - Creates integration-specific environment variable placeholders
110
56
 
111
57
  **Options:**
112
- - None
58
+ - None currently (could add `--version`, `--registry` in future)
113
59
 
114
- **Example:**
115
- ```bash
116
- cd my-app
117
- npx frigg install hubspot
118
- # -> src/integrations/HubSpotIntegration.js, listed in index.js's integrations
60
+ **Example Output:**
61
+ ```
62
+ 🔍 Finding integration module: hubspot
63
+ ✓ Found @friggframework/api-module-hubspot@2.0.5
64
+ 📦 Installing package...
65
+ ✓ Package installed successfully
66
+ 🔧 Configuring integration in app definition...
67
+ ✓ Integration configured
68
+ ⚙️ Next steps:
69
+ 1. Set HUBSPOT_CLIENT_ID in your environment
70
+ 2. Set HUBSPOT_CLIENT_SECRET in your environment
71
+ 3. Run 'frigg start' to test locally
119
72
  ```
120
73
 
121
74
  ---
@@ -157,6 +110,41 @@ Found 5 modules matching "crm"
157
110
 
158
111
  ---
159
112
 
113
+ #### `frigg validate [options]`
114
+
115
+ Validate the app definition (`index.js`) before you build or deploy it (ADR-051).
116
+
117
+ **Usage:**
118
+ ```bash
119
+ frigg validate # schema + runtime checks
120
+ frigg validate --stage prod # also the stage checks (encryption, deploy-time environment)
121
+ frigg validate --json # machine-readable report for CI
122
+ ```
123
+
124
+ **What it does:**
125
+ 1. Loads `index.js` the way `frigg build` does (current directory, or the nearest `backend/`)
126
+ 2. Validates it against the app-definition schema: unknown keys (with "did you mean"), types, and the values the infrastructure builders accept
127
+ 3. Checks what the schema cannot: integration classes (static `Definition` with a valid, unique `name`, `version`, `modules`, and API module definitions that pass core's checks), an enabled database, management settings that conflict or lack ids, encryption (`aes` keys in `environment`, KMS key source, stages that never encrypt), a user config with which login works, `'ssm'` entries without `ssm.enable`, and keys that have no effect
128
+ 4. Prints each problem with its JSON pointer and a fix; exits `1` when there are errors
129
+
130
+ **Example output:**
131
+ ```
132
+ Validating /path/to/backend/index.js (stage: prod)
133
+ error /encrpytion Unknown key "encrpytion": nothing in Frigg reads it.
134
+ fix: Did you mean "encryption"?
135
+ error /database/postgres/management /database/postgres/management is "create-new", which is not an allowed value.
136
+ fix: Use one of: "discover", "managed", "use-existing".
137
+ warning /custom custom is not read by Frigg: it has no effect.
138
+ fix: Remove it.
139
+ ✗ 2 error(s), 1 warning(s)
140
+ ```
141
+
142
+ `--json` prints `{ valid, source, stage, errors, warnings }`; each issue is `{ severity, code, pointer, message, hint }`.
143
+
144
+ `frigg build` and `frigg deploy` run the same validation first and stop on errors (`--skip-validate` bypasses it, with a loud warning). `frigg start` runs it and only warns. `frigg init` validates the generated app the same way.
145
+
146
+ ---
147
+
160
148
  #### `frigg start [options]`
161
149
 
162
150
  Start local development server with hot reload.
@@ -170,7 +158,7 @@ frigg start --frontend
170
158
  ```
171
159
 
172
160
  **What it does:**
173
- 1. Validates DATABASE_URL environment variable
161
+ 1. Validates DATABASE_URL environment variable, and the app definition (`frigg validate`; problems are printed as warnings, `--skip-validate` skips it)
174
162
  2. Detects database type (MongoDB or PostgreSQL)
175
163
  3. Checks Prisma client generation status
176
164
  4. Tests database connection
@@ -229,10 +217,12 @@ frigg deploy --region us-west-2
229
217
  frigg deploy --force
230
218
  frigg deploy --skip-env-validation
231
219
  frigg deploy --skip-doctor # Skip health check (not recommended)
220
+ frigg deploy --skip-validate # Skip app definition validation (not recommended)
232
221
  frigg deploy --no-interactive # CI/CD mode (no prompts, auto-repair safe issues)
233
222
  ```
234
223
 
235
224
  **What it does:**
225
+ 0. **Validates the app definition** (`frigg validate`) and stops on errors, unless `--skip-validate`
236
226
  1. **Runs health check** (`frigg doctor`) to detect infrastructure issues
237
227
  2. **Auto-repairs safe issues** (or prompts for confirmation in interactive mode)
238
228
  3. **Fails if critical issues found** (unless `--skip-doctor` flag used)
@@ -14,6 +14,9 @@ jest.mock('child_process', () => ({
14
14
  spawnSync: jest.fn()
15
15
  }));
16
16
 
17
+ // The app definition validation step is tested in validate-command/.
18
+ jest.mock('../../../validate-command', () => ({ preflightValidation: jest.fn(() => true) }));
19
+
17
20
  // Require after mocks
18
21
  const { spawnSync } = require('child_process');
19
22
  const { buildCommand } = require('../../../build-command');
@@ -10,6 +10,9 @@
10
10
  */
11
11
 
12
12
  // Mock dependencies BEFORE requiring modules
13
+ // The app definition validation step is tested in validate-command/.
14
+ jest.mock('../../../validate-command', () => ({ preflightValidation: jest.fn(() => true) }));
15
+
13
16
  jest.mock('child_process', () => ({
14
17
  spawn: jest.fn()
15
18
  }));
@@ -94,22 +94,4 @@ describe('CLI Command: generate-iam', () => {
94
94
  'arn:aws:kms:*:${AWS::AccountId}:key/*'
95
95
  );
96
96
  });
97
-
98
- it("grants the app's own resources, named after Definition.name", async () => {
99
- jest.doMock(
100
- mockAppDefinitionPath,
101
- () => ({ Definition: { name: 'my-app' } }),
102
- { virtual: true }
103
- );
104
-
105
- await generateIamCommand({});
106
-
107
- const [, generatedYaml] = fs.writeFile.mock.calls[0];
108
- expect(generatedYaml).toContain(
109
- 'arn:aws:cloudformation:*:${AWS::AccountId}:stack/*my-app*/*'
110
- );
111
- expect(generatedYaml).toContain(
112
- 'arn:aws:lambda:*:${AWS::AccountId}:function:*my-app*'
113
- );
114
- });
115
97
  });