@friggframework/core 2.0.0-next.120 → 2.0.0-next.121

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.
@@ -11,19 +11,65 @@
11
11
  * This adapter implements SchedulerServiceInterface for AWS EventBridge Scheduler.
12
12
  */
13
13
 
14
- const {
15
- SchedulerClient,
16
- CreateScheduleCommand,
17
- DeleteScheduleCommand,
18
- GetScheduleCommand,
19
- ResourceNotFoundException,
20
- } = require('@aws-sdk/client-scheduler');
21
-
22
14
  const { SchedulerServiceInterface } = require('./scheduler-service-interface');
23
15
 
16
+ const SCHEDULER_SDK = '@aws-sdk/client-scheduler';
17
+
18
+ /**
19
+ * Lazily load the AWS EventBridge Scheduler SDK.
20
+ *
21
+ * Requiring `@aws-sdk/client-scheduler` at module top level would put the AWS
22
+ * SDK on the load path of every consumer of `@friggframework/core`, including
23
+ * those using the mock scheduler or no scheduler at all. Loading it here, on
24
+ * construction of the EventBridge adapter, keeps it out of the module-load
25
+ * path. The adapter calls it exactly once, in its constructor, and keeps the
26
+ * classes its methods need on the instance.
27
+ *
28
+ * Only a MODULE_NOT_FOUND for the scheduler SDK itself is rewritten into an
29
+ * actionable message; any other failure (including a missing transitive
30
+ * dependency) is rethrown unchanged so the real cause is not masked.
31
+ *
32
+ * @returns {object} The relevant exports from `@aws-sdk/client-scheduler`.
33
+ */
34
+ function loadSchedulerSdk() {
35
+ try {
36
+ // Keep the literal specifier so bundlers (esbuild) can resolve it.
37
+ return require('@aws-sdk/client-scheduler');
38
+ } catch (error) {
39
+ const isSchedulerSdkMissing =
40
+ error &&
41
+ error.code === 'MODULE_NOT_FOUND' &&
42
+ typeof error.message === 'string' &&
43
+ error.message.includes(SCHEDULER_SDK);
44
+ if (isSchedulerSdkMissing) {
45
+ throw new Error(
46
+ `The EventBridge scheduler requires the "${SCHEDULER_SDK}" package, ` +
47
+ `which is not installed. Install it (\`npm install ${SCHEDULER_SDK}\`) ` +
48
+ 'to use the EventBridge scheduler provider, or use the mock scheduler provider ' +
49
+ '(SCHEDULER_PROVIDER=mock) for local development.',
50
+ { cause: error }
51
+ );
52
+ }
53
+ throw error;
54
+ }
55
+ }
56
+
24
57
  class EventBridgeSchedulerAdapter extends SchedulerServiceInterface {
25
58
  constructor({ region } = {}) {
26
59
  super();
60
+ const {
61
+ SchedulerClient,
62
+ CreateScheduleCommand,
63
+ DeleteScheduleCommand,
64
+ GetScheduleCommand,
65
+ ResourceNotFoundException,
66
+ } = loadSchedulerSdk();
67
+ this.sdk = {
68
+ CreateScheduleCommand,
69
+ DeleteScheduleCommand,
70
+ GetScheduleCommand,
71
+ ResourceNotFoundException,
72
+ };
27
73
  this.client = new SchedulerClient({
28
74
  region: region || process.env.AWS_REGION || 'us-east-1',
29
75
  });
@@ -42,7 +88,12 @@ class EventBridgeSchedulerAdapter extends SchedulerServiceInterface {
42
88
  * @param {Object} params.payload - Message payload
43
89
  * @returns {Promise<{scheduledJobId: string, scheduledAt: string}>}
44
90
  */
45
- async scheduleOneTime({ scheduleName, scheduleAt, queueResourceId, payload }) {
91
+ async scheduleOneTime({
92
+ scheduleName,
93
+ scheduleAt,
94
+ queueResourceId,
95
+ payload,
96
+ }) {
46
97
  if (!scheduleName) {
47
98
  throw new Error('scheduleName is required');
48
99
  }
@@ -59,8 +110,11 @@ class EventBridgeSchedulerAdapter extends SchedulerServiceInterface {
59
110
  }
60
111
 
61
112
  // Format date to AWS schedule expression (at(yyyy-mm-ddThh:mm:ss))
62
- const scheduleExpression = `at(${scheduleAt.toISOString().replace(/\.\d{3}Z$/, '')})`;
113
+ const scheduleExpression = `at(${scheduleAt
114
+ .toISOString()
115
+ .replace(/\.\d{3}Z$/, '')})`;
63
116
 
117
+ const { CreateScheduleCommand } = this.sdk;
64
118
  const command = new CreateScheduleCommand({
65
119
  Name: scheduleName,
66
120
  GroupName: this.scheduleGroupName,
@@ -107,6 +161,7 @@ class EventBridgeSchedulerAdapter extends SchedulerServiceInterface {
107
161
  throw new Error('scheduleName is required');
108
162
  }
109
163
 
164
+ const { DeleteScheduleCommand, ResourceNotFoundException } = this.sdk;
110
165
  const command = new DeleteScheduleCommand({
111
166
  Name: scheduleName,
112
167
  GroupName: this.scheduleGroupName,
@@ -141,6 +196,7 @@ class EventBridgeSchedulerAdapter extends SchedulerServiceInterface {
141
196
  throw new Error('scheduleName is required');
142
197
  }
143
198
 
199
+ const { GetScheduleCommand, ResourceNotFoundException } = this.sdk;
144
200
  const command = new GetScheduleCommand({
145
201
  Name: scheduleName,
146
202
  GroupName: this.scheduleGroupName,
@@ -153,9 +209,7 @@ class EventBridgeSchedulerAdapter extends SchedulerServiceInterface {
153
209
  // Format: at(yyyy-mm-ddThh:mm:ss)
154
210
  let scheduledAt = null;
155
211
  if (response.ScheduleExpression) {
156
- const match = response.ScheduleExpression.match(
157
- /^at\((.+)\)$/
158
- );
212
+ const match = response.ScheduleExpression.match(/^at\((.+)\)$/);
159
213
  if (match) {
160
214
  scheduledAt = new Date(match[1] + 'Z').toISOString();
161
215
  }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0-next.120",
4
+ "version": "2.0.0-next.121",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
8
8
  "@aws-sdk/client-lambda": "^3.714.0",
9
9
  "@aws-sdk/client-s3": "^3.588.0",
10
+ "@aws-sdk/client-scheduler": "^3.588.0",
10
11
  "@aws-sdk/client-sqs": "^3.588.0",
11
12
  "@aws-sdk/client-ssm": "^3.588.0",
12
13
  "@aws-sdk/s3-request-presigner": "^3.588.0",
@@ -47,9 +48,9 @@
47
48
  }
48
49
  },
49
50
  "devDependencies": {
50
- "@friggframework/eslint-config": "2.0.0-next.120",
51
- "@friggframework/prettier-config": "2.0.0-next.120",
52
- "@friggframework/test": "2.0.0-next.120",
51
+ "@friggframework/eslint-config": "2.0.0-next.121",
52
+ "@friggframework/prettier-config": "2.0.0-next.121",
53
+ "@friggframework/test": "2.0.0-next.121",
53
54
  "@prisma/client": "^6.19.3",
54
55
  "@types/lodash": "4.17.15",
55
56
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -89,5 +90,5 @@
89
90
  "publishConfig": {
90
91
  "access": "public"
91
92
  },
92
- "gitHead": "e13f909d7386abdcac04f4adc875f8f1e0544b88"
93
+ "gitHead": "311b30a60ef98880ceeede1594375ae2c10347eb"
93
94
  }