@batijs/cli 0.0.259 → 0.0.261

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 (104) hide show
  1. package/dist/boilerplates/@batijs/authjs/files/$package.json.js +1 -1
  2. package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +2 -2
  3. package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +2 -3
  4. package/dist/boilerplates/@batijs/aws/files/$README.md.js +109 -0
  5. package/dist/boilerplates/@batijs/aws/files/$package.json.js +138 -0
  6. package/dist/boilerplates/@batijs/aws/files/$tsconfig.json.js +15 -0
  7. package/dist/boilerplates/@batijs/aws/files/cdk/$stack-name-suffix.json.js +19 -0
  8. package/dist/boilerplates/@batijs/aws/files/cdk/bin/infrastructure.ts +85 -0
  9. package/dist/boilerplates/@batijs/aws/files/cdk/lib/vike-stack.ts +186 -0
  10. package/dist/boilerplates/@batijs/aws/files/cdk.json +72 -0
  11. package/dist/boilerplates/@batijs/aws/files/tests/aws_handler.spec.ts +116 -0
  12. package/dist/boilerplates/@batijs/aws/files/vitest.config.ts +8 -0
  13. package/dist/boilerplates/@batijs/aws/types/cdk/bin/infrastructure.d.ts +11 -0
  14. package/dist/boilerplates/@batijs/aws/types/cdk/lib/vike-stack.d.ts +13 -0
  15. package/dist/boilerplates/@batijs/aws/types/vitest.config.d.ts +2 -0
  16. package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +1 -1
  17. package/dist/boilerplates/@batijs/cloudflare/files/$tsconfig.json.js +10 -0
  18. package/dist/boilerplates/@batijs/d1/files/$README.md.js +0 -4
  19. package/dist/boilerplates/@batijs/d1/files/$package.json.js +96 -0
  20. package/dist/boilerplates/@batijs/d1/files/$wrangler.toml.js +1 -0
  21. package/dist/boilerplates/@batijs/d1/files/database/d1/helpers.ts +17 -0
  22. package/dist/boilerplates/@batijs/d1/files/vike.d.ts +8 -0
  23. package/dist/boilerplates/@batijs/d1/types/database/d1/helpers.d.ts +6 -0
  24. package/dist/boilerplates/@batijs/d1-sqlite/files/$package.json.js +10 -0
  25. package/dist/boilerplates/@batijs/d1-sqlite/files/database/d1/queries/lucia-auth.ts +28 -0
  26. package/dist/boilerplates/@batijs/d1-sqlite/files/database/d1/queries/todos.ts +10 -0
  27. package/dist/boilerplates/@batijs/d1-sqlite/files/database/migrations/lucia-auth.sql +20 -0
  28. package/dist/boilerplates/@batijs/d1-sqlite/files/database/migrations/todos.sql +4 -0
  29. package/dist/boilerplates/@batijs/d1-sqlite/types/database/d1/queries/lucia-auth.d.ts +5 -0
  30. package/dist/boilerplates/@batijs/d1-sqlite/types/database/d1/queries/todos.d.ts +6 -0
  31. package/dist/boilerplates/@batijs/drizzle/files/$.env.js +1 -0
  32. package/dist/boilerplates/@batijs/drizzle/files/$README.md.js +0 -3
  33. package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +7 -14
  34. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +10 -12
  35. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/lucia-auth.ts +38 -9
  36. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +16 -5
  37. package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +7 -4
  38. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.ts +2 -2
  39. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/lucia-auth.d.ts +19 -6
  40. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.ts +9 -2
  41. package/dist/boilerplates/@batijs/eslint/files/$package.json.js +1 -1
  42. package/dist/boilerplates/@batijs/eslint/files/eslint.config.js +2 -1
  43. package/dist/boilerplates/@batijs/express/files/$package.json.js +2 -1
  44. package/dist/boilerplates/@batijs/express/files/express-entry.ts +13 -12
  45. package/dist/boilerplates/@batijs/fastify/files/$package.json.js +2 -1
  46. package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +17 -24
  47. package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +2 -2
  48. package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +2 -2
  49. package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +2 -6
  50. package/dist/boilerplates/@batijs/h3/files/$package.json.js +1 -0
  51. package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +12 -2
  52. package/dist/boilerplates/@batijs/hattip/files/$package.json.js +15 -2
  53. package/dist/boilerplates/@batijs/hattip/files/entry_aws_lambda.ts +37 -0
  54. package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +12 -12
  55. package/dist/boilerplates/@batijs/hattip/types/entry_aws_lambda.d.ts +2 -0
  56. package/dist/boilerplates/@batijs/hono/files/$package.json.js +22 -4
  57. package/dist/boilerplates/@batijs/hono/files/entry_aws_lambda.ts +37 -0
  58. package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +12 -12
  59. package/dist/boilerplates/@batijs/hono/types/entry_aws_lambda.d.ts +3 -0
  60. package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +4 -1
  61. package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +75 -39
  62. package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +77 -33
  63. package/dist/boilerplates/@batijs/lucia-auth/types/lib/lucia-auth.d.ts +30 -10
  64. package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +13 -13
  65. package/dist/boilerplates/@batijs/react-lucia-auth/files/pages/login/+Page.tsx +2 -1
  66. package/dist/boilerplates/@batijs/shared/files/vite.config.ts +6 -0
  67. package/dist/boilerplates/@batijs/shared-db/files/server/db-middleware.ts +37 -0
  68. package/dist/boilerplates/@batijs/shared-db/types/server/db-middleware.d.ts +17 -0
  69. package/dist/boilerplates/@batijs/shared-no-db/files/$package.json.js +2 -1
  70. package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +5 -2
  71. package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +22 -4
  72. package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +2 -2
  73. package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.ts +19 -1
  74. package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +10 -4
  75. package/dist/boilerplates/@batijs/shared-todo/files/vike.d.ts +19 -0
  76. package/dist/boilerplates/@batijs/shared-todo/types/pages/todo/+data.d.ts +2 -1
  77. package/dist/boilerplates/@batijs/solid-lucia-auth/files/pages/login/+Page.tsx +2 -1
  78. package/dist/boilerplates/@batijs/sqlite/files/$.env.js +1 -0
  79. package/dist/boilerplates/@batijs/sqlite/files/$package.json.js +10 -1
  80. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/lucia-auth.ts +16 -15
  81. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/todos.ts +5 -5
  82. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/lucia-auth.d.ts +5 -5
  83. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/todos.d.ts +3 -2
  84. package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +5 -3
  85. package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +10 -3
  86. package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +15 -2
  87. package/dist/boilerplates/@batijs/telefunc/files/vike.d.ts +20 -0
  88. package/dist/boilerplates/@batijs/trpc/files/$package.json.js +10 -7
  89. package/dist/boilerplates/@batijs/trpc/files/server/trpc-handler.ts +22 -0
  90. package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +20 -4
  91. package/dist/boilerplates/@batijs/trpc/types/server/trpc-handler.d.ts +1 -0
  92. package/dist/boilerplates/@batijs/trpc/types/trpc/client.d.ts +36 -4
  93. package/dist/boilerplates/@batijs/trpc/types/trpc/server.d.ts +75 -8
  94. package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +4 -3
  95. package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +48 -27
  96. package/dist/boilerplates/@batijs/vue-lucia-auth/files/pages/login/+Page.vue +2 -1
  97. package/dist/boilerplates/boilerplates.json +61 -3
  98. package/dist/index.js +6 -1
  99. package/package.json +5 -5
  100. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/seed.ts +0 -13
  101. package/dist/boilerplates/@batijs/trpc/files/$vite.config.ts.js +0 -13
  102. package/dist/boilerplates/@batijs/trpc/files/trpc/vite-plugin.ts +0 -49
  103. package/dist/boilerplates/@batijs/trpc/types/trpc/vite-plugin.d.ts +0 -12
  104. /package/dist/boilerplates/@batijs/{drizzle/types/database/drizzle/seed.d.ts → aws/types/tests/aws_handler.spec.d.ts} +0 -0
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  "@auth/core": "^0.34.2",
45
45
  "@batijs/compile": "workspace:*",
46
46
  "@types/node": "^18.19.14",
47
- "@universal-middleware/core": "^0.2.5",
47
+ "@universal-middleware/core": "^0.2.6",
48
48
  dotenv: "^16.4.5"
49
49
  },
50
50
  dependencies: {
@@ -77,7 +77,7 @@ export async function getSession(req: Request, config: Omit<AuthConfig, "raw">):
77
77
  * Add Auth.js session to context
78
78
  * @link {@see https://authjs.dev/getting-started/session-management/get-session}
79
79
  **/
80
- export const authjsSessionMiddleware = (() => async (request, context) => {
80
+ export const authjsSessionMiddleware: Get<[], UniversalMiddleware> = () => async (request, context) => {
81
81
  try {
82
82
  return {
83
83
  ...context,
@@ -90,7 +90,7 @@ export const authjsSessionMiddleware = (() => async (request, context) => {
90
90
  session: null,
91
91
  };
92
92
  }
93
- }) satisfies Get<[], UniversalMiddleware>;
93
+ };
94
94
 
95
95
  /**
96
96
  * Auth.js route
@@ -1,5 +1,6 @@
1
1
  import { type AuthConfig } from "@auth/core";
2
2
  import type { Session } from "@auth/core/types";
3
+ import type { Get, UniversalMiddleware } from "@universal-middleware/core";
3
4
  /**
4
5
  * Retrieve Auth.js session from Request
5
6
  */
@@ -8,9 +9,7 @@ export declare function getSession(req: Request, config: Omit<AuthConfig, "raw">
8
9
  * Add Auth.js session to context
9
10
  * @link {@see https://authjs.dev/getting-started/session-management/get-session}
10
11
  **/
11
- export declare const authjsSessionMiddleware: () => (request: Request, context: Universal.Context) => Promise<{
12
- session: Session | null;
13
- }>;
12
+ export declare const authjsSessionMiddleware: Get<[], UniversalMiddleware>;
14
13
  /**
15
14
  * Auth.js route
16
15
  * @link {@see https://authjs.dev/getting-started/installation}
@@ -0,0 +1,109 @@
1
+ // files/$README.md.ts
2
+ import { loadReadme } from "@batijs/core";
3
+ async function getReadme(props) {
4
+ const content = await loadReadme(props);
5
+ const todo = `
6
+ ## *AWS CDK Deployment*
7
+
8
+ This is a boilerplate for deploying your Vike app to AWS using the AWS Cloud Development Kit (CDK) including creating a custom domain in Route53.
9
+
10
+ **Architecture:**
11
+ - S3 Bucket for static client assets (\`/dist/client/assets\`).
12
+ - Lambda function for the backend and SSR.
13
+ - CloudFront distribution for CDN and routing requests \`/assets/*\` to the S3 bucket.
14
+
15
+ This boilerplate is a starting point for deploying your Vike app to AWS. You can customize the deployment by modifying the \`cdk/lib/vike-stack.ts\` file.
16
+
17
+ ### Prerequisites
18
+
19
+ Before you get started, make sure to configure your AWS credentials.
20
+
21
+ **Loading from a file:**
22
+
23
+ You can keep your AWS credentials in a file. The credentials are found at:
24
+
25
+ \`~/.aws/credentials\` on Linux, Unix, and macOS;
26
+ \`C:\\Users\\USER_NAME\\.aws\\credentials\` on Windows
27
+
28
+ If the credentials file does not exist on your machine:
29
+
30
+ Download the AWS CLI from [here](https://aws.amazon.com/cli/) and configure your AWS credentials using the following command:
31
+ \`aws configure\`
32
+
33
+ And then use this guide to configure the credentials
34
+ The credentials file should look like:
35
+
36
+ \`
37
+ [default]
38
+ aws_access_key_id = <YOUR_ACCESS_KEY_ID>
39
+ aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
40
+ \`
41
+
42
+ **Loading from environment variables:**
43
+
44
+ AWS SDK automatically detects AWS credentials in your environment and uses them for making requests to AWS. The environment variables that you need to set are:
45
+
46
+ \`AWS_ACCESS_KEY_ID\`
47
+ \`AWS_SECRET_ACCESS_KEY\`
48
+ If you are using temporary credentials, also set:
49
+
50
+ \`AWS_SESSION_TOKEN\`
51
+ This is often the most convenient way to configure credentials when deploying your AWS CDK app in a CI environment.
52
+
53
+ > [!NOTE]
54
+ > You should change the stack name to give your app stack a distinctive name in your AWS environment. You can do so by modifying the \`infrastructure.ts.ts\` file in the \`cdk/bin\` directory.
55
+
56
+ ### Deployment to AWS
57
+
58
+ If you want to have a look at the synthesized CloudFormation template, you can run \`pnpm cdk synth\` and see the template as YAML on screen or in \`cdk.out/VikeStack.template.json\`.
59
+
60
+ > [!NOTE]
61
+ > If this is your **first time deploying a CDK app** in this environment you need to **bootstrap**:
62
+ > \`pnpm cdk bootstrap\`. (The default region based on your AWS CLI configuration will be used)
63
+
64
+ You can deploy your Vike App via the following command:
65
+ \`pnpm deploy:aws\` or \`pnpm cdk deploy\`
66
+
67
+ The URL to the CloudFront distribution will be displayed in the output of the deployment.
68
+ You can also access the CloudFront distribution domainname in the AWS SSM registry und \`vike/distribution/url\`.
69
+
70
+ ### Stack Configuration
71
+
72
+ You can configure the stack in the \`cdk/bin/infrastructure.ts\` file:
73
+ | --- | --- | --- |
74
+ | Variable | Examples | Description |
75
+ | \`domainName: "example.com",\` | "example.com" | |
76
+ | \`subDomain: "www",\` |"www" | |
77
+ | \`certificate: undefined,\` | "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012" or a certificatemanager.ICertificate | reuse an existing AWS Certificate |
78
+ | \`hostedZone: undefined,\` | route53.HostedZone.fromLookup(stack, "MyHostedZone", { domainName: "example.com" }) | |
79
+
80
+ If \`domainName\` is managed by **Route53**, the \`hostedZone\` will be updated with by lookup in Route53 based on the \`domainName\`.
81
+
82
+ These scenarios are supported:
83
+ A. \`domainName\` exists in Route53, \`subDomain\` is given - the subdomain with the domain are used as alternative domains for the CloudFront Distribution. An new Certificate for the url is created and assigned to the CF-Distribution. An Alias-Record pointing to the CF-Distribution ist created in Route53.
84
+ B. \`domainName\` exists in Route53, \`subDomain\` is given - the subdomain with the domain are used as alternative domains for the CloudFront Distribution. If \`certificate\` contains a valid entry it will be assigned to the CF-Distribution. An Alias-Record pointing to the CF-Distribution ist created in Route53.
85
+ C. \`domainName\` **does not exist** in Route53, \`subDomain\` is given - the subdomain with the domain are used as alternative domains for the CloudFront Distribution. If \`certificate\` contains a valid entry it will be assigned to the CF-Distribution. A manual created CNAME or A-Record should pointing to the CF-Distribution.
86
+
87
+ #### Custom Domain
88
+
89
+ If you have a custom domain, you can add it to the stack configuration in the \`cdk/bin/infrastructure.ts\` file:
90
+
91
+ > [!NOTE]
92
+ > If you deploy your App to a region different than \`us-east-1\` and you have never deployed to this region before, you will need to bootstrap this region too:
93
+ \`CDK_DEFAULT_REGION=us-east-1 pnpm deploy:cdk bootstrap\`
94
+
95
+
96
+ ### Destroying the Stack on AWS
97
+
98
+ To destroy the stack on AWS, run the following command:
99
+ \`pnpm cdk destroy\`
100
+
101
+ Or delete the CloudFormation stack which starts with "VikeStack-<Your App Name>" created by this project.
102
+
103
+ `;
104
+ content.addTodo(todo);
105
+ return content.finalize();
106
+ }
107
+ export {
108
+ getReadme as default
109
+ };
@@ -0,0 +1,138 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // package.json
28
+ var require_package = __commonJS({
29
+ "package.json"(exports, module) {
30
+ module.exports = {
31
+ name: "@batijs/aws",
32
+ private: true,
33
+ version: "0.0.1",
34
+ description: "",
35
+ type: "module",
36
+ scripts: {
37
+ "check-types": "tsc --noEmit",
38
+ build: "bati-compile-boilerplate"
39
+ },
40
+ keywords: [],
41
+ author: "",
42
+ license: "MIT",
43
+ devDependencies: {
44
+ "@batijs/compile": "workspace:*",
45
+ "@types/node": "^18.19.14",
46
+ "@types/which": "^3.0.4",
47
+ "aws-cdk": "^2.154.1",
48
+ "aws-cdk-lib": "^2.154.1",
49
+ cdk: "^2.154.1",
50
+ constructs: "^10.3.0",
51
+ esbuild: "^0.23.1",
52
+ "source-map-support": "^0.5.21",
53
+ tsx: "^4.19.0",
54
+ typescript: "^5.5.4",
55
+ vitest: "^2.0.5",
56
+ which: "^4.0.0"
57
+ },
58
+ dependencies: {
59
+ "@batijs/core": "workspace:*"
60
+ },
61
+ files: [
62
+ "dist/"
63
+ ],
64
+ bati: {
65
+ if: {
66
+ flag: "aws"
67
+ }
68
+ },
69
+ exports: {
70
+ "./vitest.config": {
71
+ types: "./dist/types/vitest.config.d.ts"
72
+ },
73
+ "./cdk/lib/vike-stack": {
74
+ types: "./dist/types/cdk/lib/vike-stack.d.ts"
75
+ },
76
+ "./cdk/bin/infrastructure": {
77
+ types: "./dist/types/cdk/bin/infrastructure.d.ts"
78
+ },
79
+ "./tests/aws_handler.spec": {
80
+ types: "./dist/types/tests/aws_handler.spec.d.ts"
81
+ }
82
+ },
83
+ typesVersions: {
84
+ "*": {
85
+ "vitest.config": [
86
+ "./dist/types/vitest.config.d.ts"
87
+ ],
88
+ "cdk/lib/vike-stack": [
89
+ "./dist/types/cdk/lib/vike-stack.d.ts"
90
+ ],
91
+ "cdk/bin/infrastructure": [
92
+ "./dist/types/cdk/bin/infrastructure.d.ts"
93
+ ],
94
+ "tests/aws_handler.spec": [
95
+ "./dist/types/tests/aws_handler.spec.d.ts"
96
+ ]
97
+ }
98
+ }
99
+ };
100
+ }
101
+ });
102
+
103
+ // files/$package.json.ts
104
+ import { addDependency, loadAsJson, setScripts } from "@batijs/core";
105
+ async function getPackageJson(props) {
106
+ const packageJson = await loadAsJson(props);
107
+ setScripts(packageJson, {
108
+ test: {
109
+ value: "vitest",
110
+ precedence: 0
111
+ },
112
+ "deploy:cdk": {
113
+ value: "cdk",
114
+ precedence: 0
115
+ },
116
+ "deploy:aws": {
117
+ value: "pnpm run build && cdk deploy --all",
118
+ precedence: 0
119
+ }
120
+ });
121
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
122
+ devDependencies: [
123
+ "cdk",
124
+ "aws-cdk",
125
+ "@types/node",
126
+ "tsx",
127
+ "typescript",
128
+ "esbuild",
129
+ "vitest",
130
+ "which",
131
+ "@types/which"
132
+ ],
133
+ dependencies: ["aws-cdk-lib", "constructs", "source-map-support"]
134
+ });
135
+ }
136
+ export {
137
+ getPackageJson as default
138
+ };
@@ -0,0 +1,15 @@
1
+ // files/$tsconfig.json.ts
2
+ import { loadAsJson } from "@batijs/core";
3
+ async function getTsConfig(props) {
4
+ const tsConfig = await loadAsJson(props);
5
+ tsConfig.compilerOptions.types = [
6
+ ...tsConfig.compilerOptions.types ?? [],
7
+ "@types/node",
8
+ "vitest/globals",
9
+ "@types/which"
10
+ ];
11
+ return tsConfig;
12
+ }
13
+ export {
14
+ getTsConfig as default
15
+ };
@@ -0,0 +1,19 @@
1
+ // files/cdk/$stack-name-suffix.json.ts
2
+ async function getDataJson() {
3
+ const dataJson = {
4
+ stackNameSuffix: generateRandomPrefix(8)
5
+ };
6
+ return dataJson;
7
+ }
8
+ function generateRandomPrefix(length) {
9
+ if (process.env.NODE_ENV === "test") return "TEST";
10
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
11
+ let result = "";
12
+ for (let i = 0; i < length; i++) {
13
+ result += characters.charAt(Math.floor(Math.random() * characters.length));
14
+ }
15
+ return result;
16
+ }
17
+ export {
18
+ getDataJson as default
19
+ };
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+ import "source-map-support/register";
3
+ import * as cdk from "aws-cdk-lib";
4
+ import { VikeStack } from "../lib/vike-stack";
5
+
6
+ import * as certificatemanager from "aws-cdk-lib/aws-certificatemanager";
7
+ import * as route53 from "aws-cdk-lib/aws-route53";
8
+
9
+ //# BATI.has("REMOVE-COMMENT") || "remove-comments-only"
10
+ // @ts-ignore file will be generated by the transformer
11
+ import { stackNameSuffix } from "../stack-name-suffix.json";
12
+
13
+ const env: cdk.Environment = {
14
+ account: process.env.CDK_DEFAULT_ACCOUNT,
15
+ region: process.env.CDK_DEFAULT_REGION,
16
+ };
17
+
18
+ export type CustomStackProps = cdk.StackProps & {
19
+ domainName?: string;
20
+ subDomain?: string;
21
+ certificate?: string | certificatemanager.ICertificate;
22
+ hostedZone?: route53.IHostedZone;
23
+ };
24
+
25
+ // Here you can configure the stack:
26
+ const customStackProps: CustomStackProps = {
27
+ domainName: undefined, // e.g. "example.com"
28
+ subDomain: undefined, // e.g. "www"
29
+ certificate: undefined, // e.g. "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012" or a certificatemanager.ICertificate
30
+ hostedZone: undefined, // e.g. route53.HostedZone.fromLookup(stack, "MyHostedZone", { domainName: "example.com" })
31
+ };
32
+
33
+ const app = new cdk.App();
34
+
35
+ const usEast1Stack = customStackProps?.domainName
36
+ ? new cdk.Stack(app, `VikeStack-Cert-${stackNameSuffix}`, {
37
+ env: {
38
+ ...env,
39
+ region: "us-east-1",
40
+ },
41
+ crossRegionReferences: true,
42
+ })
43
+ : undefined;
44
+
45
+ customStackProps.hostedZone = usEast1Stack
46
+ ? customStackProps?.hostedZone
47
+ ? customStackProps?.hostedZone
48
+ : customStackProps?.domainName
49
+ ? route53.HostedZone.fromLookup(usEast1Stack, "MyHostedZone", {
50
+ domainName: customStackProps.domainName,
51
+ })
52
+ : undefined
53
+ : undefined;
54
+
55
+ customStackProps.certificate = usEast1Stack ? loadCertificate(usEast1Stack, customStackProps) : undefined;
56
+
57
+ const mainStack = new VikeStack(app, `VikeStack-${stackNameSuffix}`, {
58
+ env,
59
+ crossRegionReferences: true,
60
+ customStackProps,
61
+ });
62
+
63
+ if (usEast1Stack) {
64
+ mainStack.addDependency(usEast1Stack);
65
+ app.synth();
66
+ }
67
+ function loadCertificate(stack: cdk.Stack, stackConfig: CustomStackProps): certificatemanager.ICertificate | undefined {
68
+ const { domainName, subDomain, certificate, hostedZone } = stackConfig;
69
+ if (typeof certificate === "string") {
70
+ certificatemanager.Certificate.fromCertificateArn(stack, "Certificate", certificate);
71
+ } else if (certificate) {
72
+ return certificate;
73
+ }
74
+
75
+ if (!domainName) {
76
+ return undefined;
77
+ }
78
+
79
+ const siteDomainName = `${(subDomain?.length ?? 0 > 0) ? `${subDomain}.` : ""}${domainName}`;
80
+ return new certificatemanager.Certificate(stack, "Certificate", {
81
+ domainName: siteDomainName,
82
+ //subjectAlternativeNames: props.domainAliases,
83
+ validation: certificatemanager.CertificateValidation.fromDns(hostedZone),
84
+ });
85
+ }
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ import "source-map-support/register";
3
+ import { Construct } from "constructs";
4
+ import { join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import * as cdk from "aws-cdk-lib";
7
+ import * as ssm from "aws-cdk-lib/aws-ssm";
8
+ import * as s3 from "aws-cdk-lib/aws-s3";
9
+ import * as s3deploy from "aws-cdk-lib/aws-s3-deployment";
10
+ import * as lambda from "aws-cdk-lib/aws-lambda";
11
+ import * as logs from "aws-cdk-lib/aws-logs";
12
+ import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
13
+ import * as nodejs from "aws-cdk-lib/aws-lambda-nodejs";
14
+ import * as origin from "aws-cdk-lib/aws-cloudfront-origins";
15
+ import * as api from "aws-cdk-lib/aws-apigatewayv2";
16
+ import { HttpLambdaIntegration } from "aws-cdk-lib/aws-apigatewayv2-integrations";
17
+ import * as route53 from "aws-cdk-lib/aws-route53";
18
+ import * as targets from "aws-cdk-lib/aws-route53-targets";
19
+ import { existsSync } from "node:fs";
20
+ import type { CustomStackProps } from "../bin/infrastructure";
21
+
22
+ type VikeStackProps = cdk.StackProps & {
23
+ customStackProps: CustomStackProps;
24
+ };
25
+
26
+ // Define __dirname for ES module scope
27
+ const __filename = fileURLToPath(import.meta.url);
28
+ const __dirname = join(__filename, "..");
29
+
30
+ export class VikeStack extends cdk.Stack {
31
+ readonly distributionUrlParameterName = `/${this.stackName}/distribution/url`;
32
+
33
+ constructor(scope: Construct, id: string, props: VikeStackProps) {
34
+ super(scope, id, props);
35
+
36
+ const certificate =
37
+ props.customStackProps?.certificate && typeof props.customStackProps?.certificate !== "string"
38
+ ? props.customStackProps?.certificate
39
+ : undefined;
40
+
41
+ const hostedZone = props.customStackProps?.hostedZone;
42
+ const subDomain = props.customStackProps?.subDomain;
43
+ const domainName = props.customStackProps?.domainName;
44
+ const siteDomainName = domainName
45
+ ? `${(subDomain?.length ?? 0 > 0) ? `${subDomain}.` : ""}${domainName}`
46
+ : undefined;
47
+
48
+ const bucket = new s3.Bucket(this, "StaticAssetsBucket", {
49
+ /**
50
+ * The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete
51
+ * the new bucket, and it will remain in your account until manually deleted. By setting the policy to
52
+ * DESTROY, cdk destroy will attempt to delete the bucket, but will error if the bucket is not empty.
53
+ */
54
+ removalPolicy: cdk.RemovalPolicy.DESTROY, // NOT recommended for production code
55
+
56
+ /**
57
+ * For sample purposes only, if you create an S3 bucket then populate it, stack destruction fails. This
58
+ * setting will enable full cleanup of the demo.
59
+ */
60
+ autoDeleteObjects: true, // NOT recommended for production code
61
+ });
62
+
63
+ // Create a Lambda function for the backend
64
+ const banner =
65
+ "const require = (await import('node:module')).createRequire(import.meta.url);const __filename = (await import('node:url')).fileURLToPath(import.meta.url);const __dirname = (await import('node:path')).dirname(__filename);";
66
+
67
+ const fn = new nodejs.NodejsFunction(this, "RequestHandler", {
68
+ handler: "handler",
69
+ entry: join(__dirname, "../../entry_aws_lambda.ts"),
70
+ // fix error: "Cannot find a package lock file ..." when using "bun" javascript package manager and runtime
71
+ depsLockFilePath: findBunLockFile(),
72
+ environment: {
73
+ NODE_ENV: "production",
74
+ },
75
+ bundling: {
76
+ banner,
77
+ format: nodejs.OutputFormat.ESM,
78
+ minify: true,
79
+ target: "esnext",
80
+ //nodeModules: ["react", "react-dom"],
81
+ esbuildArgs: {
82
+ "--tree-shaking": true,
83
+ },
84
+ },
85
+ runtime: lambda.Runtime.NODEJS_20_X,
86
+ architecture: lambda.Architecture.ARM_64,
87
+ memorySize: 256,
88
+ timeout: cdk.Duration.seconds(10),
89
+ logRetention: logs.RetentionDays.THREE_DAYS,
90
+ tracing: lambda.Tracing.ACTIVE,
91
+ });
92
+
93
+ const integration = new HttpLambdaIntegration("RequestHandlerIntegration", fn, {
94
+ payloadFormatVersion: api.PayloadFormatVersion.VERSION_2_0,
95
+ });
96
+
97
+ const httpApi = new api.HttpApi(this, "WebsiteApi", {
98
+ defaultIntegration: integration,
99
+ });
100
+
101
+ const httpApiUrl = `${httpApi.httpApiId}.execute-api.${cdk.Stack.of(this).region}.${cdk.Stack.of(this).urlSuffix}`;
102
+
103
+ // Create a CloudFront distribution with custom behaviors
104
+ const requestHandlerOrigin = new origin.HttpOrigin(httpApiUrl);
105
+
106
+ const requestHandlerBehavior: cloudfront.AddBehaviorOptions = {
107
+ allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
108
+ viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
109
+ cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
110
+ // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html
111
+ originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
112
+ compress: true,
113
+ };
114
+
115
+ const assetOrigin = new origin.S3Origin(bucket);
116
+ const assetBehaviorOptions = {
117
+ viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
118
+ compress: true,
119
+ };
120
+
121
+ const distribution = new cloudfront.Distribution(this, "CloudFront", {
122
+ defaultBehavior: {
123
+ origin: requestHandlerOrigin,
124
+ ...requestHandlerBehavior,
125
+ },
126
+ domainNames: siteDomainName ? [siteDomainName] : undefined,
127
+ certificate,
128
+ enableIpv6: true,
129
+ minimumProtocolVersion: cloudfront.SecurityPolicyProtocol.TLS_V1_2_2021,
130
+ httpVersion: cloudfront.HttpVersion.HTTP2_AND_3,
131
+ priceClass: cloudfront.PriceClass.PRICE_CLASS_100,
132
+ });
133
+
134
+ distribution.addBehavior("/assets/*", assetOrigin, assetBehaviorOptions);
135
+
136
+ // Deploy static assets to the S3 bucket and invalidate the CloudFront cache
137
+ new s3deploy.BucketDeployment(this, "DeployStaticAssets", {
138
+ sources: [s3deploy.Source.asset(join(__dirname, "../../dist/client"))],
139
+ destinationBucket: bucket,
140
+ distribution,
141
+ distributionPaths: ["/*"],
142
+ prune: true,
143
+ cacheControl: [
144
+ s3deploy.CacheControl.maxAge(cdk.Duration.days(365)),
145
+ s3deploy.CacheControl.sMaxAge(cdk.Duration.days(365)),
146
+ ],
147
+ });
148
+
149
+ // Create a Route 53 alias record pointing to the CloudFront distribution
150
+ if (hostedZone) {
151
+ new route53.ARecord(this, "AliasRecord", {
152
+ zone: hostedZone,
153
+ target: route53.RecordTarget.fromAlias(new targets.CloudFrontTarget(distribution)),
154
+ recordName: subDomain ?? "", // This will create a record for www.example.com
155
+ });
156
+ }
157
+
158
+ // Store the CloudFront URL in an SSM parameter
159
+ new ssm.StringParameter(this, "DistributionUrlParameter", {
160
+ parameterName: this.distributionUrlParameterName,
161
+ stringValue: siteDomainName ? siteDomainName! : distribution.distributionDomainName,
162
+ tier: ssm.ParameterTier.STANDARD,
163
+ });
164
+
165
+ // Output the CloudFront URL and API endpoint
166
+ new cdk.CfnOutput(this, "CloudFrontURL", {
167
+ value: `https://${siteDomainName ? siteDomainName : distribution.distributionDomainName}`,
168
+ });
169
+
170
+ new cdk.CfnOutput(this, "CloudFrontID", {
171
+ value: distribution.distributionId,
172
+ });
173
+ }
174
+ }
175
+
176
+ function findBunLockFile() {
177
+ let bunLockFile = join(__dirname, "../../", "bun.lockb");
178
+ if (existsSync(bunLockFile)) {
179
+ return bunLockFile;
180
+ }
181
+ bunLockFile = join(__dirname, "../../", "../../", "bun.lockb"); // special case for bat tests
182
+ if (existsSync(bunLockFile)) {
183
+ return bunLockFile;
184
+ }
185
+ return undefined;
186
+ }
@@ -0,0 +1,72 @@
1
+ {
2
+ "app": "pnpm tsx cdk/bin/infrastructure.ts",
3
+ "watch": {
4
+ "include": [
5
+ "**"
6
+ ],
7
+ "exclude": [
8
+ "README.md",
9
+ "cdk*.json",
10
+ "**/*.d.ts",
11
+ "**/*.js",
12
+ "tsconfig.json",
13
+ "package*.json",
14
+ "yarn.lock",
15
+ "node_modules",
16
+ "test"
17
+ ]
18
+ },
19
+ "context": {
20
+ "@aws-cdk/core:newStyleStackSynthesis": true,
21
+ "@aws-cdk/aws-lambda:recognizeLayerVersion": true,
22
+ "@aws-cdk/core:checkSecretUsage": true,
23
+ "@aws-cdk/core:target-partitions": [
24
+ "aws",
25
+ "aws-cn"
26
+ ],
27
+ "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
28
+ "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
29
+ "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
30
+ "@aws-cdk/aws-iam:minimizePolicies": true,
31
+ "@aws-cdk/core:validateSnapshotRemovalPolicy": true,
32
+ "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
33
+ "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
34
+ "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
35
+ "@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
36
+ "@aws-cdk/core:enablePartitionLiterals": true,
37
+ "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
38
+ "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
39
+ "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
40
+ "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
41
+ "@aws-cdk/aws-route53-patters:useCertificate": true,
42
+ "@aws-cdk/customresources:installLatestAwsSdkDefault": false,
43
+ "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
44
+ "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
45
+ "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
46
+ "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
47
+ "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
48
+ "@aws-cdk/aws-redshift:columnId": true,
49
+ "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
50
+ "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
51
+ "@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
52
+ "@aws-cdk/aws-kms:aliasNameRef": true,
53
+ "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
54
+ "@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
55
+ "@aws-cdk/aws-efs:denyAnonymousAccess": true,
56
+ "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
57
+ "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
58
+ "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
59
+ "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
60
+ "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
61
+ "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
62
+ "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
63
+ "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
64
+ "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
65
+ "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
66
+ "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
67
+ "@aws-cdk/aws-eks:nodegroupNameAttribute": true,
68
+ "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
69
+ "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
70
+ "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false
71
+ }
72
+ }