alchemy 0.1.17 → 0.2.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 (301) hide show
  1. package/lib/alchemy.d.ts +67 -0
  2. package/lib/alchemy.js +40 -0
  3. package/lib/apply.d.ts +3 -20
  4. package/lib/apply.js +86 -78
  5. package/lib/aws/account-id.d.ts +0 -1
  6. package/lib/aws/account-id.js +0 -1
  7. package/lib/aws/bucket.d.ts +4 -7
  8. package/lib/aws/bucket.js +8 -12
  9. package/lib/aws/function.d.ts +4 -7
  10. package/lib/aws/function.js +9 -30
  11. package/lib/aws/index.d.ts +1 -1
  12. package/lib/aws/index.js +1 -1
  13. package/lib/aws/oidc/github-oidc-provider.d.ts +2 -6
  14. package/lib/aws/oidc/github-oidc-provider.js +10 -15
  15. package/lib/aws/oidc/index.d.ts +0 -1
  16. package/lib/aws/oidc/index.js +0 -1
  17. package/lib/aws/oidc/oidc-provider.d.ts +4 -6
  18. package/lib/aws/oidc/oidc-provider.js +9 -11
  19. package/lib/aws/policy-attachment.d.ts +9 -0
  20. package/lib/aws/policy-attachment.js +20 -0
  21. package/lib/aws/policy.d.ts +4 -16
  22. package/lib/aws/policy.js +9 -40
  23. package/lib/aws/queue.d.ts +4 -34
  24. package/lib/aws/queue.js +10 -20
  25. package/lib/aws/role.d.ts +4 -7
  26. package/lib/aws/role.js +17 -26
  27. package/lib/aws/ses.d.ts +4 -10
  28. package/lib/aws/ses.js +118 -131
  29. package/lib/aws/table.d.ts +4 -7
  30. package/lib/aws/table.js +8 -11
  31. package/lib/cloudflare/api.d.ts +0 -1
  32. package/lib/cloudflare/api.js +0 -1
  33. package/lib/cloudflare/asset-manifest.d.ts +0 -1
  34. package/lib/cloudflare/asset-manifest.js +0 -1
  35. package/lib/cloudflare/auth.d.ts +0 -1
  36. package/lib/cloudflare/auth.js +0 -1
  37. package/lib/cloudflare/bindings.d.ts +4 -3
  38. package/lib/cloudflare/bindings.js +3 -2
  39. package/lib/cloudflare/bound.d.ts +7 -0
  40. package/lib/cloudflare/bound.js +1 -0
  41. package/lib/cloudflare/bucket.d.ts +7 -15
  42. package/lib/cloudflare/bucket.js +12 -19
  43. package/lib/cloudflare/durable-object-namespace.d.ts +0 -3
  44. package/lib/cloudflare/durable-object-namespace.js +0 -4
  45. package/lib/cloudflare/generate-asset-manifest.d.ts +0 -1
  46. package/lib/cloudflare/generate-asset-manifest.js +1 -2
  47. package/lib/cloudflare/index.d.ts +0 -1
  48. package/lib/cloudflare/index.js +0 -1
  49. package/lib/cloudflare/kv-namespace.d.ts +6 -9
  50. package/lib/cloudflare/kv-namespace.js +16 -20
  51. package/lib/cloudflare/state.d.ts +0 -1
  52. package/lib/cloudflare/state.js +0 -1
  53. package/lib/cloudflare/static-site-router.d.ts +0 -1
  54. package/lib/cloudflare/static-site-router.js +0 -4
  55. package/lib/cloudflare/static-site.d.ts +5 -11
  56. package/lib/cloudflare/static-site.js +16 -28
  57. package/lib/cloudflare/types.d.ts +0 -1
  58. package/lib/cloudflare/types.js +0 -1
  59. package/lib/cloudflare/upload-asset-manifest.d.ts +0 -1
  60. package/lib/cloudflare/upload-asset-manifest.js +0 -1
  61. package/lib/cloudflare/worker-metadata.d.ts +0 -1
  62. package/lib/cloudflare/worker-metadata.js +0 -1
  63. package/lib/cloudflare/worker-migration.d.ts +0 -1
  64. package/lib/cloudflare/worker-migration.js +0 -1
  65. package/lib/cloudflare/worker.d.ts +13 -13
  66. package/lib/cloudflare/worker.js +43 -43
  67. package/lib/context.d.ts +58 -0
  68. package/lib/context.js +36 -0
  69. package/lib/destroy.d.ts +10 -13
  70. package/lib/destroy.js +104 -43
  71. package/lib/{esbuild.d.ts → esbuild/bundle.d.ts} +4 -18
  72. package/lib/{esbuild.js → esbuild/bundle.js} +10 -24
  73. package/lib/esbuild/index.d.ts +1 -0
  74. package/lib/esbuild/index.js +1 -0
  75. package/lib/fs/file.d.ts +13 -0
  76. package/lib/fs/file.js +20 -0
  77. package/lib/fs/folder.d.ts +10 -0
  78. package/lib/fs/folder.js +16 -0
  79. package/lib/fs/index.d.ts +2 -0
  80. package/lib/fs/index.js +2 -0
  81. package/lib/github/client.d.ts +0 -1
  82. package/lib/github/client.js +0 -1
  83. package/lib/github/index.d.ts +0 -1
  84. package/lib/github/index.js +0 -1
  85. package/lib/github/secret.d.ts +6 -7
  86. package/lib/github/secret.js +30 -36
  87. package/lib/index.d.ts +7 -10
  88. package/lib/index.js +6 -9
  89. package/lib/resource.d.ts +34 -62
  90. package/lib/resource.js +29 -270
  91. package/lib/scope.d.ts +35 -14
  92. package/lib/scope.js +78 -23
  93. package/lib/secret.d.ts +7 -0
  94. package/lib/secret.js +17 -0
  95. package/lib/state.d.ts +14 -10
  96. package/lib/state.js +15 -13
  97. package/lib/stripe/index.d.ts +0 -1
  98. package/lib/stripe/index.js +0 -1
  99. package/lib/stripe/price.d.ts +4 -5
  100. package/lib/stripe/price.js +10 -20
  101. package/lib/stripe/product.d.ts +4 -5
  102. package/lib/stripe/product.js +10 -20
  103. package/lib/stripe/webhook.d.ts +4 -6
  104. package/lib/stripe/webhook.js +12 -25
  105. package/lib/test/bun.d.ts +19 -0
  106. package/lib/test/bun.js +55 -0
  107. package/lib/{utils → util}/content-type.d.ts +0 -1
  108. package/lib/{utils → util}/content-type.js +0 -1
  109. package/lib/util/encrypt.d.ts +16 -0
  110. package/lib/util/encrypt.js +44 -0
  111. package/lib/{error.d.ts → util/ignore.d.ts} +0 -1
  112. package/lib/{error.js → util/ignore.js} +0 -1
  113. package/lib/{utils → util}/retry.d.ts +0 -1
  114. package/lib/{utils → util}/retry.js +0 -1
  115. package/lib/util/serde.d.ts +3 -0
  116. package/lib/util/serde.js +46 -0
  117. package/lib/util/slugify.d.ts +1 -0
  118. package/lib/util/slugify.js +3 -0
  119. package/package.json +5 -7
  120. package/src/alchemy.ts +120 -0
  121. package/src/apply.ts +109 -111
  122. package/src/aws/bucket.ts +11 -14
  123. package/src/aws/function.ts +13 -33
  124. package/src/aws/index.ts +1 -0
  125. package/src/aws/oidc/github-oidc-provider.ts +14 -19
  126. package/src/aws/oidc/oidc-provider.ts +19 -12
  127. package/src/aws/policy-attachment.ts +51 -0
  128. package/src/aws/policy.ts +15 -60
  129. package/src/aws/queue.ts +17 -21
  130. package/src/aws/role.ts +25 -28
  131. package/src/aws/ses.ts +150 -164
  132. package/src/aws/table.ts +15 -15
  133. package/src/cloudflare/bindings.ts +12 -2
  134. package/src/cloudflare/bound.ts +18 -0
  135. package/src/cloudflare/bucket.ts +40 -48
  136. package/src/cloudflare/durable-object-namespace.ts +0 -10
  137. package/src/cloudflare/generate-asset-manifest.ts +1 -1
  138. package/src/cloudflare/kv-namespace.ts +35 -33
  139. package/src/cloudflare/static-site-router.ts +0 -3
  140. package/src/cloudflare/static-site.ts +43 -59
  141. package/src/cloudflare/worker.ts +76 -64
  142. package/src/context.ts +122 -0
  143. package/src/destroy.ts +124 -73
  144. package/src/{esbuild.ts → esbuild/bundle.ts} +16 -28
  145. package/src/esbuild/index.ts +1 -0
  146. package/src/fs/file.ts +39 -0
  147. package/src/fs/folder.ts +32 -0
  148. package/src/fs/index.ts +2 -0
  149. package/src/github/secret.ts +53 -49
  150. package/src/index.ts +8 -15
  151. package/src/resource.ts +101 -462
  152. package/src/scope.ts +101 -36
  153. package/src/secret.ts +18 -0
  154. package/src/state.ts +30 -20
  155. package/src/stripe/price.ts +17 -22
  156. package/src/stripe/product.ts +17 -22
  157. package/src/stripe/webhook.ts +21 -27
  158. package/src/test/bun.ts +105 -0
  159. package/src/util/encrypt.ts +79 -0
  160. package/src/util/serde.ts +53 -0
  161. package/src/util/slugify.ts +3 -0
  162. package/lib/$.d.ts +0 -12
  163. package/lib/$.d.ts.map +0 -1
  164. package/lib/$.js +0 -42
  165. package/lib/$.js.map +0 -1
  166. package/lib/alchemize.d.ts +0 -43
  167. package/lib/alchemize.d.ts.map +0 -1
  168. package/lib/alchemize.js +0 -112
  169. package/lib/alchemize.js.map +0 -1
  170. package/lib/apply.d.ts.map +0 -1
  171. package/lib/apply.js.map +0 -1
  172. package/lib/aws/account-id.d.ts.map +0 -1
  173. package/lib/aws/account-id.js.map +0 -1
  174. package/lib/aws/bucket.d.ts.map +0 -1
  175. package/lib/aws/bucket.js.map +0 -1
  176. package/lib/aws/function.d.ts.map +0 -1
  177. package/lib/aws/function.js.map +0 -1
  178. package/lib/aws/index.d.ts.map +0 -1
  179. package/lib/aws/index.js.map +0 -1
  180. package/lib/aws/oidc/github-oidc-provider.d.ts.map +0 -1
  181. package/lib/aws/oidc/github-oidc-provider.js.map +0 -1
  182. package/lib/aws/oidc/index.d.ts.map +0 -1
  183. package/lib/aws/oidc/index.js.map +0 -1
  184. package/lib/aws/oidc/oidc-provider.d.ts.map +0 -1
  185. package/lib/aws/oidc/oidc-provider.js.map +0 -1
  186. package/lib/aws/policy.d.ts.map +0 -1
  187. package/lib/aws/policy.js.map +0 -1
  188. package/lib/aws/queue.d.ts.map +0 -1
  189. package/lib/aws/queue.js.map +0 -1
  190. package/lib/aws/role.d.ts.map +0 -1
  191. package/lib/aws/role.js.map +0 -1
  192. package/lib/aws/ses.d.ts.map +0 -1
  193. package/lib/aws/ses.js.map +0 -1
  194. package/lib/aws/table.d.ts.map +0 -1
  195. package/lib/aws/table.js.map +0 -1
  196. package/lib/cloudflare/api.d.ts.map +0 -1
  197. package/lib/cloudflare/api.js.map +0 -1
  198. package/lib/cloudflare/asset-manifest.d.ts.map +0 -1
  199. package/lib/cloudflare/asset-manifest.js.map +0 -1
  200. package/lib/cloudflare/auth.d.ts.map +0 -1
  201. package/lib/cloudflare/auth.js.map +0 -1
  202. package/lib/cloudflare/bindings.d.ts.map +0 -1
  203. package/lib/cloudflare/bindings.js.map +0 -1
  204. package/lib/cloudflare/bucket.d.ts.map +0 -1
  205. package/lib/cloudflare/bucket.js.map +0 -1
  206. package/lib/cloudflare/durable-object-namespace.d.ts.map +0 -1
  207. package/lib/cloudflare/durable-object-namespace.js.map +0 -1
  208. package/lib/cloudflare/generate-asset-manifest.d.ts.map +0 -1
  209. package/lib/cloudflare/generate-asset-manifest.js.map +0 -1
  210. package/lib/cloudflare/index.d.ts.map +0 -1
  211. package/lib/cloudflare/index.js.map +0 -1
  212. package/lib/cloudflare/kv-namespace.d.ts.map +0 -1
  213. package/lib/cloudflare/kv-namespace.js.map +0 -1
  214. package/lib/cloudflare/state.d.ts.map +0 -1
  215. package/lib/cloudflare/state.js.map +0 -1
  216. package/lib/cloudflare/static-site-router.d.ts.map +0 -1
  217. package/lib/cloudflare/static-site-router.js.map +0 -1
  218. package/lib/cloudflare/static-site.d.ts.map +0 -1
  219. package/lib/cloudflare/static-site.js.map +0 -1
  220. package/lib/cloudflare/types.d.ts.map +0 -1
  221. package/lib/cloudflare/types.js.map +0 -1
  222. package/lib/cloudflare/upload-asset-manifest.d.ts.map +0 -1
  223. package/lib/cloudflare/upload-asset-manifest.js.map +0 -1
  224. package/lib/cloudflare/worker-metadata.d.ts.map +0 -1
  225. package/lib/cloudflare/worker-metadata.js.map +0 -1
  226. package/lib/cloudflare/worker-migration.d.ts.map +0 -1
  227. package/lib/cloudflare/worker-migration.js.map +0 -1
  228. package/lib/cloudflare/worker.d.ts.map +0 -1
  229. package/lib/cloudflare/worker.js.map +0 -1
  230. package/lib/destroy.d.ts.map +0 -1
  231. package/lib/destroy.js.map +0 -1
  232. package/lib/error.d.ts.map +0 -1
  233. package/lib/error.js.map +0 -1
  234. package/lib/esbuild.d.ts.map +0 -1
  235. package/lib/esbuild.js.map +0 -1
  236. package/lib/fs.d.ts +0 -12
  237. package/lib/fs.d.ts.map +0 -1
  238. package/lib/fs.js +0 -41
  239. package/lib/fs.js.map +0 -1
  240. package/lib/github/client.d.ts.map +0 -1
  241. package/lib/github/client.js.map +0 -1
  242. package/lib/github/index.d.ts.map +0 -1
  243. package/lib/github/index.js.map +0 -1
  244. package/lib/github/secret.d.ts.map +0 -1
  245. package/lib/github/secret.js.map +0 -1
  246. package/lib/global.d.ts +0 -16
  247. package/lib/global.d.ts.map +0 -1
  248. package/lib/global.js +0 -42
  249. package/lib/global.js.map +0 -1
  250. package/lib/index.d.ts.map +0 -1
  251. package/lib/index.js.map +0 -1
  252. package/lib/input.d.ts +0 -6
  253. package/lib/input.d.ts.map +0 -1
  254. package/lib/input.js +0 -2
  255. package/lib/input.js.map +0 -1
  256. package/lib/main.d.ts +0 -3
  257. package/lib/main.d.ts.map +0 -1
  258. package/lib/main.js +0 -32
  259. package/lib/main.js.map +0 -1
  260. package/lib/output.d.ts +0 -24
  261. package/lib/output.d.ts.map +0 -1
  262. package/lib/output.js +0 -23
  263. package/lib/output.js.map +0 -1
  264. package/lib/print.d.ts +0 -7
  265. package/lib/print.d.ts.map +0 -1
  266. package/lib/print.js +0 -10
  267. package/lib/print.js.map +0 -1
  268. package/lib/resource.d.ts.map +0 -1
  269. package/lib/resource.js.map +0 -1
  270. package/lib/scope.d.ts.map +0 -1
  271. package/lib/scope.js.map +0 -1
  272. package/lib/slug.d.ts +0 -2
  273. package/lib/slug.d.ts.map +0 -1
  274. package/lib/slug.js +0 -4
  275. package/lib/slug.js.map +0 -1
  276. package/lib/state.d.ts.map +0 -1
  277. package/lib/state.js.map +0 -1
  278. package/lib/stripe/index.d.ts.map +0 -1
  279. package/lib/stripe/index.js.map +0 -1
  280. package/lib/stripe/price.d.ts.map +0 -1
  281. package/lib/stripe/price.js.map +0 -1
  282. package/lib/stripe/product.d.ts.map +0 -1
  283. package/lib/stripe/product.js.map +0 -1
  284. package/lib/stripe/webhook.d.ts.map +0 -1
  285. package/lib/stripe/webhook.js.map +0 -1
  286. package/lib/utils/content-type.d.ts.map +0 -1
  287. package/lib/utils/content-type.js.map +0 -1
  288. package/lib/utils/retry.d.ts.map +0 -1
  289. package/lib/utils/retry.js.map +0 -1
  290. package/src/$.ts +0 -69
  291. package/src/alchemize.ts +0 -186
  292. package/src/fs.ts +0 -47
  293. package/src/global.ts +0 -63
  294. package/src/input.ts +0 -16
  295. package/src/main.ts +0 -34
  296. package/src/output.ts +0 -71
  297. package/src/print.ts +0 -18
  298. package/src/slug.ts +0 -3
  299. /package/src/{utils → util}/content-type.ts +0 -0
  300. /package/src/{error.ts → util/ignore.ts} +0 -0
  301. /package/src/{utils → util}/retry.ts +0 -0
@@ -9,13 +9,13 @@ const TRUST_POLICY_SID = "GitHubOIDCTrust";
9
9
  /**
10
10
  * Resource for configuring AWS OIDC provider for GitHub Actions
11
11
  */
12
- export class OIDCProvider extends Resource("aws::OIDCProvider", async (ctx, props) => {
12
+ export const OIDCProvider = Resource("aws::OIDCProvider", async function (id, props) {
13
13
  // Initialize AWS SDK client
14
14
  const client = new IAMClient({
15
15
  region: props.region,
16
16
  });
17
- if (ctx.event === "delete") {
18
- if (ctx.output?.providerArn) {
17
+ if (this.phase === "delete") {
18
+ if (this.output?.providerArn) {
19
19
  try {
20
20
  // First, remove our trust policy statement from the role
21
21
  const getRole = await client.send(new GetRoleCommand({
@@ -32,12 +32,12 @@ export class OIDCProvider extends Resource("aws::OIDCProvider", async (ctx, prop
32
32
  }
33
33
  // Then delete the OIDC provider if we're the last user
34
34
  const provider = await client.send(new GetOpenIDConnectProviderCommand({
35
- OpenIDConnectProviderArn: ctx.output.providerArn,
35
+ OpenIDConnectProviderArn: this.output.providerArn,
36
36
  }));
37
37
  // Only delete the provider if it exists and has no other tags
38
38
  if (provider && (!provider.Tags || provider.Tags.length === 0)) {
39
39
  await client.send(new DeleteOpenIDConnectProviderCommand({
40
- OpenIDConnectProviderArn: ctx.output.providerArn,
40
+ OpenIDConnectProviderArn: this.output.providerArn,
41
41
  }));
42
42
  }
43
43
  }
@@ -46,7 +46,7 @@ export class OIDCProvider extends Resource("aws::OIDCProvider", async (ctx, prop
46
46
  console.error("Error during cleanup:", error);
47
47
  }
48
48
  }
49
- return;
49
+ return this.destroy();
50
50
  }
51
51
  try {
52
52
  const url = "https://token.actions.githubusercontent.com";
@@ -125,16 +125,14 @@ export class OIDCProvider extends Resource("aws::OIDCProvider", async (ctx, prop
125
125
  RoleName: props.roleArn.split("/").pop(),
126
126
  PolicyDocument: JSON.stringify(policy),
127
127
  }));
128
- return {
128
+ return this({
129
129
  ...props,
130
130
  providerArn,
131
131
  createdAt: Date.now(),
132
- };
132
+ });
133
133
  }
134
134
  catch (error) {
135
135
  console.error("Error configuring OIDC provider:", error);
136
136
  throw error;
137
137
  }
138
- }) {
139
- }
140
- //# sourceMappingURL=oidc-provider.js.map
138
+ });
@@ -0,0 +1,9 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
3
+ export interface PolicyAttachmentProps {
4
+ policyArn: string;
5
+ roleName: string;
6
+ }
7
+ export interface PolicyAttachment extends Resource<"iam::PolicyAttachment">, PolicyAttachmentProps {
8
+ }
9
+ export declare const PolicyAttachment: ((this: Context<PolicyAttachment>, id: string, props: PolicyAttachmentProps) => Promise<PolicyAttachment>) | (((this: any, id: string, props: PolicyAttachmentProps) => never) & (new (_: never) => never));
@@ -0,0 +1,20 @@
1
+ import { AttachRolePolicyCommand, DetachRolePolicyCommand, IAMClient, NoSuchEntityException, } from "@aws-sdk/client-iam";
2
+ import { Resource } from "../resource";
3
+ import { ignore } from "../util/ignore";
4
+ export const PolicyAttachment = Resource("iam::PolicyAttachment", async function (id, props) {
5
+ const client = new IAMClient({});
6
+ if (this.phase === "delete") {
7
+ await ignore(NoSuchEntityException.name, () => client.send(new DetachRolePolicyCommand({
8
+ PolicyArn: props.policyArn,
9
+ RoleName: props.roleName,
10
+ })));
11
+ return this.destroy();
12
+ }
13
+ else {
14
+ await client.send(new AttachRolePolicyCommand({
15
+ PolicyArn: props.policyArn,
16
+ RoleName: props.roleName,
17
+ }));
18
+ }
19
+ return this(props);
20
+ });
@@ -1,3 +1,5 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
1
3
  export type Effect = "Allow" | "Deny";
2
4
  export interface PolicyStatement {
3
5
  Sid?: string;
@@ -21,8 +23,7 @@ export interface PolicyProps {
21
23
  path?: string;
22
24
  tags?: Record<string, string>;
23
25
  }
24
- export interface PolicyOutput extends PolicyProps {
25
- id: string;
26
+ export interface Policy extends Resource<"iam::Policy">, PolicyProps {
26
27
  arn: string;
27
28
  defaultVersionId: string;
28
29
  attachmentCount: number;
@@ -30,17 +31,4 @@ export interface PolicyOutput extends PolicyProps {
30
31
  updateDate: Date;
31
32
  isAttachable: boolean;
32
33
  }
33
- declare const Policy_base: import("../resource").Provider<"iam::Policy", [props: PolicyProps], PolicyOutput>;
34
- export declare class Policy extends Policy_base {
35
- }
36
- export interface PolicyAttachmentProps {
37
- policyArn: string;
38
- roleName: string;
39
- }
40
- export interface PolicyAttachmentOutput extends PolicyAttachmentProps {
41
- }
42
- declare const PolicyAttachment_base: import("../resource").Provider<"iam::PolicyAttachment", [props: PolicyAttachmentProps], PolicyAttachmentProps>;
43
- export declare class PolicyAttachment extends PolicyAttachment_base {
44
- }
45
- export {};
46
- //# sourceMappingURL=policy.d.ts.map
34
+ export declare const Policy: ((this: Context<Policy>, id: string, props: PolicyProps) => Promise<Policy>) | (((this: any, id: string, props: PolicyProps) => never) & (new (_: never) => never));
package/lib/aws/policy.js CHANGED
@@ -1,10 +1,9 @@
1
- import { AttachRolePolicyCommand, CreatePolicyCommand, CreatePolicyVersionCommand, DeletePolicyCommand, DeletePolicyVersionCommand, DetachRolePolicyCommand, GetPolicyCommand, GetPolicyVersionCommand, IAMClient, ListPolicyVersionsCommand, NoSuchEntityException, } from "@aws-sdk/client-iam";
2
- import { ignore } from "../error";
1
+ import { CreatePolicyCommand, CreatePolicyVersionCommand, DeletePolicyCommand, DeletePolicyVersionCommand, GetPolicyCommand, GetPolicyVersionCommand, IAMClient, ListPolicyVersionsCommand, NoSuchEntityException, } from "@aws-sdk/client-iam";
3
2
  import { Resource } from "../resource";
4
- export class Policy extends Resource("iam::Policy", async (ctx, props) => {
3
+ export const Policy = Resource("iam::Policy", async function (id, props) {
5
4
  const client = new IAMClient({});
6
5
  const policyArn = `arn:aws:iam::${process.env.AWS_ACCOUNT_ID}:policy${props.path || "/"}${props.policyName}`;
7
- if (ctx.event === "delete") {
6
+ if (this.phase === "delete") {
8
7
  try {
9
8
  // List and delete all non-default versions first
10
9
  const versions = await client.send(new ListPolicyVersionsCommand({
@@ -28,16 +27,7 @@ export class Policy extends Resource("iam::Policy", async (ctx, props) => {
28
27
  throw error;
29
28
  }
30
29
  }
31
- return {
32
- ...props,
33
- id: props.policyName,
34
- arn: policyArn,
35
- defaultVersionId: "v1",
36
- attachmentCount: 0,
37
- createDate: new Date(),
38
- updateDate: new Date(),
39
- isAttachable: true,
40
- };
30
+ return this.destroy();
41
31
  }
42
32
  else {
43
33
  try {
@@ -77,16 +67,15 @@ export class Policy extends Resource("iam::Policy", async (ctx, props) => {
77
67
  const policy = await client.send(new GetPolicyCommand({
78
68
  PolicyArn: policyArn,
79
69
  }));
80
- return {
70
+ return this({
81
71
  ...props,
82
- id: props.policyName,
83
72
  arn: policy.Policy.Arn,
84
73
  defaultVersionId: policy.Policy.DefaultVersionId,
85
74
  attachmentCount: policy.Policy.AttachmentCount,
86
75
  createDate: policy.Policy.CreateDate,
87
76
  updateDate: policy.Policy.UpdateDate,
88
77
  isAttachable: policy.Policy.IsAttachable,
89
- };
78
+ });
90
79
  }
91
80
  catch (error) {
92
81
  if (error.name === "NoSuchEntity") {
@@ -103,37 +92,17 @@ export class Policy extends Resource("iam::Policy", async (ctx, props) => {
103
92
  }))
104
93
  : undefined,
105
94
  }));
106
- return {
95
+ return this({
107
96
  ...props,
108
- id: props.policyName,
109
97
  arn: newPolicy.Policy.Arn,
110
98
  defaultVersionId: newPolicy.Policy.DefaultVersionId,
111
99
  attachmentCount: newPolicy.Policy.AttachmentCount,
112
100
  createDate: newPolicy.Policy.CreateDate,
113
101
  updateDate: newPolicy.Policy.UpdateDate,
114
102
  isAttachable: newPolicy.Policy.IsAttachable,
115
- };
103
+ });
116
104
  }
117
105
  throw error;
118
106
  }
119
107
  }
120
- }) {
121
- }
122
- export class PolicyAttachment extends Resource("iam::PolicyAttachment", async (ctx, props) => {
123
- const client = new IAMClient({});
124
- if (ctx.event === "delete") {
125
- await ignore(NoSuchEntityException.name, () => client.send(new DetachRolePolicyCommand({
126
- PolicyArn: props.policyArn,
127
- RoleName: props.roleName,
128
- })));
129
- }
130
- else {
131
- await client.send(new AttachRolePolicyCommand({
132
- PolicyArn: props.policyArn,
133
- RoleName: props.roleName,
134
- }));
135
- }
136
- return props;
137
- }) {
138
- }
139
- //# sourceMappingURL=policy.js.map
108
+ });
@@ -1,3 +1,5 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
1
3
  export interface QueueProps {
2
4
  /**
3
5
  * Name of the queue
@@ -23,40 +25,8 @@ export interface QueueProps {
23
25
  fifoThroughputLimit?: "perQueue" | "perMessageGroupId";
24
26
  tags?: Record<string, string>;
25
27
  }
26
- export interface QueueOutput extends QueueProps {
27
- id: string;
28
+ export interface Queue extends Resource<"sqs::Queue">, QueueProps {
28
29
  arn: string;
29
30
  url: string;
30
31
  }
31
- declare const Queue_base: import("../resource").Provider<"sqs::Queue", [props: QueueProps], {
32
- id: string;
33
- arn: string;
34
- url: string;
35
- /**
36
- * Name of the queue
37
- * For FIFO queues, the name must end with the .fifo suffix
38
- */
39
- queueName: string;
40
- /**
41
- * Whether this is a FIFO queue.
42
- * If true, the queueName must end with .fifo suffix
43
- */
44
- fifo?: boolean;
45
- visibilityTimeout?: number;
46
- messageRetentionPeriod?: number;
47
- maximumMessageSize?: number;
48
- delaySeconds?: number;
49
- receiveMessageWaitTimeSeconds?: number;
50
- /**
51
- * Enables content-based deduplication for FIFO queues.
52
- * Only applicable when fifo is true.
53
- */
54
- contentBasedDeduplication?: boolean;
55
- deduplicationScope?: "messageGroup" | "queue";
56
- fifoThroughputLimit?: "perQueue" | "perMessageGroupId";
57
- tags?: Record<string, string>;
58
- }>;
59
- export declare class Queue extends Queue_base {
60
- }
61
- export {};
62
- //# sourceMappingURL=queue.d.ts.map
32
+ export declare const Queue: ((this: Context<Queue>, id: string, props: QueueProps) => Promise<Queue>) | (((this: any, id: string, props: QueueProps) => never) & (new (_: never) => never));
package/lib/aws/queue.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CreateQueueCommand, DeleteQueueCommand, GetQueueAttributesCommand, GetQueueUrlCommand, SQSClient, } from "@aws-sdk/client-sqs";
2
2
  import { Resource } from "../resource";
3
- export class Queue extends Resource("sqs::Queue", async (ctx, props) => {
3
+ export const Queue = Resource("sqs::Queue", async function (id, props) {
4
4
  const client = new SQSClient({});
5
5
  // Don't automatically add .fifo suffix - user must include it in queueName
6
6
  const queueName = props.queueName;
@@ -8,7 +8,7 @@ export class Queue extends Resource("sqs::Queue", async (ctx, props) => {
8
8
  if (props.fifo && !queueName.endsWith(".fifo")) {
9
9
  throw new Error("FIFO queue names must end with .fifo suffix");
10
10
  }
11
- if (ctx.event === "delete") {
11
+ if (this.phase === "delete") {
12
12
  try {
13
13
  // Get queue URL first
14
14
  const urlResponse = await client.send(new GetQueueUrlCommand({
@@ -43,12 +43,7 @@ export class Queue extends Resource("sqs::Queue", async (ctx, props) => {
43
43
  throw error;
44
44
  }
45
45
  }
46
- return {
47
- ...props,
48
- id: props.queueName,
49
- arn: `arn:aws:sqs:${client.config.region}:${process.env.AWS_ACCOUNT_ID}:${queueName}`,
50
- url: "",
51
- };
46
+ return this.destroy();
52
47
  }
53
48
  else {
54
49
  // Create queue with attributes
@@ -99,12 +94,11 @@ export class Queue extends Resource("sqs::Queue", async (ctx, props) => {
99
94
  QueueUrl: createResponse.QueueUrl,
100
95
  AttributeNames: ["QueueArn"],
101
96
  }));
102
- return {
97
+ return this({
103
98
  ...props,
104
- id: props.queueName,
105
99
  arn: attributesResponse.Attributes.QueueArn,
106
100
  url: createResponse.QueueUrl,
107
- };
101
+ });
108
102
  }
109
103
  catch (error) {
110
104
  if (error.name === "QueueAlreadyExists") {
@@ -117,12 +111,11 @@ export class Queue extends Resource("sqs::Queue", async (ctx, props) => {
117
111
  QueueUrl: urlResponse.QueueUrl,
118
112
  AttributeNames: ["QueueArn"],
119
113
  }));
120
- return {
114
+ return this({
121
115
  ...props,
122
- id: props.queueName,
123
116
  arn: attributesResponse.Attributes.QueueArn,
124
117
  url: urlResponse.QueueUrl,
125
- };
118
+ });
126
119
  }
127
120
  else if (error.name === "QueueDeletedRecently") {
128
121
  // Queue was recently deleted, wait and retry
@@ -143,12 +136,11 @@ export class Queue extends Resource("sqs::Queue", async (ctx, props) => {
143
136
  QueueUrl: createResponse.QueueUrl,
144
137
  AttributeNames: ["QueueArn"],
145
138
  }));
146
- return {
139
+ return this({
147
140
  ...props,
148
- id: props.queueName,
149
141
  arn: attributesResponse.Attributes.QueueArn,
150
142
  url: createResponse.QueueUrl,
151
- };
143
+ });
152
144
  }
153
145
  catch (retryError) {
154
146
  if (retryError.name !== "QueueDeletedRecently" ||
@@ -162,6 +154,4 @@ export class Queue extends Resource("sqs::Queue", async (ctx, props) => {
162
154
  throw error;
163
155
  }
164
156
  }
165
- }) {
166
- }
167
- //# sourceMappingURL=queue.js.map
157
+ });
package/lib/aws/role.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
1
3
  import type { PolicyDocument } from "./policy";
2
4
  export interface RoleProps {
3
5
  roleName: string;
@@ -13,15 +15,10 @@ export interface RoleProps {
13
15
  managedPolicyArns?: string[];
14
16
  tags?: Record<string, string>;
15
17
  }
16
- export interface RoleOutput extends RoleProps {
17
- id: string;
18
+ export interface Role extends Resource<"iam::Role">, RoleProps {
18
19
  arn: string;
19
20
  uniqueId: string;
20
21
  roleId: string;
21
22
  createDate: Date;
22
23
  }
23
- declare const Role_base: import("../resource").Provider<"iam::Role", [props: RoleProps], RoleOutput>;
24
- export declare class Role extends Role_base {
25
- }
26
- export {};
27
- //# sourceMappingURL=role.d.ts.map
24
+ export declare const Role: ((this: Context<Role>, id: string, props: RoleProps) => Promise<Role>) | (((this: any, id: string, props: RoleProps) => never) & (new (_: never) => never));
package/lib/aws/role.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { AttachRolePolicyCommand, CreateRoleCommand, DeleteRoleCommand, DeleteRolePolicyCommand, DetachRolePolicyCommand, EntityAlreadyExistsException, GetRoleCommand, IAMClient, ListAttachedRolePoliciesCommand, NoSuchEntityException, PutRolePolicyCommand, TagRoleCommand, UpdateAssumeRolePolicyCommand, UpdateRoleCommand, } from "@aws-sdk/client-iam";
2
- import { ignore } from "../error";
3
2
  import { Resource } from "../resource";
4
- export class Role extends Resource("iam::Role", async (ctx, props) => {
3
+ import { ignore } from "../util/ignore";
4
+ export const Role = Resource("iam::Role", async function (id, props) {
5
5
  const client = new IAMClient({});
6
- if (ctx.event === "delete") {
6
+ if (this.phase === "delete") {
7
7
  // Delete any inline policies first
8
8
  if (props.policies) {
9
9
  for (const policy of props.policies) {
@@ -36,19 +36,12 @@ export class Role extends Resource("iam::Role", async (ctx, props) => {
36
36
  await ignore(NoSuchEntityException.name, () => client.send(new DeleteRoleCommand({
37
37
  RoleName: props.roleName,
38
38
  })));
39
- return {
40
- ...props,
41
- id: props.roleName,
42
- arn: `arn:aws:iam::${process.env.AWS_ACCOUNT_ID}:role/${props.roleName}`,
43
- uniqueId: "",
44
- roleId: "",
45
- createDate: new Date(),
46
- };
39
+ return this.destroy();
47
40
  }
48
41
  const assumeRolePolicyDocument = JSON.stringify(props.assumeRolePolicy);
49
42
  let role;
50
43
  try {
51
- if (ctx.event === "create") {
44
+ if (this.phase === "create") {
52
45
  // Try to create the role
53
46
  await client.send(new CreateRoleCommand({
54
47
  RoleName: props.roleName,
@@ -64,11 +57,11 @@ export class Role extends Resource("iam::Role", async (ctx, props) => {
64
57
  })),
65
58
  {
66
59
  Key: "alchemy_stage",
67
- Value: ctx.stage,
60
+ Value: this.stage,
68
61
  },
69
62
  {
70
63
  Key: "alchemy_resource",
71
- Value: ctx.resourceID,
64
+ Value: this.id,
72
65
  },
73
66
  ],
74
67
  }));
@@ -76,7 +69,7 @@ export class Role extends Resource("iam::Role", async (ctx, props) => {
76
69
  }
77
70
  catch (error) {
78
71
  if (error instanceof EntityAlreadyExistsException &&
79
- ctx.event === "create") {
72
+ this.phase === "create") {
80
73
  // Check if we were the ones who created it
81
74
  const existingRole = await client.send(new GetRoleCommand({
82
75
  RoleName: props.roleName,
@@ -85,8 +78,8 @@ export class Role extends Resource("iam::Role", async (ctx, props) => {
85
78
  acc[tag.Key] = tag.Value;
86
79
  return acc;
87
80
  }, {}) || {};
88
- if (roleTags.alchemy_stage !== ctx.stage ||
89
- roleTags.alchemy_resource !== ctx.resourceID) {
81
+ if (roleTags.alchemy_stage !== this.stage ||
82
+ roleTags.alchemy_resource !== this.id) {
90
83
  throw error;
91
84
  }
92
85
  }
@@ -117,8 +110,8 @@ export class Role extends Resource("iam::Role", async (ctx, props) => {
117
110
  // Update tags
118
111
  const newTags = {
119
112
  ...props.tags,
120
- alchemy_stage: ctx.stage,
121
- alchemy_resource: ctx.resourceID,
113
+ alchemy_stage: this.stage,
114
+ alchemy_resource: this.id,
122
115
  };
123
116
  const tags = Object.entries(newTags).map(([Key, Value]) => ({
124
117
  Key,
@@ -129,7 +122,7 @@ export class Role extends Resource("iam::Role", async (ctx, props) => {
129
122
  Tags: tags,
130
123
  }));
131
124
  // Handle policy changes
132
- const previousPolicies = ctx.event === "update" ? ctx.output.policies || [] : [];
125
+ const previousPolicies = this.phase === "update" ? this.output.policies || [] : [];
133
126
  const currentPolicies = props.policies || [];
134
127
  // Delete policies that were removed
135
128
  for (const oldPolicy of previousPolicies) {
@@ -184,14 +177,12 @@ export class Role extends Resource("iam::Role", async (ctx, props) => {
184
177
  if (!role?.Role) {
185
178
  throw new Error(`Failed to create or update role ${props.roleName}`);
186
179
  }
187
- return {
180
+ return this({
188
181
  ...props,
189
- id: props.roleName,
190
182
  arn: role.Role.Arn,
191
183
  uniqueId: role.Role.RoleId,
192
184
  roleId: role.Role.RoleId,
185
+ roleName: role.Role.RoleName ?? props.roleName,
193
186
  createDate: role.Role.CreateDate,
194
- };
195
- }) {
196
- }
197
- //# sourceMappingURL=role.js.map
187
+ });
188
+ });
package/lib/aws/ses.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { type DeliveryOptions, type ReputationOptions, type SendingOptions, type SuppressionOptions, type TrackingOptions } from "@aws-sdk/client-sesv2";
2
+ import type { Context } from "../context";
3
+ import { Resource } from "../resource";
2
4
  /**
3
5
  * Properties for configuring AWS SES resources
4
6
  */
@@ -43,11 +45,7 @@ export interface SESProps {
43
45
  /**
44
46
  * Output returned after SES resource creation/update
45
47
  */
46
- export interface SESOutput extends SESProps {
47
- /**
48
- * Resource ID
49
- */
50
- id: string;
48
+ export interface SES extends Resource<"aws::SES">, SESProps {
51
49
  /**
52
50
  * ARN of the configuration set if created
53
51
  */
@@ -65,11 +63,7 @@ export interface SESOutput extends SESProps {
65
63
  */
66
64
  emailIdentityArn?: string;
67
65
  }
68
- declare const SES_base: import("../resource").Provider<"aws::SES", [props: SESProps], SESOutput>;
69
66
  /**
70
67
  * AWS SES resource for creating and configuring Simple Email Service
71
68
  */
72
- export declare class SES extends SES_base {
73
- }
74
- export {};
75
- //# sourceMappingURL=ses.d.ts.map
69
+ export declare const SES: ((this: Context<SES>, id: string, props: SESProps) => Promise<SES>) | (((this: any, id: string, props: SESProps) => never) & (new (_: never) => never));