@friggframework/devtools 2.0.0--canary.700.80ec1cc.0 → 2.0.0--canary.702.047d3c4.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 (42) hide show
  1. package/README.md +1 -0
  2. package/frigg-cli/README.md +46 -1
  3. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  4. package/frigg-cli/__tests__/unit/commands/deploy.test.js +3 -0
  5. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  6. package/frigg-cli/build-command/index.js +6 -0
  7. package/frigg-cli/deploy-command/index.js +6 -0
  8. package/frigg-cli/index.js +19 -1
  9. package/frigg-cli/init-command/backend-first-handler.js +25 -46
  10. package/frigg-cli/start-command/index.js +4 -0
  11. package/frigg-cli/start-command/start-command.test.js +3 -0
  12. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  13. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  14. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +326 -0
  15. package/frigg-cli/validate-command/__tests__/validate-command.test.js +241 -0
  16. package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +119 -0
  17. package/frigg-cli/validate-command/checks/config.js +468 -0
  18. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  19. package/frigg-cli/validate-command/fixtures/bad-module/index.js +18 -0
  20. package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +76 -0
  21. package/frigg-cli/validate-command/fixtures/fathom-module/index.js +6 -0
  22. package/frigg-cli/validate-command/format-report.js +60 -0
  23. package/frigg-cli/validate-command/index.js +151 -0
  24. package/frigg-cli/validate-command/load-app-definition.js +93 -0
  25. package/frigg-cli/validate-command/load-module-definition.js +64 -0
  26. package/frigg-cli/validate-command/schema-issues.js +154 -0
  27. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  28. package/frigg-cli/validate-command/validate-module-definition.js +46 -0
  29. package/infrastructure/app-definition-schema-contract.test.js +607 -0
  30. package/infrastructure/create-frigg-infrastructure.js +4 -1
  31. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  32. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +60 -98
  33. package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -6
  34. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -30
  35. package/infrastructure/domains/integration/integration-builder.js +0 -19
  36. package/infrastructure/domains/integration/integration-builder.test.js +0 -22
  37. package/infrastructure/domains/shared/function-environments.js +1 -9
  38. package/infrastructure/domains/shared/function-environments.test.js +0 -14
  39. package/infrastructure/infrastructure-composer.js +0 -2
  40. package/package.json +7 -7
  41. package/infrastructure/domains/scheduler/trigger-builder.js +0 -114
  42. package/infrastructure/domains/scheduler/trigger-builder.test.js +0 -82
@@ -8,10 +8,10 @@ Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 P
8
8
 
9
9
  ### Key Features
10
10
 
11
- - **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-1.0 ACU default)
11
+ - **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-4 ACU default)
12
12
  - **VPC Integration**: Deployed in same private subnets as Lambda functions
13
13
  - **Secrets Manager**: Automatic credential management and rotation
14
- - **Three Management Modes**: discover, create-new, use-existing
14
+ - **Three Management Modes**: discover, managed, use-existing
15
15
  - **Security**: Private subnet deployment with security group isolation
16
16
  - **High Availability**: Multi-AZ deployment with automatic failover
17
17
 
@@ -21,12 +21,16 @@ Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 P
21
21
 
22
22
  ### App Definition Structure
23
23
 
24
+ These are the keys the Aurora builder reads (see `database.postgres` in
25
+ `packages/schemas/schemas/app-definition.schema.json`). `frigg validate`
26
+ rejects any other key under `database.postgres`.
27
+
24
28
  ```javascript
25
29
  // backend/index.js
26
30
  const appDefinition = {
27
31
  name: 'my-frigg-app',
28
32
 
29
- // Enable VPC deployment (required for Aurora)
33
+ // VPC Configuration (required for Aurora)
30
34
  vpc: {
31
35
  enable: true,
32
36
  },
@@ -36,34 +40,24 @@ const appDefinition = {
36
40
  postgres: {
37
41
  enable: true,
38
42
 
39
- // Management mode: 'discover' | 'create-new' | 'use-existing'
43
+ // 'discover' (also when omitted) | 'managed' | 'use-existing'
44
+ // Ignored when managementMode is 'managed' or 'existing'.
40
45
  management: 'discover',
41
46
 
42
- // Basic Configuration
43
- databaseName: 'frigg_db',
44
- masterUsername: 'frigg_admin',
45
-
46
- // Engine Configuration
47
- engine: 'aurora-postgresql',
48
- engineVersion: '15.3',
49
-
50
- // Scaling Configuration (Aurora Serverless v2)
51
- scaling: {
52
- minCapacity: 0.5, // ACUs (0.5 = ~1GB RAM, ~$43/month)
53
- maxCapacity: 1.0, // ACUs (1.0 = ~2GB RAM, ~$87/month)
54
- },
47
+ database: 'frigg', // database name (default 'frigg')
48
+ username: 'postgres', // master user (default 'postgres')
49
+ engineVersion: '15.13', // Aurora PostgreSQL version (default '15.13')
55
50
 
56
- // Backup Configuration
57
- backupRetentionDays: 7,
58
- preferredBackupWindow: '03:00-04:00',
51
+ // Aurora Serverless v2 capacity, in ACUs (0.5-128)
52
+ minCapacity: 0.5, // default 0.5
53
+ maxCapacity: 4, // default 4
59
54
 
60
- // Security & Advanced
61
- deletionProtection: true,
62
- enablePerformanceInsights: false,
55
+ publiclyAccessible: false, // default false (private subnets)
56
+ autoCreateCredentials: false, // discover only: create a secret for a discovered cluster
63
57
 
64
- // For use-existing mode
65
- clusterIdentifier: 'my-existing-cluster',
66
- secretArn: 'arn:aws:secretsmanager:...',
58
+ // use-existing only
59
+ // endpoint: 'mydb.cluster-abc123.us-east-1.rds.amazonaws.com',
60
+ // port: 5432,
67
61
  }
68
62
  }
69
63
  };
@@ -73,13 +67,17 @@ module.exports = {
73
67
  };
74
68
  ```
75
69
 
70
+ Backup retention (7 days), the backup and maintenance windows and deletion
71
+ settings are fixed by the builder and are not configurable through the app
72
+ definition.
73
+
76
74
  ---
77
75
 
78
76
  ## Management Modes
79
77
 
80
78
  ### 1. Discover Mode (Default)
81
79
 
82
- Automatically discovers existing Aurora clusters or creates new one if none found.
80
+ Discovers an existing Aurora cluster, or creates a new one in the stack if none is found.
83
81
 
84
82
  ```javascript
85
83
  database: {
@@ -100,63 +98,56 @@ database: {
100
98
 
101
99
  ---
102
100
 
103
- ### 2. Create-New Mode
101
+ ### 2. Managed Mode
104
102
 
105
- Always creates a new Aurora cluster, even if existing clusters are found.
103
+ Creates the cluster, instance, subnet group and secret in the stack.
106
104
 
107
105
  ```javascript
108
106
  database: {
109
107
  postgres: {
110
108
  enable: true,
111
- management: 'create-new',
112
-
113
- // Customization options
114
- databaseName: 'my_app_db',
115
- masterUsername: 'admin',
116
- engineVersion: '15.3',
117
- scaling: {
118
- minCapacity: 1.0,
119
- maxCapacity: 2.0,
120
- },
121
- backupRetentionDays: 14,
122
- deletionProtection: true,
109
+ management: 'managed',
110
+ minCapacity: 1,
111
+ maxCapacity: 2,
123
112
  }
124
113
  }
125
114
  ```
126
115
 
116
+ With the top-level `managementMode: 'managed'` (and `vpcIsolation: 'isolated'`),
117
+ Frigg manages the database per stage and `database.postgres.management` is ignored.
118
+
127
119
  **Best For**: Production environments where you want dedicated database resources.
128
120
 
129
121
  ---
130
122
 
131
123
  ### 3. Use-Existing Mode
132
124
 
133
- Uses a specific existing Aurora cluster by identifier.
125
+ Connects to an existing PostgreSQL endpoint without creating database resources.
134
126
 
135
127
  ```javascript
136
128
  database: {
137
129
  postgres: {
138
130
  enable: true,
139
131
  management: 'use-existing',
140
-
141
- // Required: existing cluster identifier
142
- clusterIdentifier: 'my-existing-aurora-cluster',
143
-
144
- // Optional: secret ARN (discovered if not provided)
145
- secretArn: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:my-db-secret',
146
-
147
- // Database name to connect to
148
- databaseName: 'frigg_db',
132
+ endpoint: 'my-cluster.cluster-abc123.us-east-1.rds.amazonaws.com', // required
133
+ port: 5432,
134
+ database: 'frigg_db',
135
+ username: 'frigg_admin',
149
136
  }
150
137
  }
151
138
  ```
152
139
 
140
+ To use an existing cluster by identifier instead, use the ownership form:
141
+ `ownership: { cluster: 'external', instance: 'external' }` with
142
+ `external: { clusterIdentifier, instanceIdentifier, secretArn }`.
143
+
153
144
  **Best For**: Shared database scenarios or when you manage Aurora outside of Frigg.
154
145
 
155
146
  ---
156
147
 
157
148
  ## Created AWS Resources
158
149
 
159
- When provisioning Aurora (`create-new` or `discover` mode without existing cluster), Frigg creates:
150
+ When provisioning Aurora (`managed`, or `discover` mode without an existing cluster), Frigg creates:
160
151
 
161
152
  ### 1. RDS DB Subnet Group
162
153
  - **Name**: `{service}-{stage}-db-subnet-group`
@@ -221,17 +212,15 @@ database: {
221
212
  database: {
222
213
  postgres: {
223
214
  enable: true,
224
- scaling: {
225
- minCapacity: 1.0, // Higher baseline for production
226
- maxCapacity: 4.0, // Handle traffic spikes
227
- },
228
- backupRetentionDays: 30, // Longer retention
229
- enablePerformanceInsights: true, // Monitoring
230
- deletionProtection: true, // Prevent accidental deletion
215
+ minCapacity: 1, // Higher baseline for production
216
+ maxCapacity: 4, // Handle traffic spikes
231
217
  }
232
218
  }
233
219
  ```
234
220
 
221
+ Backup retention, Performance Insights and deletion protection are not
222
+ configurable through the app definition; change them on the cluster.
223
+
235
224
  **Estimated Monthly Costs**:
236
225
  - **Baseline**: $87/month (1.0 ACU minimum)
237
226
  - **Peak Traffic**: $348/month (4.0 ACU maximum)
@@ -276,15 +265,9 @@ const users = await prismaClient.user.findMany();
276
265
 
277
266
  ### 4. Deletion Protection
278
267
 
279
- ```javascript
280
- database: {
281
- postgres: {
282
- deletionProtection: true, // Prevents accidental deletion
283
- }
284
- }
285
- ```
286
-
287
- **Important**: When enabled, you must manually disable deletion protection in AWS console before stack deletion.
268
+ Deletion protection is not configurable through the app definition. Enable it
269
+ on the cluster in the AWS console (or with the AWS CLI); you must then disable
270
+ it before deleting the stack.
288
271
 
289
272
  ---
290
273
 
@@ -384,7 +367,7 @@ DB_TYPE=postgresql
384
367
  database: {
385
368
  postgres: {
386
369
  enable: true,
387
- management: 'create-new',
370
+ management: 'managed',
388
371
  }
389
372
  }
390
373
  ```
@@ -411,7 +394,7 @@ DB_TYPE=postgresql
411
394
  database: {
412
395
  postgres: {
413
396
  enable: true,
414
- management: 'create-new',
397
+ management: 'managed',
415
398
  }
416
399
  }
417
400
  ```
@@ -456,13 +439,13 @@ DB_TYPE=postgresql
456
439
 
457
440
  **Error**:
458
441
  ```
459
- No Aurora cluster found in discovery mode. Set management to "create-new"...
442
+ No Aurora cluster found in discovery mode. Set management to "managed" or provide endpoint with "use-existing".
460
443
  ```
461
444
 
462
445
  **Solution**:
463
446
  1. Check VPC is enabled: `vpc.enable: true`
464
- 2. Set management mode: `management: 'create-new'`
465
- 3. Or provide cluster identifier: `clusterIdentifier: 'my-cluster'`
447
+ 2. Set management mode: `management: 'managed'`
448
+ 3. Or connect to a known endpoint: `management: 'use-existing'`, `endpoint: '...'`
466
449
 
467
450
  ---
468
451
 
@@ -544,41 +527,20 @@ Cannot create Aurora cluster: InsufficientDBInstanceCapacity
544
527
 
545
528
  ## Advanced Configuration
546
529
 
547
- ### Custom Backup Window
548
-
549
- ```javascript
550
- database: {
551
- postgres: {
552
- enable: true,
553
- backupRetentionDays: 30,
554
- preferredBackupWindow: '02:00-03:00', // UTC
555
- }
556
- }
557
- ```
558
-
559
- ### Enhanced Monitoring
560
-
561
- ```javascript
562
- database: {
563
- postgres: {
564
- enable: true,
565
- enablePerformanceInsights: true,
566
- // Performance Insights retention: 7 days (default) or 731 days
567
- }
568
- }
569
- ```
570
-
571
530
  ### Custom Engine Version
572
531
 
573
532
  ```javascript
574
533
  database: {
575
534
  postgres: {
576
535
  enable: true,
577
- engineVersion: '14.6', // Default: 15.3
536
+ engineVersion: '16.4', // Default: 15.13
578
537
  }
579
538
  }
580
539
  ```
581
540
 
541
+ The backup window, backup retention and Performance Insights are set by the
542
+ builder and are not configurable through the app definition.
543
+
582
544
  ### Read Replicas (Not Supported Yet)
583
545
 
584
546
  Frigg currently provisions a single Aurora instance. For read replicas:
@@ -141,12 +141,10 @@ class AdminScriptBuilder extends InfrastructureBuilder {
141
141
  }
142
142
 
143
143
  createAdminScriptQueue(result, appDefinition) {
144
- // Registered under custom so the serverless plugin creates it in LocalStack offline
145
- result.custom.AdminScriptQueue = '${self:service}-${self:provider.stage}-AdminScriptQueue';
146
144
  result.resources.AdminScriptQueue = {
147
145
  Type: 'AWS::SQS::Queue',
148
146
  Properties: {
149
- QueueName: '${self:custom.AdminScriptQueue}',
147
+ QueueName: '${self:service}-${self:provider.stage}-AdminScriptQueue',
150
148
  MessageRetentionPeriod: 86400, // 1 day
151
149
  VisibilityTimeout: 900, // 15 minutes (Lambda max)
152
150
  RedrivePolicy: {
@@ -266,12 +264,10 @@ class AdminScriptBuilder extends InfrastructureBuilder {
266
264
  }
267
265
 
268
266
  createReportQueue(result, appDefinition) {
269
- // Registered under custom so the serverless plugin creates it in LocalStack offline
270
- result.custom.ReportQueue = '${self:service}-${self:provider.stage}-ReportQueue';
271
267
  result.resources.ReportQueue = {
272
268
  Type: 'AWS::SQS::Queue',
273
269
  Properties: {
274
- QueueName: '${self:custom.ReportQueue}',
270
+ QueueName: '${self:service}-${self:provider.stage}-ReportQueue',
275
271
  MessageRetentionPeriod: 86400, // 1 day
276
272
  VisibilityTimeout: 900, // 15 minutes (Lambda max)
277
273
  RedrivePolicy: {
@@ -168,21 +168,6 @@ describe('AdminScriptBuilder', () => {
168
168
  expect(result.resources.AdminScriptQueue.Properties.VisibilityTimeout).toBe(900); // 15 minutes
169
169
  });
170
170
 
171
- it('registers AdminScriptQueue under custom so frigg start creates it locally', async () => {
172
- const appDefinition = {
173
- adminScripts: [{ Definition: { name: 'test-script' } }],
174
- };
175
-
176
- const result = await adminScriptBuilder.build(appDefinition, {});
177
-
178
- expect(result.custom.AdminScriptQueue).toBe(
179
- '${self:service}-${self:provider.stage}-AdminScriptQueue'
180
- );
181
- expect(result.resources.AdminScriptQueue.Properties.QueueName).toBe(
182
- '${self:custom.AdminScriptQueue}'
183
- );
184
- });
185
-
186
171
  it('should configure AdminScriptQueue redrive policy to InternalErrorQueue', async () => {
187
172
  const appDefinition = {
188
173
  adminScripts: [
@@ -636,21 +621,6 @@ describe('AdminScriptBuilder', () => {
636
621
  });
637
622
 
638
623
  describe('reports (ReportQueue + reportExecutor)', () => {
639
- it('registers ReportQueue under custom so frigg start creates it locally', async () => {
640
- const appDefinition = {
641
- reports: [{ Definition: { name: 'my-report', version: '1.0.0' } }],
642
- };
643
-
644
- const result = await adminScriptBuilder.build(appDefinition, {});
645
-
646
- expect(result.custom.ReportQueue).toBe(
647
- '${self:service}-${self:provider.stage}-ReportQueue'
648
- );
649
- expect(result.resources.ReportQueue.Properties.QueueName).toBe(
650
- '${self:custom.ReportQueue}'
651
- );
652
- });
653
-
654
624
  it('creates ReportQueue + reportExecutor and wires REPORT_QUEUE_URL when reports are present', async () => {
655
625
  const appDefinition = {
656
626
  reports: [{ Definition: { name: 'my-report', version: '1.0.0' } }],
@@ -360,25 +360,6 @@ class IntegrationBuilder extends InfrastructureBuilder {
360
360
  method: 'POST',
361
361
  },
362
362
  },
363
- // A provider (the shared runtime for published integration definitions) also receives the
364
- // webhooks of every type it provides at that type's own URL. HTTP API cannot match part of a
365
- // segment, so the whole segment is a parameter; literal routes still win over it.
366
- ...(integration.IntegrationProvider
367
- ? [
368
- {
369
- httpApi: {
370
- path: '/api/{integrationType}/webhooks',
371
- method: 'POST',
372
- },
373
- },
374
- {
375
- httpApi: {
376
- path: '/api/{integrationType}/webhooks/{integrationId}',
377
- method: 'POST',
378
- },
379
- },
380
- ]
381
- : []),
382
363
  ],
383
364
  };
384
365
  console.log(` ✓ Webhook handler function defined`);
@@ -620,28 +620,6 @@ describe('IntegrationBuilder', () => {
620
620
  ]);
621
621
  });
622
622
 
623
- it('gives a provider of integration types the webhook routes of every type it provides', async () => {
624
- const appDefinition = {
625
- integrations: [
626
- { Definition: { name: 'stripe', webhooks: true } },
627
- {
628
- Definition: { name: 'integration-runtime', webhooks: { enabled: true } },
629
- IntegrationProvider: { resolve: async () => null, list: async () => [] },
630
- },
631
- ],
632
- };
633
-
634
- const result = await integrationBuilder.build(appDefinition, {});
635
-
636
- expect(result.functions['integration-runtimeWebhook'].events.map((e) => e.httpApi.path)).toEqual([
637
- '/api/integration-runtime-integration/webhooks',
638
- '/api/integration-runtime-integration/webhooks/{integrationId}',
639
- '/api/{integrationType}/webhooks',
640
- '/api/{integrationType}/webhooks/{integrationId}',
641
- ]);
642
- expect(result.functions.stripeWebhook.events).toHaveLength(2);
643
- });
644
-
645
623
  it('emits a dedicated per-binding function (namespaced) for Tier 3 extension routes; the main handler keeps only {proxy+}', async () => {
646
624
  const appDefinition = {
647
625
  integrations: [
@@ -1,5 +1,3 @@
1
- const { hasTriggers } = require('@friggframework/core/integrations/triggers');
2
-
3
1
  /**
4
2
  * Per-function environment scoping (ADR-027)
5
3
  *
@@ -49,8 +47,7 @@ function applyFunctionEnvironments(functions, functionEnvironments = {}) {
49
47
  /**
50
48
  * Function names the integration builder creates for one integration.
51
49
  * Wire contract: must stay in sync with
52
- * IntegrationBuilder.createFunctionDefinitions (and TriggerBuilder for
53
- * `${name}Triggers`) — a drift here surfaces as a
50
+ * IntegrationBuilder.createFunctionDefinitions — a drift here surfaces as a
54
51
  * hard unknown-function error at compose time, not a silent var drop.
55
52
  *
56
53
  * @param {Object} integration - entry from appDefinition.integrations
@@ -65,11 +62,6 @@ function getIntegrationFunctionNames(integration) {
65
62
  names.splice(1, 0, `${name}Webhook`);
66
63
  }
67
64
 
68
- // TriggerBuilder (ADR-055): the tick function, which sends trigger runs to this integration's queue.
69
- if (hasTriggers(integration)) {
70
- names.push(`${name}Triggers`);
71
- }
72
-
73
65
  for (const [bindingKey, binding] of Object.entries(
74
66
  integration.Definition.extensions || {}
75
67
  )) {
@@ -67,20 +67,6 @@ describe('function-environments', () => {
67
67
  ).not.toContain('hubspotWebhook');
68
68
  });
69
69
 
70
- it('includes the trigger tick function when the integration declares triggers (ADR-055)', () => {
71
- expect(
72
- getIntegrationFunctionNames({
73
- Definition: { name: 'hubspot', triggers: { poll: { every: '15m', handler: 'poll' } } },
74
- })
75
- ).toEqual(['hubspot', 'hubspotQueueWorker', 'hubspotTriggers']);
76
- expect(
77
- getIntegrationFunctionNames({ Definition: { name: 'dd', instanceTriggers: { tick: '5m' } } })
78
- ).toContain('ddTriggers');
79
- expect(
80
- getIntegrationFunctionNames({ Definition: { name: 'hubspot', triggers: {} } })
81
- ).not.toContain('hubspotTriggers');
82
- });
83
-
84
70
  it('includes one function per routed extension binding, sanitized', () => {
85
71
  const names = getIntegrationFunctionNames({
86
72
  Definition: {
@@ -17,7 +17,6 @@ const { SsmBuilder } = require('./domains/parameters/ssm-builder');
17
17
  const { WebsocketBuilder } = require('./domains/integration/websocket-builder');
18
18
  const { IntegrationBuilder } = require('./domains/integration/integration-builder');
19
19
  const { SchedulerBuilder } = require('./domains/scheduler/scheduler-builder');
20
- const { TriggerBuilder } = require('./domains/scheduler/trigger-builder');
21
20
  const { AdminScriptBuilder } = require('./domains/admin-scripts/admin-script-builder');
22
21
 
23
22
  // Utilities
@@ -93,7 +92,6 @@ const composeServerlessDefinition = async (AppDefinition) => {
93
92
  new WebsocketBuilder(),
94
93
  new IntegrationBuilder(),
95
94
  new SchedulerBuilder(), // Add scheduler after IntegrationBuilder (depends on it)
96
- new TriggerBuilder(), // One trigger tick function per integration with triggers (ADR-055)
97
95
  new AdminScriptBuilder(),
98
96
  ]);
99
97
 
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.700.80ec1cc.0",
4
+ "version": "2.0.0--canary.702.047d3c4.0",
5
5
  "bin": {
6
6
  "frigg": "./frigg-cli/index.js"
7
7
  },
@@ -26,9 +26,9 @@
26
26
  "@babel/eslint-parser": "^7.18.9",
27
27
  "@babel/parser": "^7.25.3",
28
28
  "@babel/traverse": "^7.25.3",
29
- "@friggframework/core": "2.0.0--canary.700.80ec1cc.0",
30
- "@friggframework/schemas": "2.0.0--canary.700.80ec1cc.0",
31
- "@friggframework/test": "2.0.0--canary.700.80ec1cc.0",
29
+ "@friggframework/core": "2.0.0--canary.702.047d3c4.0",
30
+ "@friggframework/schemas": "2.0.0--canary.702.047d3c4.0",
31
+ "@friggframework/test": "2.0.0--canary.702.047d3c4.0",
32
32
  "@hapi/boom": "^10.0.1",
33
33
  "@inquirer/prompts": "^5.3.8",
34
34
  "axios": "^1.18.0",
@@ -56,8 +56,8 @@
56
56
  "validate-npm-package-name": "^5.0.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@friggframework/eslint-config": "2.0.0--canary.700.80ec1cc.0",
60
- "@friggframework/prettier-config": "2.0.0--canary.700.80ec1cc.0",
59
+ "@friggframework/eslint-config": "2.0.0--canary.702.047d3c4.0",
60
+ "@friggframework/prettier-config": "2.0.0--canary.702.047d3c4.0",
61
61
  "aws-sdk-client-mock": "^4.1.0",
62
62
  "aws-sdk-client-mock-jest": "^4.1.0",
63
63
  "jest": "^30.1.3",
@@ -89,5 +89,5 @@
89
89
  "publishConfig": {
90
90
  "access": "public"
91
91
  },
92
- "gitHead": "80ec1cc658ebdfbe53482d0705c42129685eb47f"
92
+ "gitHead": "047d3c404aa8c9636d6c2c442d28ce5e5fcf6b39"
93
93
  }
@@ -1,114 +0,0 @@
1
- /**
2
- * Trigger Builder (ADR-055 §2)
3
- *
4
- * Domain Layer - Hexagonal Architecture
5
- *
6
- * One function per integration that declares recurring triggers: `{integration}Triggers`, with the Prisma layer.
7
- * It gets one serverless `schedule` event per distinct tick of the integration's `every` / `cron` triggers (and of
8
- * the triggers it resolves per installation, `Definition.instanceTriggers`), plus one EventBridge Scheduler event per
9
- * `at` trigger, with its time zone. Each tick pages through the ENABLED installations and queues the runs that are
10
- * due (core: integrations/use-cases/run-trigger-tick.js). Nothing is created per installation, and these resources
11
- * change only when a Definition does, so they live in CloudFormation and leave with the stack.
12
- *
13
- * IAM, and why this builder adds none:
14
- * - A `rate()` tick is an EventBridge rule; the framework adds the Lambda permission for it.
15
- * - An `at` trigger uses `method: scheduler`; the framework adds `scheduler.amazonaws.com` to the function role's
16
- * trust policy and `lambda:InvokeFunction` on this function to it.
17
- * - The tick reads the integration table (the Prisma layer and the provider's database access, like the queue
18
- * worker) and sends to its own `<Name>Queue`, which the provider-level `sqs:SendMessage(Batch)` statement on
19
- * `${service}--${stage}-*Queue` already allows. It never calls EventBridge Scheduler at runtime, so it needs none
20
- * of SchedulerBuilder's scheduler:* permissions (those stay for one-time jobs).
21
- */
22
-
23
- const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
24
- const { IntegrationBuilder } = require('../integration/integration-builder');
25
- const {
26
- hasTriggers,
27
- provisioningOf,
28
- durationOf,
29
- } = require('@friggframework/core/integrations/triggers');
30
-
31
- /** EventBridge rate() for a tick in minutes: rate(1 minute), rate(5 minutes), rate(1 hour), rate(2 hours), rate(1 day). */
32
- function rateExpression(minutes) {
33
- const [count, unit] =
34
- minutes % 1440 === 0 ? [minutes / 1440, 'day'] : minutes % 60 === 0 ? [minutes / 60, 'hour'] : [minutes, 'minute'];
35
- return `rate(${count} ${unit}${count === 1 ? '' : 's'})`;
36
- }
37
-
38
- /** The function name the trigger tick for an integration runs as. Wire contract with function-environments.js. */
39
- function triggerFunctionName(integrationName) {
40
- return `${integrationName}Triggers`;
41
- }
42
-
43
- class TriggerBuilder extends InfrastructureBuilder {
44
- constructor() {
45
- super();
46
- this.name = 'TriggerBuilder';
47
- }
48
-
49
- shouldExecute(appDefinition) {
50
- return Array.isArray(appDefinition.integrations) && appDefinition.integrations.some((i) => hasTriggers(i));
51
- }
52
-
53
- getDependencies() {
54
- return ['IntegrationBuilder']; // the tick sends to the integration queue
55
- }
56
-
57
- validate(appDefinition) {
58
- const result = new ValidationResult();
59
- for (const integration of appDefinition.integrations || []) {
60
- if (!hasTriggers(integration)) continue;
61
- try {
62
- provisioningOf(integration);
63
- } catch (error) {
64
- result.addError(error.message);
65
- }
66
- }
67
- return result;
68
- }
69
-
70
- async build(appDefinition) {
71
- console.log(`\n[${this.name}] Configuring recurring triggers...`);
72
- const result = { functions: {}, resources: {}, environment: {}, custom: {}, iamStatements: [] };
73
- const usePrismaLayer = appDefinition.usePrismaLambdaLayer !== false;
74
- const functionPackageConfig = new IntegrationBuilder().createFunctionPackageConfig(usePrismaLayer, appDefinition);
75
-
76
- for (const integration of appDefinition.integrations || []) {
77
- if (!hasTriggers(integration)) continue;
78
- const name = integration.Definition.name;
79
- const { ticks, at } = provisioningOf(integration);
80
- const events = [
81
- ...ticks.map((minutes) => ({
82
- schedule: {
83
- rate: [rateExpression(minutes)],
84
- // The rule's own firing time goes in, so a repeated delivery falls in the same tick slot.
85
- inputTransformer: {
86
- inputPathsMap: { time: '$.time' },
87
- inputTemplate: `{"tick":"${durationOf(minutes)}","time":<time>}`,
88
- },
89
- },
90
- })),
91
- ...at.map((t) => ({
92
- schedule: {
93
- method: 'scheduler',
94
- rate: [t.at],
95
- ...(t.timezone ? { timezone: t.timezone } : {}),
96
- input: { at: t.name, time: '<aws.scheduler.scheduled-time>' },
97
- },
98
- })),
99
- ];
100
- result.functions[triggerFunctionName(name)] = {
101
- handler: `node_modules/@friggframework/core/handlers/workers/integration-triggers.handlers.${name}.tick`,
102
- skipEsbuild: true, // Nested exports in node_modules - skip esbuild bundling
103
- package: functionPackageConfig,
104
- ...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }), // reads the integration table
105
- timeout: 300, // a tick past its deadline hands its page cursor to the queue
106
- events,
107
- };
108
- console.log(` ✓ ${triggerFunctionName(name)}: ticks ${ticks.map(durationOf).join(', ') || 'none'}; at ${at.map((t) => t.name).join(', ') || 'none'}`);
109
- }
110
- return result;
111
- }
112
- }
113
-
114
- module.exports = { TriggerBuilder, rateExpression, triggerFunctionName };