@friggframework/devtools 2.0.0--canary.704.6a606c3.0 → 2.0.0--canary.707.2702ff3.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 (81) hide show
  1. package/README.md +0 -14
  2. package/frigg-cli/README.md +30 -83
  3. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
  4. package/frigg-cli/__tests__/unit/commands/install.test.js +341 -594
  5. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +140 -0
  6. package/frigg-cli/__tests__/unit/dependencies.test.js +5 -3
  7. package/frigg-cli/build-command/index.js +32 -1
  8. package/frigg-cli/db-setup-command/index.js +25 -0
  9. package/frigg-cli/deploy-command/index.js +50 -2
  10. package/frigg-cli/doctor-command/index.js +7 -0
  11. package/frigg-cli/generate-command/index.js +0 -1
  12. package/frigg-cli/generate-iam-command.js +7 -1
  13. package/frigg-cli/index.js +4 -12
  14. package/frigg-cli/init-command/backend-first-handler.js +554 -397
  15. package/frigg-cli/init-command/index.js +35 -82
  16. package/frigg-cli/install-command/commit-changes.js +8 -40
  17. package/frigg-cli/install-command/environment-variables.js +0 -15
  18. package/frigg-cli/install-command/index.js +21 -96
  19. package/frigg-cli/install-command/install-package.js +4 -77
  20. package/frigg-cli/install-command/integration-file.js +11 -20
  21. package/frigg-cli/install-command/template.js +75 -102
  22. package/frigg-cli/install-command/validate-package.js +4 -36
  23. package/frigg-cli/package.json +3 -3
  24. package/frigg-cli/repair-command/index.js +7 -0
  25. package/frigg-cli/start-command/index.js +58 -0
  26. package/frigg-cli/test/init-command.test.js +2 -9
  27. package/frigg-cli/utils/provider-helper.js +80 -0
  28. package/infrastructure/README.md +4 -22
  29. package/infrastructure/__tests__/compose-extension-prisma.test.js +168 -0
  30. package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +64 -0
  31. package/infrastructure/__tests__/management-api-gateway-routes.test.js +335 -0
  32. package/infrastructure/__tests__/template-generation.test.js +7 -0
  33. package/infrastructure/compose-extension-prisma.js +73 -0
  34. package/infrastructure/create-frigg-infrastructure.js +14 -0
  35. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +1 -21
  36. package/infrastructure/domains/admin-scripts/admin-script-builder.js +48 -56
  37. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +7 -76
  38. package/infrastructure/domains/database/aurora-builder.js +2 -13
  39. package/infrastructure/domains/database/aurora-builder.test.js +0 -22
  40. package/infrastructure/domains/database/migration-builder.js +175 -182
  41. package/infrastructure/domains/database/migration-builder.test.js +5 -36
  42. package/infrastructure/domains/integration/integration-builder.js +61 -65
  43. package/infrastructure/domains/integration/integration-builder.test.js +8 -73
  44. package/infrastructure/domains/parameters/offload-utils.js +1 -0
  45. package/infrastructure/domains/security/iam-generator.js +5 -112
  46. package/infrastructure/domains/security/iam-generator.test.js +0 -94
  47. package/infrastructure/domains/shared/environment-builder.js +12 -1
  48. package/infrastructure/domains/shared/environment-builder.test.js +20 -0
  49. package/infrastructure/domains/shared/types/app-definition.js +15 -1
  50. package/infrastructure/domains/shared/utilities/base-definition-factory.js +152 -93
  51. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +111 -117
  52. package/infrastructure/domains/shared/utilities/logging-config.js +4 -3
  53. package/infrastructure/domains/shared/utilities/logging-config.test.js +2 -1
  54. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +10 -0
  55. package/infrastructure/infrastructure-composer.js +13 -1
  56. package/infrastructure/infrastructure-composer.test.js +10 -3
  57. package/infrastructure/provider-build.js +126 -0
  58. package/infrastructure/scripts/build-prisma-layer.js +32 -5
  59. package/infrastructure/scripts/build-prisma-layer.test.js +35 -0
  60. package/package.json +8 -13
  61. package/test/npm-install-guard.js +104 -0
  62. package/test/npm-install-guard.test.js +53 -0
  63. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
  64. package/frigg-cli/__tests__/unit/utils/node-version.test.js +0 -66
  65. package/frigg-cli/init-command/deployment-modes.js +0 -7
  66. package/frigg-cli/init-command/safe-path.js +0 -58
  67. package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
  68. package/frigg-cli/install-command/app-definition.js +0 -174
  69. package/frigg-cli/install-command/resolve-module.js +0 -69
  70. package/frigg-cli/templates/backend/README.md +0 -267
  71. package/frigg-cli/templates/backend/env.example +0 -20
  72. package/frigg-cli/templates/backend/gitignore +0 -10
  73. package/frigg-cli/templates/backend/index.js +0 -114
  74. package/frigg-cli/templates/backend/infrastructure.js +0 -20
  75. package/frigg-cli/utils/node-version.js +0 -51
  76. package/infrastructure/__tests__/package-patterns-composition.test.js +0 -153
  77. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
  78. package/infrastructure/domains/shared/utilities/framework-version.js +0 -14
  79. package/infrastructure/domains/shared/utilities/framework-version.test.js +0 -27
  80. package/infrastructure/domains/shared/utilities/package-patterns.js +0 -35
  81. package/infrastructure/domains/shared/utilities/package-patterns.test.js +0 -112
@@ -1,148 +0,0 @@
1
- /**
2
- * The app scaffolded by `frigg init` must deploy with no always-on AWS cost.
3
- *
4
- * Scaffolds the backend template, loads its Definition and composes it the way
5
- * `frigg deploy` does (AWS discovery stubbed), then asserts the template has
6
- * no VPC, NAT gateway, Elastic IP, VPC endpoint or RDS/Aurora resource, that
7
- * no Lambda is attached to a VPC, and that field-level encryption still gets
8
- * its KMS key.
9
- */
10
-
11
- const os = require('os');
12
- const path = require('path');
13
- const fs = require('fs-extra');
14
-
15
- jest.mock('../domains/shared/resource-discovery', () => ({
16
- ...jest.requireActual('../domains/shared/resource-discovery'),
17
- gatherDiscoveredResources: jest.fn(),
18
- }));
19
- jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
20
- ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
21
- }));
22
-
23
- const {
24
- gatherDiscoveredResources,
25
- } = require('../domains/shared/resource-discovery');
26
- const { composeServerlessDefinition } = require('../infrastructure-composer');
27
- const BackendFirstHandler = require('../../frigg-cli/init-command/backend-first-handler');
28
-
29
- const FORBIDDEN_RESOURCE_TYPES = [
30
- 'AWS::EC2::VPC',
31
- 'AWS::EC2::NatGateway',
32
- 'AWS::EC2::EIP',
33
- 'AWS::EC2::VPCEndpoint',
34
- 'AWS::RDS::DBCluster',
35
- 'AWS::RDS::DBInstance',
36
- 'AWS::RDS::DBSubnetGroup',
37
- ];
38
-
39
- // An account that already holds a default VPC, subnets, a NAT gateway and an
40
- // Aurora cluster: none of it may leak into the scaffolded app's template.
41
- const BUSY_ACCOUNT_DISCOVERY = {
42
- defaultVpcId: 'vpc-123456',
43
- vpcCidr: '172.31.0.0/16',
44
- defaultSecurityGroupId: 'sg-123456',
45
- privateSubnetId1: 'subnet-123456',
46
- privateSubnetId2: 'subnet-789012',
47
- publicSubnetId1: 'subnet-public-1',
48
- publicSubnetId2: 'subnet-public-2',
49
- defaultRouteTableId: 'rtb-123456',
50
- existingNatGatewayId: 'nat-default123',
51
- auroraClusterEndpoint: 'c.cluster-abc123.us-east-1.rds.amazonaws.com',
52
- auroraPort: 5432,
53
- auroraEngine: 'aurora-postgresql',
54
- };
55
-
56
- describe('frigg init default infrastructure', () => {
57
- let tmpDir;
58
- let Definition;
59
- let logSpy;
60
-
61
- beforeAll(async () => {
62
- logSpy = jest.spyOn(console, 'log').mockImplementation();
63
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-default-infra-'));
64
- const target = path.join(tmpDir, 'demo-app');
65
- await new BackendFirstHandler(target, {
66
- yes: true,
67
- install: false,
68
- git: false,
69
- }).initialize();
70
- ({ Definition } = require(path.join(target, 'index.js')));
71
- });
72
-
73
- afterAll(() => {
74
- fs.removeSync(tmpDir);
75
- logSpy.mockRestore();
76
- });
77
-
78
- beforeEach(() => {
79
- delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
80
- process.argv = ['node', 'test'];
81
- });
82
-
83
- const compose = async (discovery) => {
84
- gatherDiscoveredResources.mockResolvedValue(discovery);
85
- // The composer mutates nested parts of the definition.
86
- return composeServerlessDefinition(
87
- JSON.parse(JSON.stringify(Definition))
88
- );
89
- };
90
-
91
- const resourceTypes = (definition) =>
92
- Object.values(definition.resources.Resources).map((r) => r.Type);
93
-
94
- it('passes the app-definition schema', () => {
95
- const { validateAppDefinition } = require('@friggframework/schemas');
96
- expect(validateAppDefinition(Definition).valid).toBe(true);
97
- });
98
-
99
- it.each([
100
- ['an empty account', {}],
101
- ['an account with existing VPC/NAT/Aurora', BUSY_ACCOUNT_DISCOVERY],
102
- ])('composes no always-on resources in %s', async (_label, discovery) => {
103
- const definition = await compose(discovery);
104
- const types = resourceTypes(definition);
105
-
106
- for (const forbidden of FORBIDDEN_RESOURCE_TYPES) {
107
- expect(types).not.toContain(forbidden);
108
- }
109
-
110
- // No Lambda is attached to a VPC.
111
- expect(definition.provider.vpc).toBeUndefined();
112
- for (const fn of Object.values(definition.functions)) {
113
- expect(fn.vpc).toBeUndefined();
114
- }
115
- for (const resource of Object.values(definition.resources.Resources)) {
116
- expect(resource.Properties?.VpcConfig).toBeUndefined();
117
- }
118
- });
119
-
120
- it('keeps field-level encryption on with a per-stage KMS key', async () => {
121
- const definition = await compose({});
122
-
123
- expect(definition.resources.Resources.FriggKMSKey.Type).toBe(
124
- 'AWS::KMS::Key'
125
- );
126
- expect(definition.provider.environment.KMS_KEY_ARN).toEqual({
127
- 'Fn::GetAtt': ['FriggKMSKey', 'Arn'],
128
- });
129
- });
130
-
131
- it('connects to the external database through DATABASE_URL', async () => {
132
- const definition = await compose({});
133
-
134
- expect(definition.provider.environment.DATABASE_URL).toBe(
135
- "${env:DATABASE_URL, ''}"
136
- );
137
- expect(definition.provider.environment.DB_TYPE).toBe('postgresql');
138
- expect(definition.resources.Resources.FriggDBSecret).toBeUndefined();
139
- });
140
-
141
- it('expires Lambda logs after 14 days', async () => {
142
- // Without provider.logRetentionInDays, osls creates log groups that
143
- // never expire, so CloudWatch storage grows forever.
144
- const definition = await compose({});
145
-
146
- expect(definition.provider.logRetentionInDays).toBe(14);
147
- });
148
- });
@@ -1,14 +0,0 @@
1
- /**
2
- * osls framework version
3
- *
4
- * Utility Layer - Hexagonal Architecture
5
- *
6
- * The single `frameworkVersion` every composed definition emits (ADR-050).
7
- * It matches the osls range in devtools and frigg-cli, so an app whose own
8
- * package.json still resolves osls 3 fails at once with
9
- * FRAMEWORK_VERSION_MISMATCH instead of packaging a different artifact.
10
- * It subsumes the ADR-048 LoggingConfig floor (>=3.58.0).
11
- */
12
- const OSLS_FRAMEWORK_VERSION = '^4.4.0';
13
-
14
- module.exports = { OSLS_FRAMEWORK_VERSION };
@@ -1,27 +0,0 @@
1
- const { OSLS_FRAMEWORK_VERSION } = require('./framework-version');
2
- const semver = require('semver');
3
-
4
- describe('OSLS_FRAMEWORK_VERSION (ADR-050)', () => {
5
- it('is the osls 4 range Frigg targets', () => {
6
- expect(OSLS_FRAMEWORK_VERSION).toBe('^4.4.0');
7
- });
8
-
9
- it.each([
10
- ['4.4.0', true],
11
- ['4.9.1', true],
12
- ['4.3.9', false],
13
- ['3.78.0', false],
14
- ['5.0.0', false],
15
- ])('osls %s satisfies it: %s', (version, expected) => {
16
- // osls compares frameworkVersion with semver.satisfies and fails
17
- // with FRAMEWORK_VERSION_MISMATCH otherwise.
18
- expect(semver.satisfies(version, OSLS_FRAMEWORK_VERSION)).toBe(expected);
19
- });
20
-
21
- it('matches the osls range devtools and frigg-cli depend on', () => {
22
- const devtools = require('../../../../package.json');
23
- const cli = require('../../../../frigg-cli/package.json');
24
- expect(devtools.devDependencies.osls).toBe(OSLS_FRAMEWORK_VERSION);
25
- expect(cli.dependencies.osls).toBe(OSLS_FRAMEWORK_VERSION);
26
- });
27
- });
@@ -1,35 +0,0 @@
1
- /**
2
- * Function package patterns
3
- *
4
- * Utility Layer - Hexagonal Architecture
5
- *
6
- * osls 4 rejects `package.include` / `package.exclude` and only reads
7
- * `package.patterns` (ADR-050). Builders keep their include and exclude lists
8
- * and pass them through this helper, so one place owns the negation.
9
- *
10
- * osls resolves a function's files with `resolveFilePathsFromPatterns`: an
11
- * ordered list evaluated last-match-wins. On osls 3 a function `exclude` was
12
- * placed (negated) ahead of the function `include`. Frigg emits no
13
- * service-level include, exclude or patterns, so `[!exclude..., include...]`
14
- * reproduces the osls 3 order exactly, and is valid on osls 3 and osls 4.
15
- *
16
- * An exclude that already starts with `!` was treated by osls 3 as an include
17
- * in exclude position; it is emitted un-negated in the same position here.
18
- */
19
-
20
- /**
21
- * @param {Object} [lists]
22
- * @param {string[]} [lists.include] - Globs to (re-)add after the excludes
23
- * @param {string[]} [lists.exclude] - Globs to remove
24
- * @returns {string[]} Value for `package.patterns`
25
- */
26
- function toPackagePatterns({ include = [], exclude = [] } = {}) {
27
- return [
28
- ...exclude.map((pattern) =>
29
- pattern.startsWith('!') ? pattern.slice(1) : `!${pattern}`
30
- ),
31
- ...include,
32
- ];
33
- }
34
-
35
- module.exports = { toPackagePatterns };
@@ -1,112 +0,0 @@
1
- /**
2
- * Tests for the function package patterns helper (ADR-050)
3
- */
4
-
5
- const { toPackagePatterns } = require('./package-patterns');
6
- const { nestedNodeModulesExcludes } = require('./nested-node-modules');
7
-
8
- /**
9
- * The ordered list osls 3 built in resolveFilePathsFromPatterns for a function
10
- * that set `package.include` / `package.exclude` (no service-level patterns,
11
- * which Frigg never emits, and before the dev-dependency patterns that both
12
- * versions append identically).
13
- */
14
- function osls3FunctionOrder({ include = [], exclude = [] }) {
15
- const patterns = [];
16
- exclude.forEach((p) => patterns.push(p.charAt(0) !== '!' ? `!${p}` : p.substring(1)));
17
- include.forEach((p) => patterns.push(p));
18
- return patterns;
19
- }
20
-
21
- /**
22
- * The ordered list osls 3 and osls 4 build for a function that sets
23
- * `package.patterns`: the patterns go in include position, unchanged.
24
- */
25
- function patternsFunctionOrder(patterns) {
26
- return [...patterns];
27
- }
28
-
29
- describe('toPackagePatterns', () => {
30
- const cases = [
31
- {
32
- name: 'excludes first (negated), then includes',
33
- lists: {
34
- include: ['ca.pem'],
35
- exclude: ['node_modules/aws-sdk/**', '.env'],
36
- },
37
- expected: ['!node_modules/aws-sdk/**', '!.env', 'ca.pem'],
38
- },
39
- {
40
- name: 'an exclude that already starts with ! becomes an include in exclude position',
41
- lists: {
42
- include: [],
43
- exclude: ['node_modules/**', '!node_modules/keep/**'],
44
- },
45
- expected: ['!node_modules/**', 'node_modules/keep/**'],
46
- },
47
- {
48
- name: 'an include re-adds a path that an exclude removed',
49
- lists: {
50
- include: ['config/ca.pem'],
51
- exclude: ['config/**'],
52
- },
53
- expected: ['!config/**', 'config/ca.pem'],
54
- },
55
- {
56
- name: 'empty lists',
57
- lists: { include: [], exclude: [] },
58
- expected: [],
59
- },
60
- {
61
- name: 'only excludes',
62
- lists: { exclude: ['test/**'] },
63
- expected: ['!test/**'],
64
- },
65
- {
66
- name: 'only includes',
67
- lists: { include: ['ca.pem'] },
68
- expected: ['ca.pem'],
69
- },
70
- ];
71
-
72
- it.each(cases)('$name', ({ lists, expected }) => {
73
- const patterns = toPackagePatterns(lists);
74
- expect(patterns).toEqual(expected);
75
- // Same evaluation order osls 3 applied to include/exclude.
76
- expect(patternsFunctionOrder(patterns)).toEqual(osls3FunctionOrder(lists));
77
- });
78
-
79
- it('returns an empty list when called with no arguments', () => {
80
- expect(toPackagePatterns()).toEqual([]);
81
- });
82
-
83
- it('does not mutate its inputs', () => {
84
- const exclude = ['a/**'];
85
- const include = ['b'];
86
- toPackagePatterns({ include, exclude });
87
- expect(exclude).toEqual(['a/**']);
88
- expect(include).toEqual(['b']);
89
- });
90
-
91
- describe('with nestedNodeModulesExcludes output', () => {
92
- it('negates the single catch-all glob by default', () => {
93
- const exclude = nestedNodeModulesExcludes({}, true);
94
- expect(toPackagePatterns({ exclude })).toEqual([
95
- '!node_modules/**/node_modules/**',
96
- ]);
97
- });
98
-
99
- it('negates every scoped glob when keepNestedNodeModules is set', () => {
100
- const appDefinition = { lambda: { keepNestedNodeModules: true } };
101
- const exclude = nestedNodeModulesExcludes(appDefinition, true);
102
- const patterns = toPackagePatterns({ exclude });
103
-
104
- expect(patterns).toEqual(exclude.map((p) => `!${p}`));
105
- expect(patterns).toContain('!node_modules/**/node_modules/@friggframework/**');
106
- expect(patterns).not.toContain('!node_modules/**/node_modules/**');
107
- expect(patternsFunctionOrder(patterns)).toEqual(
108
- osls3FunctionOrder({ exclude })
109
- );
110
- });
111
- });
112
- });