alchemy 0.2.3 → 0.2.5

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 (141) 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/data.d.ts +101 -0
  6. package/lib/ai/data.js +70 -0
  7. package/lib/ai/document.d.ts +101 -0
  8. package/lib/ai/document.js +82 -0
  9. package/lib/ai/index.d.ts +3 -0
  10. package/lib/ai/index.js +3 -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 +287 -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/data.ts +149 -0
  96. package/src/ai/document.ts +165 -0
  97. package/src/ai/index.ts +3 -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 +338 -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/lib/docs/index.d.ts +0 -1
  139. package/lib/docs/index.js +0 -1
  140. package/src/docs/document.ts +0 -225
  141. package/src/docs/index.ts +0 -1
package/lib/alchemy.js CHANGED
@@ -6,6 +6,10 @@ import { secret } from "./secret";
6
6
  // TODO: support browser
7
7
  const DEFAULT_STAGE = process.env.ALCHEMY_STAGE ?? process.env.USER ?? "dev";
8
8
  export const alchemy = _alchemy;
9
+ /**
10
+ * Implementation of the alchemy function that handles both application scoping
11
+ * and template string interpolation.
12
+ */
9
13
  function _alchemy(...args) {
10
14
  if (typeof args[0] === "string") {
11
15
  const [appName, options] = args;
@@ -23,7 +27,7 @@ function _alchemy(...args) {
23
27
  : 0;
24
28
  const indent = " ".repeat(leadingSpaces);
25
29
  return (async () => {
26
- const { isFileCollection, isFileRef } = await import("./fs/file");
30
+ const { isFileCollection, isFileRef } = await import("./fs");
27
31
  const appendices = {};
28
32
  const stringValues = await Promise.all(values.map(async function resolve(value) {
29
33
  if (typeof value === "string") {
@@ -88,8 +92,17 @@ _alchemy.scope = scope;
88
92
  _alchemy.secret = secret;
89
93
  /**
90
94
  * Enter a new scope synchronously.
91
- * @param options
92
- * @returns
95
+ *
96
+ * @example
97
+ * // Create a scope with a password for secret handling
98
+ * await using scope = alchemy.scope("my-scope", {
99
+ * password: process.env.SECRET_PASSPHRASE
100
+ * });
101
+ *
102
+ * // Use secrets within the scope
103
+ * const resource = await Resource("my-resource", {
104
+ * apiKey: alchemy.secret(process.env.API_KEY)
105
+ * });
93
106
  */
94
107
  function scope(id, options) {
95
108
  const scope = new Scope({
@@ -102,6 +115,21 @@ function scope(id, options) {
102
115
  scope.enter();
103
116
  return scope;
104
117
  }
118
+ /**
119
+ * Run a function in a new scope asynchronously.
120
+ * Useful for isolating secret handling with a specific password.
121
+ *
122
+ * @example
123
+ * // Run operations in a scope with its own password
124
+ * await alchemy.run("secure-scope", {
125
+ * password: process.env.SCOPE_PASSWORD
126
+ * }, async () => {
127
+ * // Secrets in this scope will use this password
128
+ * const resource = await Resource("my-resource", {
129
+ * apiKey: alchemy.secret(process.env.API_KEY)
130
+ * });
131
+ * });
132
+ */
105
133
  async function run(...args) {
106
134
  const [id, options, fn] = typeof args[1] === "function"
107
135
  ? [args[0], undefined, args[1]]
@@ -1,18 +1,104 @@
1
1
  import type { Context } from "../context";
2
2
  import { Resource } from "../resource";
3
+ /**
4
+ * Properties for creating or updating an S3 bucket
5
+ */
3
6
  export interface BucketProps {
7
+ /**
8
+ * The name of the bucket. Must be globally unique across all AWS accounts.
9
+ * Should be lowercase alphanumeric characters or hyphens.
10
+ */
4
11
  bucketName: string;
12
+ /**
13
+ * Optional tags to apply to the bucket for organization and cost tracking.
14
+ * Each tag is a key-value pair.
15
+ */
5
16
  tags?: Record<string, string>;
6
17
  }
18
+ /**
19
+ * Output returned after S3 bucket creation/update
20
+ */
7
21
  export interface Bucket extends Resource<"s3::Bucket">, BucketProps {
22
+ /**
23
+ * The ARN (Amazon Resource Name) of the bucket
24
+ * Format: arn:aws:s3:::bucket-name
25
+ */
8
26
  arn: string;
27
+ /**
28
+ * The global domain name for the bucket
29
+ * Format: bucket-name.s3.amazonaws.com
30
+ */
9
31
  bucketDomainName: string;
32
+ /**
33
+ * The regional domain name for the bucket
34
+ * Format: bucket-name.s3.region.amazonaws.com
35
+ */
10
36
  bucketRegionalDomainName?: string;
37
+ /**
38
+ * The S3 hosted zone ID for the region where the bucket resides
39
+ * Used for DNS configuration with Route 53
40
+ */
11
41
  hostedZoneId?: string;
42
+ /**
43
+ * The AWS region where the bucket is located
44
+ */
12
45
  region?: string;
46
+ /**
47
+ * The website endpoint URL if static website hosting is enabled
48
+ * Format: http://bucket-name.s3-website-region.amazonaws.com
49
+ */
13
50
  websiteEndpoint?: string;
51
+ /**
52
+ * The website domain if static website hosting is enabled
53
+ * Format: bucket-name.s3-website-region.amazonaws.com
54
+ */
14
55
  websiteDomain?: string;
56
+ /**
57
+ * Whether versioning is enabled for the bucket
58
+ */
15
59
  versioningEnabled?: boolean;
60
+ /**
61
+ * The canned ACL applied to the bucket
62
+ * Common values: private, public-read, public-read-write, authenticated-read
63
+ */
16
64
  acl?: string;
17
65
  }
18
- export declare const Bucket: ((this: Context<Bucket>, id: string, props: BucketProps) => Promise<Bucket>) | (((this: any, id: string, props?: BucketProps | undefined) => never) & (new (_: never) => never));
66
+ /**
67
+ * AWS S3 Bucket Resource
68
+ *
69
+ * Creates and manages Amazon S3 buckets with support for versioning, tags, and regional configuration.
70
+ * S3 buckets provide scalable object storage for any type of data, with features like versioning,
71
+ * lifecycle policies, and fine-grained access control.
72
+ *
73
+ * @example
74
+ * // Create a basic S3 bucket with default settings
75
+ * const basicBucket = await Bucket("my-app-storage", {
76
+ * bucketName: "my-app-storage",
77
+ * tags: {
78
+ * Environment: "production",
79
+ * Project: "my-app"
80
+ * }
81
+ * });
82
+ *
83
+ * @example
84
+ * // Create a bucket with versioning enabled and specific tags
85
+ * const versionedBucket = await Bucket("document-archive", {
86
+ * bucketName: "document-archive",
87
+ * tags: {
88
+ * Environment: "production",
89
+ * Purpose: "document-storage",
90
+ * Versioning: "enabled"
91
+ * }
92
+ * });
93
+ *
94
+ * @example
95
+ * // Create a development bucket with minimal configuration
96
+ * const devBucket = await Bucket("dev-testing", {
97
+ * bucketName: "dev-testing",
98
+ * tags: {
99
+ * Environment: "development",
100
+ * Temporary: "true"
101
+ * }
102
+ * });
103
+ */
104
+ export declare const Bucket: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Bucket>, id: string, props: BucketProps) => Promise<Bucket>);
package/lib/aws/bucket.js CHANGED
@@ -1,6 +1,44 @@
1
1
  import { CreateBucketCommand, DeleteBucketCommand, GetBucketAclCommand, GetBucketLocationCommand, GetBucketTaggingCommand, GetBucketVersioningCommand, HeadBucketCommand, NoSuchBucket, PutBucketTaggingCommand, S3Client, } from "@aws-sdk/client-s3";
2
2
  import { Resource } from "../resource";
3
3
  import { ignore } from "../util/ignore";
4
+ /**
5
+ * AWS S3 Bucket Resource
6
+ *
7
+ * Creates and manages Amazon S3 buckets with support for versioning, tags, and regional configuration.
8
+ * S3 buckets provide scalable object storage for any type of data, with features like versioning,
9
+ * lifecycle policies, and fine-grained access control.
10
+ *
11
+ * @example
12
+ * // Create a basic S3 bucket with default settings
13
+ * const basicBucket = await Bucket("my-app-storage", {
14
+ * bucketName: "my-app-storage",
15
+ * tags: {
16
+ * Environment: "production",
17
+ * Project: "my-app"
18
+ * }
19
+ * });
20
+ *
21
+ * @example
22
+ * // Create a bucket with versioning enabled and specific tags
23
+ * const versionedBucket = await Bucket("document-archive", {
24
+ * bucketName: "document-archive",
25
+ * tags: {
26
+ * Environment: "production",
27
+ * Purpose: "document-storage",
28
+ * Versioning: "enabled"
29
+ * }
30
+ * });
31
+ *
32
+ * @example
33
+ * // Create a development bucket with minimal configuration
34
+ * const devBucket = await Bucket("dev-testing", {
35
+ * bucketName: "dev-testing",
36
+ * tags: {
37
+ * Environment: "development",
38
+ * Temporary: "true"
39
+ * }
40
+ * });
41
+ */
4
42
  export const Bucket = Resource("s3::Bucket", async function (id, props) {
5
43
  const client = new S3Client({});
6
44
  if (this.phase === "delete") {
@@ -81,7 +119,16 @@ export const Bucket = Resource("s3::Bucket", async function (id, props) {
81
119
  });
82
120
  }
83
121
  });
84
- // Helper function to get S3 hosted zone IDs by region
122
+ /**
123
+ * Helper function to get S3 hosted zone IDs by region
124
+ *
125
+ * Returns the S3 hosted zone ID for a given AWS region. These IDs are used when
126
+ * configuring Route 53 DNS records that point to S3 buckets. If the region is not
127
+ * found in the mapping, defaults to the us-east-1 hosted zone ID.
128
+ *
129
+ * @param region - The AWS region code (e.g., us-east-1, eu-west-1)
130
+ * @returns The S3 hosted zone ID for the region
131
+ */
85
132
  function getHostedZoneId(region) {
86
133
  const hostedZoneIds = {
87
134
  "us-east-1": "Z3AQBSTGFYJSTF",
@@ -1,50 +1,235 @@
1
1
  import { Architecture, Runtime } from "@aws-sdk/client-lambda";
2
2
  import type { Context } from "../context";
3
3
  import { Resource } from "../resource";
4
+ /**
5
+ * Properties for creating or updating a Lambda function
6
+ */
4
7
  export interface FunctionProps {
8
+ /**
9
+ * Name of the Lambda function
10
+ */
5
11
  functionName: string;
12
+ /**
13
+ * Path to the zip file containing the function code
14
+ */
6
15
  zipPath: string;
16
+ /**
17
+ * ARN of the IAM role that Lambda assumes when executing the function
18
+ */
7
19
  roleArn: string;
20
+ /**
21
+ * Function handler in the format 'file.function'
22
+ * For Node.js this is typically 'index.handler' or similar
23
+ */
8
24
  handler?: string;
25
+ /**
26
+ * Lambda runtime environment for the function
27
+ * @default nodejs20.x if not specified
28
+ */
9
29
  runtime?: Runtime;
30
+ /**
31
+ * CPU architecture for the function
32
+ * @default x86_64 if not specified
33
+ */
10
34
  architecture?: Architecture;
35
+ /**
36
+ * Description of the function's purpose
37
+ */
11
38
  description?: string;
39
+ /**
40
+ * Maximum execution time in seconds
41
+ * @default 3 seconds if not specified
42
+ */
12
43
  timeout?: number;
44
+ /**
45
+ * Amount of memory available to the function in MB
46
+ * @default 128 MB if not specified
47
+ */
13
48
  memorySize?: number;
49
+ /**
50
+ * Environment variables available to the function code
51
+ */
14
52
  environment?: Record<string, string>;
53
+ /**
54
+ * Resource tags for the function
55
+ */
15
56
  tags?: Record<string, string>;
57
+ /**
58
+ * Function URL configuration for direct HTTP(S) invocation
59
+ */
16
60
  url?: {
61
+ /**
62
+ * Authentication type for the function URL
63
+ */
17
64
  authType?: "AWS_IAM" | "NONE";
65
+ /**
66
+ * CORS configuration for the function URL
67
+ */
18
68
  cors?: {
69
+ /**
70
+ * Whether to allow credentials in CORS requests
71
+ */
19
72
  allowCredentials?: boolean;
73
+ /**
74
+ * Allowed headers in CORS requests
75
+ */
20
76
  allowHeaders?: string[];
77
+ /**
78
+ * Allowed HTTP methods in CORS requests
79
+ */
21
80
  allowMethods?: string[];
81
+ /**
82
+ * Allowed origins in CORS requests
83
+ */
22
84
  allowOrigins?: string[];
85
+ /**
86
+ * Headers exposed to the browser
87
+ */
23
88
  exposeHeaders?: string[];
89
+ /**
90
+ * CORS preflight cache time in seconds
91
+ */
24
92
  maxAge?: number;
25
93
  };
26
94
  };
27
95
  }
96
+ /**
97
+ * Output returned after Lambda function creation/update
98
+ */
28
99
  export interface Function extends Resource<"lambda::Function">, FunctionProps {
100
+ /**
101
+ * ARN of the Lambda function
102
+ */
29
103
  arn: string;
104
+ /**
105
+ * Timestamp of the last function modification
106
+ */
30
107
  lastModified: string;
108
+ /**
109
+ * Function version
110
+ */
31
111
  version: string;
112
+ /**
113
+ * ARN with version suffix
114
+ */
32
115
  qualifiedArn: string;
116
+ /**
117
+ * ARN for invoking the function through API Gateway
118
+ */
33
119
  invokeArn: string;
120
+ /**
121
+ * SHA256 hash of the function code
122
+ */
34
123
  sourceCodeHash: string;
124
+ /**
125
+ * Size of the function code in bytes
126
+ */
35
127
  sourceCodeSize: number;
128
+ /**
129
+ * Size of ephemeral storage (/tmp) in MB
130
+ */
36
131
  ephemeralStorageSize?: number;
132
+ /**
133
+ * List of supported CPU architectures
134
+ */
37
135
  architectures: string[];
136
+ /**
137
+ * ARN of the master function (Lambda@Edge only)
138
+ */
38
139
  masterArn?: string;
140
+ /**
141
+ * Unique identifier for the current function code/config
142
+ */
39
143
  revisionId: string;
144
+ /**
145
+ * Current state of the function
146
+ */
40
147
  state?: string;
148
+ /**
149
+ * Reason for the current state
150
+ */
41
151
  stateReason?: string;
152
+ /**
153
+ * Code for the current state reason
154
+ */
42
155
  stateReasonCode?: string;
156
+ /**
157
+ * Status of the last update operation
158
+ */
43
159
  lastUpdateStatus?: string;
160
+ /**
161
+ * Reason for the last update status
162
+ */
44
163
  lastUpdateStatusReason?: string;
164
+ /**
165
+ * Code for the last update status reason
166
+ */
45
167
  lastUpdateStatusReasonCode?: string;
168
+ /**
169
+ * Function package type (Zip or Image)
170
+ */
46
171
  packageType: string;
172
+ /**
173
+ * ARN of the signing profile version
174
+ */
47
175
  signingProfileVersionArn?: string;
176
+ /**
177
+ * ARN of the signing job
178
+ */
48
179
  signingJobArn?: string;
49
180
  }
50
- export declare const Function: ((this: Context<Function>, id: string, props: FunctionProps) => Promise<Function>) | (((this: any, id: string, props?: FunctionProps | undefined) => never) & (new (_: never) => never));
181
+ /**
182
+ * AWS Lambda Function Resource
183
+ *
184
+ * Creates and manages AWS Lambda functions with support for Node.js runtimes, custom handlers,
185
+ * environment variables, and function URLs. Handles deployment packaging, IAM role
186
+ * stabilization, and function updates.
187
+ *
188
+ * @example
189
+ * // Create a basic Lambda function with minimal configuration
190
+ * const basicFunction = await Function("api-handler", {
191
+ * functionName: "api-handler",
192
+ * zipPath: "./dist/api.zip",
193
+ * roleArn: role.arn,
194
+ * runtime: Runtime.nodejs20x,
195
+ * handler: "index.handler",
196
+ * tags: {
197
+ * Environment: "production"
198
+ * }
199
+ * });
200
+ *
201
+ * @example
202
+ * // Create a function with environment variables and custom memory/timeout
203
+ * const configuredFunction = await Function("worker", {
204
+ * functionName: "worker",
205
+ * zipPath: "./dist/worker.zip",
206
+ * roleArn: role.arn,
207
+ * runtime: Runtime.nodejs20x,
208
+ * handler: "worker.process",
209
+ * memorySize: 512,
210
+ * timeout: 30,
211
+ * environment: {
212
+ * QUEUE_URL: queue.url,
213
+ * LOG_LEVEL: "info"
214
+ * }
215
+ * });
216
+ *
217
+ * @example
218
+ * // Create a function with a public URL endpoint and CORS
219
+ * const apiFunction = await Function("public-api", {
220
+ * functionName: "public-api",
221
+ * zipPath: "./dist/api.zip",
222
+ * roleArn: role.arn,
223
+ * handler: "api.handler",
224
+ * url: {
225
+ * authType: "NONE",
226
+ * cors: {
227
+ * allowOrigins: ["*"],
228
+ * allowMethods: ["GET", "POST"],
229
+ * allowHeaders: ["content-type"],
230
+ * maxAge: 86400
231
+ * }
232
+ * }
233
+ * });
234
+ */
235
+ export declare const Function: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Function>, id: string, props: FunctionProps) => Promise<Function>);
@@ -3,14 +3,60 @@ import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { Resource } from "../resource";
5
5
  import { ignore } from "../util/ignore";
6
- async function resolveRegion(client) {
7
- const region = client.config.region;
8
- if (typeof region === "string")
9
- return region;
10
- if (typeof region === "function")
11
- return region();
12
- throw new Error("Could not resolve AWS region");
13
- }
6
+ /**
7
+ * AWS Lambda Function Resource
8
+ *
9
+ * Creates and manages AWS Lambda functions with support for Node.js runtimes, custom handlers,
10
+ * environment variables, and function URLs. Handles deployment packaging, IAM role
11
+ * stabilization, and function updates.
12
+ *
13
+ * @example
14
+ * // Create a basic Lambda function with minimal configuration
15
+ * const basicFunction = await Function("api-handler", {
16
+ * functionName: "api-handler",
17
+ * zipPath: "./dist/api.zip",
18
+ * roleArn: role.arn,
19
+ * runtime: Runtime.nodejs20x,
20
+ * handler: "index.handler",
21
+ * tags: {
22
+ * Environment: "production"
23
+ * }
24
+ * });
25
+ *
26
+ * @example
27
+ * // Create a function with environment variables and custom memory/timeout
28
+ * const configuredFunction = await Function("worker", {
29
+ * functionName: "worker",
30
+ * zipPath: "./dist/worker.zip",
31
+ * roleArn: role.arn,
32
+ * runtime: Runtime.nodejs20x,
33
+ * handler: "worker.process",
34
+ * memorySize: 512,
35
+ * timeout: 30,
36
+ * environment: {
37
+ * QUEUE_URL: queue.url,
38
+ * LOG_LEVEL: "info"
39
+ * }
40
+ * });
41
+ *
42
+ * @example
43
+ * // Create a function with a public URL endpoint and CORS
44
+ * const apiFunction = await Function("public-api", {
45
+ * functionName: "public-api",
46
+ * zipPath: "./dist/api.zip",
47
+ * roleArn: role.arn,
48
+ * handler: "api.handler",
49
+ * url: {
50
+ * authType: "NONE",
51
+ * cors: {
52
+ * allowOrigins: ["*"],
53
+ * allowMethods: ["GET", "POST"],
54
+ * allowHeaders: ["content-type"],
55
+ * maxAge: 86400
56
+ * }
57
+ * }
58
+ * });
59
+ */
14
60
  export const Function = Resource("lambda::Function", async function (id, props) {
15
61
  const client = new LambdaClient({});
16
62
  const region = await resolveRegion(client);
@@ -172,3 +218,11 @@ async function zipCode(filePath) {
172
218
  platform: "UNIX",
173
219
  });
174
220
  }
221
+ async function resolveRegion(client) {
222
+ const region = client.config.region;
223
+ if (typeof region === "string")
224
+ return region;
225
+ if (typeof region === "function")
226
+ return region();
227
+ throw new Error("Could not resolve AWS region");
228
+ }
@@ -1,7 +1,88 @@
1
1
  import { OIDCProvider, type OIDCProviderProps } from "./oidc-provider";
2
+ /**
3
+ * Properties for configuring GitHub-specific OIDC provider
4
+ * Simplified version of OIDCProviderProps that omits the thumbprint
5
+ * since it's automatically set to GitHub's known value
6
+ */
2
7
  export interface GitHubOIDCProviderProps extends Omit<OIDCProviderProps, "thumbprint"> {
8
+ /**
9
+ * The GitHub organization or user that owns the repository
10
+ * Example: "my-org" or "my-username"
11
+ */
3
12
  owner: string;
13
+ /**
14
+ * The name of the GitHub repository
15
+ * Example: "my-repo"
16
+ */
4
17
  repository: string;
5
18
  }
6
19
  export type GitHubOIDCProvider = ReturnType<typeof GitHubOIDCProvider>;
20
+ /**
21
+ * GitHub-specific OIDC Provider Resource
22
+ *
23
+ * A simplified wrapper around OIDCProvider that automatically sets the correct
24
+ * thumbprint for GitHub Actions. This is the recommended way to set up OIDC
25
+ * authentication for GitHub Actions workflows.
26
+ *
27
+ * @example
28
+ * // Create a GitHub OIDC provider for all branches
29
+ * const provider = await GitHubOIDCProvider("github", {
30
+ * owner: "my-org",
31
+ * repository: "my-repo",
32
+ * roleArn: "arn:aws:iam::123456789012:role/github-actions"
33
+ * });
34
+ *
35
+ * @example
36
+ * // Create a GitHub OIDC provider with branch and environment restrictions
37
+ * const provider = await GitHubOIDCProvider("github-restricted", {
38
+ * owner: "my-org",
39
+ * repository: "my-repo",
40
+ * branches: ["main", "prod"],
41
+ * environments: ["staging", "production"],
42
+ * roleArn: "arn:aws:iam::123456789012:role/github-actions",
43
+ * maxSessionDuration: 7200
44
+ * });
45
+ *
46
+ * @example
47
+ * // Complete setup with IAM role and OIDC provider
48
+ * import { Role, getAccountId } from "../aws";
49
+ *
50
+ * // Get the AWS account ID
51
+ * const accountId = await getAccountId();
52
+ *
53
+ * // Create the IAM role that GitHub Actions will assume
54
+ * const githubRole = await Role("github-oidc-role", {
55
+ * roleName: "github-actions-role",
56
+ * assumeRolePolicy: {
57
+ * Version: "2012-10-17",
58
+ * Statement: [
59
+ * {
60
+ * Sid: "GitHubOIDC",
61
+ * Effect: "Allow",
62
+ * Principal: {
63
+ * Federated: `arn:aws:iam::${accountId}:oidc-provider/token.actions.githubusercontent.com`
64
+ * },
65
+ * Action: "sts:AssumeRoleWithWebIdentity",
66
+ * Condition: {
67
+ * StringEquals: {
68
+ * "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
69
+ * },
70
+ * StringLike: {
71
+ * "token.actions.githubusercontent.com:sub": "repo:my-org/my-repo:*"
72
+ * }
73
+ * }
74
+ * }
75
+ * ]
76
+ * },
77
+ * // Add required managed policies or inline policies for your use case
78
+ * managedPolicyArns: ["arn:aws:iam::aws:policy/ReadOnlyAccess"]
79
+ * });
80
+ *
81
+ * // Create the OIDC provider using the role
82
+ * const provider = await GitHubOIDCProvider("github-oidc", {
83
+ * owner: "my-org",
84
+ * repository: "my-repo",
85
+ * roleArn: githubRole.arn
86
+ * });
87
+ */
7
88
  export declare const GitHubOIDCProvider: (id: string, props: GitHubOIDCProviderProps) => Promise<OIDCProvider>;