@stacksjs/cloud 0.58.48 → 0.58.50

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 (42) hide show
  1. package/dist/index.js +144 -60
  2. package/package.json +34 -33
  3. package/src/cloud/ai.ts +94 -0
  4. package/src/cloud/aws-sdk-layer/nodejs/package-lock.json +386 -0
  5. package/src/cloud/aws-sdk-layer/nodejs/package.json +15 -0
  6. package/src/cloud/cache.ts +0 -0
  7. package/src/cloud/cdn.ts +374 -0
  8. package/src/cloud/cli.ts +45 -0
  9. package/src/cloud/compute.ts +202 -0
  10. package/src/cloud/dashboard.ts +85 -0
  11. package/src/cloud/database.ts +0 -0
  12. package/src/cloud/deployment.ts +41 -0
  13. package/src/cloud/dns.ts +34 -0
  14. package/src/cloud/docs.ts +51 -0
  15. package/src/cloud/email.ts +339 -0
  16. package/src/cloud/file-system.ts +35 -0
  17. package/src/cloud/index.ts +103 -0
  18. package/src/cloud/jump-box.ts +48 -0
  19. package/src/cloud/lambda/ask/index.js +35 -0
  20. package/src/cloud/lambda/cli-setup/index.js +67 -0
  21. package/src/cloud/lambda/summarize/index.js +35 -0
  22. package/src/cloud/network.ts +32 -0
  23. package/src/cloud/package/README.md +59 -0
  24. package/src/cloud/package/package.json +63 -0
  25. package/src/cloud/permissions.ts +33 -0
  26. package/src/cloud/queue.ts +0 -0
  27. package/src/cloud/redirects.ts +45 -0
  28. package/src/cloud/router-layer/nodejs/package.json +15 -0
  29. package/src/cloud/search-engine.ts +108 -0
  30. package/src/cloud/security.ts +259 -0
  31. package/src/cloud/storage.ts +168 -0
  32. package/src/edge/origin-request.ts +49 -0
  33. package/src/helpers.ts +597 -0
  34. package/src/index.ts +3 -0
  35. package/src/runtime/README.md +116 -0
  36. package/src/runtime/bootstrap +3 -0
  37. package/src/runtime/example/lambda.ts +36 -0
  38. package/src/runtime/runtime.ts +830 -0
  39. package/src/runtime/scripts/build-layer.ts +104 -0
  40. package/src/runtime/scripts/publish-layer.ts +110 -0
  41. package/src/runtime/server.ts +39 -0
  42. package/src/types.ts +28 -0
@@ -0,0 +1,104 @@
1
+ // HACK: https://github.com/oven-sh/bun/issues/2081
2
+ import { createReadStream, createWriteStream } from 'node:fs'
3
+ import process from 'node:process'
4
+ import { Command, Flags } from '@oclif/core'
5
+ import { path as p } from '@stacksjs/path'
6
+ import JSZip from 'jszip'
7
+
8
+ process.stdout.getWindowSize = () => [80, 80]
9
+ process.stderr.getWindowSize = () => [80, 80]
10
+
11
+ export class BuildCommand extends Command {
12
+ static summary = 'Build a custom Lambda layer for Stacks & Bun.'
13
+
14
+ static flags = {
15
+ arch: Flags.string({
16
+ description: 'The architecture type to support.',
17
+ options: ['x64', 'aarch64'],
18
+ default: 'aarch64',
19
+ }),
20
+ release: Flags.string({
21
+ description: 'The release of Bun to install.',
22
+ default: 'latest',
23
+ }),
24
+ url: Flags.string({
25
+ description: 'A custom URL to download Bun.',
26
+ exclusive: ['release'],
27
+ }),
28
+ output: Flags.file({
29
+ exists: false,
30
+
31
+ default: async () => ['bun-lambda-layer.zip'],
32
+ }),
33
+ layer: Flags.string({
34
+ description: 'The name of the Lambda layer.',
35
+ multiple: true,
36
+ default: ['stacks'],
37
+ }),
38
+ region: Flags.string({
39
+ description: 'The region to publish the layer.',
40
+ multiple: true,
41
+ default: [],
42
+ }),
43
+ public: Flags.boolean({
44
+ description: 'If the layer should be public.',
45
+ default: false,
46
+ }),
47
+ }
48
+
49
+ async run() {
50
+ const result = await this.parse(BuildCommand)
51
+ const { flags } = result
52
+ this.debug('Options:', flags)
53
+ const { arch, release, url, output } = flags
54
+ const { href } = new URL(url ?? `https://bun.sh/download/${release}/linux/${arch}?avx2=true`)
55
+ this.log('Downloading...', href)
56
+ const response = await fetch(href, {
57
+ headers: {
58
+ 'User-Agent': 'stacks-lambda',
59
+ },
60
+ })
61
+ if (response.url !== href)
62
+ this.debug('Redirected URL:', response.url)
63
+
64
+ this.debug('Response:', response.status, response.statusText)
65
+ if (!response.ok) {
66
+ const reason = await response.text()
67
+ this.error(reason, { exit: 1 })
68
+ }
69
+ this.log('Extracting...')
70
+ const buffer = await response.arrayBuffer()
71
+ let archive
72
+ try {
73
+ archive = await JSZip.loadAsync(buffer)
74
+ }
75
+ catch (cause) {
76
+ this.debug(cause)
77
+ this.error('Failed to unzip file:', { exit: 1 })
78
+ }
79
+ this.debug('Extracted archive:', Object.keys(archive.files))
80
+ const bun = archive.filter((_, { dir, name }) => !dir && name.endsWith('bun'))[0]
81
+ if (!bun)
82
+ this.error('Failed to find executable in zip', { exit: 1 })
83
+
84
+ const cwd = bun.name.split('/')[0]
85
+ archive = archive.folder(cwd) ?? archive
86
+ for (const filename of ['bootstrap', 'runtime.ts']) {
87
+ const path = p.join(__dirname, '..', filename)
88
+ archive.file(filename, createReadStream(path))
89
+ }
90
+ this.log('Saving...', output)
91
+ archive
92
+ .generateNodeStream({
93
+ streamFiles: true,
94
+ compression: 'DEFLATE',
95
+ compressionOptions: {
96
+ level: 9,
97
+ },
98
+ })
99
+ .pipe(createWriteStream(p.projectStoragePath(`framework/cloud/${output}`)))
100
+ this.log('Saved')
101
+ }
102
+ }
103
+
104
+ await BuildCommand.run(process.argv.slice(2))
@@ -0,0 +1,110 @@
1
+ import { spawnSync } from 'node:child_process'
2
+ import process from 'node:process'
3
+ import { BuildCommand } from './build-layer'
4
+
5
+ export class PublishCommand extends BuildCommand {
6
+ static summary = 'Publish a custom Lambda layer for Bun.'
7
+
8
+ #aws(args: string[]): string {
9
+ this.debug('$', 'aws', ...args)
10
+ const { status, stdout, stderr } = spawnSync('aws', args, {
11
+ stdio: 'pipe',
12
+ })
13
+ const result = stdout.toString('utf-8').trim()
14
+ if (status === 0)
15
+ return result
16
+
17
+ const reason = stderr.toString('utf-8').trim() || result
18
+ throw new Error(`aws ${args.join(' ')} exited with ${status}: ${reason}`)
19
+ }
20
+
21
+ async run() {
22
+ const { flags } = await this.parse(PublishCommand)
23
+ this.debug('Options:', flags)
24
+ try {
25
+ const version = this.#aws(['--version'])
26
+ this.debug('AWS CLI:', version)
27
+ }
28
+ catch (error) {
29
+ this.debug(error)
30
+ this.error(
31
+ 'Install the `aws` CLI to continue: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html',
32
+ { exit: 1 },
33
+ )
34
+ }
35
+ const { layer, region, arch, output, public: _isPublic } = flags
36
+ if (region.includes('*')) {
37
+ // prettier-ignore
38
+ const result = this.#aws([
39
+ 'ec2',
40
+ 'describe-regions',
41
+ '--query',
42
+ 'Regions[].RegionName',
43
+ '--output',
44
+ 'json',
45
+ ])
46
+ region.length = 0
47
+ for (const name of JSON.parse(result))
48
+ region.push(name)
49
+ }
50
+ else if (!region.length) {
51
+ // prettier-ignore
52
+ region.push(this.#aws([
53
+ 'configure',
54
+ 'get',
55
+ 'region',
56
+ ]))
57
+ }
58
+ this.log('Publishing...')
59
+ for (const regionName of region) {
60
+ for (const layerName of layer) {
61
+ // prettier-ignore
62
+ const result = this.#aws([
63
+ 'lambda',
64
+ 'publish-layer-version',
65
+ '--layer-name',
66
+ layerName,
67
+ '--region',
68
+ regionName,
69
+ '--description',
70
+ 'Bun is an incredibly fast JavaScript runtime, bundler, transpiler, and package manager.',
71
+ '--license-info',
72
+ 'MIT',
73
+ '--compatible-architectures',
74
+ arch === 'x64' ? 'x86_64' : 'arm64',
75
+ '--compatible-runtimes',
76
+ 'provided.al2',
77
+ 'provided',
78
+ '--zip-file',
79
+ `fileb://${output}`,
80
+ '--output',
81
+ 'json',
82
+ ])
83
+ const { LayerVersionArn } = JSON.parse(result)
84
+ this.log('Published', LayerVersionArn)
85
+ // if (isPublic) {
86
+ // prettier-ignore
87
+ this.#aws([
88
+ 'lambda',
89
+ 'add-layer-version-permission',
90
+ '--layer-name',
91
+ layerName,
92
+ '--region',
93
+ regionName,
94
+ '--version-number',
95
+ LayerVersionArn.split(':').pop(),
96
+ '--statement-id',
97
+ `${layerName}-public`,
98
+ '--action',
99
+ 'lambda:GetLayerVersion',
100
+ '--principal',
101
+ '*',
102
+ ])
103
+ // }
104
+ }
105
+ }
106
+ this.log('Done')
107
+ }
108
+ }
109
+
110
+ await PublishCommand.run(process.argv.slice(2))
@@ -0,0 +1,39 @@
1
+ import type { Server } from 'bun'
2
+ import { serverResponse } from '@stacksjs/router'
3
+
4
+ export default {
5
+ async fetch(request: Request, server: Server): Promise<Response | undefined> {
6
+ // eslint-disable-next-line no-console
7
+ console.log('Request', {
8
+ url: request.url,
9
+ method: request.method,
10
+ headers: request.headers.toJSON(),
11
+ body: request.body ? await request.text() : null,
12
+ })
13
+
14
+ if (server.upgrade(request)) {
15
+ // eslint-disable-next-line no-console
16
+ console.log('WebSocket upgraded')
17
+ return
18
+ }
19
+
20
+ return serverResponse(request)
21
+ },
22
+
23
+ websocket: {
24
+ // async open(ws: ServerWebSocket): Promise<void> {
25
+ // // eslint-disable-next-line no-console
26
+ // console.log('WebSocket opened')
27
+ // },
28
+
29
+ // async message(ws: ServerWebSocket, message: string): Promise<void> {
30
+ // // eslint-disable-next-line no-console
31
+ // console.log('WebSocket message', message)
32
+ // },
33
+
34
+ // async close(ws: ServerWebSocket, code: number, reason?: string): Promise<void> {
35
+ // // eslint-disable-next-line no-console
36
+ // console.log('WebSocket closed', { code, reason })
37
+ // },
38
+ },
39
+ }
package/src/types.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { AppEnvType } from '@stacksjs/types'
2
+ import type { StackProps } from 'aws-cdk-lib'
3
+
4
+ export interface CloudOptions extends StackProps {
5
+ name: string
6
+ env: {
7
+ account: string
8
+ region: string
9
+ }
10
+ slug: string
11
+ appEnv: AppEnvType
12
+ appName: string
13
+ domain: string
14
+ timestamp: string
15
+ }
16
+
17
+ export interface NestedCloudProps {
18
+ name: string
19
+ env: {
20
+ account: string
21
+ region: string
22
+ }
23
+ slug: string
24
+ appEnv: AppEnvType
25
+ appName: string
26
+ domain: string
27
+ timestamp: string
28
+ }