@stacksjs/cloud 0.70.23 → 0.70.25

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.
@@ -0,0 +1,15 @@
1
+ import type { CloudConfig } from '@stacksjs/ts-cloud';
2
+ import type { CloudOptions } from '../types';
3
+ /**
4
+ * Cloud orchestrator using ts-cloud InfrastructureGenerator.
5
+ *
6
+ * This replaces the previous CDK-based Stack class. Infrastructure is now
7
+ * generated as CloudFormation templates via ts-cloud and deployed through
8
+ * the deploy module.
9
+ */
10
+ export declare class Cloud {
11
+ props: CloudOptions;
12
+ constructor(cloudConfig: CloudConfig, props: CloudOptions);
13
+ generate(): string;
14
+ shouldDeployApi(): boolean;
15
+ }
@@ -1,8 +1,27 @@
1
- import type { CountryCode, RegisterDomainCommandOutput } from '@aws-sdk/client-route-53-domains';
2
1
  import type { Result } from '@stacksjs/error-handling';
3
-
4
- declare const appEnv: unknown;
5
2
  export declare function getSecurityGroupId(securityGroupName: string): Promise<Result<string | undefined, string>>;
3
+ export declare function purchaseDomain(domain: string, options: PurchaseOptions): Result<Promise<{ OperationId: string }>, Error>;
4
+ export declare function getJumpBoxInstanceId(name?: string): Promise<string | undefined>;
5
+ export declare function deleteEc2Instance(id: string, stackName?: string): Promise<Result<string, string>>;
6
+ export declare function deleteJumpBox(stackName?: string): Promise<Result<string, string>>;
7
+ export declare function deleteIamUsers(): Promise<Result<string, string>>;
8
+ export declare function deleteStacksBuckets(): Promise<Result<string, string | Error>>;
9
+ export declare function deleteStacksFunctions(): Promise<Result<string, string>>;
10
+ export declare function deleteLogGroups(): Promise<Result<string, Error>>;
11
+ export declare function deleteParameterStore(): Promise<Result<string, string>>;
12
+ export declare function deleteVpcs(): Promise<Result<string, Error>>;
13
+ export declare function deleteCdkRemnants(): Promise<Result<string, Error>>;
14
+ export declare function deleteSubnets(): Promise<Result<string, Error>>;
15
+ export declare function hasBeenDeployed(): Promise<Result<boolean, Error>>;
16
+ export declare function getJumpBoxInstanceProfileName(): Promise<Result<string | undefined, string>>;
17
+ export declare function addJumpBox(stackName?: string): Promise<Result<string, string>>;
18
+ export declare function getJumpBoxSecurityGroupName(): Promise<Result<string | undefined, string>>;
19
+ export declare function getSecurityGroupFromInstanceId(instanceId: string): Promise<string | undefined>;
20
+ export declare function isFirstDeployment(): Promise<boolean>;
21
+ export declare function isFailedState(): Promise<boolean>;
22
+ export declare function getOrCreateTimestamp(): Promise<string>;
23
+ // get the CloudFront distribution ID of the current stack
24
+ export declare function getCloudFrontDistributionId(): Promise<string>;
6
25
  export declare interface PurchaseOptions {
7
26
  domain: string
8
27
  years: number
@@ -15,7 +34,7 @@ export declare interface PurchaseOptions {
15
34
  adminAddressLine2: string
16
35
  adminCity: string
17
36
  adminState: string
18
- adminCountry: CountryCode
37
+ adminCountry: string
19
38
  adminZip: string
20
39
  adminPhone: string
21
40
  adminEmail: string
@@ -26,7 +45,7 @@ export declare interface PurchaseOptions {
26
45
  techAddressLine2: string
27
46
  techCity: string
28
47
  techState: string
29
- techCountry: CountryCode
48
+ techCountry: string
30
49
  techZip: string
31
50
  techPhone: string
32
51
  techEmail: string
@@ -37,36 +56,13 @@ export declare interface PurchaseOptions {
37
56
  registrantAddressLine2: string
38
57
  registrantCity: string
39
58
  registrantState: string
40
- registrantCountry: CountryCode
59
+ registrantCountry: string
41
60
  registrantZip: string
42
61
  registrantPhone: string
43
62
  registrantEmail: string
44
63
  privacyAdmin: boolean
45
64
  privacyTech: boolean
46
65
  privacyRegistrant: boolean
47
- contactType: ContactType
66
+ contactType: 'PERSON' | 'COMPANY' | 'ASSOCIATION' | 'PUBLIC_BODY' | 'RESELLER'
48
67
  verbose: boolean
49
68
  }
50
- export declare function purchaseDomain(domain: string, options: PurchaseOptions): Result<Promise<RegisterDomainCommandOutput>, Error>;
51
- export declare function getJumpBoxInstanceId(name?: string): Promise<string | undefined>;
52
- export declare function deleteEc2Instance(id: string, stackName?: string): Promise<Result<string, string>>;
53
- export declare function deleteJumpBox(stackName?: string): Promise<Result<string, string>>;
54
- export declare function deleteIamUsers(): Promise<Result<string, string>>;
55
- export declare function deleteStacksBuckets(): Promise<Result<string, string | Error>>;
56
- export declare function deleteStacksFunctions(): Promise<Result<string, string>>;
57
- export declare function deleteLogGroups(): Promise<Result<string, Error>>;
58
- export declare function deleteParameterStore(): Promise<Result<string, string>>;
59
- export declare function deleteVpcs(): Promise<Result<string, Error>>;
60
- export declare function deleteCdkRemnants(): Promise<Result<string, Error>>;
61
- export declare function deleteSubnets(): Promise<Result<string, Error>>;
62
- export declare function hasBeenDeployed(): Promise<Result<boolean, Error>>;
63
- export declare function getJumpBoxInstanceProfileName(): Promise<Result<string | undefined, string>>;
64
- export declare function addJumpBox(stackName?: string): Promise<Result<string, string>>;
65
- export declare function getJumpBoxSecurityGroupName(): Promise<Result<string | undefined, string>>;
66
- export declare function getSecurityGroupFromInstanceId(instanceId: string): Promise<string | undefined>;
67
- export declare function isFirstDeployment(): Promise<boolean>;
68
- export declare function isFailedState(): Promise<boolean>;
69
- export declare function getOrCreateTimestamp(): Promise<string>;
70
- export declare function getCloudFrontDistributionId(): Promise<string>;
71
-
72
- export { InstanceType }
@@ -0,0 +1,3 @@
1
+ export type * from './types';
2
+ export * from './cloud';
3
+ export * from './helpers';
@@ -1,7 +1,5 @@
1
1
  import type { AppEnvType } from '@stacksjs/types';
2
- import type { StackProps } from 'aws-cdk-lib';
3
-
4
- export declare interface CloudOptions extends StackProps {
2
+ export declare interface CloudOptions {
5
3
  name: string
6
4
  env: {
7
5
  account: string
@@ -24,4 +22,4 @@ export declare interface NestedCloudProps {
24
22
  appName: string
25
23
  domain: string
26
24
  timestamp: string
27
- }
25
+ }
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@stacksjs/cloud",
3
3
  "type": "module",
4
- "version": "0.70.23",
4
+ "version": "0.70.25",
5
5
  "description": "The Stacks cloud/serverless integration & implementation.",
6
6
  "author": "Chris Breuer",
7
- "contributors": ["Chris Breuer <chris@stacksjs.org>"],
7
+ "contributors": [
8
+ "Chris Breuer <chris@stacksjs.com>"
9
+ ],
8
10
  "license": "MIT",
9
11
  "funding": "https://github.com/sponsors/chrisbbreuer",
10
12
  "homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/cloud#readme",
@@ -26,54 +28,40 @@
26
28
  ],
27
29
  "exports": {
28
30
  ".": {
31
+ "bun": "./src/index.ts",
29
32
  "types": "./dist/index.d.ts",
30
33
  "import": "./dist/index.js"
31
34
  },
32
35
  "./*": {
36
+ "bun": "./src/*",
33
37
  "import": "./dist/*"
34
38
  }
35
39
  },
36
40
  "module": "dist/index.js",
37
41
  "types": "dist/index.d.ts",
38
- "files": ["README.md", "dist"],
42
+ "files": [
43
+ "README.md",
44
+ "dist"
45
+ ],
39
46
  "scripts": {
40
- "bootstrap": "bunx --bun cdk bootstrap",
41
- "deploy": "cd ../.. && bun run build && cd ../docs && bun run build && cd ../core/cloud && bunx --bun cdk deploy --require-approval never",
42
47
  "build": "bun build.ts",
43
- "build-edge": "bun build ./src/edge/origin-request.ts --outfile ./dist/origin-request.js",
44
48
  "typecheck": "bun tsc --noEmit",
45
49
  "prepublishOnly": "bun run build"
46
50
  },
51
+ "dependencies": {
52
+ "@stacksjs/ts-cloud": "^0.2.15"
53
+ },
47
54
  "devDependencies": {
48
- "@aws-sdk/client-bedrock": "^3.777.0",
49
- "@aws-sdk/client-cloudformation": "^3.777.0",
50
- "@aws-sdk/client-cloudfront": "^3.777.0",
51
- "@aws-sdk/client-cloudwatch-logs": "^3.777.0",
52
- "@aws-sdk/client-dynamodb": "3.777.0",
53
- "@aws-sdk/client-ec2": "^3.779.0",
54
- "@aws-sdk/client-efs": "^3.777.0",
55
- "@aws-sdk/client-iam": "^3.777.0",
56
- "@aws-sdk/client-lambda": "^3.777.0",
57
- "@aws-sdk/client-route-53-domains": "^3.777.0",
58
- "@aws-sdk/client-s3": "^3.779.0",
59
- "@aws-sdk/client-ses": "^3.777.0",
60
- "@aws-sdk/client-sesv2": "^3.779.0",
61
- "@aws-sdk/client-ssm": "^3.777.0",
62
- "@stacksjs/cli": "0.70.22",
63
- "@stacksjs/config": "0.70.22",
64
- "@stacksjs/development": "0.70.22",
65
- "@stacksjs/dns": "0.70.22",
66
- "@stacksjs/env": "0.70.22",
67
- "@stacksjs/logging": "0.70.22",
68
- "@stacksjs/path": "0.70.22",
69
- "@stacksjs/router": "0.70.22",
70
- "@stacksjs/storage": "0.70.22",
71
- "@stacksjs/utils": "0.70.22",
72
- "@stacksjs/validation": "0.70.22",
73
- "aws-cdk": "^2.1006.0",
74
- "aws-cdk-lib": "^2.187.0",
75
- "aws4fetch": "^1.0.20",
76
- "constructs": "^10.4.2",
77
- "source-map-support": "^0.5.21"
55
+ "@stacksjs/cli": "0.70.23",
56
+ "@stacksjs/config": "0.70.23",
57
+ "better-dx": "^0.2.12",
58
+ "@stacksjs/dns": "0.70.23",
59
+ "@stacksjs/env": "0.70.23",
60
+ "@stacksjs/logging": "0.70.23",
61
+ "@stacksjs/path": "0.70.23",
62
+ "@stacksjs/router": "0.70.23",
63
+ "@stacksjs/storage": "0.70.23",
64
+ "@stacksjs/utils": "0.70.23",
65
+ "@stacksjs/validation": "0.70.23"
78
66
  }
79
67
  }
package/dist/ai.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { Construct } from 'constructs';
2
- import type { NestedCloudProps } from '../types';
3
-
4
- export declare interface AiStackProps extends NestedCloudProps {}
5
- export declare class AiStack {
6
- constructor(scope: Construct, props: AiStackProps) {
7
- const bedrockAccessPolicy = new iam.PolicyStatement({
8
- effect: iam.Effect.ALLOW,
9
- actions: ['bedrock:InvokeModel', 'bedrock:InvokeModelWithResponseStream'],
10
- resources: config.ai.models?.map((model: string) => `arn:aws:bedrock:us-east-1::foundation-model/${model}`),
11
- })
12
-
13
- const bedrockAccessRole = new iam.Role(scope, 'BedrockAccessRole', {
14
- assumedBy: new iam.ServicePrincipal('ecs-tasks.amazonaws.com'),
15
- managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonECSTaskExecutionRolePolicy')],
16
- })
17
-
18
- bedrockAccessRole.addToPolicy(bedrockAccessPolicy)
19
- }
20
- }
package/dist/cdn.d.ts DELETED
@@ -1,271 +0,0 @@
1
- import type { ApplicationLoadBalancer } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
2
- import type { Construct } from 'constructs';
3
- import type { NestedCloudProps } from '../types';
4
-
5
- export declare interface CdnStackProps extends NestedCloudProps {
6
- certificate: acm.Certificate
7
- logBucket: s3.Bucket
8
- publicBucket: s3.Bucket
9
- docsBucket?: s3.Bucket
10
- firewall: wafv2.CfnWebACL
11
- originRequestFunction: lambda.Function
12
- zone: route53.IHostedZone
13
- webServer?: lambda.Function
14
- webServerUrl?: lambda.FunctionUrl
15
- lb?: ApplicationLoadBalancer
16
- }
17
- export declare class CdnStack {
18
- mainDistribution: cloudfront.Distribution
19
- docsDistribution: cloudfront.Distribution | undefined
20
- cdnCachePolicy: cloudfront.CachePolicy
21
- mainVanityUrl!: string
22
- docsVanityUrl: string | undefined
23
- realtimeLogConfig!: cloudfront.RealtimeLogConfig
24
- props: CdnStackProps
25
-
26
- constructor(scope: Construct, props: CdnStackProps) {
27
- this.props = props
28
-
29
- this.cdnCachePolicy = new cloudfront.CachePolicy(scope, 'CdnCachePolicy', {
30
- comment: 'Stacks CDN Cache Policy',
31
- cachePolicyName: `${props.slug}-${props.appEnv}-cdn-cache-policy`,
32
- minTtl: config.cloud.cdn?.minTtl ? Duration.seconds(config.cloud.cdn.minTtl) : undefined,
33
- defaultTtl: config.cloud.cdn?.defaultTtl ? Duration.seconds(config.cloud.cdn.defaultTtl) : undefined,
34
- maxTtl: config.cloud.cdn?.maxTtl ? Duration.seconds(config.cloud.cdn.maxTtl) : undefined,
35
- cookieBehavior: this.getCookieBehavior(config.cloud.cdn?.cookieBehavior),
36
- })
37
-
38
- const originAccessControl = new cloudfront.S3OriginAccessControl(scope, 'WebOAC', {
39
- originAccessControlName: `${props.slug}-${props.appEnv}-web-oac-${props.timestamp}`,
40
- description: 'Access from CloudFront to the frontend bucket.',
41
- signing: cloudfront.Signing.SIGV4_NO_OVERRIDE,
42
- })
43
-
44
- if (config.app.docMode) {
45
- this.mainDistribution = this.createDistribution(
46
- scope,
47
- props,
48
- props.docsBucket as s3.Bucket,
49
- this.createDocsOriginRequestFunction(scope),
50
- props.domain,
51
- 'MainCdn',
52
- originAccessControl,
53
- )
54
- }
55
- else {
56
- this.mainDistribution = this.createDistribution(
57
- scope,
58
- props,
59
- props.publicBucket,
60
- props.originRequestFunction,
61
- props.domain,
62
- 'MainCdn',
63
- originAccessControl,
64
- )
65
-
66
- if (props.docsBucket) {
67
- this.docsDistribution = this.createDistribution(
68
- scope,
69
- props,
70
- props.docsBucket,
71
- this.createDocsOriginRequestFunction(scope),
72
- `docs.${props.domain}`,
73
- 'DocsCdn',
74
- originAccessControl,
75
- )
76
- }
77
- }
78
-
79
- this.createRoute53Records(scope, props)
80
-
81
- this.createOutputs(scope, props)
82
- }
83
-
84
- createDistribution(
85
- scope: Construct,
86
- props: CdnStackProps,
87
- sourceBucket: s3.Bucket,
88
- originRequestFunction: lambda.Function,
89
- domainName: string,
90
- id: string,
91
- originAccessControl: cloudfront.S3OriginAccessControl,
92
- ): cloudfront.Distribution {
93
- return new cloudfront.Distribution(scope, id, {
94
- domainNames: [domainName],
95
- defaultRootObject: 'index.html',
96
- comment: `CDN for ${domainName}`,
97
- certificate: props.certificate,
98
- enableLogging: true,
99
- logBucket: props.logBucket,
100
- httpVersion: cloudfront.HttpVersion.HTTP2_AND_3,
101
- priceClass: cloudfront.PriceClass.PRICE_CLASS_ALL,
102
- enabled: true,
103
- minimumProtocolVersion: cloudfront.SecurityPolicyProtocol.TLS_V1_2_2021,
104
- webAclId: props.firewall.attrArn,
105
- enableIpv6: true,
106
- defaultBehavior: {
107
- origin: new origins.S3StaticWebsiteOrigin(sourceBucket, {
108
- originPath: '/',
109
- originAccessControlId: originAccessControl.originAccessControlId,
110
- }),
111
- edgeLambdas: [
112
- {
113
- eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
114
- functionVersion: originRequestFunction.currentVersion,
115
- },
116
- ],
117
- compress: config.cloud.cdn?.compress,
118
- allowedMethods: this.allowedMethods(),
119
- cachedMethods: this.cachedMethods(),
120
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
121
- cachePolicy: this.cdnCachePolicy,
122
- },
123
- errorResponses: [
124
- {
125
- httpStatus: 404,
126
- responsePagePath: '/index.html',
127
- responseHttpStatus: 200,
128
- ttl: Duration.millis(0),
129
- },
130
- {
131
- httpStatus: 403,
132
- responsePagePath: '/index.html',
133
- responseHttpStatus: 200,
134
- ttl: Duration.millis(0),
135
- },
136
- ],
137
- })
138
- }
139
-
140
- createRoute53Records(scope: Construct, props: CdnStackProps): void {
141
- new route53.ARecord(scope, 'MainAliasRecord', {
142
- recordName: props.domain,
143
- zone: props.zone,
144
- target: route53.RecordTarget.fromAlias(new targets.CloudFrontTarget(this.mainDistribution)),
145
- })
146
-
147
- if (this.docsDistribution) {
148
- new route53.ARecord(scope, 'DocsAliasRecord', {
149
- recordName: `docs.${props.domain}`,
150
- zone: props.zone,
151
- target: route53.RecordTarget.fromAlias(new targets.CloudFrontTarget(this.docsDistribution)),
152
- })
153
- }
154
- }
155
-
156
- createOutputs(scope: Construct, props: CdnStackProps): void {
157
- new Output(scope, 'MainDistributionId', {
158
- value: this.mainDistribution.distributionId,
159
- })
160
-
161
- new Output(scope, 'MainUrl', {
162
- value: `https:
163
- description: 'The URL of the deployed main application',
164
- })
165
-
166
- this.mainVanityUrl = `https:
167
- new Output(scope, 'MainVanityUrl', {
168
- value: this.mainVanityUrl,
169
- description: 'The vanity URL of the deployed main application',
170
- })
171
-
172
- if (this.docsDistribution) {
173
- new Output(scope, 'DocsDistributionId', {
174
- value: this.docsDistribution.distributionId,
175
- })
176
-
177
- this.docsVanityUrl = `https:
178
- new Output(scope, 'DocsAppVanityUrl', {
179
- value: this.docsVanityUrl,
180
- description: 'The vanity URL of the deployed docs application',
181
- })
182
- }
183
- }
184
-
185
- createDocsOriginRequestFunction(scope: Construct): lambda.Function {
186
- const docsOriginRequestFunction = new lambda.Function(scope, 'DocsOriginRequestFunction', {
187
- functionName: `${this.props.slug}-${this.props.appEnv}-docs-origin-request-function-${this.props.timestamp}`,
188
- description: 'Custom origin request function for the docs',
189
- runtime: lambda.Runtime.NODEJS_20_X,
190
- handler: 'index.handler',
191
- code: lambda.Code.fromInline(`
192
- const config = {
193
- suffix: '.html',
194
- }
195
-
196
- const regexSuffixless = /\\/[^/.]+$/
197
- const regexTrailingSlash = /.+\\/$/
198
-
199
- exports.handler = (event, context, callback) => {
200
- const request = event.Records[0].cf.request;
201
- const uri = request.uri;
202
-
203
- if (uri === '/') {
204
- request.uri = '/index.html';
205
- callback(null, request);
206
- return;
207
- }
208
-
209
- if (uri.match(regexSuffixless)) {
210
- request.uri = uri + '.html';
211
- callback(null, request);
212
- return;
213
- }
214
-
215
- if (uri.match(regexTrailingSlash)) {
216
- request.uri = uri.slice(0, -1) + '.html';
217
- callback(null, request);
218
- return;
219
- }
220
-
221
- callback(null, request);
222
- };
223
- `),
224
- })
225
-
226
- new lambda.CfnPermission(scope, 'DocsOriginRequestFunctionPermission', {
227
- action: 'lambda:InvokeFunction',
228
- principal: 'edgelambda.amazonaws.com',
229
- functionName: docsOriginRequestFunction.functionName,
230
- })
231
-
232
- return docsOriginRequestFunction
233
- }
234
-
235
- getCookieBehavior(cookieBehavior: string | undefined): cloudfront.CacheCookieBehavior | undefined {
236
- switch (cookieBehavior) {
237
- case 'none':
238
- return cloudfront.CacheCookieBehavior.none()
239
- case 'all':
240
- return cloudfront.CacheCookieBehavior.all()
241
- case 'allowList':
242
- return cloudfront.CacheCookieBehavior.allowList(...(config.cloud.cdn?.allowList.cookies || []))
243
- default:
244
- return undefined
245
- }
246
- }
247
-
248
- allowedMethods(): cloudfront.AllowedMethods {
249
- switch (config.cloud.cdn?.allowedMethods) {
250
- case 'ALL':
251
- return cloudfront.AllowedMethods.ALLOW_ALL
252
- case 'GET_HEAD':
253
- return cloudfront.AllowedMethods.ALLOW_GET_HEAD
254
- case 'GET_HEAD_OPTIONS':
255
- return cloudfront.AllowedMethods.ALLOW_GET_HEAD_OPTIONS
256
- default:
257
- return cloudfront.AllowedMethods.ALLOW_ALL
258
- }
259
- }
260
-
261
- cachedMethods(): cloudfront.CachedMethods {
262
- switch (config.cloud.cdn?.cachedMethods) {
263
- case 'GET_HEAD':
264
- return cloudfront.CachedMethods.CACHE_GET_HEAD
265
- case 'GET_HEAD_OPTIONS':
266
- return cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS
267
- default:
268
- return cloudfront.CachedMethods.CACHE_GET_HEAD
269
- }
270
- }
271
- }
package/dist/cli.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import type { Construct } from 'constructs';
2
- import type { NestedCloudProps } from '../types';
3
-
4
- export declare interface CliStackProps extends NestedCloudProps {}
5
- export declare class CliStack {
6
- constructor(scope: Construct, props: CliStackProps) {
7
- new Output(scope, 'CliSetupUrl', {
8
- value: `https:
9
- description: 'URL to trigger the CLI setup function',
10
- })
11
- }
12
- }