@friggframework/devtools 2.0.0--canary.705.9cfd819.0 → 2.0.0--canary.704.6a606c3.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 +14 -0
- package/frigg-cli/README.md +83 -30
- 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 +594 -341
- package/frigg-cli/__tests__/unit/dependencies.test.js +3 -5
- package/frigg-cli/__tests__/unit/utils/node-version.test.js +66 -0
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +12 -4
- package/frigg-cli/init-command/backend-first-handler.js +397 -554
- 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 +3 -3
- 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/utils/node-version.js +51 -0
- package/infrastructure/README.md +20 -0
- package/infrastructure/__tests__/package-patterns-composition.test.js +153 -0
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +21 -1
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +50 -46
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +46 -7
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/database/migration-builder.js +182 -175
- package/infrastructure/domains/database/migration-builder.test.js +36 -5
- package/infrastructure/domains/integration/integration-builder.js +65 -61
- package/infrastructure/domains/integration/integration-builder.test.js +73 -8
- package/infrastructure/domains/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +83 -124
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +116 -26
- package/infrastructure/domains/shared/utilities/framework-version.js +14 -0
- package/infrastructure/domains/shared/utilities/framework-version.test.js +27 -0
- package/infrastructure/domains/shared/utilities/logging-config.js +3 -4
- package/infrastructure/domains/shared/utilities/logging-config.test.js +1 -2
- package/infrastructure/domains/shared/utilities/package-patterns.js +35 -0
- package/infrastructure/domains/shared/utilities/package-patterns.test.js +112 -0
- package/infrastructure/infrastructure-composer.test.js +3 -3
- package/package.json +13 -8
|
@@ -886,8 +886,8 @@ describe('IntegrationBuilder', () => {
|
|
|
886
886
|
const result = await integrationBuilder.build(appDefinition, {});
|
|
887
887
|
|
|
888
888
|
expect(result.functions.testWebhook.package).toBeDefined();
|
|
889
|
-
expect(result.functions.testWebhook.package.
|
|
890
|
-
expect(result.functions.testWebhook.package.
|
|
889
|
+
expect(result.functions.testWebhook.package.patterns).toContain('!node_modules/aws-sdk/**');
|
|
890
|
+
expect(result.functions.testWebhook.package.patterns).toContain('!node_modules/@prisma/**');
|
|
891
891
|
});
|
|
892
892
|
});
|
|
893
893
|
|
|
@@ -982,8 +982,8 @@ describe('IntegrationBuilder', () => {
|
|
|
982
982
|
expect(result.functions.asana.layers).toBeUndefined();
|
|
983
983
|
expect(result.functions.asanaQueueWorker.layers).toBeUndefined();
|
|
984
984
|
expect(result.functions.asanaWebhook.layers).toBeUndefined();
|
|
985
|
-
expect(result.functions.asana.package.
|
|
986
|
-
expect.arrayContaining(['node_modules/@prisma/**'])
|
|
985
|
+
expect(result.functions.asana.package.patterns).not.toEqual(
|
|
986
|
+
expect.arrayContaining(['!node_modules/@prisma/**'])
|
|
987
987
|
);
|
|
988
988
|
});
|
|
989
989
|
});
|
|
@@ -1091,14 +1091,14 @@ describe('IntegrationBuilder nested node_modules (lambda.keepNestedNodeModules)'
|
|
|
1091
1091
|
...(lambda && { lambda }),
|
|
1092
1092
|
});
|
|
1093
1093
|
const packagedFunctions = (result) =>
|
|
1094
|
-
Object.values(result.functions).filter((fn) => fn.package?.
|
|
1094
|
+
Object.values(result.functions).filter((fn) => fn.package?.patterns);
|
|
1095
1095
|
|
|
1096
1096
|
it('excludes every nested node_modules by default', async () => {
|
|
1097
1097
|
const result = await new IntegrationBuilder().build(appDefinition(), {});
|
|
1098
1098
|
|
|
1099
1099
|
expect(packagedFunctions(result).length).toBeGreaterThan(0);
|
|
1100
1100
|
for (const fn of packagedFunctions(result)) {
|
|
1101
|
-
expect(fn.package.
|
|
1101
|
+
expect(fn.package.patterns).toContain('!node_modules/**/node_modules/**');
|
|
1102
1102
|
}
|
|
1103
1103
|
});
|
|
1104
1104
|
|
|
@@ -1109,8 +1109,73 @@ describe('IntegrationBuilder nested node_modules (lambda.keepNestedNodeModules)'
|
|
|
1109
1109
|
);
|
|
1110
1110
|
|
|
1111
1111
|
for (const fn of packagedFunctions(result)) {
|
|
1112
|
-
expect(fn.package.
|
|
1113
|
-
expect(fn.package.
|
|
1112
|
+
expect(fn.package.patterns).not.toContain('!node_modules/**/node_modules/**');
|
|
1113
|
+
expect(fn.package.patterns).toContain('!node_modules/**/node_modules/@friggframework/**');
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
describe('IntegrationBuilder function package patterns (ADR-050)', () => {
|
|
1119
|
+
const appDefinition = {
|
|
1120
|
+
integrations: [
|
|
1121
|
+
{
|
|
1122
|
+
Definition: {
|
|
1123
|
+
name: 'hubspot',
|
|
1124
|
+
webhooks: true,
|
|
1125
|
+
extensions: {
|
|
1126
|
+
hubspotWebhooks: {
|
|
1127
|
+
extension: {
|
|
1128
|
+
name: 'hubspot-webhooks',
|
|
1129
|
+
routes: [
|
|
1130
|
+
{
|
|
1131
|
+
path: '/webhooks',
|
|
1132
|
+
method: 'POST',
|
|
1133
|
+
event: 'HUBSPOT_WEBHOOK_RECEIVED',
|
|
1134
|
+
},
|
|
1135
|
+
],
|
|
1136
|
+
events: {
|
|
1137
|
+
HUBSPOT_WEBHOOK_RECEIVED: {
|
|
1138
|
+
type: 'LIFE_CYCLE_EVENT',
|
|
1139
|
+
handler: () => {},
|
|
1140
|
+
},
|
|
1141
|
+
},
|
|
1142
|
+
},
|
|
1143
|
+
handlers: {},
|
|
1144
|
+
},
|
|
1145
|
+
},
|
|
1146
|
+
},
|
|
1147
|
+
},
|
|
1148
|
+
],
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
it('emits package.patterns, never include/exclude, on every function it packages', async () => {
|
|
1152
|
+
const result = await new IntegrationBuilder().build(appDefinition, {});
|
|
1153
|
+
|
|
1154
|
+
const expected = [
|
|
1155
|
+
'hubspot',
|
|
1156
|
+
'hubspotWebhook',
|
|
1157
|
+
'hubspot__hubspotWebhooks',
|
|
1158
|
+
'hubspotQueueWorker',
|
|
1159
|
+
'dlqProcessor',
|
|
1160
|
+
];
|
|
1161
|
+
for (const name of expected) {
|
|
1162
|
+
const pkg = result.functions[name]?.package;
|
|
1163
|
+
expect(pkg).toBeDefined();
|
|
1164
|
+
expect(pkg).not.toHaveProperty('include');
|
|
1165
|
+
expect(pkg).not.toHaveProperty('exclude');
|
|
1166
|
+
// Integration functions only exclude, so every pattern is negated.
|
|
1167
|
+
expect(pkg.patterns.length).toBeGreaterThan(0);
|
|
1168
|
+
expect(pkg.patterns.every((p) => p.startsWith('!'))).toBe(true);
|
|
1169
|
+
expect(pkg.patterns).toEqual(
|
|
1170
|
+
expect.arrayContaining([
|
|
1171
|
+
'!node_modules/aws-sdk/**',
|
|
1172
|
+
'!node_modules/@prisma/**',
|
|
1173
|
+
'!node_modules/**/node_modules/**',
|
|
1174
|
+
'!node_modules/osls/**',
|
|
1175
|
+
'!test/**',
|
|
1176
|
+
])
|
|
1177
|
+
);
|
|
1178
|
+
expect(pkg.patterns).not.toContain('!src/**');
|
|
1114
1179
|
}
|
|
1115
1180
|
});
|
|
1116
1181
|
});
|
|
@@ -4,6 +4,11 @@ const path = require('path');
|
|
|
4
4
|
* Generate IAM CloudFormation template
|
|
5
5
|
* @param {Object} options - Generation options
|
|
6
6
|
* @param {string} [options.appName='Frigg'] - Application name
|
|
7
|
+
* @param {string} [options.serviceName] - The osls service name the app deploys
|
|
8
|
+
* under (Definition.name). Resource grants that match `*frigg*` are also
|
|
9
|
+
* granted for `*<serviceName>*`, because `frigg deploy` names the stack,
|
|
10
|
+
* functions, role, queues, topics, alarms, log groups, layer and buckets
|
|
11
|
+
* after the service, not after "frigg".
|
|
7
12
|
* @param {Object} [options.features={}] - Enabled features { vpc, kms, ssm, websockets }
|
|
8
13
|
* @param {string} [options.userPrefix='frigg-deployment-user'] - IAM user name prefix
|
|
9
14
|
* @param {string} [options.stackName='frigg-deployment-iam'] - CloudFormation stack name
|
|
@@ -16,7 +21,8 @@ function generateIAMCloudFormation(options = {}) {
|
|
|
16
21
|
features = {},
|
|
17
22
|
userPrefix = 'frigg-deployment-user',
|
|
18
23
|
stackName = 'frigg-deployment-iam',
|
|
19
|
-
ssmKmsKeyArn
|
|
24
|
+
ssmKmsKeyArn,
|
|
25
|
+
serviceName,
|
|
20
26
|
} = options;
|
|
21
27
|
|
|
22
28
|
const deploymentUserName = userPrefix;
|
|
@@ -525,6 +531,51 @@ function generateIAMCloudFormation(options = {}) {
|
|
|
525
531
|
},
|
|
526
532
|
];
|
|
527
533
|
|
|
534
|
+
coreStatements.push(
|
|
535
|
+
{
|
|
536
|
+
Sid: 'FriggLambdaLayers',
|
|
537
|
+
Effect: 'Allow',
|
|
538
|
+
Action: [
|
|
539
|
+
'lambda:PublishLayerVersion',
|
|
540
|
+
'lambda:DeleteLayerVersion',
|
|
541
|
+
'lambda:GetLayerVersion',
|
|
542
|
+
],
|
|
543
|
+
Resource: [
|
|
544
|
+
{
|
|
545
|
+
'Fn::Sub':
|
|
546
|
+
'arn:aws:lambda:*:${AWS::AccountId}:layer:*frigg*',
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
'Fn::Sub':
|
|
550
|
+
'arn:aws:lambda:*:${AWS::AccountId}:layer:*frigg*:*',
|
|
551
|
+
},
|
|
552
|
+
],
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
// Buckets the app's stack creates (e.g. the migration-status
|
|
556
|
+
// bucket); CloudFormation names them after the stack, in lower case.
|
|
557
|
+
Sid: 'FriggAppBuckets',
|
|
558
|
+
Effect: 'Allow',
|
|
559
|
+
Action: [
|
|
560
|
+
's3:CreateBucket',
|
|
561
|
+
's3:DeleteBucket',
|
|
562
|
+
's3:PutBucketPolicy',
|
|
563
|
+
's3:DeleteBucketPolicy',
|
|
564
|
+
's3:PutBucketVersioning',
|
|
565
|
+
's3:PutBucketPublicAccessBlock',
|
|
566
|
+
's3:PutEncryptionConfiguration',
|
|
567
|
+
's3:PutLifecycleConfiguration',
|
|
568
|
+
's3:PutBucketTagging',
|
|
569
|
+
's3:GetBucketLocation',
|
|
570
|
+
's3:ListBucket',
|
|
571
|
+
's3:GetObject',
|
|
572
|
+
's3:PutObject',
|
|
573
|
+
's3:DeleteObject',
|
|
574
|
+
],
|
|
575
|
+
Resource: ['arn:aws:s3:::*frigg*', 'arn:aws:s3:::*frigg*/*'],
|
|
576
|
+
}
|
|
577
|
+
);
|
|
578
|
+
|
|
528
579
|
template.Resources.FriggCoreDeploymentPolicy = {
|
|
529
580
|
Type: 'AWS::IAM::ManagedPolicy',
|
|
530
581
|
Properties: {
|
|
@@ -768,10 +819,59 @@ function generateIAMCloudFormation(options = {}) {
|
|
|
768
819
|
},
|
|
769
820
|
};
|
|
770
821
|
|
|
822
|
+
expandResourceNamePatterns(template, serviceName);
|
|
823
|
+
|
|
771
824
|
// Convert to YAML
|
|
772
825
|
return convertToYAML(template);
|
|
773
826
|
}
|
|
774
827
|
|
|
828
|
+
const FRIGG_NAME_PATTERN = '*frigg*';
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Next to every policy resource that matches `*frigg*`, add the same
|
|
832
|
+
* resource for `*<serviceName>*` (lower case for S3 bucket ARNs), so an app
|
|
833
|
+
* that is not named "frigg" can manage its own stack resources.
|
|
834
|
+
*
|
|
835
|
+
* @param {Object} template - CloudFormation template (mutated)
|
|
836
|
+
* @param {string} [serviceName]
|
|
837
|
+
*/
|
|
838
|
+
function expandResourceNamePatterns(template, serviceName) {
|
|
839
|
+
if (!serviceName || /frigg/i.test(serviceName)) {
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const servicePattern = `*${serviceName}*`;
|
|
843
|
+
const expand = (resource) => {
|
|
844
|
+
const value =
|
|
845
|
+
typeof resource === 'string'
|
|
846
|
+
? resource
|
|
847
|
+
: resource && resource['Fn::Sub'];
|
|
848
|
+
if (typeof value !== 'string' || !value.includes(FRIGG_NAME_PATTERN)) {
|
|
849
|
+
return [resource];
|
|
850
|
+
}
|
|
851
|
+
const pattern = value.startsWith('arn:aws:s3:::')
|
|
852
|
+
? servicePattern.toLowerCase()
|
|
853
|
+
: servicePattern;
|
|
854
|
+
const scoped = value.split(FRIGG_NAME_PATTERN).join(pattern);
|
|
855
|
+
return [
|
|
856
|
+
resource,
|
|
857
|
+
typeof resource === 'string' ? scoped : { 'Fn::Sub': scoped },
|
|
858
|
+
];
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
for (const resource of Object.values(template.Resources)) {
|
|
862
|
+
const statements = resource?.Properties?.PolicyDocument?.Statement;
|
|
863
|
+
if (!Array.isArray(statements)) continue;
|
|
864
|
+
for (const statement of statements) {
|
|
865
|
+
if (statement.Resource === undefined) continue;
|
|
866
|
+
const expanded = [].concat(statement.Resource).flatMap(expand);
|
|
867
|
+
statement.Resource =
|
|
868
|
+
Array.isArray(statement.Resource) || expanded.length > 1
|
|
869
|
+
? expanded
|
|
870
|
+
: expanded[0];
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
775
875
|
/**
|
|
776
876
|
* Convert JavaScript object to CloudFormation YAML
|
|
777
877
|
* @param {Object} obj - JavaScript object
|
|
@@ -796,8 +896,7 @@ function getFeatureSummary(appDefinition) {
|
|
|
796
896
|
const features = {
|
|
797
897
|
core: true, // Always enabled
|
|
798
898
|
vpc: appDefinition.vpc?.enable === true,
|
|
799
|
-
kms:
|
|
800
|
-
appDefinition.encryption?.fieldLevelEncryptionMethod === 'kms',
|
|
899
|
+
kms: appDefinition.encryption?.fieldLevelEncryptionMethod === 'kms',
|
|
801
900
|
ssm: appDefinition.ssm?.enable === true,
|
|
802
901
|
websockets: appDefinition.websockets?.enable === true,
|
|
803
902
|
};
|
|
@@ -808,6 +907,8 @@ function getFeatureSummary(appDefinition) {
|
|
|
808
907
|
features,
|
|
809
908
|
integrationCount,
|
|
810
909
|
appName: appDefinition.name || 'Unnamed Frigg App',
|
|
910
|
+
// What createBaseDefinition uses as the osls service name.
|
|
911
|
+
serviceName: appDefinition.name || 'create-frigg-app',
|
|
811
912
|
ssmKmsKeyArn: appDefinition.ssm?.kmsKeyArn,
|
|
812
913
|
};
|
|
813
914
|
}
|
|
@@ -817,7 +918,10 @@ function getFeatureSummary(appDefinition) {
|
|
|
817
918
|
* @returns {Object} Basic IAM policy document
|
|
818
919
|
*/
|
|
819
920
|
function generateBasicIAMPolicy() {
|
|
820
|
-
const basicPolicyPath = path.join(
|
|
921
|
+
const basicPolicyPath = path.join(
|
|
922
|
+
__dirname,
|
|
923
|
+
'templates/iam-policy-basic.json'
|
|
924
|
+
);
|
|
821
925
|
return require(basicPolicyPath);
|
|
822
926
|
}
|
|
823
927
|
|
|
@@ -826,7 +930,10 @@ function generateBasicIAMPolicy() {
|
|
|
826
930
|
* @returns {Object} Full IAM policy document
|
|
827
931
|
*/
|
|
828
932
|
function generateFullIAMPolicy() {
|
|
829
|
-
const fullPolicyPath = path.join(
|
|
933
|
+
const fullPolicyPath = path.join(
|
|
934
|
+
__dirname,
|
|
935
|
+
'templates/iam-policy-full.json'
|
|
936
|
+
);
|
|
830
937
|
return require(fullPolicyPath);
|
|
831
938
|
}
|
|
832
939
|
|
|
@@ -313,4 +313,98 @@ describe('IAM Generator', () => {
|
|
|
313
313
|
expect(yaml).toContain('CredentialsSecretArn:');
|
|
314
314
|
});
|
|
315
315
|
});
|
|
316
|
+
|
|
317
|
+
describe("scoping to the app's own resources", () => {
|
|
318
|
+
const yaml = require('js-yaml');
|
|
319
|
+
const policyResources = (template, policy) =>
|
|
320
|
+
template.Resources[
|
|
321
|
+
policy
|
|
322
|
+
].Properties.PolicyDocument.Statement.flatMap((statement) =>
|
|
323
|
+
[].concat(statement.Resource)
|
|
324
|
+
).map((r) => (typeof r === 'string' ? r : r['Fn::Sub']));
|
|
325
|
+
|
|
326
|
+
// `frigg deploy` names everything after the service (Definition.name):
|
|
327
|
+
// stack my-app-prod, functions my-app-prod-auth, role
|
|
328
|
+
// my-app-prod-us-east-1-lambdaRole, queues my-app-internal-error-queue-prod
|
|
329
|
+
// and my-app-prod-DbMigrationQueue, layer my-app-prisma-prod, and
|
|
330
|
+
// CloudFormation-named topics, alarms and buckets prefixed my-app-prod.
|
|
331
|
+
const generate = (appDefinition) => {
|
|
332
|
+
const summary = getFeatureSummary(appDefinition);
|
|
333
|
+
return yaml.load(
|
|
334
|
+
generateIAMCloudFormation({
|
|
335
|
+
appName: summary.appName,
|
|
336
|
+
serviceName: summary.serviceName,
|
|
337
|
+
features: summary.features,
|
|
338
|
+
})
|
|
339
|
+
);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
it('reports the service name osls deploys under', () => {
|
|
343
|
+
expect(getFeatureSummary({ name: 'my-app' }).serviceName).toBe(
|
|
344
|
+
'my-app'
|
|
345
|
+
);
|
|
346
|
+
expect(getFeatureSummary({}).serviceName).toBe('create-frigg-app');
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('lets an app whose name does not contain "frigg" deploy its stack and resources', () => {
|
|
350
|
+
const resources = policyResources(
|
|
351
|
+
generate({ name: 'my-app' }),
|
|
352
|
+
'FriggCoreDeploymentPolicy'
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
for (const expected of [
|
|
356
|
+
'arn:aws:cloudformation:*:${AWS::AccountId}:stack/*my-app*/*',
|
|
357
|
+
'arn:aws:lambda:*:${AWS::AccountId}:function:*my-app*',
|
|
358
|
+
'arn:aws:iam::${AWS::AccountId}:role/*my-app*',
|
|
359
|
+
'arn:aws:sqs:*:${AWS::AccountId}:*my-app*',
|
|
360
|
+
'arn:aws:sns:*:${AWS::AccountId}:*my-app*',
|
|
361
|
+
'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/*my-app*',
|
|
362
|
+
'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/*my-app*:*',
|
|
363
|
+
'arn:aws:cloudwatch:*:${AWS::AccountId}:alarm:*my-app*',
|
|
364
|
+
'arn:aws:lambda:*:${AWS::AccountId}:layer:*my-app*',
|
|
365
|
+
'arn:aws:lambda:*:${AWS::AccountId}:layer:*my-app*:*',
|
|
366
|
+
'arn:aws:s3:::*my-app*',
|
|
367
|
+
'arn:aws:s3:::*my-app*/*',
|
|
368
|
+
]) {
|
|
369
|
+
expect(resources).toContain(expected);
|
|
370
|
+
}
|
|
371
|
+
// Existing grants for frigg-named resources are kept.
|
|
372
|
+
expect(resources).toContain(
|
|
373
|
+
'arn:aws:lambda:*:${AWS::AccountId}:function:*frigg*'
|
|
374
|
+
);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('matches S3 bucket names in lower case', () => {
|
|
378
|
+
const resources = policyResources(
|
|
379
|
+
generate({ name: 'MyApp' }),
|
|
380
|
+
'FriggCoreDeploymentPolicy'
|
|
381
|
+
);
|
|
382
|
+
expect(resources).toContain('arn:aws:s3:::*myapp*');
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('scopes the SSM parameter grant to the app too', () => {
|
|
386
|
+
const template = generate({
|
|
387
|
+
name: 'my-app',
|
|
388
|
+
ssm: { enable: true },
|
|
389
|
+
});
|
|
390
|
+
const resources = policyResources(template, 'FriggSSMPolicy');
|
|
391
|
+
expect(resources).toContain(
|
|
392
|
+
'arn:aws:ssm:*:${AWS::AccountId}:parameter/*my-app*'
|
|
393
|
+
);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('does not duplicate grants for an app named frigg', () => {
|
|
397
|
+
const resources = policyResources(
|
|
398
|
+
generate({ name: 'frigg' }),
|
|
399
|
+
'FriggCoreDeploymentPolicy'
|
|
400
|
+
);
|
|
401
|
+
expect(
|
|
402
|
+
resources.filter(
|
|
403
|
+
(r) =>
|
|
404
|
+
r ===
|
|
405
|
+
'arn:aws:lambda:*:${AWS::AccountId}:function:*frigg*'
|
|
406
|
+
)
|
|
407
|
+
).toHaveLength(1);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
316
410
|
});
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
const { buildEnvironment } = require('../environment-builder');
|
|
11
11
|
const { nestedNodeModulesExcludes } = require('./nested-node-modules');
|
|
12
|
+
const { toPackagePatterns } = require('./package-patterns');
|
|
12
13
|
const { buildLoggingProviderConfig } = require('./logging-config');
|
|
14
|
+
const { OSLS_FRAMEWORK_VERSION } = require('./framework-version');
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Create base serverless definition with core functions and resources
|
|
@@ -37,143 +39,95 @@ function createBaseDefinition(
|
|
|
37
39
|
const loggingConfig = buildLoggingProviderConfig(AppDefinition.logging);
|
|
38
40
|
|
|
39
41
|
// Package config for handlers that skip esbuild (need node_modules dependencies)
|
|
40
|
-
// Include backend src/ and index.js since handlers load the app definition
|
|
42
|
+
// Include backend src/ and index.js since handlers load the app definition.
|
|
43
|
+
// osls 4 only reads package.patterns (ADR-050): excludes first, then includes.
|
|
41
44
|
const skipEsbuildPackageConfig = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// Exclude AWS SDK (provided by Lambda runtime)
|
|
59
|
-
'node_modules/aws-sdk/**',
|
|
60
|
-
'node_modules/@aws-sdk/**',
|
|
61
|
-
|
|
62
|
-
// Exclude dev/test dependencies
|
|
63
|
-
'node_modules/@friggframework/test/**',
|
|
64
|
-
'node_modules/@friggframework/eslint-config/**',
|
|
65
|
-
'node_modules/@friggframework/prettier-config/**',
|
|
66
|
-
'node_modules/jest/**',
|
|
67
|
-
'node_modules/prettier/**',
|
|
68
|
-
'node_modules/eslint/**',
|
|
69
|
-
|
|
70
|
-
...nestedNodeModulesExcludes(AppDefinition, usePrismaLayer),
|
|
71
|
-
|
|
72
|
-
// Exclude build tools (not needed at runtime)
|
|
73
|
-
'node_modules/esbuild/**',
|
|
74
|
-
'node_modules/@esbuild/**',
|
|
75
|
-
'node_modules/typescript/**',
|
|
76
|
-
'node_modules/webpack/**',
|
|
77
|
-
'node_modules/osls/**',
|
|
78
|
-
'node_modules/serverless-esbuild/**',
|
|
79
|
-
'node_modules/serverless-jetpack/**',
|
|
80
|
-
'node_modules/serverless-offline/**',
|
|
81
|
-
'node_modules/serverless-offline-sqs/**',
|
|
82
|
-
'node_modules/serverless-dotenv-plugin/**',
|
|
83
|
-
'node_modules/serverless-kms-grants/**',
|
|
84
|
-
// Note: DO NOT exclude serverless-http - it's a runtime dependency!
|
|
85
|
-
|
|
86
|
-
// Exclude local dev files and environment files (NEVER deploy .env files!)
|
|
87
|
-
'.env',
|
|
88
|
-
'.env.*',
|
|
89
|
-
'.env.local',
|
|
90
|
-
'.env.*.local',
|
|
91
|
-
'**/.env',
|
|
92
|
-
'**/.env.*',
|
|
93
|
-
'deploy.log',
|
|
94
|
-
'.env.backup',
|
|
95
|
-
'docker-compose.yml',
|
|
96
|
-
'jest.config.js',
|
|
97
|
-
'jest.unit.config.js',
|
|
98
|
-
'.eslintrc.json',
|
|
99
|
-
'.prettierrc',
|
|
100
|
-
'.prettierignore',
|
|
101
|
-
'.markdownlintignore',
|
|
102
|
-
'package-lock.json',
|
|
103
|
-
|
|
104
|
-
// Exclude test files and layers (keep src/ - needed for app definition and integrations)
|
|
105
|
-
'test/**',
|
|
106
|
-
'layers/**',
|
|
107
|
-
'coverage/**',
|
|
108
|
-
// Note: DO NOT exclude src/** - handlers need src/integrations and src/api-modules at runtime
|
|
109
|
-
'**/*.test.js',
|
|
110
|
-
'**/*.spec.js',
|
|
111
|
-
'**/.claude-flow/**',
|
|
112
|
-
'**/.swarm/**',
|
|
113
|
-
],
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Function-level package config to exclude Prisma and AWS SDK
|
|
117
|
-
const functionPackageConfig = {
|
|
118
|
-
exclude: [
|
|
119
|
-
// Exclude AWS SDK (already in Lambda runtime or externalized by esbuild)
|
|
120
|
-
'node_modules/aws-sdk/**',
|
|
121
|
-
'node_modules/@aws-sdk/**',
|
|
45
|
+
patterns: toPackagePatterns({
|
|
46
|
+
// Explicitly include project files that handlers need
|
|
47
|
+
include: [
|
|
48
|
+
// Include DocumentDB TLS certificate if configured
|
|
49
|
+
...(AppDefinition.database?.documentDB?.tlsCAFile
|
|
50
|
+
? [AppDefinition.database.documentDB.tlsCAFile.replace(/^\.\//, '')]
|
|
51
|
+
: []),
|
|
52
|
+
],
|
|
53
|
+
exclude: [
|
|
54
|
+
// Exclude Prisma (provided via Lambda Layer)
|
|
55
|
+
...(usePrismaLayer ? [
|
|
56
|
+
'node_modules/@prisma/**',
|
|
57
|
+
'node_modules/.prisma/**',
|
|
58
|
+
'node_modules/prisma/**',
|
|
59
|
+
'node_modules/@friggframework/core/generated/**',
|
|
60
|
+
] : []),
|
|
122
61
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
'node_modules/@
|
|
126
|
-
'node_modules/.prisma/**',
|
|
127
|
-
'node_modules/prisma/**',
|
|
128
|
-
'node_modules/@friggframework/core/generated/**',
|
|
129
|
-
] : []),
|
|
62
|
+
// Exclude AWS SDK (provided by Lambda runtime)
|
|
63
|
+
'node_modules/aws-sdk/**',
|
|
64
|
+
'node_modules/@aws-sdk/**',
|
|
130
65
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
66
|
+
// Exclude dev/test dependencies
|
|
67
|
+
'node_modules/@friggframework/test/**',
|
|
68
|
+
'node_modules/@friggframework/eslint-config/**',
|
|
69
|
+
'node_modules/@friggframework/prettier-config/**',
|
|
70
|
+
'node_modules/jest/**',
|
|
71
|
+
'node_modules/prettier/**',
|
|
72
|
+
'node_modules/eslint/**',
|
|
134
73
|
|
|
135
|
-
|
|
136
|
-
'.env',
|
|
137
|
-
'.env.*',
|
|
138
|
-
'.env.local',
|
|
139
|
-
'.env.*.local',
|
|
140
|
-
'**/.env',
|
|
141
|
-
'**/.env.*',
|
|
74
|
+
...nestedNodeModulesExcludes(AppDefinition, usePrismaLayer),
|
|
142
75
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
76
|
+
// Exclude build tools (not needed at runtime)
|
|
77
|
+
'node_modules/esbuild/**',
|
|
78
|
+
'node_modules/@esbuild/**',
|
|
79
|
+
'node_modules/typescript/**',
|
|
80
|
+
'node_modules/webpack/**',
|
|
81
|
+
'node_modules/osls/**',
|
|
82
|
+
'node_modules/serverless-esbuild/**',
|
|
83
|
+
'node_modules/serverless-jetpack/**',
|
|
84
|
+
'node_modules/serverless-offline/**',
|
|
85
|
+
'node_modules/serverless-offline-sqs/**',
|
|
86
|
+
'node_modules/serverless-dotenv-plugin/**',
|
|
87
|
+
'node_modules/serverless-kms-grants/**',
|
|
88
|
+
// Note: DO NOT exclude serverless-http - it's a runtime dependency!
|
|
152
89
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
90
|
+
// Exclude local dev files and environment files (NEVER deploy .env files!)
|
|
91
|
+
'.env',
|
|
92
|
+
'.env.*',
|
|
93
|
+
'.env.local',
|
|
94
|
+
'.env.*.local',
|
|
95
|
+
'**/.env',
|
|
96
|
+
'**/.env.*',
|
|
97
|
+
'deploy.log',
|
|
98
|
+
'.env.backup',
|
|
99
|
+
'docker-compose.yml',
|
|
100
|
+
'jest.config.js',
|
|
101
|
+
'jest.unit.config.js',
|
|
102
|
+
'.eslintrc.json',
|
|
103
|
+
'.prettierrc',
|
|
104
|
+
'.prettierignore',
|
|
105
|
+
'.markdownlintignore',
|
|
106
|
+
'package-lock.json',
|
|
159
107
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
108
|
+
// Exclude test files and layers (keep src/ - needed for app definition and integrations)
|
|
109
|
+
'test/**',
|
|
110
|
+
'layers/**',
|
|
111
|
+
'coverage/**',
|
|
112
|
+
// Note: DO NOT exclude src/** - handlers need src/integrations and src/api-modules at runtime
|
|
113
|
+
'**/*.test.js',
|
|
114
|
+
'**/*.spec.js',
|
|
115
|
+
'**/.claude-flow/**',
|
|
116
|
+
'**/.swarm/**',
|
|
117
|
+
],
|
|
118
|
+
}),
|
|
166
119
|
};
|
|
167
120
|
|
|
168
121
|
return {
|
|
169
|
-
frameworkVersion:
|
|
122
|
+
frameworkVersion: OSLS_FRAMEWORK_VERSION,
|
|
170
123
|
service: AppDefinition.name || 'create-frigg-app',
|
|
171
124
|
package: {
|
|
172
125
|
individually: true,
|
|
173
126
|
},
|
|
174
127
|
// Only use .env for local development (offline mode)
|
|
175
|
-
// Production deployments should use environment vars from infrastructure
|
|
176
|
-
useDotenv:
|
|
128
|
+
// Production deployments should use environment vars from infrastructure.
|
|
129
|
+
// Emitted only when true: osls 4 accepts `useDotenv: true` or no key (ADR-050).
|
|
130
|
+
...(process.argv.includes('offline') && { useDotenv: true }),
|
|
177
131
|
provider: {
|
|
178
132
|
name: AppDefinition.provider || 'aws',
|
|
179
133
|
...(process.env.AWS_PROFILE && { profile: process.env.AWS_PROFILE }),
|
|
@@ -383,12 +337,18 @@ function createBaseDefinition(
|
|
|
383
337
|
},
|
|
384
338
|
},
|
|
385
339
|
},
|
|
340
|
+
// The functions above use `httpApi` events, so osls creates
|
|
341
|
+
// an HTTP API (API Gateway v2, logical ID HttpApi) with only
|
|
342
|
+
// the `$default` stage. HTTP APIs publish `5xx`, not the REST
|
|
343
|
+
// API metric `5XXError`, and the ApiId dimension identifies
|
|
344
|
+
// this API (a Stage dimension would have to be `$default`).
|
|
345
|
+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-metrics.html
|
|
386
346
|
ApiGatewayAlarm5xx: {
|
|
387
347
|
Type: 'AWS::CloudWatch::Alarm',
|
|
388
348
|
Properties: {
|
|
389
349
|
AlarmDescription: 'API Gateway 5xx Errors',
|
|
390
350
|
Namespace: 'AWS/ApiGateway',
|
|
391
|
-
MetricName: '
|
|
351
|
+
MetricName: '5xx',
|
|
392
352
|
Statistic: 'Sum',
|
|
393
353
|
Threshold: 0,
|
|
394
354
|
ComparisonOperator: 'GreaterThanThreshold',
|
|
@@ -397,7 +357,6 @@ function createBaseDefinition(
|
|
|
397
357
|
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
398
358
|
Dimensions: [
|
|
399
359
|
{ Name: 'ApiId', Value: { Ref: 'HttpApi' } },
|
|
400
|
-
{ Name: 'Stage', Value: '${self:provider.stage}' },
|
|
401
360
|
],
|
|
402
361
|
},
|
|
403
362
|
},
|