alchemy 0.2.3 → 0.2.4

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 (138) hide show
  1. package/lib/ai/ark.d.ts +11 -0
  2. package/lib/ai/ark.js +86 -0
  3. package/lib/ai/client.d.ts +51 -0
  4. package/lib/ai/client.js +29 -0
  5. package/lib/ai/document.d.ts +97 -0
  6. package/lib/ai/document.js +82 -0
  7. package/lib/{docs → ai}/index.d.ts +1 -0
  8. package/lib/{docs → ai}/index.js +1 -0
  9. package/lib/ai/object.d.ts +101 -0
  10. package/lib/ai/object.js +70 -0
  11. package/lib/alchemy.d.ts +83 -2
  12. package/lib/alchemy.js +31 -3
  13. package/lib/aws/bucket.d.ts +87 -1
  14. package/lib/aws/bucket.js +48 -1
  15. package/lib/aws/function.d.ts +186 -1
  16. package/lib/aws/function.js +62 -8
  17. package/lib/aws/oidc/github-oidc-provider.d.ts +81 -0
  18. package/lib/aws/oidc/github-oidc-provider.js +68 -0
  19. package/lib/aws/oidc/oidc-provider.d.ts +14 -6
  20. package/lib/aws/oidc/oidc-provider.js +26 -5
  21. package/lib/aws/policy-attachment.d.ts +44 -1
  22. package/lib/aws/policy-attachment.js +31 -0
  23. package/lib/aws/policy.d.ts +160 -1
  24. package/lib/aws/policy.js +78 -0
  25. package/lib/aws/queue.d.ts +83 -1
  26. package/lib/aws/queue.js +39 -0
  27. package/lib/aws/role.d.ts +162 -1
  28. package/lib/aws/role.js +114 -0
  29. package/lib/aws/ses.d.ts +57 -2
  30. package/lib/aws/ses.js +42 -1
  31. package/lib/aws/table.d.ts +96 -1
  32. package/lib/aws/table.js +36 -0
  33. package/lib/cloudflare/asset-manifest.js +0 -1
  34. package/lib/cloudflare/bound.js +0 -1
  35. package/lib/cloudflare/bucket.d.ts +37 -1
  36. package/lib/cloudflare/bucket.js +36 -0
  37. package/lib/cloudflare/durable-object-namespace.d.ts +25 -0
  38. package/lib/cloudflare/durable-object-namespace.js +22 -0
  39. package/lib/cloudflare/kv-namespace.d.ts +37 -1
  40. package/lib/cloudflare/kv-namespace.js +36 -0
  41. package/lib/cloudflare/static-site.d.ts +53 -1
  42. package/lib/cloudflare/static-site.js +53 -1
  43. package/lib/cloudflare/worker-metadata.js +0 -1
  44. package/lib/cloudflare/worker.d.ts +64 -1
  45. package/lib/cloudflare/worker.js +63 -0
  46. package/lib/cloudflare/wrangler.json.d.ts +1 -1
  47. package/lib/cloudflare/zone-settings.js +0 -1
  48. package/lib/cloudflare/zone.d.ts +56 -1
  49. package/lib/cloudflare/zone.js +55 -0
  50. package/lib/destroy.js +1 -1
  51. package/lib/esbuild/bundle.d.ts +43 -4
  52. package/lib/esbuild/bundle.js +16 -0
  53. package/lib/fs/file-collection.d.ts +16 -0
  54. package/lib/fs/file-collection.js +6 -0
  55. package/lib/fs/file-ref.d.ts +14 -0
  56. package/lib/fs/file-ref.js +6 -0
  57. package/lib/fs/file.d.ts +71 -25
  58. package/lib/fs/file.js +20 -44
  59. package/lib/fs/folder.d.ts +37 -5
  60. package/lib/fs/folder.js +26 -2
  61. package/lib/fs/index.d.ts +6 -0
  62. package/lib/fs/index.js +6 -0
  63. package/lib/fs/json-file.d.ts +16 -0
  64. package/lib/fs/json-file.js +7 -0
  65. package/lib/fs/text-file.d.ts +12 -0
  66. package/lib/fs/text-file.js +7 -0
  67. package/lib/fs/typescript-file.d.ts +19 -0
  68. package/lib/fs/typescript-file.js +14 -0
  69. package/lib/fs/yaml-file.d.ts +19 -0
  70. package/lib/fs/yaml-file.js +8 -0
  71. package/lib/github/secret.d.ts +63 -2
  72. package/lib/github/secret.js +61 -1
  73. package/lib/internal/docs.d.ts +5 -0
  74. package/lib/internal/docs.js +324 -0
  75. package/lib/resource.d.ts +1 -1
  76. package/lib/secret.d.ts +67 -0
  77. package/lib/secret.js +67 -0
  78. package/lib/shadcn/component.d.ts +1 -1
  79. package/lib/stripe/price.d.ts +51 -1
  80. package/lib/stripe/price.js +50 -0
  81. package/lib/stripe/product.d.ts +39 -1
  82. package/lib/stripe/product.js +38 -0
  83. package/lib/stripe/webhook.d.ts +46 -1
  84. package/lib/stripe/webhook.js +45 -0
  85. package/lib/test/bun.d.ts +64 -0
  86. package/lib/test/bun.js +35 -3
  87. package/lib/util/serde.js +14 -0
  88. package/lib/vite/vite.d.ts +1 -1
  89. package/lib/vitepress/dependencies.d.ts +2 -6
  90. package/lib/vitepress/vitepress.d.ts +12 -1
  91. package/lib/vitepress/vitepress.js +29 -23
  92. package/package.json +8 -3
  93. package/src/ai/ark.ts +118 -0
  94. package/src/ai/client.ts +78 -0
  95. package/src/ai/document.ts +160 -0
  96. package/src/{docs → ai}/index.ts +1 -0
  97. package/src/ai/object.ts +149 -0
  98. package/src/alchemy.ts +88 -5
  99. package/src/aws/bucket.ts +111 -7
  100. package/src/aws/function.ts +231 -10
  101. package/src/aws/oidc/github-oidc-provider.ts +83 -0
  102. package/src/aws/oidc/oidc-provider.ts +39 -7
  103. package/src/aws/policy-attachment.ts +44 -1
  104. package/src/aws/policy.ts +177 -2
  105. package/src/aws/queue.ts +89 -0
  106. package/src/aws/role.ts +174 -2
  107. package/src/aws/ses.ts +56 -1
  108. package/src/aws/table.ts +103 -0
  109. package/src/cloudflare/bucket.ts +36 -0
  110. package/src/cloudflare/durable-object-namespace.ts +25 -0
  111. package/src/cloudflare/kv-namespace.ts +36 -0
  112. package/src/cloudflare/static-site.ts +53 -1
  113. package/src/cloudflare/worker.ts +63 -0
  114. package/src/cloudflare/zone.ts +55 -0
  115. package/src/destroy.ts +1 -1
  116. package/src/esbuild/bundle.ts +53 -3
  117. package/src/fs/file-collection.ts +24 -0
  118. package/src/fs/file-ref.ts +22 -0
  119. package/src/fs/file.ts +70 -77
  120. package/src/fs/folder.ts +44 -5
  121. package/src/fs/index.ts +6 -0
  122. package/src/fs/json-file.ts +23 -0
  123. package/src/fs/text-file.ts +19 -0
  124. package/src/fs/typescript-file.ts +36 -0
  125. package/src/fs/yaml-file.ts +26 -0
  126. package/src/github/secret.ts +65 -2
  127. package/src/internal/docs.ts +369 -0
  128. package/src/resource.ts +1 -1
  129. package/src/secret.ts +67 -0
  130. package/src/stripe/price.ts +50 -0
  131. package/src/stripe/product.ts +38 -0
  132. package/src/stripe/webhook.ts +45 -0
  133. package/src/test/bun.ts +83 -3
  134. package/src/util/serde.ts +17 -0
  135. package/src/vitepress/vitepress.ts +47 -26
  136. package/lib/docs/document.d.ts +0 -123
  137. package/lib/docs/document.js +0 -67
  138. package/src/docs/document.ts +0 -225
package/src/aws/bucket.ts CHANGED
@@ -14,23 +14,118 @@ import type { Context } from "../context";
14
14
  import { Resource } from "../resource";
15
15
  import { ignore } from "../util/ignore";
16
16
 
17
+ /**
18
+ * Properties for creating or updating an S3 bucket
19
+ */
17
20
  export interface BucketProps {
21
+ /**
22
+ * The name of the bucket. Must be globally unique across all AWS accounts.
23
+ * Should be lowercase alphanumeric characters or hyphens.
24
+ */
18
25
  bucketName: string;
26
+
27
+ /**
28
+ * Optional tags to apply to the bucket for organization and cost tracking.
29
+ * Each tag is a key-value pair.
30
+ */
19
31
  tags?: Record<string, string>;
20
32
  }
21
33
 
34
+ /**
35
+ * Output returned after S3 bucket creation/update
36
+ */
22
37
  export interface Bucket extends Resource<"s3::Bucket">, BucketProps {
38
+ /**
39
+ * The ARN (Amazon Resource Name) of the bucket
40
+ * Format: arn:aws:s3:::bucket-name
41
+ */
23
42
  arn: string;
24
- bucketDomainName: string; // Format: bucket-name.s3.amazonaws.com
25
- bucketRegionalDomainName?: string; // Format: bucket-name.s3.region.amazonaws.com
26
- hostedZoneId?: string; // S3 hosted zone ID for the region
27
- region?: string; // AWS Region where bucket resides
28
- websiteEndpoint?: string; // Only if website hosting is enabled
29
- websiteDomain?: string; // Only if website hosting is enabled
43
+
44
+ /**
45
+ * The global domain name for the bucket
46
+ * Format: bucket-name.s3.amazonaws.com
47
+ */
48
+ bucketDomainName: string;
49
+
50
+ /**
51
+ * The regional domain name for the bucket
52
+ * Format: bucket-name.s3.region.amazonaws.com
53
+ */
54
+ bucketRegionalDomainName?: string;
55
+
56
+ /**
57
+ * The S3 hosted zone ID for the region where the bucket resides
58
+ * Used for DNS configuration with Route 53
59
+ */
60
+ hostedZoneId?: string;
61
+
62
+ /**
63
+ * The AWS region where the bucket is located
64
+ */
65
+ region?: string;
66
+
67
+ /**
68
+ * The website endpoint URL if static website hosting is enabled
69
+ * Format: http://bucket-name.s3-website-region.amazonaws.com
70
+ */
71
+ websiteEndpoint?: string;
72
+
73
+ /**
74
+ * The website domain if static website hosting is enabled
75
+ * Format: bucket-name.s3-website-region.amazonaws.com
76
+ */
77
+ websiteDomain?: string;
78
+
79
+ /**
80
+ * Whether versioning is enabled for the bucket
81
+ */
30
82
  versioningEnabled?: boolean;
83
+
84
+ /**
85
+ * The canned ACL applied to the bucket
86
+ * Common values: private, public-read, public-read-write, authenticated-read
87
+ */
31
88
  acl?: string;
32
89
  }
33
90
 
91
+ /**
92
+ * AWS S3 Bucket Resource
93
+ *
94
+ * Creates and manages Amazon S3 buckets with support for versioning, tags, and regional configuration.
95
+ * S3 buckets provide scalable object storage for any type of data, with features like versioning,
96
+ * lifecycle policies, and fine-grained access control.
97
+ *
98
+ * @example
99
+ * // Create a basic S3 bucket with default settings
100
+ * const basicBucket = await Bucket("my-app-storage", {
101
+ * bucketName: "my-app-storage",
102
+ * tags: {
103
+ * Environment: "production",
104
+ * Project: "my-app"
105
+ * }
106
+ * });
107
+ *
108
+ * @example
109
+ * // Create a bucket with versioning enabled and specific tags
110
+ * const versionedBucket = await Bucket("document-archive", {
111
+ * bucketName: "document-archive",
112
+ * tags: {
113
+ * Environment: "production",
114
+ * Purpose: "document-storage",
115
+ * Versioning: "enabled"
116
+ * }
117
+ * });
118
+ *
119
+ * @example
120
+ * // Create a development bucket with minimal configuration
121
+ * const devBucket = await Bucket("dev-testing", {
122
+ * bucketName: "dev-testing",
123
+ * tags: {
124
+ * Environment: "development",
125
+ * Temporary: "true"
126
+ * }
127
+ * });
128
+ */
34
129
  export const Bucket = Resource(
35
130
  "s3::Bucket",
36
131
  async function (this: Context<Bucket>, id: string, props: BucketProps) {
@@ -136,7 +231,16 @@ export const Bucket = Resource(
136
231
  },
137
232
  );
138
233
 
139
- // Helper function to get S3 hosted zone IDs by region
234
+ /**
235
+ * Helper function to get S3 hosted zone IDs by region
236
+ *
237
+ * Returns the S3 hosted zone ID for a given AWS region. These IDs are used when
238
+ * configuring Route 53 DNS records that point to S3 buckets. If the region is not
239
+ * found in the mapping, defaults to the us-east-1 hosted zone ID.
240
+ *
241
+ * @param region - The AWS region code (e.g., us-east-1, eu-west-1)
242
+ * @returns The S3 hosted zone ID for the region
243
+ */
140
244
  function getHostedZoneId(region: string): string {
141
245
  const hostedZoneIds: Record<string, string> = {
142
246
  "us-east-1": "Z3AQBSTGFYJSTF",
@@ -16,61 +16,275 @@ import type { Context } from "../context";
16
16
  import { Resource } from "../resource";
17
17
  import { ignore } from "../util/ignore";
18
18
 
19
- async function resolveRegion(client: LambdaClient): Promise<string> {
20
- const region = client.config.region;
21
- if (typeof region === "string") return region;
22
- if (typeof region === "function") return region();
23
- throw new Error("Could not resolve AWS region");
24
- }
25
-
19
+ /**
20
+ * Properties for creating or updating a Lambda function
21
+ */
26
22
  export interface FunctionProps {
23
+ /**
24
+ * Name of the Lambda function
25
+ */
27
26
  functionName: string;
27
+
28
+ /**
29
+ * Path to the zip file containing the function code
30
+ */
28
31
  zipPath: string;
32
+
33
+ /**
34
+ * ARN of the IAM role that Lambda assumes when executing the function
35
+ */
29
36
  roleArn: string;
37
+
38
+ /**
39
+ * Function handler in the format 'file.function'
40
+ * For Node.js this is typically 'index.handler' or similar
41
+ */
30
42
  handler?: string;
43
+
44
+ /**
45
+ * Lambda runtime environment for the function
46
+ * @default nodejs20.x if not specified
47
+ */
31
48
  runtime?: Runtime;
49
+
50
+ /**
51
+ * CPU architecture for the function
52
+ * @default x86_64 if not specified
53
+ */
32
54
  architecture?: Architecture;
55
+
56
+ /**
57
+ * Description of the function's purpose
58
+ */
33
59
  description?: string;
60
+
61
+ /**
62
+ * Maximum execution time in seconds
63
+ * @default 3 seconds if not specified
64
+ */
34
65
  timeout?: number;
66
+
67
+ /**
68
+ * Amount of memory available to the function in MB
69
+ * @default 128 MB if not specified
70
+ */
35
71
  memorySize?: number;
72
+
73
+ /**
74
+ * Environment variables available to the function code
75
+ */
36
76
  environment?: Record<string, string>;
77
+
78
+ /**
79
+ * Resource tags for the function
80
+ */
37
81
  tags?: Record<string, string>;
82
+
83
+ /**
84
+ * Function URL configuration for direct HTTP(S) invocation
85
+ */
38
86
  url?: {
87
+ /**
88
+ * Authentication type for the function URL
89
+ */
39
90
  authType?: "AWS_IAM" | "NONE";
91
+
92
+ /**
93
+ * CORS configuration for the function URL
94
+ */
40
95
  cors?: {
96
+ /**
97
+ * Whether to allow credentials in CORS requests
98
+ */
41
99
  allowCredentials?: boolean;
100
+
101
+ /**
102
+ * Allowed headers in CORS requests
103
+ */
42
104
  allowHeaders?: string[];
105
+
106
+ /**
107
+ * Allowed HTTP methods in CORS requests
108
+ */
43
109
  allowMethods?: string[];
110
+
111
+ /**
112
+ * Allowed origins in CORS requests
113
+ */
44
114
  allowOrigins?: string[];
115
+
116
+ /**
117
+ * Headers exposed to the browser
118
+ */
45
119
  exposeHeaders?: string[];
120
+
121
+ /**
122
+ * CORS preflight cache time in seconds
123
+ */
46
124
  maxAge?: number;
47
125
  };
48
126
  };
49
127
  }
50
128
 
129
+ /**
130
+ * Output returned after Lambda function creation/update
131
+ */
51
132
  export interface Function extends Resource<"lambda::Function">, FunctionProps {
133
+ /**
134
+ * ARN of the Lambda function
135
+ */
52
136
  arn: string;
137
+
138
+ /**
139
+ * Timestamp of the last function modification
140
+ */
53
141
  lastModified: string;
142
+
143
+ /**
144
+ * Function version
145
+ */
54
146
  version: string;
55
- qualifiedArn: string; // ARN with version
56
- invokeArn: string; // ARN for API Gateway
147
+
148
+ /**
149
+ * ARN with version suffix
150
+ */
151
+ qualifiedArn: string;
152
+
153
+ /**
154
+ * ARN for invoking the function through API Gateway
155
+ */
156
+ invokeArn: string;
157
+
158
+ /**
159
+ * SHA256 hash of the function code
160
+ */
57
161
  sourceCodeHash: string;
162
+
163
+ /**
164
+ * Size of the function code in bytes
165
+ */
58
166
  sourceCodeSize: number;
167
+
168
+ /**
169
+ * Size of ephemeral storage (/tmp) in MB
170
+ */
59
171
  ephemeralStorageSize?: number;
172
+
173
+ /**
174
+ * List of supported CPU architectures
175
+ */
60
176
  architectures: string[];
61
- masterArn?: string; // Only for Lambda@Edge
177
+
178
+ /**
179
+ * ARN of the master function (Lambda@Edge only)
180
+ */
181
+ masterArn?: string;
182
+
183
+ /**
184
+ * Unique identifier for the current function code/config
185
+ */
62
186
  revisionId: string;
187
+
188
+ /**
189
+ * Current state of the function
190
+ */
63
191
  state?: string;
192
+
193
+ /**
194
+ * Reason for the current state
195
+ */
64
196
  stateReason?: string;
197
+
198
+ /**
199
+ * Code for the current state reason
200
+ */
65
201
  stateReasonCode?: string;
202
+
203
+ /**
204
+ * Status of the last update operation
205
+ */
66
206
  lastUpdateStatus?: string;
207
+
208
+ /**
209
+ * Reason for the last update status
210
+ */
67
211
  lastUpdateStatusReason?: string;
212
+
213
+ /**
214
+ * Code for the last update status reason
215
+ */
68
216
  lastUpdateStatusReasonCode?: string;
217
+
218
+ /**
219
+ * Function package type (Zip or Image)
220
+ */
69
221
  packageType: string;
222
+
223
+ /**
224
+ * ARN of the signing profile version
225
+ */
70
226
  signingProfileVersionArn?: string;
227
+
228
+ /**
229
+ * ARN of the signing job
230
+ */
71
231
  signingJobArn?: string;
72
232
  }
73
233
 
234
+ /**
235
+ * AWS Lambda Function Resource
236
+ *
237
+ * Creates and manages AWS Lambda functions with support for Node.js runtimes, custom handlers,
238
+ * environment variables, and function URLs. Handles deployment packaging, IAM role
239
+ * stabilization, and function updates.
240
+ *
241
+ * @example
242
+ * // Create a basic Lambda function with minimal configuration
243
+ * const basicFunction = await Function("api-handler", {
244
+ * functionName: "api-handler",
245
+ * zipPath: "./dist/api.zip",
246
+ * roleArn: role.arn,
247
+ * runtime: Runtime.nodejs20x,
248
+ * handler: "index.handler",
249
+ * tags: {
250
+ * Environment: "production"
251
+ * }
252
+ * });
253
+ *
254
+ * @example
255
+ * // Create a function with environment variables and custom memory/timeout
256
+ * const configuredFunction = await Function("worker", {
257
+ * functionName: "worker",
258
+ * zipPath: "./dist/worker.zip",
259
+ * roleArn: role.arn,
260
+ * runtime: Runtime.nodejs20x,
261
+ * handler: "worker.process",
262
+ * memorySize: 512,
263
+ * timeout: 30,
264
+ * environment: {
265
+ * QUEUE_URL: queue.url,
266
+ * LOG_LEVEL: "info"
267
+ * }
268
+ * });
269
+ *
270
+ * @example
271
+ * // Create a function with a public URL endpoint and CORS
272
+ * const apiFunction = await Function("public-api", {
273
+ * functionName: "public-api",
274
+ * zipPath: "./dist/api.zip",
275
+ * roleArn: role.arn,
276
+ * handler: "api.handler",
277
+ * url: {
278
+ * authType: "NONE",
279
+ * cors: {
280
+ * allowOrigins: ["*"],
281
+ * allowMethods: ["GET", "POST"],
282
+ * allowHeaders: ["content-type"],
283
+ * maxAge: 86400
284
+ * }
285
+ * }
286
+ * });
287
+ */
74
288
  export const Function = Resource(
75
289
  "lambda::Function",
76
290
  async function (this: Context<Function>, id: string, props: FunctionProps) {
@@ -280,3 +494,10 @@ async function zipCode(filePath: string): Promise<Buffer> {
280
494
  platform: "UNIX",
281
495
  });
282
496
  }
497
+
498
+ async function resolveRegion(client: LambdaClient): Promise<string> {
499
+ const region = client.config.region;
500
+ if (typeof region === "string") return region;
501
+ if (typeof region === "function") return region();
502
+ throw new Error("Could not resolve AWS region");
503
+ }
@@ -7,13 +7,96 @@ import { OIDCProvider, type OIDCProviderProps } from "./oidc-provider";
7
7
  */
8
8
  const DEFAULT_GITHUB_THUMBPRINT = "6938fd4d98bab03faadb97b34396831e3780aea1";
9
9
 
10
+ /**
11
+ * Properties for configuring GitHub-specific OIDC provider
12
+ * Simplified version of OIDCProviderProps that omits the thumbprint
13
+ * since it's automatically set to GitHub's known value
14
+ */
10
15
  export interface GitHubOIDCProviderProps
11
16
  extends Omit<OIDCProviderProps, "thumbprint"> {
17
+ /**
18
+ * The GitHub organization or user that owns the repository
19
+ * Example: "my-org" or "my-username"
20
+ */
12
21
  owner: string;
22
+
23
+ /**
24
+ * The name of the GitHub repository
25
+ * Example: "my-repo"
26
+ */
13
27
  repository: string;
14
28
  }
29
+
15
30
  export type GitHubOIDCProvider = ReturnType<typeof GitHubOIDCProvider>;
16
31
 
32
+ /**
33
+ * GitHub-specific OIDC Provider Resource
34
+ *
35
+ * A simplified wrapper around OIDCProvider that automatically sets the correct
36
+ * thumbprint for GitHub Actions. This is the recommended way to set up OIDC
37
+ * authentication for GitHub Actions workflows.
38
+ *
39
+ * @example
40
+ * // Create a GitHub OIDC provider for all branches
41
+ * const provider = await GitHubOIDCProvider("github", {
42
+ * owner: "my-org",
43
+ * repository: "my-repo",
44
+ * roleArn: "arn:aws:iam::123456789012:role/github-actions"
45
+ * });
46
+ *
47
+ * @example
48
+ * // Create a GitHub OIDC provider with branch and environment restrictions
49
+ * const provider = await GitHubOIDCProvider("github-restricted", {
50
+ * owner: "my-org",
51
+ * repository: "my-repo",
52
+ * branches: ["main", "prod"],
53
+ * environments: ["staging", "production"],
54
+ * roleArn: "arn:aws:iam::123456789012:role/github-actions",
55
+ * maxSessionDuration: 7200
56
+ * });
57
+ *
58
+ * @example
59
+ * // Complete setup with IAM role and OIDC provider
60
+ * import { Role, getAccountId } from "../aws";
61
+ *
62
+ * // Get the AWS account ID
63
+ * const accountId = await getAccountId();
64
+ *
65
+ * // Create the IAM role that GitHub Actions will assume
66
+ * const githubRole = await Role("github-oidc-role", {
67
+ * roleName: "github-actions-role",
68
+ * assumeRolePolicy: {
69
+ * Version: "2012-10-17",
70
+ * Statement: [
71
+ * {
72
+ * Sid: "GitHubOIDC",
73
+ * Effect: "Allow",
74
+ * Principal: {
75
+ * Federated: `arn:aws:iam::${accountId}:oidc-provider/token.actions.githubusercontent.com`
76
+ * },
77
+ * Action: "sts:AssumeRoleWithWebIdentity",
78
+ * Condition: {
79
+ * StringEquals: {
80
+ * "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
81
+ * },
82
+ * StringLike: {
83
+ * "token.actions.githubusercontent.com:sub": "repo:my-org/my-repo:*"
84
+ * }
85
+ * }
86
+ * }
87
+ * ]
88
+ * },
89
+ * // Add required managed policies or inline policies for your use case
90
+ * managedPolicyArns: ["arn:aws:iam::aws:policy/ReadOnlyAccess"]
91
+ * });
92
+ *
93
+ * // Create the OIDC provider using the role
94
+ * const provider = await GitHubOIDCProvider("github-oidc", {
95
+ * owner: "my-org",
96
+ * repository: "my-repo",
97
+ * roleArn: githubRole.arn
98
+ * });
99
+ */
17
100
  export const GitHubOIDCProvider = async (
18
101
  id: string,
19
102
  props: GitHubOIDCProviderProps,
@@ -17,43 +17,52 @@ import { getAccountId } from "../account-id";
17
17
  export interface OIDCProviderProps {
18
18
  /**
19
19
  * The GitHub organization or user that owns the repository
20
+ * Example: "my-org" or "my-username"
20
21
  */
21
22
  owner: string;
22
23
 
23
24
  /**
24
25
  * The name of the GitHub repository
26
+ * Example: "my-repo"
25
27
  */
26
28
  repository: string;
27
29
 
28
30
  /**
29
31
  * Optional list of branches to restrict access to
30
32
  * If not provided, all branches will be allowed
33
+ * Example: ["main", "prod"]
31
34
  */
32
35
  branches?: string[];
33
36
 
34
37
  /**
35
38
  * Optional list of environments to restrict access to
36
39
  * If not provided, all environments will be allowed
40
+ * Example: ["staging", "production"]
37
41
  */
38
42
  environments?: string[];
39
43
 
40
44
  /**
41
45
  * The ARN of the IAM role to be assumed
46
+ * Format: arn:aws:iam::account-id:role/role-name
42
47
  */
43
48
  roleArn: string;
44
49
 
45
50
  /**
46
- * Optional maximum session duration in seconds (default: 3600)
51
+ * Optional maximum session duration in seconds
52
+ * Default: 3600 (1 hour)
53
+ * Range: 900-43200 seconds (15 minutes to 12 hours)
47
54
  */
48
55
  maxSessionDuration?: number;
49
56
 
50
57
  /**
51
58
  * Thumbprint for the OIDC provider
59
+ * Used to verify the identity provider's server certificate
52
60
  */
53
61
  thumbprint: string;
54
62
 
55
63
  /**
56
- * Optional AWS region (defaults to AWS_REGION environment variable)
64
+ * Optional AWS region
65
+ * @default AWS_REGION environment variable
57
66
  */
58
67
  region?: string;
59
68
  }
@@ -66,24 +75,47 @@ export interface OIDCProvider
66
75
  OIDCProviderProps {
67
76
  /**
68
77
  * The ARN of the OIDC provider
78
+ * Format: arn:aws:iam::account-id:oidc-provider/token.actions.githubusercontent.com
69
79
  */
70
80
  providerArn: string;
71
81
 
72
82
  /**
73
83
  * Time at which the provider was created
84
+ * Unix timestamp in milliseconds
74
85
  */
75
86
  createdAt: number;
76
87
  }
77
88
 
78
89
  /**
79
- * Unique identifier for our trust policy statement
80
- * Used to track and remove our specific statement without affecting others
90
+ * AWS OIDC Provider Resource for GitHub Actions
91
+ *
92
+ * Creates and manages an OpenID Connect (OIDC) identity provider in AWS IAM
93
+ * for GitHub Actions workflows. This enables secure, token-based authentication
94
+ * between GitHub Actions and AWS without storing long-term credentials.
95
+ *
96
+ * @example
97
+ * // Create an OIDC provider for all branches
98
+ * const provider = await OIDCProvider("github", {
99
+ * owner: "my-org",
100
+ * repository: "my-repo",
101
+ * roleArn: "arn:aws:iam::123456789012:role/github-actions",
102
+ * thumbprint: "6938fd4d98bab03faadb97b34396831e3780aea1"
103
+ * });
104
+ *
105
+ * @example
106
+ * // Create an OIDC provider restricted to specific branches and environments
107
+ * const provider = await OIDCProvider("github-restricted", {
108
+ * owner: "my-org",
109
+ * repository: "my-repo",
110
+ * branches: ["main", "prod"],
111
+ * environments: ["staging", "production"],
112
+ * roleArn: "arn:aws:iam::123456789012:role/github-actions",
113
+ * thumbprint: "6938fd4d98bab03faadb97b34396831e3780aea1",
114
+ * maxSessionDuration: 7200
115
+ * });
81
116
  */
82
117
  const TRUST_POLICY_SID = "GitHubOIDCTrust";
83
118
 
84
- /**
85
- * Resource for configuring AWS OIDC provider for GitHub Actions
86
- */
87
119
  export const OIDCProvider = Resource(
88
120
  "aws::OIDCProvider",
89
121
  async function (
@@ -8,16 +8,59 @@ import type { Context } from "../context";
8
8
  import { Resource } from "../resource";
9
9
  import { ignore } from "../util/ignore";
10
10
 
11
- // PolicyAttachment resource
11
+ /**
12
+ * Properties for creating or updating a policy attachment
13
+ */
12
14
  export interface PolicyAttachmentProps {
15
+ /**
16
+ * ARN of the IAM policy to attach
17
+ */
13
18
  policyArn: string;
19
+
20
+ /**
21
+ * Name of the IAM role to attach the policy to
22
+ */
14
23
  roleName: string;
15
24
  }
16
25
 
26
+ /**
27
+ * Output returned after policy attachment creation/update
28
+ */
17
29
  export interface PolicyAttachment
18
30
  extends Resource<"iam::PolicyAttachment">,
19
31
  PolicyAttachmentProps {}
20
32
 
33
+ /**
34
+ * AWS IAM Policy Attachment Resource
35
+ *
36
+ * Attaches an IAM policy to a role, enabling the role to use the permissions defined in the policy.
37
+ *
38
+ * @example
39
+ * // Attach an AWS managed policy to a role
40
+ * const adminAccess = await PolicyAttachment("admin-policy", {
41
+ * policyArn: "arn:aws:iam::aws:policy/AdministratorAccess",
42
+ * roleName: role.name
43
+ * });
44
+ *
45
+ * @example
46
+ * // Attach a custom policy to a role
47
+ * const customPolicy = await PolicyAttachment("custom-policy", {
48
+ * policyArn: policy.arn,
49
+ * roleName: role.name
50
+ * });
51
+ *
52
+ * @example
53
+ * // Attach multiple policies to a role
54
+ * const s3Access = await PolicyAttachment("s3-access", {
55
+ * policyArn: "arn:aws:iam::aws:policy/AmazonS3FullAccess",
56
+ * roleName: role.name
57
+ * });
58
+ *
59
+ * const sqsAccess = await PolicyAttachment("sqs-access", {
60
+ * policyArn: "arn:aws:iam::aws:policy/AmazonSQSFullAccess",
61
+ * roleName: role.name
62
+ * });
63
+ */
21
64
  export const PolicyAttachment = Resource(
22
65
  "iam::PolicyAttachment",
23
66
  async function (