@friggframework/devtools 2.0.0--canary.702.3f342da.0 → 2.0.0--canary.689.dadb9f7.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/README.md +0 -1
- package/frigg-cli/README.md +1 -46
- package/frigg-cli/__tests__/unit/commands/build.test.js +0 -3
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +0 -3
- package/frigg-cli/build-command/index.js +0 -6
- package/frigg-cli/deploy-command/index.js +0 -6
- package/frigg-cli/index.js +1 -19
- package/frigg-cli/init-command/backend-first-handler.js +46 -25
- package/frigg-cli/start-command/index.js +0 -4
- package/frigg-cli/start-command/start-command.test.js +0 -3
- package/infrastructure/create-frigg-infrastructure.js +1 -4
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +98 -60
- package/package.json +7 -7
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +0 -92
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +0 -63
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +0 -133
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +0 -326
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +0 -241
- package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +0 -119
- package/frigg-cli/validate-command/checks/config.js +0 -468
- package/frigg-cli/validate-command/checks/integrations.js +0 -274
- package/frigg-cli/validate-command/fixtures/bad-module/index.js +0 -18
- package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +0 -76
- package/frigg-cli/validate-command/fixtures/fathom-module/index.js +0 -6
- package/frigg-cli/validate-command/format-report.js +0 -60
- package/frigg-cli/validate-command/index.js +0 -151
- package/frigg-cli/validate-command/load-app-definition.js +0 -93
- package/frigg-cli/validate-command/load-module-definition.js +0 -64
- package/frigg-cli/validate-command/schema-issues.js +0 -154
- package/frigg-cli/validate-command/validate-app-definition.js +0 -60
- package/frigg-cli/validate-command/validate-module-definition.js +0 -46
- package/infrastructure/app-definition-schema-contract.test.js +0 -607
- package/infrastructure/create-frigg-infrastructure.test.js +0 -51
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const os = require('os');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
const { validateCommand, runValidation, preflightValidation } = require('..');
|
|
6
|
-
|
|
7
|
-
const GOOD_INDEX = `
|
|
8
|
-
class Api { static requesterType = 'apiKey'; }
|
|
9
|
-
const definition = {
|
|
10
|
-
moduleName: 'acme',
|
|
11
|
-
API: Api,
|
|
12
|
-
requiredAuthMethods: {
|
|
13
|
-
getEntityDetails: async () => {},
|
|
14
|
-
getCredentialDetails: async () => {},
|
|
15
|
-
testAuthRequest: async () => {},
|
|
16
|
-
apiPropertiesToPersist: { credential: ['api_key'], entity: [] },
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
class AcmeIntegration {
|
|
20
|
-
static Definition = { name: 'acme', version: '1.0.0', modules: { acme: { definition } } };
|
|
21
|
-
}
|
|
22
|
-
module.exports = {
|
|
23
|
-
Definition: {
|
|
24
|
-
name: 'frigg-app',
|
|
25
|
-
integrations: [AcmeIntegration],
|
|
26
|
-
user: { usePassword: true },
|
|
27
|
-
encryption: { fieldLevelEncryptionMethod: 'kms', createResourceIfNoneFound: true },
|
|
28
|
-
database: { postgres: { enable: true, management: 'use-existing', endpoint: 'db.example.com' } },
|
|
29
|
-
environment: { DATABASE_URL: true },
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
`;
|
|
33
|
-
|
|
34
|
-
const BAD_INDEX = `
|
|
35
|
-
module.exports = {
|
|
36
|
-
Definition: {
|
|
37
|
-
integrations: [{ name: 'not-a-class' }],
|
|
38
|
-
database: { postgres: { enable: true, management: 'create-new' } },
|
|
39
|
-
encrpytion: { fieldLevelEncryptionMethod: 'kms' },
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
function backend(indexSource) {
|
|
45
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-validate-'));
|
|
46
|
-
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"backend"}');
|
|
47
|
-
fs.writeFileSync(path.join(dir, 'index.js'), indexSource);
|
|
48
|
-
return dir;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
describe('frigg validate', () => {
|
|
52
|
-
const dirs = [];
|
|
53
|
-
let log;
|
|
54
|
-
let warn;
|
|
55
|
-
let error;
|
|
56
|
-
let exit;
|
|
57
|
-
|
|
58
|
-
beforeEach(() => {
|
|
59
|
-
log = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
60
|
-
warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
61
|
-
error = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
62
|
-
exit = jest.spyOn(process, 'exit').mockImplementation(() => {});
|
|
63
|
-
process.exitCode = undefined;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
afterEach(() => {
|
|
67
|
-
jest.restoreAllMocks();
|
|
68
|
-
process.exitCode = undefined;
|
|
69
|
-
for (const dir of dirs.splice(0))
|
|
70
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const inBackend = (source) => {
|
|
74
|
-
const dir = backend(source);
|
|
75
|
-
dirs.push(dir);
|
|
76
|
-
jest.spyOn(process, 'cwd').mockReturnValue(dir);
|
|
77
|
-
return dir;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
it('passes an app with integration classes and exits 0', async () => {
|
|
81
|
-
inBackend(GOOD_INDEX);
|
|
82
|
-
|
|
83
|
-
const report = await validateCommand({ stage: 'prod' });
|
|
84
|
-
|
|
85
|
-
expect(report.errors).toEqual([]);
|
|
86
|
-
expect(process.exitCode).toBeUndefined();
|
|
87
|
-
expect(log.mock.calls.flat().join('\n')).toContain(
|
|
88
|
-
'The app definition is valid'
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('prints errors with pointers and hints and exits 1', async () => {
|
|
93
|
-
inBackend(BAD_INDEX);
|
|
94
|
-
|
|
95
|
-
const report = await validateCommand({});
|
|
96
|
-
const output = log.mock.calls.flat().join('\n');
|
|
97
|
-
|
|
98
|
-
expect(process.exitCode).toBe(1);
|
|
99
|
-
expect(report.errors.map((e) => e.pointer)).toEqual(
|
|
100
|
-
expect.arrayContaining([
|
|
101
|
-
'/encrpytion',
|
|
102
|
-
'/database/postgres/management',
|
|
103
|
-
'/integrations/0',
|
|
104
|
-
])
|
|
105
|
-
);
|
|
106
|
-
expect(output).toContain('/encrpytion');
|
|
107
|
-
expect(output).toContain('Did you mean "encryption"?');
|
|
108
|
-
expect(output).toContain(
|
|
109
|
-
'Use one of: "discover", "managed", "use-existing"'
|
|
110
|
-
);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('--json prints a machine-readable report', async () => {
|
|
114
|
-
inBackend(BAD_INDEX);
|
|
115
|
-
|
|
116
|
-
await validateCommand({ json: true, stage: 'prod' });
|
|
117
|
-
const json = JSON.parse(log.mock.calls[0][0]);
|
|
118
|
-
|
|
119
|
-
expect(json).toEqual(
|
|
120
|
-
expect.objectContaining({
|
|
121
|
-
valid: false,
|
|
122
|
-
stage: 'prod',
|
|
123
|
-
errors: expect.arrayContaining([
|
|
124
|
-
expect.objectContaining({
|
|
125
|
-
pointer: '/encrpytion',
|
|
126
|
-
code: 'unknown-key',
|
|
127
|
-
severity: 'error',
|
|
128
|
-
}),
|
|
129
|
-
]),
|
|
130
|
-
warnings: expect.any(Array),
|
|
131
|
-
})
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('reports a backend that fails to load', () => {
|
|
136
|
-
const dir = backend("require('./missing-file');");
|
|
137
|
-
dirs.push(dir);
|
|
138
|
-
|
|
139
|
-
const report = runValidation({ cwd: dir });
|
|
140
|
-
|
|
141
|
-
expect(report.errors).toEqual([
|
|
142
|
-
expect.objectContaining({
|
|
143
|
-
code: 'load-failed',
|
|
144
|
-
message: expect.stringContaining('missing-file'),
|
|
145
|
-
}),
|
|
146
|
-
]);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('reports a directory without a backend', () => {
|
|
150
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-empty-'));
|
|
151
|
-
dirs.push(dir);
|
|
152
|
-
|
|
153
|
-
expect(runValidation({ cwd: dir }).errors).toEqual([
|
|
154
|
-
expect.objectContaining({ code: 'backend-not-found' }),
|
|
155
|
-
]);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('finds the backend/ directory from the project root', () => {
|
|
159
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-root-'));
|
|
160
|
-
dirs.push(root);
|
|
161
|
-
fs.mkdirSync(path.join(root, 'backend'));
|
|
162
|
-
fs.writeFileSync(path.join(root, 'backend', 'package.json'), '{}');
|
|
163
|
-
fs.writeFileSync(path.join(root, 'backend', 'index.js'), GOOD_INDEX);
|
|
164
|
-
|
|
165
|
-
expect(runValidation({ cwd: root }).source).toBe(
|
|
166
|
-
path.join(root, 'backend', 'index.js')
|
|
167
|
-
);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('reports an index.js without a Definition', () => {
|
|
171
|
-
const dir = backend('module.exports = {};');
|
|
172
|
-
dirs.push(dir);
|
|
173
|
-
|
|
174
|
-
expect(runValidation({ cwd: dir }).errors).toEqual([
|
|
175
|
-
expect.objectContaining({ code: 'definition-not-exported' }),
|
|
176
|
-
]);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe('preflightValidation', () => {
|
|
180
|
-
it('stops build/deploy on errors', () => {
|
|
181
|
-
inBackend(BAD_INDEX);
|
|
182
|
-
|
|
183
|
-
const proceed = preflightValidation({
|
|
184
|
-
command: 'deploy',
|
|
185
|
-
options: { stage: 'prod' },
|
|
186
|
-
failOnErrors: true,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
expect(proceed).toBe(false);
|
|
190
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
191
|
-
expect(error.mock.calls.flat().join('\n')).toContain(
|
|
192
|
-
'--skip-validate'
|
|
193
|
-
);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('lets build/deploy continue on a valid definition', () => {
|
|
197
|
-
inBackend(GOOD_INDEX);
|
|
198
|
-
|
|
199
|
-
expect(
|
|
200
|
-
preflightValidation({
|
|
201
|
-
command: 'build',
|
|
202
|
-
options: { stage: 'prod' },
|
|
203
|
-
failOnErrors: true,
|
|
204
|
-
})
|
|
205
|
-
).toBe(true);
|
|
206
|
-
expect(exit).not.toHaveBeenCalled();
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('only warns for start', () => {
|
|
210
|
-
inBackend(BAD_INDEX);
|
|
211
|
-
|
|
212
|
-
expect(
|
|
213
|
-
preflightValidation({
|
|
214
|
-
command: 'start',
|
|
215
|
-
options: {},
|
|
216
|
-
failOnErrors: false,
|
|
217
|
-
})
|
|
218
|
-
).toBe(true);
|
|
219
|
-
expect(exit).not.toHaveBeenCalled();
|
|
220
|
-
const output = log.mock.calls.flat().join('\n');
|
|
221
|
-
expect(output).toContain('warning');
|
|
222
|
-
expect(output).not.toMatch(/^\s+error /m);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('--skip-validate skips validation, loudly', () => {
|
|
226
|
-
inBackend(BAD_INDEX);
|
|
227
|
-
|
|
228
|
-
expect(
|
|
229
|
-
preflightValidation({
|
|
230
|
-
command: 'deploy',
|
|
231
|
-
options: { skipValidate: true },
|
|
232
|
-
failOnErrors: true,
|
|
233
|
-
})
|
|
234
|
-
).toBe(true);
|
|
235
|
-
expect(exit).not.toHaveBeenCalled();
|
|
236
|
-
expect(warn.mock.calls.flat().join('\n')).toContain(
|
|
237
|
-
'VALIDATION SKIPPED'
|
|
238
|
-
);
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const os = require('os');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
validateCommand,
|
|
7
|
-
runModuleValidation,
|
|
8
|
-
} = require('..');
|
|
9
|
-
|
|
10
|
-
const FIXTURES = path.join(__dirname, '..', 'fixtures');
|
|
11
|
-
const FATHOM_DIR = path.join(FIXTURES, 'fathom-module');
|
|
12
|
-
const BAD_DIR = path.join(FIXTURES, 'bad-module');
|
|
13
|
-
|
|
14
|
-
describe('frigg validate --module', () => {
|
|
15
|
-
let log;
|
|
16
|
-
let cwdSpy;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
log = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
20
|
-
process.exitCode = undefined;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
jest.restoreAllMocks();
|
|
25
|
-
process.exitCode = undefined;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const inDir = (dir) => {
|
|
29
|
-
cwdSpy = jest.spyOn(process, 'cwd').mockReturnValue(dir);
|
|
30
|
-
return dir;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
it('passes the Fathom fixture with --module', async () => {
|
|
34
|
-
inDir(FATHOM_DIR);
|
|
35
|
-
|
|
36
|
-
const report = await validateCommand({ module: true });
|
|
37
|
-
|
|
38
|
-
expect(report.errors).toEqual([]);
|
|
39
|
-
expect(process.exitCode).toBeUndefined();
|
|
40
|
-
expect(report.source).toBe(path.join(FATHOM_DIR, 'index.js'));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('passes when target is "module" (frigg validate module)', async () => {
|
|
44
|
-
inDir(FATHOM_DIR);
|
|
45
|
-
|
|
46
|
-
const report = await validateCommand({ target: 'module' });
|
|
47
|
-
|
|
48
|
-
expect(report.errors).toEqual([]);
|
|
49
|
-
expect(process.exitCode).toBeUndefined();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('fails the bad fixture listing JSON field paths', async () => {
|
|
53
|
-
inDir(BAD_DIR);
|
|
54
|
-
|
|
55
|
-
const report = await validateCommand({ module: true });
|
|
56
|
-
const output = log.mock.calls.flat().join('\n');
|
|
57
|
-
const pointers = report.errors.map((e) => e.pointer);
|
|
58
|
-
|
|
59
|
-
expect(process.exitCode).toBe(1);
|
|
60
|
-
expect(pointers).toEqual(
|
|
61
|
-
expect.arrayContaining([
|
|
62
|
-
'/notARealField',
|
|
63
|
-
'/moduleName',
|
|
64
|
-
'/getName',
|
|
65
|
-
'/requiredAuthMethods/getEntityDetails',
|
|
66
|
-
'/requiredAuthMethods/getCredentialDetails',
|
|
67
|
-
'/requiredAuthMethods/testAuthRequest',
|
|
68
|
-
'/requiredAuthMethods/apiPropertiesToPersist',
|
|
69
|
-
])
|
|
70
|
-
);
|
|
71
|
-
expect(output).toContain('/notARealField');
|
|
72
|
-
expect(output).toContain('/moduleName');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('--json prints a machine-readable report for module mode', async () => {
|
|
76
|
-
inDir(BAD_DIR);
|
|
77
|
-
|
|
78
|
-
await validateCommand({ module: true, json: true });
|
|
79
|
-
const json = JSON.parse(log.mock.calls[0][0]);
|
|
80
|
-
|
|
81
|
-
expect(json).toEqual(
|
|
82
|
-
expect.objectContaining({
|
|
83
|
-
valid: false,
|
|
84
|
-
source: path.join(BAD_DIR, 'index.js'),
|
|
85
|
-
errors: expect.arrayContaining([
|
|
86
|
-
expect.objectContaining({
|
|
87
|
-
pointer: '/notARealField',
|
|
88
|
-
code: 'unknown-key',
|
|
89
|
-
severity: 'error',
|
|
90
|
-
}),
|
|
91
|
-
]),
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('runModuleValidation reports a missing index.js', () => {
|
|
97
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-mod-'));
|
|
98
|
-
try {
|
|
99
|
-
expect(runModuleValidation({ cwd: dir }).errors).toEqual([
|
|
100
|
-
expect.objectContaining({ code: 'module-index-not-found' }),
|
|
101
|
-
]);
|
|
102
|
-
} finally {
|
|
103
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('does not change app-mode when --module is absent', async () => {
|
|
108
|
-
// No backend in Fathom fixture dir: app mode should fail to find a backend.
|
|
109
|
-
inDir(FATHOM_DIR);
|
|
110
|
-
|
|
111
|
-
const report = await validateCommand({});
|
|
112
|
-
|
|
113
|
-
expect(report.errors).toEqual([
|
|
114
|
-
expect.objectContaining({ code: 'backend-not-found' }),
|
|
115
|
-
]);
|
|
116
|
-
expect(process.exitCode).toBe(1);
|
|
117
|
-
expect(cwdSpy).toHaveBeenCalled();
|
|
118
|
-
});
|
|
119
|
-
});
|