@friggframework/devtools 2.0.0--canary.606.7fde0eb.0 → 2.0.0--canary.608.03436383054a.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/infrastructure/domains/integration/integration-builder.js +107 -0
- package/infrastructure/domains/integration/integration-builder.test.js +121 -1
- package/infrastructure/domains/security/iam-generator.js +4 -0
- package/infrastructure/domains/security/iam-generator.test.js +16 -0
- package/infrastructure/domains/security/templates/frigg-deployment-iam-stack.yaml +3 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +14 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +6 -0
- package/package.json +7 -7
|
@@ -196,6 +196,10 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
196
196
|
);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
// App-level FIFO queue for dispatch:'queue' events — one per app,
|
|
200
|
+
// independent of per-integration queue ownership.
|
|
201
|
+
this.createUserActionQueue(result, functionPackageConfig, usePrismaLayer);
|
|
202
|
+
|
|
199
203
|
for (const integration of appDefinition.integrations) {
|
|
200
204
|
const integrationName = integration.Definition.name;
|
|
201
205
|
const queueDecision = decisions.integrations[integrationName].queue;
|
|
@@ -472,6 +476,109 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
472
476
|
console.log(' ✓ Created InternalErrorQueue resource');
|
|
473
477
|
}
|
|
474
478
|
|
|
479
|
+
/**
|
|
480
|
+
* Create the app-level FIFO queue + FIFO DLQ + worker used by integration
|
|
481
|
+
* events declared with `dispatch: 'queue'`.
|
|
482
|
+
*
|
|
483
|
+
* A single queue serves every integration: `MessageGroupId = integrationId`
|
|
484
|
+
* (set by the producer) serializes events per integration while letting
|
|
485
|
+
* distinct integrations process in parallel. Always created, like the
|
|
486
|
+
* InternalErrorQueue — idle cost is ~$0.
|
|
487
|
+
*/
|
|
488
|
+
createUserActionQueue(result, functionPackageConfig, usePrismaLayer = true) {
|
|
489
|
+
const queueName =
|
|
490
|
+
'${self:service}-${self:provider.stage}-FriggUserActionQueue.fifo';
|
|
491
|
+
const dlqName =
|
|
492
|
+
'${self:service}-${self:provider.stage}-FriggUserActionDLQ.fifo';
|
|
493
|
+
|
|
494
|
+
result.custom.FriggUserActionQueue = queueName;
|
|
495
|
+
result.custom.FriggUserActionDLQ = dlqName;
|
|
496
|
+
|
|
497
|
+
// A FIFO source queue can only redrive to a FIFO DLQ.
|
|
498
|
+
result.resources.FriggUserActionDLQ = {
|
|
499
|
+
Type: 'AWS::SQS::Queue',
|
|
500
|
+
Properties: {
|
|
501
|
+
QueueName: '${self:custom.FriggUserActionDLQ}',
|
|
502
|
+
FifoQueue: true,
|
|
503
|
+
MessageRetentionPeriod: 1209600, // 14 days
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// ContentBasedDeduplication is intentionally OMITTED. The producer
|
|
508
|
+
// supplies a unique MessageDeduplicationId per send, so two distinct
|
|
509
|
+
// requests with identical bodies both run — content-based dedup would
|
|
510
|
+
// hash the body and silently drop the second within the 5-min window.
|
|
511
|
+
result.resources.FriggUserActionQueue = {
|
|
512
|
+
Type: 'AWS::SQS::Queue',
|
|
513
|
+
Properties: {
|
|
514
|
+
QueueName: '${self:custom.FriggUserActionQueue}',
|
|
515
|
+
FifoQueue: true,
|
|
516
|
+
MessageRetentionPeriod: 345600, // 4 days
|
|
517
|
+
VisibilityTimeout: 1800, // >= worker timeout (900s)
|
|
518
|
+
RedrivePolicy: {
|
|
519
|
+
maxReceiveCount: 2,
|
|
520
|
+
deadLetterTargetArn: {
|
|
521
|
+
'Fn::GetAtt': ['FriggUserActionDLQ', 'Arn'],
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
// Expose the queue URL to ALL Lambdas — both the HTTP handlers that
|
|
528
|
+
// produce events and the worker that consumes them.
|
|
529
|
+
result.environment.USER_ACTION_QUEUE_URL = {
|
|
530
|
+
Ref: 'FriggUserActionQueue',
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
// Any message in the FIFO DLQ is a failed eventual event.
|
|
534
|
+
result.resources.FriggUserActionDLQAlarm = {
|
|
535
|
+
Type: 'AWS::CloudWatch::Alarm',
|
|
536
|
+
Properties: {
|
|
537
|
+
AlarmDescription:
|
|
538
|
+
'Messages in FriggUserActionDLQ — eventual (queued) integration event failures',
|
|
539
|
+
Namespace: 'AWS/SQS',
|
|
540
|
+
MetricName: 'ApproximateNumberOfMessagesVisible',
|
|
541
|
+
Statistic: 'Maximum',
|
|
542
|
+
Threshold: 0,
|
|
543
|
+
ComparisonOperator: 'GreaterThanThreshold',
|
|
544
|
+
EvaluationPeriods: 1,
|
|
545
|
+
Period: 300,
|
|
546
|
+
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
547
|
+
Dimensions: [
|
|
548
|
+
{
|
|
549
|
+
Name: 'QueueName',
|
|
550
|
+
Value: {
|
|
551
|
+
'Fn::GetAtt': ['FriggUserActionDLQ', 'QueueName'],
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
],
|
|
555
|
+
},
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// Single app-level worker. NO reservedConcurrency: FIFO already
|
|
559
|
+
// serializes per MessageGroupId; capping at 1 would serialize across
|
|
560
|
+
// ALL integrations and kill cross-integration parallelism.
|
|
561
|
+
result.functions.userActionQueueWorker = {
|
|
562
|
+
handler:
|
|
563
|
+
'node_modules/@friggframework/core/handlers/workers/user-action-worker.userActionQueueWorker',
|
|
564
|
+
skipEsbuild: true,
|
|
565
|
+
package: functionPackageConfig,
|
|
566
|
+
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
567
|
+
timeout: 900,
|
|
568
|
+
events: [
|
|
569
|
+
{
|
|
570
|
+
sqs: {
|
|
571
|
+
arn: { 'Fn::GetAtt': ['FriggUserActionQueue', 'Arn'] },
|
|
572
|
+
batchSize: 1,
|
|
573
|
+
functionResponseType: 'ReportBatchItemFailures',
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
],
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
console.log(' ✓ Created FriggUserActionQueue (.fifo) + DLQ + worker');
|
|
580
|
+
}
|
|
581
|
+
|
|
475
582
|
/**
|
|
476
583
|
* Use external InternalErrorQueue
|
|
477
584
|
*/
|
|
@@ -751,9 +751,12 @@ describe('IntegrationBuilder', () => {
|
|
|
751
751
|
|
|
752
752
|
const functionKeys = Object.keys(result.functions);
|
|
753
753
|
|
|
754
|
-
// Expected order: dlqProcessor
|
|
754
|
+
// Expected order: dlqProcessor + userActionQueueWorker (both
|
|
755
|
+
// app-level, created before the integration loop), then webhook,
|
|
756
|
+
// integration, queueWorker.
|
|
755
757
|
expect(functionKeys).toEqual([
|
|
756
758
|
'dlqProcessor',
|
|
759
|
+
'userActionQueueWorker',
|
|
757
760
|
'testWebhook',
|
|
758
761
|
'test',
|
|
759
762
|
'testQueueWorker',
|
|
@@ -935,5 +938,122 @@ describe('IntegrationBuilder', () => {
|
|
|
935
938
|
);
|
|
936
939
|
});
|
|
937
940
|
});
|
|
941
|
+
|
|
942
|
+
describe('User-Action FIFO queue', () => {
|
|
943
|
+
const appDefinition = {
|
|
944
|
+
integrations: [{ Definition: { name: 'test' } }],
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
it('creates a FIFO queue without ContentBasedDeduplication', async () => {
|
|
948
|
+
const result = await integrationBuilder.build(appDefinition, {});
|
|
949
|
+
|
|
950
|
+
const q = result.resources.FriggUserActionQueue;
|
|
951
|
+
expect(q).toBeDefined();
|
|
952
|
+
expect(q.Type).toBe('AWS::SQS::Queue');
|
|
953
|
+
expect(q.Properties.FifoQueue).toBe(true);
|
|
954
|
+
expect(q.Properties.ContentBasedDeduplication).toBeUndefined();
|
|
955
|
+
expect(q.Properties.VisibilityTimeout).toBe(1800);
|
|
956
|
+
expect(q.Properties.MessageRetentionPeriod).toBe(345600);
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
it('redrives to the FIFO DLQ with maxReceiveCount 2', async () => {
|
|
960
|
+
const result = await integrationBuilder.build(appDefinition, {});
|
|
961
|
+
|
|
962
|
+
expect(
|
|
963
|
+
result.resources.FriggUserActionQueue.Properties.RedrivePolicy
|
|
964
|
+
).toEqual({
|
|
965
|
+
maxReceiveCount: 2,
|
|
966
|
+
deadLetterTargetArn: {
|
|
967
|
+
'Fn::GetAtt': ['FriggUserActionDLQ', 'Arn'],
|
|
968
|
+
},
|
|
969
|
+
});
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
it('creates a FIFO DLQ with 14-day retention', async () => {
|
|
973
|
+
const result = await integrationBuilder.build(appDefinition, {});
|
|
974
|
+
|
|
975
|
+
const dlq = result.resources.FriggUserActionDLQ;
|
|
976
|
+
expect(dlq).toBeDefined();
|
|
977
|
+
expect(dlq.Properties.FifoQueue).toBe(true);
|
|
978
|
+
expect(dlq.Properties.MessageRetentionPeriod).toBe(1209600);
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
it('creates the worker bound to the FIFO queue ARN with no reservedConcurrency', async () => {
|
|
982
|
+
const result = await integrationBuilder.build(appDefinition, {});
|
|
983
|
+
|
|
984
|
+
const worker = result.functions.userActionQueueWorker;
|
|
985
|
+
expect(worker).toBeDefined();
|
|
986
|
+
expect(worker.handler).toBe(
|
|
987
|
+
'node_modules/@friggframework/core/handlers/workers/user-action-worker.userActionQueueWorker'
|
|
988
|
+
);
|
|
989
|
+
expect(worker.timeout).toBe(900);
|
|
990
|
+
expect(worker.reservedConcurrency).toBeUndefined();
|
|
991
|
+
expect(worker.events).toEqual([
|
|
992
|
+
{
|
|
993
|
+
sqs: {
|
|
994
|
+
arn: { 'Fn::GetAtt': ['FriggUserActionQueue', 'Arn'] },
|
|
995
|
+
batchSize: 1,
|
|
996
|
+
functionResponseType: 'ReportBatchItemFailures',
|
|
997
|
+
},
|
|
998
|
+
},
|
|
999
|
+
]);
|
|
1000
|
+
});
|
|
1001
|
+
|
|
1002
|
+
it('exposes USER_ACTION_QUEUE_URL to all Lambdas', async () => {
|
|
1003
|
+
const result = await integrationBuilder.build(appDefinition, {});
|
|
1004
|
+
|
|
1005
|
+
expect(result.environment.USER_ACTION_QUEUE_URL).toEqual({
|
|
1006
|
+
Ref: 'FriggUserActionQueue',
|
|
1007
|
+
});
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
it('alarms on the FIFO DLQ via the InternalErrorBridgeTopic', async () => {
|
|
1011
|
+
const result = await integrationBuilder.build(appDefinition, {});
|
|
1012
|
+
|
|
1013
|
+
const alarm = result.resources.FriggUserActionDLQAlarm;
|
|
1014
|
+
expect(alarm).toBeDefined();
|
|
1015
|
+
expect(alarm.Properties.AlarmActions).toEqual([
|
|
1016
|
+
{ Ref: 'InternalErrorBridgeTopic' },
|
|
1017
|
+
]);
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
it('creates exactly one FIFO queue + worker regardless of integration count', async () => {
|
|
1021
|
+
const result = await integrationBuilder.build(
|
|
1022
|
+
{
|
|
1023
|
+
integrations: [
|
|
1024
|
+
{ Definition: { name: 'hubspot' } },
|
|
1025
|
+
{ Definition: { name: 'salesforce' } },
|
|
1026
|
+
{ Definition: { name: 'slack' } },
|
|
1027
|
+
],
|
|
1028
|
+
},
|
|
1029
|
+
{}
|
|
1030
|
+
);
|
|
1031
|
+
|
|
1032
|
+
const fifoQueues = Object.keys(result.resources).filter(
|
|
1033
|
+
(k) => k === 'FriggUserActionQueue'
|
|
1034
|
+
);
|
|
1035
|
+
expect(fifoQueues).toHaveLength(1);
|
|
1036
|
+
expect(result.functions.userActionQueueWorker).toBeDefined();
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
it('does not make per-integration queues FIFO', async () => {
|
|
1040
|
+
const result = await integrationBuilder.build(appDefinition, {});
|
|
1041
|
+
|
|
1042
|
+
expect(
|
|
1043
|
+
result.resources.TestQueue.Properties.FifoQueue
|
|
1044
|
+
).toBeUndefined();
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
it('omits the Prisma layer on the worker when usePrismaLambdaLayer=false', async () => {
|
|
1048
|
+
const result = await integrationBuilder.build(
|
|
1049
|
+
{ usePrismaLambdaLayer: false, integrations: [{ Definition: { name: 'test' } }] },
|
|
1050
|
+
{}
|
|
1051
|
+
);
|
|
1052
|
+
|
|
1053
|
+
expect(
|
|
1054
|
+
result.functions.userActionQueueWorker.layers
|
|
1055
|
+
).toBeUndefined();
|
|
1056
|
+
});
|
|
1057
|
+
});
|
|
938
1058
|
});
|
|
939
1059
|
|
|
@@ -426,6 +426,10 @@ function generateIAMCloudFormation(options = {}) {
|
|
|
426
426
|
],
|
|
427
427
|
Resource: [
|
|
428
428
|
{ 'Fn::Sub': 'arn:aws:sqs:*:${AWS::AccountId}:*frigg*' },
|
|
429
|
+
// IAM wildcard matching is case-sensitive; the app-level FIFO
|
|
430
|
+
// queue is named "...-FriggUserActionQueue.fifo", which the
|
|
431
|
+
// lowercase "*frigg*" glob would not match.
|
|
432
|
+
{ 'Fn::Sub': 'arn:aws:sqs:*:${AWS::AccountId}:*Frigg*' },
|
|
429
433
|
{
|
|
430
434
|
'Fn::Sub':
|
|
431
435
|
'arn:aws:sqs:*:${AWS::AccountId}:internal-error-queue-*',
|
|
@@ -182,6 +182,22 @@ describe('IAM Generator', () => {
|
|
|
182
182
|
expect(yaml).toContain('internal-error-queue-*');
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
+
it('should include a case-sensitive *Frigg* SQS resource for the FIFO queue', () => {
|
|
186
|
+
const appDefinition = {
|
|
187
|
+
name: 'test-app',
|
|
188
|
+
integrations: [],
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const summary = getFeatureSummary(appDefinition);
|
|
192
|
+
const yaml = generateIAMCloudFormation({
|
|
193
|
+
appName: summary.appName,
|
|
194
|
+
features: summary.features,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// The lowercase "*frigg*" glob would not match "...-FriggUserActionQueue.fifo".
|
|
198
|
+
expect(yaml).toContain(':*Frigg*');
|
|
199
|
+
});
|
|
200
|
+
|
|
185
201
|
it('should generate outputs section', () => {
|
|
186
202
|
const appDefinition = {
|
|
187
203
|
name: 'test-app',
|
|
@@ -205,6 +205,9 @@ Resources:
|
|
|
205
205
|
- 'sqs:UntagQueue'
|
|
206
206
|
Resource:
|
|
207
207
|
- !Sub 'arn:aws:sqs:*:${AWS::AccountId}:*frigg*'
|
|
208
|
+
# Case-sensitive glob: the app-level FIFO queue is named
|
|
209
|
+
# "...-FriggUserActionQueue.fifo" which "*frigg*" would not match.
|
|
210
|
+
- !Sub 'arn:aws:sqs:*:${AWS::AccountId}:*Frigg*'
|
|
208
211
|
- !Sub 'arn:aws:sqs:*:${AWS::AccountId}:internal-error-queue-*'
|
|
209
212
|
|
|
210
213
|
# SNS permissions
|
|
@@ -196,6 +196,10 @@ function createBaseDefinition(
|
|
|
196
196
|
],
|
|
197
197
|
Resource: [
|
|
198
198
|
{ 'Fn::GetAtt': ['InternalErrorQueue', 'Arn'] },
|
|
199
|
+
// Explicit ARN: the per-integration glob below ends in
|
|
200
|
+
// "-*Queue" and does NOT match the ".fifo" suffix, so the
|
|
201
|
+
// app-level FIFO queue must be listed directly.
|
|
202
|
+
{ 'Fn::GetAtt': ['FriggUserActionQueue', 'Arn'] },
|
|
199
203
|
{
|
|
200
204
|
'Fn::Join': [
|
|
201
205
|
':',
|
|
@@ -311,6 +315,16 @@ function createBaseDefinition(
|
|
|
311
315
|
{ httpApi: { path: '/health/{proxy+}', method: 'GET' } },
|
|
312
316
|
],
|
|
313
317
|
},
|
|
318
|
+
reporting: {
|
|
319
|
+
handler: 'node_modules/@friggframework/core/handlers/routers/reporting.handler',
|
|
320
|
+
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
321
|
+
skipEsbuild: true, // Handlers in node_modules don't need bundling
|
|
322
|
+
package: skipEsbuildPackageConfig,
|
|
323
|
+
events: [
|
|
324
|
+
{ httpApi: { path: '/api/v2/reports', method: 'GET' } },
|
|
325
|
+
{ httpApi: { path: '/api/v2/reports/{proxy+}', method: 'GET' } },
|
|
326
|
+
],
|
|
327
|
+
},
|
|
314
328
|
// Note: dbMigrate removed - MigrationBuilder now handles migration infrastructure
|
|
315
329
|
// See: packages/devtools/infrastructure/domains/database/migration-builder.js
|
|
316
330
|
},
|
|
@@ -133,6 +133,12 @@ describe('Base Definition Factory', () => {
|
|
|
133
133
|
stmt => stmt.Action.includes('sqs:SendMessage')
|
|
134
134
|
);
|
|
135
135
|
expect(sqsPermission).toBeDefined();
|
|
136
|
+
|
|
137
|
+
// The per-integration glob ends in "-*Queue" and won't match the
|
|
138
|
+
// ".fifo" app-level queue, so its ARN must be listed explicitly.
|
|
139
|
+
expect(sqsPermission.Resource).toContainEqual({
|
|
140
|
+
'Fn::GetAtt': ['FriggUserActionQueue', 'Arn'],
|
|
141
|
+
});
|
|
136
142
|
});
|
|
137
143
|
|
|
138
144
|
it('should include required plugins', () => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.608.03436383054a.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"frigg": "./frigg-cli/index.js"
|
|
7
7
|
},
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"@babel/eslint-parser": "^7.18.9",
|
|
26
26
|
"@babel/parser": "^7.25.3",
|
|
27
27
|
"@babel/traverse": "^7.25.3",
|
|
28
|
-
"@friggframework/core": "2.0.0--canary.
|
|
29
|
-
"@friggframework/schemas": "2.0.0--canary.
|
|
30
|
-
"@friggframework/test": "2.0.0--canary.
|
|
28
|
+
"@friggframework/core": "2.0.0--canary.608.03436383054a.0",
|
|
29
|
+
"@friggframework/schemas": "2.0.0--canary.608.03436383054a.0",
|
|
30
|
+
"@friggframework/test": "2.0.0--canary.608.03436383054a.0",
|
|
31
31
|
"@hapi/boom": "^10.0.1",
|
|
32
32
|
"@inquirer/prompts": "^5.3.8",
|
|
33
33
|
"axios": "^1.18.0",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"validate-npm-package-name": "^5.0.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
59
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
58
|
+
"@friggframework/eslint-config": "2.0.0--canary.608.03436383054a.0",
|
|
59
|
+
"@friggframework/prettier-config": "2.0.0--canary.608.03436383054a.0",
|
|
60
60
|
"aws-sdk-client-mock": "^4.1.0",
|
|
61
61
|
"aws-sdk-client-mock-jest": "^4.1.0",
|
|
62
62
|
"jest": "^30.1.3",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"access": "public"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "03436383054a3ee70bd4de8f13a1907890a627da"
|
|
92
92
|
}
|