@friggframework/devtools 2.0.0-next.69 → 2.0.0-next.70
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.
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduler Builder
|
|
3
|
+
*
|
|
4
|
+
* Domain Layer - Hexagonal Architecture
|
|
5
|
+
*
|
|
6
|
+
* Responsible for:
|
|
7
|
+
* - Creating EventBridge Scheduler ScheduleGroup resource
|
|
8
|
+
* - Creating IAM Role for EventBridge Scheduler to send messages to SQS
|
|
9
|
+
* - Adding necessary IAM statements for Lambda to create/delete schedules
|
|
10
|
+
*
|
|
11
|
+
* This builder enables integrations to schedule one-time jobs (e.g., webhook renewals)
|
|
12
|
+
* using AWS EventBridge Scheduler.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
|
|
16
|
+
|
|
17
|
+
class SchedulerBuilder extends InfrastructureBuilder {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this.name = 'SchedulerBuilder';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
shouldExecute(appDefinition) {
|
|
24
|
+
// Enable scheduler if explicitly enabled or if any integration has webhooks
|
|
25
|
+
// (webhooks often need renewal scheduling)
|
|
26
|
+
if (appDefinition.scheduler?.enable === true) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Check if any integration has webhooks enabled
|
|
31
|
+
if (Array.isArray(appDefinition.integrations)) {
|
|
32
|
+
return appDefinition.integrations.some(
|
|
33
|
+
(integration) =>
|
|
34
|
+
integration?.Definition?.webhooks?.enabled === true ||
|
|
35
|
+
integration?.Definition?.webhooks === true
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getDependencies() {
|
|
43
|
+
return ['IntegrationBuilder']; // Needs integration queues to exist
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
validate(appDefinition) {
|
|
47
|
+
const result = new ValidationResult();
|
|
48
|
+
// No validation required - scheduler is optional
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async build(appDefinition, discoveredResources) {
|
|
53
|
+
console.log(`\n[${this.name}] Configuring EventBridge Scheduler...`);
|
|
54
|
+
|
|
55
|
+
const result = {
|
|
56
|
+
functions: {},
|
|
57
|
+
resources: {},
|
|
58
|
+
environment: {},
|
|
59
|
+
custom: {},
|
|
60
|
+
iamStatements: [],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Create ScheduleGroup resource
|
|
64
|
+
this.createScheduleGroup(result);
|
|
65
|
+
|
|
66
|
+
// Create IAM Role for EventBridge Scheduler
|
|
67
|
+
this.createSchedulerExecutionRole(appDefinition, result);
|
|
68
|
+
|
|
69
|
+
// Add IAM statements for Lambda to manage schedules
|
|
70
|
+
this.addSchedulerIamStatements(result);
|
|
71
|
+
|
|
72
|
+
// Add environment variables
|
|
73
|
+
this.addEnvironmentVariables(result);
|
|
74
|
+
|
|
75
|
+
console.log(`[${this.name}] ✅ Scheduler configuration completed`);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create EventBridge Scheduler ScheduleGroup
|
|
81
|
+
* Uses stage-specific naming to allow multiple deployments in same AWS account
|
|
82
|
+
*/
|
|
83
|
+
createScheduleGroup(result) {
|
|
84
|
+
const scheduleGroupName = '${self:service}-${self:provider.stage}-schedules';
|
|
85
|
+
|
|
86
|
+
result.resources.FriggScheduleGroup = {
|
|
87
|
+
Type: 'AWS::Scheduler::ScheduleGroup',
|
|
88
|
+
Properties: {
|
|
89
|
+
Name: scheduleGroupName,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
console.log(` ✓ Created ScheduleGroup: ${scheduleGroupName}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create IAM Role for EventBridge Scheduler to send messages to SQS
|
|
98
|
+
*/
|
|
99
|
+
createSchedulerExecutionRole(appDefinition, result) {
|
|
100
|
+
// Collect all integration queue ARNs
|
|
101
|
+
const queueArns = [];
|
|
102
|
+
if (Array.isArray(appDefinition.integrations)) {
|
|
103
|
+
appDefinition.integrations.forEach((integration) => {
|
|
104
|
+
const integrationName = integration?.Definition?.name;
|
|
105
|
+
if (integrationName) {
|
|
106
|
+
const capitalizedName =
|
|
107
|
+
integrationName.charAt(0).toUpperCase() +
|
|
108
|
+
integrationName.slice(1);
|
|
109
|
+
queueArns.push({
|
|
110
|
+
'Fn::GetAtt': [`${capitalizedName}Queue`, 'Arn'],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// If no queues found, use a placeholder (shouldn't happen if IntegrationBuilder ran)
|
|
117
|
+
if (queueArns.length === 0) {
|
|
118
|
+
console.warn(
|
|
119
|
+
' ⚠ No integration queues found for scheduler role'
|
|
120
|
+
);
|
|
121
|
+
queueArns.push('arn:aws:sqs:*:*:*'); // Fallback
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
result.resources.SchedulerExecutionRole = {
|
|
125
|
+
Type: 'AWS::IAM::Role',
|
|
126
|
+
Properties: {
|
|
127
|
+
RoleName:
|
|
128
|
+
'${self:service}-${self:provider.stage}-scheduler-role',
|
|
129
|
+
AssumeRolePolicyDocument: {
|
|
130
|
+
Version: '2012-10-17',
|
|
131
|
+
Statement: [
|
|
132
|
+
{
|
|
133
|
+
Effect: 'Allow',
|
|
134
|
+
Principal: {
|
|
135
|
+
Service: 'scheduler.amazonaws.com',
|
|
136
|
+
},
|
|
137
|
+
Action: 'sts:AssumeRole',
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
Policies: [
|
|
142
|
+
{
|
|
143
|
+
PolicyName: 'SchedulerSQSPolicy',
|
|
144
|
+
PolicyDocument: {
|
|
145
|
+
Version: '2012-10-17',
|
|
146
|
+
Statement: [
|
|
147
|
+
{
|
|
148
|
+
Effect: 'Allow',
|
|
149
|
+
Action: ['sqs:SendMessage'],
|
|
150
|
+
Resource: queueArns,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
console.log(' ✓ Created SchedulerExecutionRole');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Add IAM statements for Lambda functions to manage schedules
|
|
164
|
+
*/
|
|
165
|
+
addSchedulerIamStatements(result) {
|
|
166
|
+
result.iamStatements.push(
|
|
167
|
+
{
|
|
168
|
+
Effect: 'Allow',
|
|
169
|
+
Action: [
|
|
170
|
+
'scheduler:CreateSchedule',
|
|
171
|
+
'scheduler:DeleteSchedule',
|
|
172
|
+
'scheduler:GetSchedule',
|
|
173
|
+
],
|
|
174
|
+
Resource: {
|
|
175
|
+
'Fn::Sub': [
|
|
176
|
+
'arn:aws:scheduler:${AWS::Region}:${AWS::AccountId}:schedule/${GroupName}/*',
|
|
177
|
+
{ GroupName: { Ref: 'FriggScheduleGroup' } },
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
Effect: 'Allow',
|
|
183
|
+
Action: ['iam:PassRole'],
|
|
184
|
+
Resource: { 'Fn::GetAtt': ['SchedulerExecutionRole', 'Arn'] },
|
|
185
|
+
Condition: {
|
|
186
|
+
StringEquals: {
|
|
187
|
+
'iam:PassedToService': 'scheduler.amazonaws.com',
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
console.log(' ✓ Added scheduler IAM statements');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Add environment variables for scheduler configuration
|
|
198
|
+
*/
|
|
199
|
+
addEnvironmentVariables(result) {
|
|
200
|
+
result.environment.SCHEDULER_ROLE_ARN = {
|
|
201
|
+
'Fn::GetAtt': ['SchedulerExecutionRole', 'Arn'],
|
|
202
|
+
};
|
|
203
|
+
result.environment.SCHEDULE_GROUP_NAME = {
|
|
204
|
+
Ref: 'FriggScheduleGroup',
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
console.log(' ✓ Added scheduler environment variables');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
module.exports = { SchedulerBuilder };
|
|
@@ -16,6 +16,7 @@ const { MigrationBuilder } = require('./domains/database/migration-builder');
|
|
|
16
16
|
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
|
+
const { SchedulerBuilder } = require('./domains/scheduler/scheduler-builder');
|
|
19
20
|
|
|
20
21
|
// Utilities
|
|
21
22
|
const { modifyHandlerPaths } = require('./domains/shared/utilities/handler-path-resolver');
|
|
@@ -51,6 +52,7 @@ const composeServerlessDefinition = async (AppDefinition) => {
|
|
|
51
52
|
new SsmBuilder(),
|
|
52
53
|
new WebsocketBuilder(),
|
|
53
54
|
new IntegrationBuilder(),
|
|
55
|
+
new SchedulerBuilder(), // Add scheduler after IntegrationBuilder (depends on it)
|
|
54
56
|
]);
|
|
55
57
|
|
|
56
58
|
// Build all infrastructure (orchestrator handles validation, dependencies, parallel execution)
|
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-next.
|
|
4
|
+
"version": "2.0.0-next.70",
|
|
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-next.
|
|
29
|
-
"@friggframework/schemas": "2.0.0-next.
|
|
30
|
-
"@friggframework/test": "2.0.0-next.
|
|
28
|
+
"@friggframework/core": "2.0.0-next.70",
|
|
29
|
+
"@friggframework/schemas": "2.0.0-next.70",
|
|
30
|
+
"@friggframework/test": "2.0.0-next.70",
|
|
31
31
|
"@hapi/boom": "^10.0.1",
|
|
32
32
|
"@inquirer/prompts": "^5.3.8",
|
|
33
33
|
"axios": "^1.7.2",
|
|
@@ -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-next.
|
|
59
|
-
"@friggframework/prettier-config": "2.0.0-next.
|
|
58
|
+
"@friggframework/eslint-config": "2.0.0-next.70",
|
|
59
|
+
"@friggframework/prettier-config": "2.0.0-next.70",
|
|
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": "dee1112300e01813e68b2598c3a722d1a31e1677"
|
|
92
92
|
}
|