@friggframework/devtools 2.0.0-next.45 → 2.0.0-next.47
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/infrastructure/ARCHITECTURE.md +487 -0
- package/infrastructure/HEALTH.md +468 -0
- package/infrastructure/README.md +51 -0
- package/infrastructure/__tests__/postgres-config.test.js +914 -0
- package/infrastructure/__tests__/template-generation.test.js +687 -0
- package/infrastructure/create-frigg-infrastructure.js +1 -1
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +630 -0
- package/infrastructure/{DEPLOYMENT-INSTRUCTIONS.md → docs/deployment-instructions.md} +3 -3
- package/infrastructure/{IAM-POLICY-TEMPLATES.md → docs/iam-policy-templates.md} +9 -10
- package/infrastructure/domains/database/aurora-builder.js +809 -0
- package/infrastructure/domains/database/aurora-builder.test.js +950 -0
- package/infrastructure/domains/database/aurora-discovery.js +87 -0
- package/infrastructure/domains/database/aurora-discovery.test.js +188 -0
- package/infrastructure/domains/database/aurora-resolver.js +210 -0
- package/infrastructure/domains/database/aurora-resolver.test.js +347 -0
- package/infrastructure/domains/database/migration-builder.js +695 -0
- package/infrastructure/domains/database/migration-builder.test.js +294 -0
- package/infrastructure/domains/database/migration-resolver.js +163 -0
- package/infrastructure/domains/database/migration-resolver.test.js +337 -0
- package/infrastructure/domains/health/application/ports/IPropertyReconciler.js +164 -0
- package/infrastructure/domains/health/application/ports/IResourceDetector.js +129 -0
- package/infrastructure/domains/health/application/ports/IResourceImporter.js +142 -0
- package/infrastructure/domains/health/application/ports/IStackRepository.js +131 -0
- package/infrastructure/domains/health/application/ports/index.js +26 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/execute-resource-import-use-case.test.js +679 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +167 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +1130 -0
- package/infrastructure/domains/health/application/use-cases/execute-resource-import-use-case.js +221 -0
- package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.js +152 -0
- package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.test.js +343 -0
- package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.js +535 -0
- package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.test.js +376 -0
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.js +213 -0
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +441 -0
- package/infrastructure/domains/health/docs/ACME-DEV-DRIFT-ANALYSIS.md +267 -0
- package/infrastructure/domains/health/docs/BUILD-VS-DEPLOYED-TEMPLATE-ANALYSIS.md +324 -0
- package/infrastructure/domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md +386 -0
- package/infrastructure/domains/health/docs/SPEC-CLEANUP-COMMAND.md +1419 -0
- package/infrastructure/domains/health/docs/TDD-IMPLEMENTATION-SUMMARY.md +391 -0
- package/infrastructure/domains/health/docs/TEMPLATE-COMPARISON-IMPLEMENTATION.md +551 -0
- package/infrastructure/domains/health/domain/entities/issue.js +299 -0
- package/infrastructure/domains/health/domain/entities/issue.test.js +528 -0
- package/infrastructure/domains/health/domain/entities/property-mismatch.js +108 -0
- package/infrastructure/domains/health/domain/entities/property-mismatch.test.js +275 -0
- package/infrastructure/domains/health/domain/entities/resource.js +159 -0
- package/infrastructure/domains/health/domain/entities/resource.test.js +432 -0
- package/infrastructure/domains/health/domain/entities/stack-health-report.js +306 -0
- package/infrastructure/domains/health/domain/entities/stack-health-report.test.js +601 -0
- package/infrastructure/domains/health/domain/services/__tests__/health-score-percentage-based.test.js +380 -0
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +971 -0
- package/infrastructure/domains/health/domain/services/__tests__/import-template-generator.test.js +1150 -0
- package/infrastructure/domains/health/domain/services/__tests__/logical-id-mapper.test.js +672 -0
- package/infrastructure/domains/health/domain/services/__tests__/template-parser.test.js +496 -0
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +419 -0
- package/infrastructure/domains/health/domain/services/health-score-calculator.js +248 -0
- package/infrastructure/domains/health/domain/services/health-score-calculator.test.js +504 -0
- package/infrastructure/domains/health/domain/services/import-progress-monitor.js +195 -0
- package/infrastructure/domains/health/domain/services/import-template-generator.js +435 -0
- package/infrastructure/domains/health/domain/services/logical-id-mapper.js +345 -0
- package/infrastructure/domains/health/domain/services/mismatch-analyzer.js +234 -0
- package/infrastructure/domains/health/domain/services/mismatch-analyzer.test.js +431 -0
- package/infrastructure/domains/health/domain/services/property-mutability-config.js +382 -0
- package/infrastructure/domains/health/domain/services/template-parser.js +245 -0
- package/infrastructure/domains/health/domain/services/update-progress-monitor.js +192 -0
- package/infrastructure/domains/health/domain/value-objects/health-score.js +138 -0
- package/infrastructure/domains/health/domain/value-objects/health-score.test.js +267 -0
- package/infrastructure/domains/health/domain/value-objects/property-mutability.js +161 -0
- package/infrastructure/domains/health/domain/value-objects/property-mutability.test.js +198 -0
- package/infrastructure/domains/health/domain/value-objects/resource-state.js +167 -0
- package/infrastructure/domains/health/domain/value-objects/resource-state.test.js +196 -0
- package/infrastructure/domains/health/domain/value-objects/stack-identifier.js +192 -0
- package/infrastructure/domains/health/domain/value-objects/stack-identifier.test.js +262 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-cfn-tagged.test.js +312 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-multi-stack.test.js +367 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +432 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.js +784 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +1133 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.js +565 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +554 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.js +318 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.test.js +398 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.js +777 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.test.js +580 -0
- package/infrastructure/domains/integration/integration-builder.js +397 -0
- package/infrastructure/domains/integration/integration-builder.test.js +593 -0
- package/infrastructure/domains/integration/integration-resolver.js +170 -0
- package/infrastructure/domains/integration/integration-resolver.test.js +369 -0
- package/infrastructure/domains/integration/websocket-builder.js +69 -0
- package/infrastructure/domains/integration/websocket-builder.test.js +195 -0
- package/infrastructure/domains/networking/vpc-builder.js +1829 -0
- package/infrastructure/domains/networking/vpc-builder.test.js +1262 -0
- package/infrastructure/domains/networking/vpc-discovery.js +177 -0
- package/infrastructure/domains/networking/vpc-discovery.test.js +350 -0
- package/infrastructure/domains/networking/vpc-resolver.js +324 -0
- package/infrastructure/domains/networking/vpc-resolver.test.js +501 -0
- package/infrastructure/domains/parameters/ssm-builder.js +79 -0
- package/infrastructure/domains/parameters/ssm-builder.test.js +189 -0
- package/infrastructure/domains/parameters/ssm-discovery.js +84 -0
- package/infrastructure/domains/parameters/ssm-discovery.test.js +210 -0
- package/infrastructure/{iam-generator.js → domains/security/iam-generator.js} +2 -2
- package/infrastructure/domains/security/kms-builder.js +366 -0
- package/infrastructure/domains/security/kms-builder.test.js +374 -0
- package/infrastructure/domains/security/kms-discovery.js +80 -0
- package/infrastructure/domains/security/kms-discovery.test.js +177 -0
- package/infrastructure/domains/security/kms-resolver.js +96 -0
- package/infrastructure/domains/security/kms-resolver.test.js +216 -0
- package/infrastructure/domains/shared/base-builder.js +112 -0
- package/infrastructure/domains/shared/base-resolver.js +186 -0
- package/infrastructure/domains/shared/base-resolver.test.js +305 -0
- package/infrastructure/domains/shared/builder-orchestrator.js +212 -0
- package/infrastructure/domains/shared/builder-orchestrator.test.js +213 -0
- package/infrastructure/domains/shared/cloudformation-discovery-v2.js +334 -0
- package/infrastructure/domains/shared/cloudformation-discovery.js +375 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +590 -0
- package/infrastructure/domains/shared/environment-builder.js +119 -0
- package/infrastructure/domains/shared/environment-builder.test.js +247 -0
- package/infrastructure/domains/shared/providers/aws-provider-adapter.js +544 -0
- package/infrastructure/domains/shared/providers/aws-provider-adapter.test.js +377 -0
- package/infrastructure/domains/shared/providers/azure-provider-adapter.stub.js +93 -0
- package/infrastructure/domains/shared/providers/cloud-provider-adapter.js +136 -0
- package/infrastructure/domains/shared/providers/gcp-provider-adapter.stub.js +82 -0
- package/infrastructure/domains/shared/providers/provider-factory.js +108 -0
- package/infrastructure/domains/shared/providers/provider-factory.test.js +170 -0
- package/infrastructure/domains/shared/resource-discovery.js +192 -0
- package/infrastructure/domains/shared/resource-discovery.test.js +552 -0
- package/infrastructure/domains/shared/types/app-definition.js +205 -0
- package/infrastructure/domains/shared/types/discovery-result.js +106 -0
- package/infrastructure/domains/shared/types/discovery-result.test.js +258 -0
- package/infrastructure/domains/shared/types/index.js +46 -0
- package/infrastructure/domains/shared/types/resource-ownership.js +108 -0
- package/infrastructure/domains/shared/types/resource-ownership.test.js +101 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +380 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js.bak +338 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +248 -0
- package/infrastructure/domains/shared/utilities/handler-path-resolver.js +134 -0
- package/infrastructure/domains/shared/utilities/handler-path-resolver.test.js +268 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +55 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +138 -0
- package/infrastructure/{env-validator.js → domains/shared/validation/env-validator.js} +2 -1
- package/infrastructure/domains/shared/validation/env-validator.test.js +173 -0
- package/infrastructure/esbuild.config.js +53 -0
- package/infrastructure/infrastructure-composer.js +87 -0
- package/infrastructure/{serverless-template.test.js → infrastructure-composer.test.js} +115 -24
- package/infrastructure/scripts/build-prisma-layer.js +553 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +102 -0
- package/infrastructure/{build-time-discovery.js → scripts/build-time-discovery.js} +80 -48
- package/infrastructure/{build-time-discovery.test.js → scripts/build-time-discovery.test.js} +5 -4
- package/layers/prisma/nodejs/package.json +8 -0
- package/management-ui/server/utils/cliIntegration.js +1 -1
- package/management-ui/server/utils/environment/awsParameterStore.js +29 -18
- package/package.json +11 -11
- package/frigg-cli/.eslintrc.js +0 -141
- package/frigg-cli/__tests__/unit/commands/build.test.js +0 -251
- package/frigg-cli/__tests__/unit/commands/db-setup.test.js +0 -548
- package/frigg-cli/__tests__/unit/commands/install.test.js +0 -400
- package/frigg-cli/__tests__/unit/commands/ui.test.js +0 -346
- package/frigg-cli/__tests__/unit/utils/database-validator.test.js +0 -366
- package/frigg-cli/__tests__/unit/utils/error-messages.test.js +0 -304
- package/frigg-cli/__tests__/unit/utils/prisma-runner.test.js +0 -486
- package/frigg-cli/__tests__/utils/mock-factory.js +0 -270
- package/frigg-cli/__tests__/utils/prisma-mock.js +0 -194
- package/frigg-cli/__tests__/utils/test-fixtures.js +0 -463
- package/frigg-cli/__tests__/utils/test-setup.js +0 -287
- package/frigg-cli/build-command/index.js +0 -65
- package/frigg-cli/db-setup-command/index.js +0 -193
- package/frigg-cli/deploy-command/index.js +0 -175
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +0 -301
- package/frigg-cli/generate-command/azure-generator.js +0 -43
- package/frigg-cli/generate-command/gcp-generator.js +0 -47
- package/frigg-cli/generate-command/index.js +0 -332
- package/frigg-cli/generate-command/terraform-generator.js +0 -555
- package/frigg-cli/generate-iam-command.js +0 -118
- package/frigg-cli/index.js +0 -75
- package/frigg-cli/index.test.js +0 -158
- package/frigg-cli/init-command/backend-first-handler.js +0 -756
- package/frigg-cli/init-command/index.js +0 -93
- package/frigg-cli/init-command/template-handler.js +0 -143
- package/frigg-cli/install-command/backend-js.js +0 -33
- package/frigg-cli/install-command/commit-changes.js +0 -16
- package/frigg-cli/install-command/environment-variables.js +0 -127
- package/frigg-cli/install-command/environment-variables.test.js +0 -136
- package/frigg-cli/install-command/index.js +0 -54
- package/frigg-cli/install-command/install-package.js +0 -13
- package/frigg-cli/install-command/integration-file.js +0 -30
- package/frigg-cli/install-command/logger.js +0 -12
- package/frigg-cli/install-command/template.js +0 -90
- package/frigg-cli/install-command/validate-package.js +0 -75
- package/frigg-cli/jest.config.js +0 -124
- package/frigg-cli/package.json +0 -54
- package/frigg-cli/start-command/index.js +0 -149
- package/frigg-cli/start-command/start-command.test.js +0 -297
- package/frigg-cli/test/init-command.test.js +0 -180
- package/frigg-cli/test/npm-registry.test.js +0 -319
- package/frigg-cli/ui-command/index.js +0 -154
- package/frigg-cli/utils/app-resolver.js +0 -319
- package/frigg-cli/utils/backend-path.js +0 -25
- package/frigg-cli/utils/database-validator.js +0 -161
- package/frigg-cli/utils/error-messages.js +0 -257
- package/frigg-cli/utils/npm-registry.js +0 -167
- package/frigg-cli/utils/prisma-runner.js +0 -280
- package/frigg-cli/utils/process-manager.js +0 -199
- package/frigg-cli/utils/repo-detection.js +0 -405
- package/infrastructure/aws-discovery.js +0 -1176
- package/infrastructure/aws-discovery.test.js +0 -1220
- package/infrastructure/serverless-template.js +0 -2094
- /package/infrastructure/{WEBSOCKET-CONFIGURATION.md → docs/WEBSOCKET-CONFIGURATION.md} +0 -0
- /package/infrastructure/{GENERATE-IAM-DOCS.md → docs/generate-iam-command.md} +0 -0
- /package/infrastructure/{iam-generator.test.js → domains/security/iam-generator.test.js} +0 -0
- /package/infrastructure/{frigg-deployment-iam-stack.yaml → domains/security/templates/frigg-deployment-iam-stack.yaml} +0 -0
- /package/infrastructure/{iam-policy-basic.json → domains/security/templates/iam-policy-basic.json} +0 -0
- /package/infrastructure/{iam-policy-full.json → domains/security/templates/iam-policy-full.json} +0 -0
- /package/infrastructure/{run-discovery.js → scripts/run-discovery.js} +0 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for MigrationBuilder
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { MigrationBuilder } = require('./migration-builder');
|
|
6
|
+
|
|
7
|
+
describe('MigrationBuilder', () => {
|
|
8
|
+
let builder;
|
|
9
|
+
let originalEnv;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
builder = new MigrationBuilder();
|
|
13
|
+
originalEnv = { ...process.env };
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
process.env = originalEnv;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('shouldExecute', () => {
|
|
21
|
+
it('should return true for PostgreSQL by default', () => {
|
|
22
|
+
const appDef = {
|
|
23
|
+
database: {},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
expect(builder.shouldExecute(appDef)).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return true when PostgreSQL is explicitly enabled', () => {
|
|
30
|
+
const appDef = {
|
|
31
|
+
database: {
|
|
32
|
+
postgres: {
|
|
33
|
+
enable: true,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
expect(builder.shouldExecute(appDef)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return false when PostgreSQL is explicitly disabled', () => {
|
|
42
|
+
const appDef = {
|
|
43
|
+
database: {
|
|
44
|
+
postgres: {
|
|
45
|
+
enable: false,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
expect(builder.shouldExecute(appDef)).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should return false in local mode', () => {
|
|
54
|
+
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
55
|
+
|
|
56
|
+
const appDef = {
|
|
57
|
+
database: {
|
|
58
|
+
postgres: {
|
|
59
|
+
enable: true,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
expect(builder.shouldExecute(appDef)).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should return true for MongoDB-only (defaults to PostgreSQL)', () => {
|
|
68
|
+
const appDef = {
|
|
69
|
+
database: {
|
|
70
|
+
mongodb: {
|
|
71
|
+
enable: true,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
expect(builder.shouldExecute(appDef)).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('getDependencies', () => {
|
|
81
|
+
it('should have no dependencies', () => {
|
|
82
|
+
expect(builder.getDependencies()).toEqual([]);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('validate', () => {
|
|
87
|
+
it('should always return valid', () => {
|
|
88
|
+
const appDef = {
|
|
89
|
+
database: {
|
|
90
|
+
postgres: {
|
|
91
|
+
enable: true,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const result = builder.validate(appDef);
|
|
97
|
+
|
|
98
|
+
expect(result.valid).toBe(true);
|
|
99
|
+
expect(result.errors).toEqual([]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('build', () => {
|
|
104
|
+
it('should create SQS queue resource', async () => {
|
|
105
|
+
const appDef = {
|
|
106
|
+
database: {
|
|
107
|
+
postgres: {
|
|
108
|
+
enable: true,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const result = await builder.build(appDef, {});
|
|
114
|
+
|
|
115
|
+
expect(result.resources.DbMigrationQueue).toBeDefined();
|
|
116
|
+
expect(result.resources.DbMigrationQueue.Type).toBe('AWS::SQS::Queue');
|
|
117
|
+
expect(result.resources.DbMigrationQueue.Properties.QueueName).toBe(
|
|
118
|
+
'${self:service}-${self:provider.stage}-DbMigrationQueue'
|
|
119
|
+
);
|
|
120
|
+
expect(result.resources.DbMigrationQueue.Properties.VisibilityTimeout).toBe(900);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should create S3 migration status bucket', async () => {
|
|
124
|
+
const appDef = {
|
|
125
|
+
database: {
|
|
126
|
+
postgres: {
|
|
127
|
+
enable: true,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const result = await builder.build(appDef, {});
|
|
133
|
+
|
|
134
|
+
expect(result.resources.FriggMigrationStatusBucket).toBeDefined();
|
|
135
|
+
expect(result.resources.FriggMigrationStatusBucket.Type).toBe('AWS::S3::Bucket');
|
|
136
|
+
expect(result.resources.FriggMigrationStatusBucket.DeletionPolicy).toBe('Retain');
|
|
137
|
+
expect(result.resources.FriggMigrationStatusBucket.Properties.VersioningConfiguration.Status).toBe('Enabled');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should add queue URL to environment', async () => {
|
|
141
|
+
const appDef = {
|
|
142
|
+
database: {
|
|
143
|
+
postgres: {
|
|
144
|
+
enable: true,
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const result = await builder.build(appDef, {});
|
|
150
|
+
|
|
151
|
+
expect(result.environment.DB_MIGRATION_QUEUE_URL).toEqual({
|
|
152
|
+
Ref: 'DbMigrationQueue',
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should add SQS IAM permissions', async () => {
|
|
157
|
+
const appDef = {
|
|
158
|
+
database: {
|
|
159
|
+
postgres: {
|
|
160
|
+
enable: true,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const result = await builder.build(appDef, {});
|
|
166
|
+
|
|
167
|
+
expect(result.iamStatements).toContainEqual({
|
|
168
|
+
Effect: 'Allow',
|
|
169
|
+
Action: [
|
|
170
|
+
'sqs:SendMessage',
|
|
171
|
+
'sqs:GetQueueUrl',
|
|
172
|
+
'sqs:GetQueueAttributes',
|
|
173
|
+
],
|
|
174
|
+
Resource: { 'Fn::GetAtt': ['DbMigrationQueue', 'Arn'] },
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should add S3 IAM permissions including ListBucket', async () => {
|
|
179
|
+
const appDef = {
|
|
180
|
+
database: {
|
|
181
|
+
postgres: {
|
|
182
|
+
enable: true,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const result = await builder.build(appDef, {});
|
|
188
|
+
|
|
189
|
+
// Should have object-level permissions
|
|
190
|
+
expect(result.iamStatements).toContainEqual(
|
|
191
|
+
expect.objectContaining({
|
|
192
|
+
Effect: 'Allow',
|
|
193
|
+
Action: expect.arrayContaining([
|
|
194
|
+
's3:PutObject',
|
|
195
|
+
's3:GetObject',
|
|
196
|
+
's3:DeleteObject',
|
|
197
|
+
]),
|
|
198
|
+
Resource: expect.objectContaining({
|
|
199
|
+
'Fn::Join': expect.anything(),
|
|
200
|
+
}),
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
// Should have bucket-level ListBucket permission (needed to check if objects exist)
|
|
205
|
+
expect(result.iamStatements).toContainEqual(
|
|
206
|
+
expect.objectContaining({
|
|
207
|
+
Effect: 'Allow',
|
|
208
|
+
Action: ['s3:ListBucket'],
|
|
209
|
+
Resource: { 'Fn::GetAtt': ['FriggMigrationStatusBucket', 'Arn'] },
|
|
210
|
+
})
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should create dbMigrationRouter function definition', async () => {
|
|
215
|
+
const appDef = {
|
|
216
|
+
database: {
|
|
217
|
+
postgres: {
|
|
218
|
+
enable: true,
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const result = await builder.build(appDef, {});
|
|
224
|
+
|
|
225
|
+
expect(result.functions.dbMigrationRouter).toBeDefined();
|
|
226
|
+
expect(result.functions.dbMigrationRouter.handler).toBe(
|
|
227
|
+
'node_modules/@friggframework/core/handlers/routers/db-migration.handler'
|
|
228
|
+
);
|
|
229
|
+
expect(result.functions.dbMigrationRouter.skipEsbuild).toBe(true);
|
|
230
|
+
expect(result.functions.dbMigrationRouter.timeout).toBe(30);
|
|
231
|
+
expect(result.functions.dbMigrationRouter.memorySize).toBe(512);
|
|
232
|
+
expect(result.functions.dbMigrationRouter.events).toHaveLength(3);
|
|
233
|
+
expect(result.functions.dbMigrationRouter.events).toContainEqual({
|
|
234
|
+
httpApi: { path: '/db-migrate/status', method: 'GET' },
|
|
235
|
+
});
|
|
236
|
+
expect(result.functions.dbMigrationRouter.events).toContainEqual({
|
|
237
|
+
httpApi: { path: '/db-migrate', method: 'POST' },
|
|
238
|
+
});
|
|
239
|
+
expect(result.functions.dbMigrationRouter.events).toContainEqual({
|
|
240
|
+
httpApi: { path: '/db-migrate/{processId}', method: 'GET' },
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should create dbMigrationWorker function definition', async () => {
|
|
245
|
+
const appDef = {
|
|
246
|
+
database: {
|
|
247
|
+
postgres: {
|
|
248
|
+
enable: true,
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const result = await builder.build(appDef, {});
|
|
254
|
+
|
|
255
|
+
expect(result.functions.dbMigrationWorker).toBeDefined();
|
|
256
|
+
expect(result.functions.dbMigrationWorker.handler).toBe(
|
|
257
|
+
'node_modules/@friggframework/core/handlers/workers/db-migration.handler'
|
|
258
|
+
);
|
|
259
|
+
expect(result.functions.dbMigrationWorker.skipEsbuild).toBe(true);
|
|
260
|
+
expect(result.functions.dbMigrationWorker.reservedConcurrency).toBe(1);
|
|
261
|
+
expect(result.functions.dbMigrationWorker.timeout).toBe(900);
|
|
262
|
+
expect(result.functions.dbMigrationWorker.memorySize).toBe(1024);
|
|
263
|
+
expect(result.functions.dbMigrationWorker.layers).toEqual([{ Ref: 'PrismaLambdaLayer' }]);
|
|
264
|
+
expect(result.functions.dbMigrationWorker.events).toHaveLength(1);
|
|
265
|
+
expect(result.functions.dbMigrationWorker.events[0].sqs).toEqual({
|
|
266
|
+
arn: { 'Fn::GetAtt': ['DbMigrationQueue', 'Arn'] },
|
|
267
|
+
batchSize: 1,
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should add WORKER_FUNCTION_NAME to router environment', async () => {
|
|
272
|
+
const appDef = {
|
|
273
|
+
database: {
|
|
274
|
+
postgres: {
|
|
275
|
+
enable: true,
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const result = await builder.build(appDef, {});
|
|
281
|
+
|
|
282
|
+
expect(result.functions.dbMigrationRouter.environment.WORKER_FUNCTION_NAME).toEqual({
|
|
283
|
+
Ref: 'DbMigrationWorkerLambdaFunction',
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
describe('getName', () => {
|
|
289
|
+
it('should return MigrationBuilder', () => {
|
|
290
|
+
expect(builder.getName()).toBe('MigrationBuilder');
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration Resource Resolver
|
|
3
|
+
*
|
|
4
|
+
* Resolves migration resource ownership based on user intent and discovered resources.
|
|
5
|
+
*
|
|
6
|
+
* Migration resources:
|
|
7
|
+
* - S3 bucket for migration status tracking
|
|
8
|
+
* - SQS queue for migration jobs
|
|
9
|
+
*
|
|
10
|
+
* Ownership Resolution Logic:
|
|
11
|
+
* - User sets 'stack' → Create resources in CloudFormation stack
|
|
12
|
+
* - User sets 'external' → Use existing resources (discovered)
|
|
13
|
+
* - User sets 'auto' (or unspecified):
|
|
14
|
+
* - If resources found in stack → Use stack resources (STACK)
|
|
15
|
+
* - If resources found externally → Use external resources (EXTERNAL)
|
|
16
|
+
* - If nothing found → Create in stack (STACK)
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const BaseResourceResolver = require('../shared/base-resolver');
|
|
20
|
+
const { ResourceOwnership } = require('../shared/types');
|
|
21
|
+
|
|
22
|
+
class MigrationResourceResolver extends BaseResourceResolver {
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Resolve S3 migration status bucket ownership
|
|
29
|
+
* @param {Object} appDefinition - Application definition
|
|
30
|
+
* @param {Object} discovery - Structured discovery result
|
|
31
|
+
* @returns {Object} Ownership decision with metadata
|
|
32
|
+
*/
|
|
33
|
+
resolveBucket(appDefinition, discovery) {
|
|
34
|
+
// Get user intent from app definition
|
|
35
|
+
const userIntent = appDefinition.migration?.ownership?.bucket || ResourceOwnership.AUTO;
|
|
36
|
+
|
|
37
|
+
// Check if bucket exists in CloudFormation stack
|
|
38
|
+
const inStack = this.isInStack('FriggMigrationStatusBucket', discovery);
|
|
39
|
+
|
|
40
|
+
if (userIntent === ResourceOwnership.STACK) {
|
|
41
|
+
// Explicit: Create/manage in stack
|
|
42
|
+
const stackResource = inStack ? this.findInStack('FriggMigrationStatusBucket', discovery) : null;
|
|
43
|
+
return this.createStackDecision(
|
|
44
|
+
stackResource?.physicalId || null,
|
|
45
|
+
inStack ? 'Found FriggMigrationStatusBucket in CloudFormation stack' : 'Will create FriggMigrationStatusBucket in stack'
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (userIntent === ResourceOwnership.EXTERNAL) {
|
|
50
|
+
// Explicit: Use external bucket
|
|
51
|
+
const external = this.findExternal('AWS::S3::Bucket', discovery);
|
|
52
|
+
if (!external) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
'ownership.bucket=external but no S3 bucket discovered. ' +
|
|
55
|
+
'Provide migrationStatusBucket in discoveredResources or set ownership.bucket=stack'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return this.createExternalDecision(
|
|
59
|
+
external.physicalId,
|
|
60
|
+
'Using external S3 bucket per ownership.bucket=external'
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// AUTO resolution
|
|
65
|
+
if (inStack) {
|
|
66
|
+
const stackResource = this.findInStack('FriggMigrationStatusBucket', discovery);
|
|
67
|
+
return this.createStackDecision(
|
|
68
|
+
stackResource.physicalId,
|
|
69
|
+
'Found FriggMigrationStatusBucket in CloudFormation stack'
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Check for external bucket
|
|
74
|
+
const external = this.findExternal('AWS::S3::Bucket', discovery);
|
|
75
|
+
if (external) {
|
|
76
|
+
return this.createExternalDecision(
|
|
77
|
+
external.physicalId,
|
|
78
|
+
'Found external S3 bucket via discovery'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// No bucket found - create in stack
|
|
83
|
+
return this.createStackDecision(
|
|
84
|
+
null,
|
|
85
|
+
'No existing migration bucket - will create in stack'
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Resolve SQS migration queue ownership
|
|
91
|
+
* @param {Object} appDefinition - Application definition
|
|
92
|
+
* @param {Object} discovery - Structured discovery result
|
|
93
|
+
* @returns {Object} Ownership decision with metadata
|
|
94
|
+
*/
|
|
95
|
+
resolveQueue(appDefinition, discovery) {
|
|
96
|
+
// Get user intent from app definition
|
|
97
|
+
const userIntent = appDefinition.migration?.ownership?.queue || ResourceOwnership.AUTO;
|
|
98
|
+
|
|
99
|
+
// Check if queue exists in CloudFormation stack
|
|
100
|
+
const inStack = this.isInStack('DbMigrationQueue', discovery);
|
|
101
|
+
|
|
102
|
+
if (userIntent === ResourceOwnership.STACK) {
|
|
103
|
+
// Explicit: Create/manage in stack
|
|
104
|
+
const stackResource = inStack ? this.findInStack('DbMigrationQueue', discovery) : null;
|
|
105
|
+
return this.createStackDecision(
|
|
106
|
+
stackResource?.physicalId || null,
|
|
107
|
+
inStack ? 'Found DbMigrationQueue in CloudFormation stack' : 'Will create DbMigrationQueue in stack'
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (userIntent === ResourceOwnership.EXTERNAL) {
|
|
112
|
+
// Explicit: Use external queue
|
|
113
|
+
const external = this.findExternal('AWS::SQS::Queue', discovery);
|
|
114
|
+
if (!external) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
'ownership.queue=external but no SQS queue discovered. ' +
|
|
117
|
+
'Provide migrationQueueUrl in discoveredResources or set ownership.queue=stack'
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return this.createExternalDecision(
|
|
121
|
+
external.physicalId,
|
|
122
|
+
'Using external SQS queue per ownership.queue=external'
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// AUTO resolution
|
|
127
|
+
if (inStack) {
|
|
128
|
+
const stackResource = this.findInStack('DbMigrationQueue', discovery);
|
|
129
|
+
return this.createStackDecision(
|
|
130
|
+
stackResource.physicalId,
|
|
131
|
+
'Found DbMigrationQueue in CloudFormation stack'
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Check for external queue
|
|
136
|
+
const external = this.findExternal('AWS::SQS::Queue', discovery);
|
|
137
|
+
if (external) {
|
|
138
|
+
return this.createExternalDecision(
|
|
139
|
+
external.physicalId,
|
|
140
|
+
'Found external SQS queue via discovery'
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// No queue found - create in stack
|
|
145
|
+
return this.createStackDecision(
|
|
146
|
+
null,
|
|
147
|
+
'No existing migration queue - will create in stack'
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Resolve all migration resources
|
|
153
|
+
* Convenience method for resolving all migration resource ownership
|
|
154
|
+
*/
|
|
155
|
+
resolveAll(appDefinition, discovery) {
|
|
156
|
+
return {
|
|
157
|
+
bucket: this.resolveBucket(appDefinition, discovery),
|
|
158
|
+
queue: this.resolveQueue(appDefinition, discovery),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = { MigrationResourceResolver };
|