alchemy 0.1.13 → 0.1.14

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 (86) hide show
  1. package/README.md +12 -2
  2. package/lib/aws/account-id.d.ts +5 -0
  3. package/lib/aws/account-id.d.ts.map +1 -0
  4. package/lib/aws/account-id.js +10 -0
  5. package/lib/aws/account-id.js.map +1 -0
  6. package/lib/aws/index.d.ts +1 -0
  7. package/lib/aws/index.d.ts.map +1 -1
  8. package/lib/aws/index.js +1 -0
  9. package/lib/aws/index.js.map +1 -1
  10. package/lib/aws/oidc/github-oidc-provider.d.ts +11 -0
  11. package/lib/aws/oidc/github-oidc-provider.d.ts.map +1 -0
  12. package/lib/aws/oidc/github-oidc-provider.js +22 -0
  13. package/lib/aws/oidc/github-oidc-provider.js.map +1 -0
  14. package/lib/aws/oidc/index.d.ts +3 -0
  15. package/lib/aws/oidc/index.d.ts.map +1 -0
  16. package/lib/aws/oidc/index.js +3 -0
  17. package/lib/aws/oidc/index.js.map +1 -0
  18. package/lib/aws/oidc/oidc-provider.d.ts +60 -0
  19. package/lib/aws/oidc/oidc-provider.d.ts.map +1 -0
  20. package/lib/aws/oidc/oidc-provider.js +140 -0
  21. package/lib/aws/oidc/oidc-provider.js.map +1 -0
  22. package/lib/aws/queue.d.ts +24 -0
  23. package/lib/aws/queue.d.ts.map +1 -1
  24. package/lib/aws/queue.js +6 -1
  25. package/lib/aws/queue.js.map +1 -1
  26. package/lib/aws/role.d.ts.map +1 -1
  27. package/lib/aws/role.js +49 -1
  28. package/lib/aws/role.js.map +1 -1
  29. package/lib/aws/ses.d.ts.map +1 -1
  30. package/lib/aws/ses.js +20 -28
  31. package/lib/aws/ses.js.map +1 -1
  32. package/lib/aws/table.d.ts.map +1 -1
  33. package/lib/aws/table.js +95 -73
  34. package/lib/aws/table.js.map +1 -1
  35. package/lib/cloudflare/bindings.d.ts +7 -2
  36. package/lib/cloudflare/bindings.d.ts.map +1 -1
  37. package/lib/cloudflare/durable-object-namespace.d.ts +2 -5
  38. package/lib/cloudflare/durable-object-namespace.d.ts.map +1 -1
  39. package/lib/cloudflare/durable-object-namespace.js +1 -6
  40. package/lib/cloudflare/durable-object-namespace.js.map +1 -1
  41. package/lib/cloudflare/kv-namespace.d.ts +3 -0
  42. package/lib/cloudflare/kv-namespace.d.ts.map +1 -1
  43. package/lib/cloudflare/kv-namespace.js +4 -0
  44. package/lib/cloudflare/kv-namespace.js.map +1 -1
  45. package/lib/cloudflare/static-site.d.ts.map +1 -1
  46. package/lib/cloudflare/static-site.js +12 -30
  47. package/lib/cloudflare/static-site.js.map +1 -1
  48. package/lib/cloudflare/worker.d.ts +6 -3
  49. package/lib/cloudflare/worker.d.ts.map +1 -1
  50. package/lib/cloudflare/worker.js +41 -15
  51. package/lib/cloudflare/worker.js.map +1 -1
  52. package/lib/github/client.d.ts +34 -0
  53. package/lib/github/client.d.ts.map +1 -0
  54. package/lib/github/client.js +91 -0
  55. package/lib/github/client.js.map +1 -0
  56. package/lib/github/index.d.ts +2 -0
  57. package/lib/github/index.d.ts.map +1 -0
  58. package/lib/github/index.js +2 -0
  59. package/lib/github/index.js.map +1 -0
  60. package/lib/github/secret.d.ts +46 -0
  61. package/lib/github/secret.d.ts.map +1 -0
  62. package/lib/github/secret.js +103 -0
  63. package/lib/github/secret.js.map +1 -0
  64. package/lib/utils/retry.d.ts +13 -0
  65. package/lib/utils/retry.d.ts.map +1 -0
  66. package/lib/utils/retry.js +31 -0
  67. package/lib/utils/retry.js.map +1 -0
  68. package/package.json +10 -2
  69. package/src/aws/account-id.ts +11 -0
  70. package/src/aws/index.ts +1 -0
  71. package/src/aws/oidc/github-oidc-provider.ts +34 -0
  72. package/src/aws/oidc/index.ts +2 -0
  73. package/src/aws/oidc/oidc-provider.ts +253 -0
  74. package/src/aws/queue.ts +23 -1
  75. package/src/aws/role.ts +69 -0
  76. package/src/aws/ses.ts +27 -31
  77. package/src/aws/table.ts +113 -82
  78. package/src/cloudflare/bindings.ts +8 -2
  79. package/src/cloudflare/durable-object-namespace.ts +4 -10
  80. package/src/cloudflare/kv-namespace.ts +11 -0
  81. package/src/cloudflare/static-site.ts +13 -32
  82. package/src/cloudflare/worker.ts +52 -22
  83. package/src/github/client.ts +115 -0
  84. package/src/github/index.ts +1 -0
  85. package/src/github/secret.ts +172 -0
  86. package/src/utils/retry.ts +36 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alchemy",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "module": "./lib/index.js",
6
6
  "scripts": {
@@ -12,10 +12,12 @@
12
12
  ".": "./lib/index.js",
13
13
  "./agent": "./lib/agent/index.js",
14
14
  "./aws": "./lib/aws/index.js",
15
+ "./aws/oidc": "./lib/aws/oidc/index.js",
15
16
  "./cloudflare": "./lib/cloudflare/index.js",
16
17
  "./esbuild": "./lib/esbuild.js",
17
18
  "./markdown": "./lib/markdown/index.js",
18
19
  "./fs": "./lib/fs.js",
20
+ "./github": "./lib/github/index.js",
19
21
  "./stripe": "./lib/stripe/index.js",
20
22
  "./typescript": "./lib/typescript/index.js"
21
23
  },
@@ -28,12 +30,15 @@
28
30
  "@aws-sdk/client-sagemaker": "^3.0.0",
29
31
  "@aws-sdk/client-ses": "^3.0.0",
30
32
  "@aws-sdk/client-sesv2": "^3.0.0",
31
- "@aws-sdk/client-sqs": "^3.0.1",
33
+ "@aws-sdk/client-sqs": "^3.0.0",
34
+ "@aws-sdk/client-sts": "^3.0.0",
35
+ "@octokit/rest": "^21.1.1",
32
36
  "ai": "^4.1.16",
33
37
  "diff": "^7.0.0",
34
38
  "esbuild": "^0.24.2",
35
39
  "glob": "^10.3.10",
36
40
  "hono": "^4.7.4",
41
+ "libsodium-wrappers": "^0.7.15",
37
42
  "jszip": "^3.0.0",
38
43
  "stripe": "^17.7.0",
39
44
  "turndown": "^7.2.0",
@@ -44,12 +49,15 @@
44
49
  "@ai-sdk/openai": "^1.1.9",
45
50
  "@biomejs/biome": "^1.9.4",
46
51
  "@cloudflare/workers-types": "^4.20250303.0",
52
+ "@octokit/rest": "^21.1.1",
47
53
  "@types/bun": "latest",
48
54
  "@types/diff": "^5.0.0",
55
+ "@types/libsodium-wrappers": "^0.7.14",
49
56
  "@types/node": "latest",
50
57
  "@types/turndown": "^5.0.5",
51
58
  "ai": "^4.1.16",
52
59
  "change-case": "^5.4.4",
60
+ "libsodium-wrappers": "^0.7.15",
53
61
  "openpgp": "^6.1.0",
54
62
  "turndown": "^7.2.0",
55
63
  "typescript": "latest",
@@ -0,0 +1,11 @@
1
+ import { GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts";
2
+
3
+ const sts = new STSClient({});
4
+
5
+ /**
6
+ * Helper to get the current AWS account ID
7
+ */
8
+ export async function getAccountId(): Promise<string> {
9
+ const identity = await sts.send(new GetCallerIdentityCommand({}));
10
+ return identity.Account!;
11
+ }
package/src/aws/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./account-id";
1
2
  export * from "./bucket";
2
3
  export * from "./function";
3
4
  export * from "./policy";
@@ -0,0 +1,34 @@
1
+ import type { Input } from "../../input";
2
+ import { isOutput } from "../../output";
3
+ import { OIDCProvider, type OIDCProviderProps } from "./oidc-provider";
4
+
5
+ /**
6
+ * Default thumbprint for GitHub's OIDC provider
7
+ * This is the certificate thumbprint that GitHub uses to sign OIDC tokens
8
+ * @see https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#adding-the-identity-provider-to-aws
9
+ */
10
+ const DEFAULT_GITHUB_THUMBPRINT = "6938fd4d98bab03faadb97b34396831e3780aea1";
11
+
12
+ export interface GitHubOIDCProviderProps
13
+ extends Omit<OIDCProviderProps, "thumbprint"> {
14
+ owner: string;
15
+ repository: string;
16
+ thumbprint?: string;
17
+ }
18
+
19
+ export class GitHubOIDCProvider extends OIDCProvider {
20
+ constructor(id: string, props: Input<GitHubOIDCProviderProps>) {
21
+ super(
22
+ id,
23
+ isOutput<GitHubOIDCProviderProps>(props)
24
+ ? props.apply((props) => ({
25
+ ...props,
26
+ thumbprint: props.thumbprint ?? DEFAULT_GITHUB_THUMBPRINT,
27
+ }))
28
+ : ({
29
+ ...props,
30
+ thumbprint: props.thumbprint ?? DEFAULT_GITHUB_THUMBPRINT,
31
+ } as Input<OIDCProviderProps>),
32
+ );
33
+ }
34
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./github-oidc-provider";
2
+ export * from "./oidc-provider";
@@ -0,0 +1,253 @@
1
+ import {
2
+ CreateOpenIDConnectProviderCommand,
3
+ DeleteOpenIDConnectProviderCommand,
4
+ GetOpenIDConnectProviderCommand,
5
+ GetRoleCommand,
6
+ IAMClient,
7
+ type Tag,
8
+ UpdateAssumeRolePolicyCommand,
9
+ } from "@aws-sdk/client-iam";
10
+ import { type Context, Resource } from "../../resource";
11
+ import { getAccountId } from "../account-id";
12
+
13
+ /**
14
+ * Properties for configuring an AWS OIDC provider for GitHub Actions
15
+ */
16
+ export interface OIDCProviderProps {
17
+ /**
18
+ * The GitHub organization or user that owns the repository
19
+ */
20
+ owner: string;
21
+
22
+ /**
23
+ * The name of the GitHub repository
24
+ */
25
+ repository: string;
26
+
27
+ /**
28
+ * Optional list of branches to restrict access to
29
+ * If not provided, all branches will be allowed
30
+ */
31
+ branches?: string[];
32
+
33
+ /**
34
+ * Optional list of environments to restrict access to
35
+ * If not provided, all environments will be allowed
36
+ */
37
+ environments?: string[];
38
+
39
+ /**
40
+ * The ARN of the IAM role to be assumed
41
+ */
42
+ roleArn: string;
43
+
44
+ /**
45
+ * Optional maximum session duration in seconds (default: 3600)
46
+ */
47
+ maxSessionDuration?: number;
48
+
49
+ /**
50
+ * Thumbprint for the OIDC provider
51
+ */
52
+ thumbprint: string;
53
+
54
+ /**
55
+ * Optional AWS region (defaults to AWS_REGION environment variable)
56
+ */
57
+ region?: string;
58
+ }
59
+
60
+ /**
61
+ * Output returned after OIDC provider configuration
62
+ */
63
+ export interface OIDCProviderOutput extends OIDCProviderProps {
64
+ /**
65
+ * The ARN of the OIDC provider
66
+ */
67
+ providerArn: string;
68
+
69
+ /**
70
+ * Time at which the provider was created
71
+ */
72
+ createdAt: number;
73
+ }
74
+
75
+ /**
76
+ * Unique identifier for our trust policy statement
77
+ * Used to track and remove our specific statement without affecting others
78
+ */
79
+ const TRUST_POLICY_SID = "GitHubOIDCTrust";
80
+
81
+ /**
82
+ * Resource for configuring AWS OIDC provider for GitHub Actions
83
+ */
84
+ export class OIDCProvider extends Resource(
85
+ "aws::OIDCProvider",
86
+ async (ctx: Context<OIDCProviderOutput>, props: OIDCProviderProps) => {
87
+ // Initialize AWS SDK client
88
+ const client = new IAMClient({
89
+ region: props.region,
90
+ });
91
+
92
+ if (ctx.event === "delete") {
93
+ if (ctx.output?.providerArn) {
94
+ try {
95
+ // First, remove our trust policy statement from the role
96
+ const getRole = await client.send(
97
+ new GetRoleCommand({
98
+ RoleName: props.roleArn.split("/").pop(),
99
+ }),
100
+ );
101
+
102
+ if (getRole.Role?.AssumeRolePolicyDocument) {
103
+ const policy = JSON.parse(
104
+ decodeURIComponent(getRole.Role.AssumeRolePolicyDocument),
105
+ );
106
+
107
+ // Remove our specific statement while preserving others
108
+ policy.Statement = policy.Statement.filter(
109
+ (stmt: any) => stmt.Sid !== TRUST_POLICY_SID,
110
+ );
111
+
112
+ await client.send(
113
+ new UpdateAssumeRolePolicyCommand({
114
+ RoleName: props.roleArn.split("/").pop(),
115
+ PolicyDocument: JSON.stringify(policy),
116
+ }),
117
+ );
118
+ }
119
+
120
+ // Then delete the OIDC provider if we're the last user
121
+ const provider = await client.send(
122
+ new GetOpenIDConnectProviderCommand({
123
+ OpenIDConnectProviderArn: ctx.output.providerArn,
124
+ }),
125
+ );
126
+
127
+ // Only delete the provider if it exists and has no other tags
128
+ if (provider && (!provider.Tags || provider.Tags.length === 0)) {
129
+ await client.send(
130
+ new DeleteOpenIDConnectProviderCommand({
131
+ OpenIDConnectProviderArn: ctx.output.providerArn,
132
+ }),
133
+ );
134
+ }
135
+ } catch (error) {
136
+ // Log but don't throw on cleanup errors
137
+ console.error("Error during cleanup:", error);
138
+ }
139
+ }
140
+ return;
141
+ }
142
+
143
+ try {
144
+ const url = "https://token.actions.githubusercontent.com";
145
+ const thumbprint = props.thumbprint;
146
+
147
+ // Create or get existing OIDC provider
148
+ let providerArn: string;
149
+ try {
150
+ const createProvider = await client.send(
151
+ new CreateOpenIDConnectProviderCommand({
152
+ Url: url,
153
+ ClientIDList: ["sts.amazonaws.com"],
154
+ ThumbprintList: [thumbprint],
155
+ Tags: [
156
+ {
157
+ Key: "ManagedBy",
158
+ Value: "alchemy",
159
+ },
160
+ ] as Tag[],
161
+ }),
162
+ );
163
+ providerArn = createProvider.OpenIDConnectProviderArn!;
164
+ } catch (error: any) {
165
+ if (error.name === "EntityAlreadyExistsException") {
166
+ // Provider exists, use its ARN
167
+ providerArn = `arn:aws:iam::${await getAccountId()}:oidc-provider/${url}`;
168
+ } else {
169
+ throw error;
170
+ }
171
+ }
172
+
173
+ // Get current role policy
174
+ const getRole = await client.send(
175
+ new GetRoleCommand({
176
+ RoleName: props.roleArn.split("/").pop(),
177
+ }),
178
+ );
179
+
180
+ let policy: any;
181
+ if (getRole.Role?.AssumeRolePolicyDocument) {
182
+ policy = JSON.parse(
183
+ decodeURIComponent(getRole.Role.AssumeRolePolicyDocument),
184
+ );
185
+ } else {
186
+ policy = {
187
+ Version: "2012-10-17",
188
+ Statement: [],
189
+ };
190
+ }
191
+
192
+ // Construct the trust policy conditions
193
+ const conditions: Record<string, any> = {
194
+ StringEquals: {
195
+ "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
196
+ "token.actions.githubusercontent.com:sub": `repo:${props.owner}/${props.repository}:`,
197
+ },
198
+ };
199
+
200
+ if (props.branches?.length) {
201
+ conditions.StringEquals["token.actions.githubusercontent.com:sub"] =
202
+ props.branches.map(
203
+ (branch) =>
204
+ `repo:${props.owner}/${props.repository}:ref:refs/heads/${branch}`,
205
+ );
206
+ }
207
+
208
+ if (props.environments?.length) {
209
+ conditions.StringEquals["token.actions.githubusercontent.com:sub"] =
210
+ props.environments.map(
211
+ (env) =>
212
+ `repo:${props.owner}/${props.repository}:environment:${env}`,
213
+ );
214
+ }
215
+
216
+ // Create our policy statement
217
+ const ourStatement = {
218
+ Sid: TRUST_POLICY_SID,
219
+ Effect: "Allow",
220
+ Principal: {
221
+ Federated: providerArn,
222
+ },
223
+ Action: "sts:AssumeRoleWithWebIdentity",
224
+ Condition: conditions,
225
+ };
226
+
227
+ // Remove any existing statement with our SID and add the new one
228
+ policy.Statement = [
229
+ ...policy.Statement.filter(
230
+ (stmt: any) => stmt.Sid !== TRUST_POLICY_SID,
231
+ ),
232
+ ourStatement,
233
+ ];
234
+
235
+ // Update the role's trust policy
236
+ await client.send(
237
+ new UpdateAssumeRolePolicyCommand({
238
+ RoleName: props.roleArn.split("/").pop(),
239
+ PolicyDocument: JSON.stringify(policy),
240
+ }),
241
+ );
242
+
243
+ return {
244
+ ...props,
245
+ providerArn,
246
+ createdAt: Date.now(),
247
+ };
248
+ } catch (error) {
249
+ console.error("Error configuring OIDC provider:", error);
250
+ throw error;
251
+ }
252
+ },
253
+ ) {}
package/src/aws/queue.ts CHANGED
@@ -8,14 +8,30 @@ import {
8
8
  import { Resource } from "../resource";
9
9
 
10
10
  export interface QueueProps {
11
+ /**
12
+ * Name of the queue
13
+ * For FIFO queues, the name must end with the .fifo suffix
14
+ */
11
15
  queueName: string;
16
+
17
+ /**
18
+ * Whether this is a FIFO queue.
19
+ * If true, the queueName must end with .fifo suffix
20
+ */
12
21
  fifo?: boolean;
22
+
13
23
  visibilityTimeout?: number;
14
24
  messageRetentionPeriod?: number;
15
25
  maximumMessageSize?: number;
16
26
  delaySeconds?: number;
17
27
  receiveMessageWaitTimeSeconds?: number;
28
+
29
+ /**
30
+ * Enables content-based deduplication for FIFO queues.
31
+ * Only applicable when fifo is true.
32
+ */
18
33
  contentBasedDeduplication?: boolean;
34
+
19
35
  deduplicationScope?: "messageGroup" | "queue";
20
36
  fifoThroughputLimit?: "perQueue" | "perMessageGroupId";
21
37
  tags?: Record<string, string>;
@@ -31,7 +47,13 @@ export class Queue extends Resource(
31
47
  "sqs::Queue",
32
48
  async (ctx, props: QueueProps) => {
33
49
  const client = new SQSClient({});
34
- const queueName = props.fifo ? `${props.queueName}.fifo` : props.queueName;
50
+ // Don't automatically add .fifo suffix - user must include it in queueName
51
+ const queueName = props.queueName;
52
+
53
+ // Validate that FIFO queues have .fifo suffix
54
+ if (props.fifo && !queueName.endsWith(".fifo")) {
55
+ throw new Error("FIFO queue names must end with .fifo suffix");
56
+ }
35
57
 
36
58
  if (ctx.event === "delete") {
37
59
  try {
package/src/aws/role.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import {
2
+ AttachRolePolicyCommand,
2
3
  CreateRoleCommand,
3
4
  DeleteRoleCommand,
4
5
  DeleteRolePolicyCommand,
6
+ DetachRolePolicyCommand,
5
7
  EntityAlreadyExistsException,
6
8
  GetRoleCommand,
7
9
  IAMClient,
10
+ ListAttachedRolePoliciesCommand,
8
11
  NoSuchEntityException,
9
12
  PutRolePolicyCommand,
10
13
  type Tag,
@@ -59,6 +62,32 @@ export class Role extends Resource(
59
62
  }
60
63
  }
61
64
 
65
+ // We need to detach managed policies before deleting the role
66
+ // First, get all attached policies
67
+ try {
68
+ const attachedPoliciesResponse = await client.send(
69
+ new ListAttachedRolePoliciesCommand({
70
+ RoleName: props.roleName,
71
+ }),
72
+ );
73
+
74
+ // Detach all managed policies
75
+ const attachedPolicies =
76
+ attachedPoliciesResponse.AttachedPolicies || [];
77
+ for (const policy of attachedPolicies) {
78
+ await client.send(
79
+ new DetachRolePolicyCommand({
80
+ RoleName: props.roleName,
81
+ PolicyArn: policy.PolicyArn!,
82
+ }),
83
+ );
84
+ }
85
+ } catch (error: any) {
86
+ if (error.name !== NoSuchEntityException.name) {
87
+ throw error;
88
+ }
89
+ }
90
+
62
91
  await ignore(NoSuchEntityException.name, () =>
63
92
  client.send(
64
93
  new DeleteRoleCommand({
@@ -229,6 +258,46 @@ export class Role extends Resource(
229
258
  }
230
259
  }
231
260
 
261
+ // Handle managed policy attachments
262
+ // Get currently attached policies
263
+ const attachedPoliciesResponse = await client.send(
264
+ new ListAttachedRolePoliciesCommand({
265
+ RoleName: props.roleName,
266
+ }),
267
+ );
268
+
269
+ const currentAttachedPolicies =
270
+ attachedPoliciesResponse.AttachedPolicies || [];
271
+ const currentPolicyArns = currentAttachedPolicies.map((p) => p.PolicyArn!);
272
+
273
+ // If we're updating, use an empty array as default when managedPolicyArns is undefined
274
+ // to ensure we detach all managed policies
275
+ const desiredPolicyArns = props.managedPolicyArns || [];
276
+
277
+ // Detach policies that are no longer needed
278
+ for (const policyArn of currentPolicyArns) {
279
+ if (!desiredPolicyArns.includes(policyArn)) {
280
+ await client.send(
281
+ new DetachRolePolicyCommand({
282
+ RoleName: props.roleName,
283
+ PolicyArn: policyArn,
284
+ }),
285
+ );
286
+ }
287
+ }
288
+
289
+ // Attach new policies that weren't attached before
290
+ for (const policyArn of desiredPolicyArns) {
291
+ if (!currentPolicyArns.includes(policyArn)) {
292
+ await client.send(
293
+ new AttachRolePolicyCommand({
294
+ RoleName: props.roleName,
295
+ PolicyArn: policyArn,
296
+ }),
297
+ );
298
+ }
299
+ }
300
+
232
301
  if (!role?.Role) {
233
302
  throw new Error(`Failed to create or update role ${props.roleName}`);
234
303
  }
package/src/aws/ses.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {
2
- AlreadyExistsException,
3
2
  CreateConfigurationSetCommand,
4
3
  CreateEmailIdentityCommand,
5
4
  DeleteConfigurationSetCommand,
@@ -8,6 +7,11 @@ import {
8
7
  GetConfigurationSetCommand,
9
8
  GetEmailIdentityCommand,
10
9
  NotFoundException,
10
+ PutConfigurationSetDeliveryOptionsCommand,
11
+ PutConfigurationSetReputationOptionsCommand,
12
+ PutConfigurationSetSendingOptionsCommand,
13
+ PutConfigurationSetSuppressionOptionsCommand,
14
+ PutConfigurationSetTrackingOptionsCommand,
11
15
  PutEmailIdentityDkimAttributesCommand,
12
16
  type ReputationOptions,
13
17
  SESv2Client,
@@ -103,7 +107,7 @@ export interface SESOutput extends SESProps {
103
107
  */
104
108
  export class SES extends Resource(
105
109
  "aws::SES",
106
- async (ctx: Context<SESOutput>, props: SESProps): Promise<SESOutput> => {
110
+ async (ctx: Context<SESOutput>, props: SESProps) => {
107
111
  // Create SES client
108
112
  const client = new SESv2Client({});
109
113
 
@@ -138,10 +142,7 @@ export class SES extends Resource(
138
142
  }
139
143
 
140
144
  // Return empty output for delete
141
- return {
142
- ...props,
143
- id,
144
- };
145
+ return;
145
146
  }
146
147
 
147
148
  // Created resources
@@ -154,66 +155,68 @@ export class SES extends Resource(
154
155
  if (props.configurationSetName) {
155
156
  try {
156
157
  // Check if configuration set exists
157
- let getConfigResult;
158
+ let configSetExists = false;
158
159
  try {
159
- getConfigResult = await client.send(
160
+ await client.send(
160
161
  new GetConfigurationSetCommand({
161
162
  ConfigurationSetName: props.configurationSetName,
162
163
  }),
163
164
  );
165
+ configSetExists = true;
164
166
  } catch (error) {
165
167
  if (error instanceof NotFoundException) {
166
- getConfigResult = null;
168
+ configSetExists = false;
167
169
  } else {
168
170
  throw error;
169
171
  }
170
172
  }
171
173
 
172
- if (getConfigResult) {
173
- // For updating configuration set, we need to use individual commands
174
- // since there's no unified UpdateConfigurationSetCommand
175
-
174
+ if (configSetExists) {
175
+ // Update existing configuration set using appropriate update commands
176
176
  if (props.sendingOptions) {
177
177
  await client.send(
178
- new CreateConfigurationSetCommand({
178
+ new PutConfigurationSetSendingOptionsCommand({
179
179
  ConfigurationSetName: props.configurationSetName,
180
- SendingOptions: props.sendingOptions,
180
+ SendingEnabled: props.sendingOptions.SendingEnabled,
181
181
  }),
182
182
  );
183
183
  }
184
184
 
185
185
  if (props.reputationOptions) {
186
186
  await client.send(
187
- new CreateConfigurationSetCommand({
187
+ new PutConfigurationSetReputationOptionsCommand({
188
188
  ConfigurationSetName: props.configurationSetName,
189
- ReputationOptions: props.reputationOptions,
189
+ ReputationMetricsEnabled:
190
+ props.reputationOptions.ReputationMetricsEnabled,
190
191
  }),
191
192
  );
192
193
  }
193
194
 
194
195
  if (props.trackingOptions) {
195
196
  await client.send(
196
- new CreateConfigurationSetCommand({
197
+ new PutConfigurationSetTrackingOptionsCommand({
197
198
  ConfigurationSetName: props.configurationSetName,
198
- TrackingOptions: props.trackingOptions,
199
+ CustomRedirectDomain:
200
+ props.trackingOptions.CustomRedirectDomain,
199
201
  }),
200
202
  );
201
203
  }
202
204
 
203
205
  if (props.suppressionOptions) {
204
206
  await client.send(
205
- new CreateConfigurationSetCommand({
207
+ new PutConfigurationSetSuppressionOptionsCommand({
206
208
  ConfigurationSetName: props.configurationSetName,
207
- SuppressionOptions: props.suppressionOptions,
209
+ SuppressedReasons: props.suppressionOptions.SuppressedReasons,
208
210
  }),
209
211
  );
210
212
  }
211
213
 
212
214
  if (props.deliveryOptions) {
213
215
  await client.send(
214
- new CreateConfigurationSetCommand({
216
+ new PutConfigurationSetDeliveryOptionsCommand({
215
217
  ConfigurationSetName: props.configurationSetName,
216
- DeliveryOptions: props.deliveryOptions,
218
+ TlsPolicy: props.deliveryOptions.TlsPolicy,
219
+ SendingPoolName: props.deliveryOptions.SendingPoolName,
217
220
  }),
218
221
  );
219
222
  }
@@ -241,14 +244,7 @@ export class SES extends Resource(
241
244
  configurationSetArn = `arn:aws:ses:${process.env.AWS_REGION}:${process.env.AWS_ACCOUNT_ID}:configuration-set/${props.configurationSetName}`;
242
245
  }
243
246
  } catch (error: any) {
244
- if (error instanceof AlreadyExistsException) {
245
- // If it already exists but we couldn't get it (permissions issue), continue
246
- console.warn(
247
- `Configuration set ${props.configurationSetName} already exists but cannot be retrieved`,
248
- );
249
- } else {
250
- throw error;
251
- }
247
+ throw error;
252
248
  }
253
249
  }
254
250