@friggframework/devtools 2.0.0--canary.702.d5e6de1.0 → 2.0.0--canary.666.abcf913.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 +80 -41
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +30 -24
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
- package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
- package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
- package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +12 -13
- package/frigg-cli/init-command/backend-first-handler.js +377 -512
- package/frigg-cli/init-command/deployment-modes.js +7 -0
- package/frigg-cli/init-command/index.js +82 -35
- package/frigg-cli/init-command/safe-path.js +58 -0
- package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
- package/frigg-cli/install-command/app-definition.js +174 -0
- package/frigg-cli/install-command/commit-changes.js +40 -8
- package/frigg-cli/install-command/environment-variables.js +15 -0
- package/frigg-cli/install-command/index.js +96 -21
- package/frigg-cli/install-command/install-package.js +77 -4
- package/frigg-cli/install-command/integration-file.js +20 -11
- package/frigg-cli/install-command/resolve-module.js +69 -0
- package/frigg-cli/install-command/template.js +102 -75
- package/frigg-cli/install-command/validate-package.js +36 -4
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/templates/backend/README.md +267 -0
- package/frigg-cli/templates/backend/env.example +20 -0
- package/frigg-cli/templates/backend/gitignore +10 -0
- package/frigg-cli/templates/backend/index.js +114 -0
- package/frigg-cli/templates/backend/infrastructure.js +20 -0
- package/frigg-cli/test/init-command.test.js +9 -2
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +123 -6
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +21 -0
- package/frigg-cli/validate-command/checks/config.js +50 -14
- package/frigg-cli/validate-command/format-report.js +2 -4
- package/frigg-cli/validate-command/index.js +4 -48
- package/frigg-cli/validate-command/load-app-definition.js +17 -5
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +281 -0
- package/infrastructure/__tests__/postgres-config.test.js +241 -835
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
- package/infrastructure/__tests__/template-generation.test.js +36 -8
- package/infrastructure/app-definition-schema-contract.test.js +22 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +21 -1
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
- package/infrastructure/domains/networking/vpc-builder.js +18 -8
- package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
- package/infrastructure/domains/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +26 -2
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +34 -1
- package/infrastructure/infrastructure-composer.test.js +268 -794
- package/infrastructure/scripts/build-prisma-layer.test.js +28 -7
- package/infrastructure/scripts/build-time-discovery.test.js +18 -3
- package/package.json +10 -8
- package/frigg-cli/index.test.js +0 -158
- package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +0 -119
- 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/load-module-definition.js +0 -64
- package/frigg-cli/validate-command/validate-module-definition.js +0 -46
- package/infrastructure/integration.test.js +0 -381
|
@@ -143,14 +143,35 @@ describe('getMigrationsPackages()', () => {
|
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
describe('getMigrationSourcePath()', () => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
// getMigrationSourcePath() returns the first search path whose
|
|
147
|
+
// prisma-<dbType>/migrations directory exists on disk, so the test needs a
|
|
148
|
+
// real directory rather than a made-up absolute path.
|
|
149
|
+
const fs = require('fs');
|
|
150
|
+
const os = require('os');
|
|
151
|
+
const path = require('path');
|
|
152
|
+
let tmpRoot;
|
|
153
|
+
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-prisma-layer-'));
|
|
156
|
+
});
|
|
149
157
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
158
|
+
afterEach(() => {
|
|
159
|
+
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should return the migrations path of the first search path that has one', () => {
|
|
163
|
+
const missing = path.join(tmpRoot, 'missing');
|
|
164
|
+
const core = path.join(tmpRoot, 'packages', 'core');
|
|
165
|
+
const expected = path.join(core, 'prisma-postgresql', 'migrations');
|
|
166
|
+
fs.mkdirSync(expected, { recursive: true });
|
|
167
|
+
|
|
168
|
+
const sourcePath = getMigrationSourcePath([missing, core], 'postgresql');
|
|
169
|
+
expect(sourcePath).toBe(expected);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should return null when no search path has migrations for the database type', () => {
|
|
173
|
+
const sourcePath = getMigrationSourcePath([tmpRoot], 'postgresql');
|
|
174
|
+
expect(sourcePath).toBeNull();
|
|
154
175
|
});
|
|
155
176
|
});
|
|
156
177
|
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
// SKIPPED: BuildTimeDiscovery lazily requires './aws-discovery', which was
|
|
5
|
+
// deleted in the hexagonal infrastructure refactor (7b36f0f4). Discovery now
|
|
6
|
+
// lives in domains/shared/resource-discovery.js + providers/aws-provider-adapter.js,
|
|
7
|
+
// and nothing in devtools, the CLI or the serverless plugin invokes
|
|
8
|
+
// build-time-discovery.js / run-discovery.js any more, so this suite cannot load
|
|
9
|
+
// its subject. Either port BuildTimeDiscovery to gatherDiscoveredResources() and
|
|
10
|
+
// rewrite these tests, or delete the dead module and this suite.
|
|
11
|
+
// Tracked in https://github.com/friggframework/frigg/issues/708
|
|
12
|
+
let BuildTimeDiscovery;
|
|
13
|
+
let runBuildTimeDiscovery;
|
|
14
|
+
let AWSDiscovery;
|
|
5
15
|
|
|
6
16
|
// Mock dependencies
|
|
7
17
|
jest.mock('fs');
|
|
8
18
|
// Mock will be updated when tests are rewritten for new provider architecture
|
|
9
19
|
// jest.mock('./aws-discovery');
|
|
10
20
|
|
|
11
|
-
describe('BuildTimeDiscovery', () => {
|
|
21
|
+
describe.skip('BuildTimeDiscovery', () => {
|
|
22
|
+
beforeAll(() => {
|
|
23
|
+
({ BuildTimeDiscovery, runBuildTimeDiscovery } = require('./build-time-discovery'));
|
|
24
|
+
({ AWSDiscovery } = require('./aws-discovery'));
|
|
25
|
+
});
|
|
26
|
+
|
|
12
27
|
let buildTimeDiscovery;
|
|
13
28
|
let mockAWSDiscovery;
|
|
14
29
|
const originalEnv = process.env;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/devtools",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
4
|
+
"version": "2.0.0--canary.666.abcf913.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"frigg": "./frigg-cli/index.js"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
9
|
"frigg-cli/",
|
|
10
|
+
"frigg-cli/templates/",
|
|
10
11
|
"infrastructure/",
|
|
11
12
|
"migrations/",
|
|
12
13
|
"management-ui/dist/",
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
"@aws-sdk/client-cloudformation": "^3.705.0",
|
|
19
20
|
"@aws-sdk/client-ec2": "^3.835.0",
|
|
20
21
|
"@aws-sdk/client-kms": "^3.835.0",
|
|
22
|
+
"@aws-sdk/client-lambda": "^3.714.0",
|
|
21
23
|
"@aws-sdk/client-rds": "^3.906.0",
|
|
22
24
|
"@aws-sdk/client-s3": "^3.917.0",
|
|
23
25
|
"@aws-sdk/client-secrets-manager": "^3.906.0",
|
|
@@ -26,9 +28,9 @@
|
|
|
26
28
|
"@babel/eslint-parser": "^7.18.9",
|
|
27
29
|
"@babel/parser": "^7.25.3",
|
|
28
30
|
"@babel/traverse": "^7.25.3",
|
|
29
|
-
"@friggframework/core": "2.0.0--canary.
|
|
30
|
-
"@friggframework/schemas": "2.0.0--canary.
|
|
31
|
-
"@friggframework/test": "2.0.0--canary.
|
|
31
|
+
"@friggframework/core": "2.0.0--canary.666.abcf913.0",
|
|
32
|
+
"@friggframework/schemas": "2.0.0--canary.666.abcf913.0",
|
|
33
|
+
"@friggframework/test": "2.0.0--canary.666.abcf913.0",
|
|
32
34
|
"@hapi/boom": "^10.0.1",
|
|
33
35
|
"@inquirer/prompts": "^5.3.8",
|
|
34
36
|
"axios": "^1.18.0",
|
|
@@ -56,12 +58,12 @@
|
|
|
56
58
|
"validate-npm-package-name": "^5.0.0"
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {
|
|
59
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
60
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
61
|
+
"@friggframework/eslint-config": "2.0.0--canary.666.abcf913.0",
|
|
62
|
+
"@friggframework/prettier-config": "2.0.0--canary.666.abcf913.0",
|
|
61
63
|
"aws-sdk-client-mock": "^4.1.0",
|
|
62
64
|
"aws-sdk-client-mock-jest": "^4.1.0",
|
|
63
65
|
"jest": "^30.1.3",
|
|
64
|
-
"osls": "^3.
|
|
66
|
+
"osls": "^3.78.0",
|
|
65
67
|
"prettier": "^2.7.1",
|
|
66
68
|
"serverless-dotenv-plugin": "^6.0.0",
|
|
67
69
|
"serverless-esbuild": "^1.54.3",
|
|
@@ -89,5 +91,5 @@
|
|
|
89
91
|
"publishConfig": {
|
|
90
92
|
"access": "public"
|
|
91
93
|
},
|
|
92
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "abcf913cf7580597fd286b2f5b93d3ccf4609ef6"
|
|
93
95
|
}
|
package/frigg-cli/index.test.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
const { Command } = require('commander');
|
|
2
|
-
const { installCommand } = require('./index');
|
|
3
|
-
const { validatePackageExists } = require('./install-command/validate-package');
|
|
4
|
-
const { findNearestBackendPackageJson, validateBackendPath } = require('@friggframework/core');
|
|
5
|
-
const { installPackage } = require('./install-command/install-package');
|
|
6
|
-
const { createIntegrationFile } = require('./install-command/integration-file');
|
|
7
|
-
const { updateBackendJsFile } = require('./install-command/backend-js');
|
|
8
|
-
const { commitChanges } = require('./install-command/commit-changes');
|
|
9
|
-
const { logInfo, logError } = require('./install-command/logger');
|
|
10
|
-
|
|
11
|
-
describe('CLI Command Tests', () => {
|
|
12
|
-
it('should successfully install an API module when all steps complete without errors', async () => {
|
|
13
|
-
const mockApiModuleName = 'testModule';
|
|
14
|
-
const mockPackageName = `@friggframework/api-module-${mockApiModuleName}`;
|
|
15
|
-
const mockBackendPath = '/mock/backend/path';
|
|
16
|
-
|
|
17
|
-
jest.mock('./install-command/validate-package', () => ({
|
|
18
|
-
validatePackageExists: jest.fn().mockResolvedValue(true),
|
|
19
|
-
}));
|
|
20
|
-
jest.mock('./utils/backend-path', () => ({
|
|
21
|
-
findNearestBackendPackageJson: jest
|
|
22
|
-
.fn()
|
|
23
|
-
.mockReturnValue(mockBackendPath),
|
|
24
|
-
validateBackendPath: jest.fn().mockReturnValue(true),
|
|
25
|
-
}));
|
|
26
|
-
jest.mock('./install-command/install-package', () => ({
|
|
27
|
-
installPackage: jest.fn().mockReturnValue(true),
|
|
28
|
-
}));
|
|
29
|
-
jest.mock('./install-command/integration-file', () => ({
|
|
30
|
-
createIntegrationFile: jest.fn().mockReturnValue(true),
|
|
31
|
-
}));
|
|
32
|
-
jest.mock('./install-command/backend-js', () => ({
|
|
33
|
-
updateBackendJsFile: jest.fn().mockReturnValue(true),
|
|
34
|
-
}));
|
|
35
|
-
jest.mock('./install-command/commit-changes', () => ({
|
|
36
|
-
commitChanges: jest.fn().mockReturnValue(true),
|
|
37
|
-
}));
|
|
38
|
-
jest.mock('./install-command/logger', () => ({
|
|
39
|
-
logInfo: jest.fn(),
|
|
40
|
-
logError: jest.fn(),
|
|
41
|
-
}));
|
|
42
|
-
|
|
43
|
-
const program = new Command();
|
|
44
|
-
program
|
|
45
|
-
.command('install <apiModuleName>')
|
|
46
|
-
.description('Install an API module')
|
|
47
|
-
.action(installCommand);
|
|
48
|
-
|
|
49
|
-
await program.parseAsync(['node', 'install', mockApiModuleName]);
|
|
50
|
-
|
|
51
|
-
expect(validatePackageExists).toHaveBeenCalledWith(mockPackageName);
|
|
52
|
-
expect(findNearestBackendPackageJson).toHaveBeenCalled();
|
|
53
|
-
expect(validateBackendPath).toHaveBeenCalledWith(mockBackendPath);
|
|
54
|
-
expect(installPackage).toHaveBeenCalledWith(
|
|
55
|
-
mockBackendPath,
|
|
56
|
-
mockPackageName
|
|
57
|
-
);
|
|
58
|
-
expect(createIntegrationFile).toHaveBeenCalledWith(
|
|
59
|
-
mockBackendPath,
|
|
60
|
-
mockApiModuleName
|
|
61
|
-
);
|
|
62
|
-
expect(updateBackendJsFile).toHaveBeenCalledWith(
|
|
63
|
-
mockBackendPath,
|
|
64
|
-
mockApiModuleName
|
|
65
|
-
);
|
|
66
|
-
expect(commitChanges).toHaveBeenCalledWith(
|
|
67
|
-
mockBackendPath,
|
|
68
|
-
mockApiModuleName
|
|
69
|
-
);
|
|
70
|
-
expect(logInfo).toHaveBeenCalledWith(
|
|
71
|
-
`Successfully installed ${mockPackageName} and updated the project.`
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should log an error and exit with code 1 if the package does not exist', async () => {
|
|
76
|
-
const mockExit = jest
|
|
77
|
-
.spyOn(process, 'exit')
|
|
78
|
-
.mockImplementation(() => {});
|
|
79
|
-
const mockLogError = jest
|
|
80
|
-
.spyOn(require('./install-command/logger'), 'logError')
|
|
81
|
-
.mockImplementation(() => {});
|
|
82
|
-
const mockValidatePackageExists = jest
|
|
83
|
-
.spyOn(
|
|
84
|
-
require('./install-command/validate-package'),
|
|
85
|
-
'validatePackageExists'
|
|
86
|
-
)
|
|
87
|
-
.mockImplementation(() => {
|
|
88
|
-
throw new Error('Package not found');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const program = new Command();
|
|
92
|
-
program
|
|
93
|
-
.command('install <apiModuleName>')
|
|
94
|
-
.description('Install an API module')
|
|
95
|
-
.action(installCommand);
|
|
96
|
-
|
|
97
|
-
await program.parseAsync(['node', 'install', 'nonexistent-package']);
|
|
98
|
-
|
|
99
|
-
expect(mockValidatePackageExists).toHaveBeenCalledWith(
|
|
100
|
-
'@friggframework/api-module-nonexistent-package'
|
|
101
|
-
);
|
|
102
|
-
expect(mockLogError).toHaveBeenCalledWith(
|
|
103
|
-
'An error occurred:',
|
|
104
|
-
expect.any(Error)
|
|
105
|
-
);
|
|
106
|
-
expect(mockExit).toHaveBeenCalledWith(1);
|
|
107
|
-
|
|
108
|
-
mockExit.mockRestore();
|
|
109
|
-
mockLogError.mockRestore();
|
|
110
|
-
mockValidatePackageExists.mockRestore();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should log an error and exit with code 1 if the backend path is invalid', async () => {
|
|
114
|
-
const mockLogError = jest
|
|
115
|
-
.spyOn(require('./install-command/logger'), 'logError')
|
|
116
|
-
.mockImplementation(() => {});
|
|
117
|
-
const mockProcessExit = jest
|
|
118
|
-
.spyOn(process, 'exit')
|
|
119
|
-
.mockImplementation(() => {});
|
|
120
|
-
const mockValidatePackageExists = jest
|
|
121
|
-
.spyOn(
|
|
122
|
-
require('./install-command/validate-package'),
|
|
123
|
-
'validatePackageExists'
|
|
124
|
-
)
|
|
125
|
-
.mockResolvedValue(true);
|
|
126
|
-
const mockFindNearestBackendPackageJson = jest
|
|
127
|
-
.spyOn(
|
|
128
|
-
require('./utils/backend-path'),
|
|
129
|
-
'findNearestBackendPackageJson'
|
|
130
|
-
)
|
|
131
|
-
.mockReturnValue('/invalid/path');
|
|
132
|
-
const mockValidateBackendPath = jest
|
|
133
|
-
.spyOn(require('./utils/backend-path'), 'validateBackendPath')
|
|
134
|
-
.mockImplementation(() => {
|
|
135
|
-
throw new Error('Invalid backend path');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const program = new Command();
|
|
139
|
-
program
|
|
140
|
-
.command('install <apiModuleName>')
|
|
141
|
-
.description('Install an API module')
|
|
142
|
-
.action(installCommand);
|
|
143
|
-
|
|
144
|
-
await program.parseAsync(['node', 'install', 'test-module']);
|
|
145
|
-
|
|
146
|
-
expect(mockLogError).toHaveBeenCalledWith(
|
|
147
|
-
'An error occurred:',
|
|
148
|
-
expect.any(Error)
|
|
149
|
-
);
|
|
150
|
-
expect(mockProcessExit).toHaveBeenCalledWith(1);
|
|
151
|
-
|
|
152
|
-
mockLogError.mockRestore();
|
|
153
|
-
mockProcessExit.mockRestore();
|
|
154
|
-
mockValidatePackageExists.mockRestore();
|
|
155
|
-
mockFindNearestBackendPackageJson.mockRestore();
|
|
156
|
-
mockValidateBackendPath.mockRestore();
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -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
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Intentionally invalid API module for frigg validate --module fail tests.
|
|
3
|
-
*/
|
|
4
|
-
class BadApi {}
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
Api: BadApi,
|
|
8
|
-
Definition: {
|
|
9
|
-
// missing moduleName, getName; unknown top-level key; auth methods incomplete
|
|
10
|
-
API: BadApi,
|
|
11
|
-
modelName: 'Bad',
|
|
12
|
-
notARealField: true,
|
|
13
|
-
requiredAuthMethods: {
|
|
14
|
-
// missing getEntityDetails, getCredentialDetails, testAuthRequest, apiPropertiesToPersist
|
|
15
|
-
getAuthorizationRequirements: () => ({ type: 'apiKey' }),
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fixture reproducing the Fathom API module Definition from
|
|
3
|
-
* friggframework/api-module-library `next`, packages/v1-ready/fathom.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
class FathomApi {
|
|
7
|
-
static requesterType = 'apiKey';
|
|
8
|
-
|
|
9
|
-
setApiKey(apiKey) {
|
|
10
|
-
this.api_key = apiKey;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async listMeetings() {
|
|
14
|
-
return { items: [] };
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const Definition = {
|
|
19
|
-
API: FathomApi,
|
|
20
|
-
getName: () => 'fathom',
|
|
21
|
-
moduleName: 'fathom',
|
|
22
|
-
modelName: 'Fathom',
|
|
23
|
-
requiredAuthMethods: {
|
|
24
|
-
getAuthorizationRequirements: () => ({
|
|
25
|
-
type: 'apiKey',
|
|
26
|
-
data: {
|
|
27
|
-
jsonSchema: {
|
|
28
|
-
title: 'Fathom Authentication',
|
|
29
|
-
type: 'object',
|
|
30
|
-
required: ['api_key'],
|
|
31
|
-
properties: {
|
|
32
|
-
api_key: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
title: 'API Key',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
uiSchema: {
|
|
39
|
-
api_key: {
|
|
40
|
-
'ui:widget': 'password',
|
|
41
|
-
'ui:help':
|
|
42
|
-
'Generate an API key in Fathom under User Settings > API Access. Sent as the X-Api-Key header.',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
}),
|
|
47
|
-
setAuthParams: async (api, params) => {
|
|
48
|
-
const apiKey = params?.api_key || params?.access_token || null;
|
|
49
|
-
api.setApiKey(apiKey);
|
|
50
|
-
},
|
|
51
|
-
getEntityDetails: async (api, callbackParams, tokenResponse, userId) => {
|
|
52
|
-
return {
|
|
53
|
-
identifiers: { externalId: 'fixture@example.com', userId },
|
|
54
|
-
details: { name: 'Fathom' },
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
getCredentialDetails: async (api, userId) => {
|
|
58
|
-
return {
|
|
59
|
-
identifiers: { externalId: 'fixture@example.com', userId },
|
|
60
|
-
details: {},
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
apiPropertiesToPersist: {
|
|
64
|
-
credential: ['api_key'],
|
|
65
|
-
entity: [],
|
|
66
|
-
},
|
|
67
|
-
testAuthRequest: async (api) => {
|
|
68
|
-
return api.listMeetings({});
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
env: {
|
|
72
|
-
api_key: 'test-fathom-api-key',
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
module.exports = { Definition, Api: FathomApi };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Load the `Definition` exported by an API module's `./index.js`
|
|
6
|
-
* (`{ Api, Definition }`). Used by `frigg validate --module`.
|
|
7
|
-
*
|
|
8
|
-
* @param {object} [params]
|
|
9
|
-
* @param {string} [params.cwd]
|
|
10
|
-
* @returns {{ ok: true, definition: object, indexPath: string }
|
|
11
|
-
* | { ok: false, issue: object }}
|
|
12
|
-
*/
|
|
13
|
-
function loadModuleDefinition({ cwd = process.cwd() } = {}) {
|
|
14
|
-
const indexPath = path.join(cwd, 'index.js');
|
|
15
|
-
if (!fs.existsSync(indexPath)) {
|
|
16
|
-
return {
|
|
17
|
-
ok: false,
|
|
18
|
-
issue: {
|
|
19
|
-
severity: 'error',
|
|
20
|
-
code: 'module-index-not-found',
|
|
21
|
-
pointer: '',
|
|
22
|
-
message: `No API module index.js found at ${indexPath}.`,
|
|
23
|
-
hint: 'Run `frigg validate --module` from the module directory (the one that exports `{ Api, Definition }`).',
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let mod;
|
|
29
|
-
try {
|
|
30
|
-
const resolved = require.resolve(indexPath);
|
|
31
|
-
delete require.cache[resolved];
|
|
32
|
-
mod = require(indexPath);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return {
|
|
35
|
-
ok: false,
|
|
36
|
-
issue: {
|
|
37
|
-
severity: 'error',
|
|
38
|
-
code: 'load-failed',
|
|
39
|
-
pointer: '',
|
|
40
|
-
message: `${indexPath} failed to load: ${error.message}`,
|
|
41
|
-
hint: 'Fix the error above; the module must load cleanly.',
|
|
42
|
-
stack: error.stack,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const definition = mod && mod.Definition;
|
|
48
|
-
if (!definition || typeof definition !== 'object') {
|
|
49
|
-
return {
|
|
50
|
-
ok: false,
|
|
51
|
-
issue: {
|
|
52
|
-
severity: 'error',
|
|
53
|
-
code: 'definition-not-exported',
|
|
54
|
-
pointer: '',
|
|
55
|
-
message: `${indexPath} does not export a Definition object.`,
|
|
56
|
-
hint: 'Export `{ Api, Definition }` from index.js.',
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return { ok: true, definition, indexPath };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
module.exports = { loadModuleDefinition };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validate an API module Definition: the JSON Schema plus the structural
|
|
3
|
-
* checks `checkModuleDefinition` runs for modules listed on an app
|
|
4
|
-
* (ADR-051). Pure: no I/O.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
validateApiModuleDefinition,
|
|
9
|
-
getSchema,
|
|
10
|
-
} = require('@friggframework/schemas');
|
|
11
|
-
const { schemaErrorsToIssues } = require('./schema-issues');
|
|
12
|
-
const { checkModuleDefinition } = require('./checks/integrations');
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {object} params
|
|
16
|
-
* @param {object} params.definition the `Definition` exported by the module
|
|
17
|
-
* @returns {{ errors: object[], warnings: object[] }}
|
|
18
|
-
*/
|
|
19
|
-
function validateModuleDefinition({ definition }) {
|
|
20
|
-
const schemaResult = validateApiModuleDefinition(definition);
|
|
21
|
-
const issues = schemaErrorsToIssues(
|
|
22
|
-
schemaResult.errors,
|
|
23
|
-
getSchema('api-module-definition')
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const structural =
|
|
27
|
-
definition && typeof definition === 'object'
|
|
28
|
-
? checkModuleDefinition(definition, '')
|
|
29
|
-
: [];
|
|
30
|
-
|
|
31
|
-
const seen = new Set(issues.map((i) => `${i.code}:${i.pointer}`));
|
|
32
|
-
for (const issue of structural) {
|
|
33
|
-
const key = `${issue.code}:${issue.pointer}`;
|
|
34
|
-
if (!seen.has(key)) {
|
|
35
|
-
seen.add(key);
|
|
36
|
-
issues.push(issue);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
errors: issues.filter((i) => i.severity === 'error'),
|
|
42
|
-
warnings: issues.filter((i) => i.severity !== 'error'),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = { validateModuleDefinition };
|