@jaypie/mcp 0.1.10 → 0.2.1
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.
- package/dist/datadog.d.ts +212 -0
- package/dist/index.js +1461 -6
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
- package/prompts/Development_Process.md +57 -35
- package/prompts/Jaypie_CDK_Constructs_and_Patterns.md +143 -19
- package/prompts/Jaypie_Express_Package.md +35 -15
- package/prompts/Jaypie_Init_Express_on_Lambda.md +66 -38
- package/prompts/Jaypie_Init_Lambda_Package.md +202 -83
- package/prompts/Jaypie_Init_Project_Subpackage.md +21 -26
- package/prompts/Jaypie_Legacy_Patterns.md +4 -0
- package/prompts/Jaypie_Repokit.md +103 -0
- package/prompts/Templates_CDK_Subpackage.md +113 -0
- package/prompts/Templates_Express_Subpackage.md +183 -0
- package/prompts/Templates_Project_Monorepo.md +326 -0
- package/prompts/Templates_Project_Subpackage.md +93 -0
- package/prompts/Jaypie_Mongoose_Models_Package.md +0 -231
- package/prompts/Jaypie_Mongoose_with_Express_CRUD.md +0 -1000
- package/prompts/templates/cdk-subpackage/bin/cdk.ts +0 -11
- package/prompts/templates/cdk-subpackage/cdk.json +0 -19
- package/prompts/templates/cdk-subpackage/lib/cdk-app.ts +0 -41
- package/prompts/templates/cdk-subpackage/lib/cdk-infrastructure.ts +0 -15
- package/prompts/templates/express-subpackage/index.ts +0 -8
- package/prompts/templates/express-subpackage/src/app.ts +0 -18
- package/prompts/templates/express-subpackage/src/handler.config.ts +0 -44
- package/prompts/templates/express-subpackage/src/routes/resource/__tests__/resourceGet.route.spec.ts +0 -29
- package/prompts/templates/express-subpackage/src/routes/resource/resourceGet.route.ts +0 -22
- package/prompts/templates/express-subpackage/src/routes/resource.router.ts +0 -11
- package/prompts/templates/express-subpackage/src/types/express.ts +0 -9
- package/prompts/templates/project-monorepo/.vscode/settings.json +0 -72
- package/prompts/templates/project-monorepo/eslint.config.mjs +0 -1
- package/prompts/templates/project-monorepo/gitignore +0 -11
- package/prompts/templates/project-monorepo/package.json +0 -20
- package/prompts/templates/project-monorepo/tsconfig.base.json +0 -18
- package/prompts/templates/project-monorepo/tsconfig.json +0 -6
- package/prompts/templates/project-monorepo/vitest.workspace.js +0 -3
- package/prompts/templates/project-subpackage/package.json +0 -16
- package/prompts/templates/project-subpackage/tsconfig.json +0 -11
- package/prompts/templates/project-subpackage/vite.config.ts +0 -21
- package/prompts/templates/project-subpackage/vitest.config.ts +0 -7
- package/prompts/templates/project-subpackage/vitest.setup.ts +0 -6
|
@@ -33,10 +33,13 @@ new JaypieLambda(this, "MyFunction", {
|
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
Features:
|
|
36
|
-
- Automatic Datadog integration when `DATADOG_API_KEY_ARN` exists
|
|
36
|
+
- Automatic Datadog integration when `DATADOG_API_KEY_ARN` or `CDK_ENV_DATADOG_API_KEY_ARN` exists
|
|
37
37
|
- Default environment variables from `PROJECT_*` settings
|
|
38
|
-
- Provisioned concurrency support
|
|
39
|
-
- Secrets management via `JaypieEnvSecret
|
|
38
|
+
- Provisioned concurrency support via `provisionedConcurrentExecutions`
|
|
39
|
+
- Secrets management via `secrets` array (JaypieEnvSecret[])
|
|
40
|
+
- Direct secret integration via `envSecrets` object
|
|
41
|
+
- Parameter Store/Secrets Manager layer via `paramsAndSecrets`
|
|
42
|
+
- VPC, security groups, filesystem, and all standard Lambda configuration options
|
|
40
43
|
|
|
41
44
|
### Queue-Lambda Patterns
|
|
42
45
|
|
|
@@ -45,18 +48,33 @@ Use `JaypieQueuedLambda` for SQS-triggered Lambdas:
|
|
|
45
48
|
new JaypieQueuedLambda(this, "Worker", {
|
|
46
49
|
code: "dist",
|
|
47
50
|
fifo: true,
|
|
48
|
-
batchSize: 10
|
|
51
|
+
batchSize: 10,
|
|
52
|
+
visibilityTimeout: Duration.seconds(900)
|
|
49
53
|
});
|
|
50
54
|
```
|
|
51
55
|
|
|
56
|
+
Features:
|
|
57
|
+
- Auto-creates SQS queue and connects to Lambda
|
|
58
|
+
- Implements both `lambda.IFunction` and `sqs.IQueue` interfaces
|
|
59
|
+
- Auto-injects `CDK_ENV_QUEUE_URL` environment variable
|
|
60
|
+
- Grants consume and send permissions to Lambda
|
|
61
|
+
|
|
52
62
|
Use `JaypieBucketQueuedLambda` for S3-triggered processing:
|
|
53
63
|
```typescript
|
|
54
64
|
new JaypieBucketQueuedLambda(this, "Processor", {
|
|
55
65
|
code: "dist",
|
|
56
|
-
bucketName: "my-bucket"
|
|
66
|
+
bucketName: "my-bucket",
|
|
67
|
+
bucketOptions: { versioned: true } // Optional S3 configuration
|
|
57
68
|
});
|
|
58
69
|
```
|
|
59
70
|
|
|
71
|
+
Features:
|
|
72
|
+
- Extends `JaypieQueuedLambda` with S3 bucket and event notifications
|
|
73
|
+
- Forces non-FIFO queue (S3 limitation)
|
|
74
|
+
- Auto-injects `CDK_ENV_BUCKET_NAME` environment variable
|
|
75
|
+
- Grants read/write permissions to Lambda
|
|
76
|
+
- Implements `s3.IBucket` interface
|
|
77
|
+
|
|
60
78
|
### API Gateway
|
|
61
79
|
|
|
62
80
|
Use `JaypieApiGateway` for REST APIs with custom domains:
|
|
@@ -101,22 +119,37 @@ new JaypieEnvSecret(this, "API_KEY");
|
|
|
101
119
|
// Explicit configuration
|
|
102
120
|
new JaypieEnvSecret(this, "ApiKey", {
|
|
103
121
|
envKey: "API_KEY",
|
|
104
|
-
provider: true, // Exports for other stacks
|
|
105
|
-
consumer: false
|
|
122
|
+
provider: true, // Exports for other stacks (default: PROJECT_ENV=sandbox)
|
|
123
|
+
consumer: false, // Imports from provider stack (default: PROJECT_ENV=personal)
|
|
124
|
+
value: "secret-value", // Direct value (alternative to envKey)
|
|
125
|
+
generateSecretString: {}, // Auto-generate secret
|
|
106
126
|
});
|
|
107
127
|
```
|
|
108
128
|
|
|
129
|
+
Provider/consumer pattern:
|
|
130
|
+
- Provider stacks (sandbox) create and export secrets
|
|
131
|
+
- Consumer stacks (personal/ephemeral) import secrets by name
|
|
132
|
+
- Export name format: `env-${PROJECT_ENV}-${PROJECT_KEY}-${id}`
|
|
133
|
+
|
|
109
134
|
### Web Hosting
|
|
110
135
|
|
|
111
136
|
Use `JaypieWebDeploymentBucket` for static sites:
|
|
112
137
|
```typescript
|
|
113
138
|
new JaypieWebDeploymentBucket(this, "WebSite", {
|
|
114
139
|
host: "www.example.com",
|
|
115
|
-
zone: "example.com"
|
|
140
|
+
zone: "example.com",
|
|
141
|
+
certificate: true // Creates new cert; can pass ICertificate or false
|
|
116
142
|
});
|
|
117
143
|
```
|
|
118
144
|
|
|
119
|
-
|
|
145
|
+
Features:
|
|
146
|
+
- Creates S3 bucket with website hosting enabled
|
|
147
|
+
- Creates CloudFront distribution with SSL certificate
|
|
148
|
+
- Creates Route53 DNS records
|
|
149
|
+
- Auto-creates GitHub deployment role when `CDK_ENV_REPO` is set
|
|
150
|
+
- Production environments get optimized caching (index.html excluded)
|
|
151
|
+
- Implements `s3.IBucket` interface
|
|
152
|
+
- Can use `CDK_ENV_WEB_HOST` or `CDK_ENV_WEB_SUBDOMAIN` + hosted zone
|
|
120
153
|
|
|
121
154
|
### Hosted Zones
|
|
122
155
|
|
|
@@ -130,32 +163,123 @@ new JaypieHostedZone(this, "Zone", {
|
|
|
130
163
|
## Environment Variables
|
|
131
164
|
|
|
132
165
|
Configure constructs via environment:
|
|
133
|
-
|
|
166
|
+
|
|
167
|
+
### API Configuration
|
|
168
|
+
- `CDK_ENV_API_HOST_NAME`: Full API domain name
|
|
169
|
+
- `CDK_ENV_API_SUBDOMAIN`: API subdomain (combined with CDK_ENV_API_HOSTED_ZONE)
|
|
134
170
|
- `CDK_ENV_API_HOSTED_ZONE`: API hosted zone
|
|
135
|
-
|
|
171
|
+
|
|
172
|
+
### Web Configuration
|
|
173
|
+
- `CDK_ENV_WEB_HOST`: Full web domain name
|
|
174
|
+
- `CDK_ENV_WEB_SUBDOMAIN`: Web subdomain (combined with CDK_ENV_WEB_HOSTED_ZONE)
|
|
136
175
|
- `CDK_ENV_WEB_HOSTED_ZONE`: Web hosted zone
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
- `
|
|
176
|
+
|
|
177
|
+
### General DNS
|
|
178
|
+
- `CDK_ENV_HOSTED_ZONE`: Fallback hosted zone (used by API and Web if specific zones not set)
|
|
179
|
+
|
|
180
|
+
### Deployment
|
|
181
|
+
- `CDK_ENV_REPO`: GitHub repository for deployment roles (format: owner/repo)
|
|
182
|
+
|
|
183
|
+
### Datadog Integration
|
|
184
|
+
- `DATADOG_API_KEY_ARN`: Datadog API key secret ARN (primary)
|
|
185
|
+
- `CDK_ENV_DATADOG_API_KEY_ARN`: Datadog API key secret ARN (fallback)
|
|
186
|
+
- `CDK_ENV_DATADOG_ROLE_ARN`: Datadog IAM role ARN for extended permissions
|
|
187
|
+
|
|
188
|
+
### Project Configuration
|
|
189
|
+
- `PROJECT_ENV`: Environment name (sandbox, production, personal, etc.)
|
|
140
190
|
- `PROJECT_KEY`: Project identifier
|
|
141
191
|
- `PROJECT_SERVICE`: Service name
|
|
142
192
|
- `PROJECT_SPONSOR`: Cost allocation tag
|
|
193
|
+
- `PROJECT_NONCE`: Unique identifier for ephemeral builds
|
|
194
|
+
|
|
195
|
+
### Infrastructure Tracking
|
|
196
|
+
- `CDK_ENV_INFRASTRUCTURE_STACK_SHA`: Git SHA for infrastructure stack tagging
|
|
197
|
+
|
|
198
|
+
### Auto-Injected (Set by Constructs)
|
|
199
|
+
- `CDK_ENV_BUCKET_NAME`: S3 bucket name (set by JaypieBucketQueuedLambda)
|
|
200
|
+
- `CDK_ENV_QUEUE_URL`: SQS queue URL (set by JaypieQueuedLambda)
|
|
143
201
|
|
|
144
202
|
## Helper Functions
|
|
145
203
|
|
|
146
204
|
Use helper utilities:
|
|
147
205
|
```typescript
|
|
148
|
-
import { constructStackName, constructEnvName, isEnv } from "@jaypie/constructs
|
|
206
|
+
import { constructStackName, constructEnvName, isEnv } from "@jaypie/constructs";
|
|
149
207
|
|
|
150
208
|
const stackName = constructStackName("app"); // project-env-app
|
|
151
209
|
const resourceName = constructEnvName("bucket"); // project-env-bucket
|
|
152
210
|
const isProduction = isEnv("production");
|
|
153
211
|
```
|
|
154
212
|
|
|
213
|
+
## Additional Helper Functions
|
|
214
|
+
|
|
215
|
+
Available from `@jaypie/constructs`:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import {
|
|
219
|
+
isProductionEnv,
|
|
220
|
+
isSandboxEnv,
|
|
221
|
+
jaypieLambdaEnv,
|
|
222
|
+
constructTagger,
|
|
223
|
+
resolveHostedZone,
|
|
224
|
+
resolveDatadogLayers,
|
|
225
|
+
resolveDatadogForwarderFunction,
|
|
226
|
+
resolveDatadogLoggingDestination,
|
|
227
|
+
resolveParamsAndSecrets,
|
|
228
|
+
extendDatadogRole,
|
|
229
|
+
envHostname,
|
|
230
|
+
isValidHostname,
|
|
231
|
+
isValidSubdomain,
|
|
232
|
+
mergeDomain,
|
|
233
|
+
} from "@jaypie/constructs";
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Common usage:
|
|
237
|
+
- `isProductionEnv()`: Returns true if PROJECT_ENV is production
|
|
238
|
+
- `isSandboxEnv()`: Returns true if PROJECT_ENV is sandbox
|
|
239
|
+
- `jaypieLambdaEnv({ initialEnvironment })`: Merges PROJECT_* vars into Lambda env
|
|
240
|
+
- `resolveHostedZone(scope, { zone })`: Gets IHostedZone from string or object
|
|
241
|
+
- `extendDatadogRole(lambda)`: Adds Datadog IAM permissions when CDK_ENV_DATADOG_ROLE_ARN set
|
|
242
|
+
|
|
243
|
+
## Additional Constructs
|
|
244
|
+
|
|
245
|
+
Other constructs available but not commonly used:
|
|
246
|
+
|
|
247
|
+
### Base and Infrastructure
|
|
248
|
+
- `JaypieStack`: Base stack with standard tagging and configuration
|
|
249
|
+
|
|
250
|
+
### Specialized Secrets
|
|
251
|
+
- `JaypieDatadogSecret`: Datadog API key secret management
|
|
252
|
+
- `JaypieMongoDbSecret`: MongoDB connection string secret
|
|
253
|
+
- `JaypieOpenAiSecret`: OpenAI API key secret
|
|
254
|
+
- `JaypieTraceSigningKeySecret`: Trace signing key secret
|
|
255
|
+
|
|
256
|
+
### DNS and Networking
|
|
257
|
+
- `JaypieDnsRecord`: Create individual DNS records in hosted zones
|
|
258
|
+
|
|
259
|
+
### Deployment and CI/CD
|
|
260
|
+
- `JaypieGitHubDeployRole`: GitHub Actions OIDC deployment role
|
|
261
|
+
|
|
262
|
+
### Event-Driven
|
|
263
|
+
- `JaypieEventsRule`: EventBridge rules with standard configuration
|
|
264
|
+
|
|
265
|
+
### Advanced Features
|
|
266
|
+
- `JaypieNextJs`: Next.js application deployment (uses cdk-nextjs-standalone)
|
|
267
|
+
- `JaypieDatadogForwarder`: Datadog log forwarder Lambda setup
|
|
268
|
+
- `JaypieOrganizationTrail`: CloudTrail organization-wide trail
|
|
269
|
+
- `JaypieSsoPermissions`: AWS IAM Identity Center permission sets
|
|
270
|
+
- `JaypieSsoSyncApplication`: SSO sync application for Google Workspace
|
|
271
|
+
- `JaypieAccountLoggingBucket`: Account-level centralized logging bucket
|
|
272
|
+
- `JaypieDatadogBucket`: Datadog-specific S3 bucket
|
|
273
|
+
- `JaypieStaticWebBucket`: Static web bucket (simpler than JaypieWebDeploymentBucket)
|
|
274
|
+
- `JaypieDistribution`: CloudFront distribution construct
|
|
275
|
+
|
|
155
276
|
## Tagging Strategy
|
|
156
277
|
|
|
157
278
|
Constructs apply standard tags:
|
|
158
|
-
- `role`: Resource role (api, processing, networking, hosting)
|
|
159
|
-
- `vendor`: External service provider
|
|
160
|
-
- `service`: Service category
|
|
161
|
-
- `sponsor`: Cost allocation
|
|
279
|
+
- `role`: Resource role (api, processing, networking, hosting, deploy, monitoring, security, storage, stack)
|
|
280
|
+
- `vendor`: External service provider (auth0, datadog, mongodb, openai, knowtrace)
|
|
281
|
+
- `service`: Service category (datadog, infrastructure, libraries, sso, trace)
|
|
282
|
+
- `sponsor`: Cost allocation
|
|
283
|
+
- `project`: Project identifier (from PROJECT_KEY)
|
|
284
|
+
- `env`: Environment name (from PROJECT_ENV)
|
|
285
|
+
- `stackSha`: Git SHA for infrastructure stacks (from CDK_ENV_INFRASTRUCTURE_STACK_SHA)
|
|
@@ -5,7 +5,7 @@ globs: packages/express/**
|
|
|
5
5
|
|
|
6
6
|
# Jaypie Express Package
|
|
7
7
|
|
|
8
|
-
Jaypie provides Express utilities through `@jaypie/express` (also available via `jaypie`). The
|
|
8
|
+
Jaypie provides Express utilities through `@jaypie/express` (also available via `jaypie`). The main export is `expressHandler`, a function that wraps Express route handlers to add error handling, logging, lifecycle hooks, and automatic response formatting.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ npm install @jaypie/express
|
|
|
17
17
|
|
|
18
18
|
## expressHandler
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Wraps Express route handlers with error handling, logging, and lifecycle management.
|
|
21
21
|
|
|
22
22
|
### Basic Usage
|
|
23
23
|
|
|
@@ -35,7 +35,7 @@ app.get("/hello", myRoute);
|
|
|
35
35
|
|
|
36
36
|
### Return Value Handling
|
|
37
37
|
|
|
38
|
-
expressHandler automatically formats responses:
|
|
38
|
+
expressHandler automatically formats responses based on return values:
|
|
39
39
|
|
|
40
40
|
| Return Value | HTTP Status | Response |
|
|
41
41
|
|--------------|-------------|----------|
|
|
@@ -43,10 +43,13 @@ expressHandler automatically formats responses:
|
|
|
43
43
|
| Array | 200 | JSON body |
|
|
44
44
|
| String (JSON) | 200 | Parsed JSON |
|
|
45
45
|
| String (other) | 200 | Text body |
|
|
46
|
+
| Number | 200 | Sent via `res.send()` |
|
|
46
47
|
| `true` | 201 Created | Empty |
|
|
47
48
|
| `null`, `undefined`, `false` | 204 No Content | Empty |
|
|
48
49
|
| Object with `.json()` method | 200 | Result of `.json()` |
|
|
49
50
|
|
|
51
|
+
**Note:** If you call `res.json()`, `res.send()`, or `res.end()` directly in your handler, expressHandler will log a warning but respect your call. Prefer using return values instead.
|
|
52
|
+
|
|
50
53
|
### Options
|
|
51
54
|
|
|
52
55
|
```typescript
|
|
@@ -75,9 +78,16 @@ const handler2 = expressHandler(options, async (req, res) => {
|
|
|
75
78
|
|
|
76
79
|
## Lifecycle Hooks
|
|
77
80
|
|
|
81
|
+
Lifecycle hooks execute in this order:
|
|
82
|
+
1. Setup functions (in array order)
|
|
83
|
+
2. Locals functions (in object key order, after all setup)
|
|
84
|
+
3. Validate functions (in array order)
|
|
85
|
+
4. Main handler
|
|
86
|
+
5. Teardown functions (always run, even on error)
|
|
87
|
+
|
|
78
88
|
### Setup Functions
|
|
79
89
|
|
|
80
|
-
Run before the main handler. Use for initialization, authentication checks, or setting up request context.
|
|
90
|
+
Run before validation and the main handler. Use for initialization, authentication checks, or setting up request context.
|
|
81
91
|
|
|
82
92
|
```typescript
|
|
83
93
|
import { expressHandler } from "jaypie";
|
|
@@ -105,7 +115,7 @@ const handler = expressHandler(
|
|
|
105
115
|
|
|
106
116
|
### Teardown Functions
|
|
107
117
|
|
|
108
|
-
Run after the main handler completes
|
|
118
|
+
Run after the main handler completes. Teardown functions execute regardless of success or error, making them suitable for cleanup operations.
|
|
109
119
|
|
|
110
120
|
```typescript
|
|
111
121
|
import type { JaypieHandlerTeardown } from "jaypie";
|
|
@@ -157,7 +167,7 @@ const handler = expressHandler(
|
|
|
157
167
|
|
|
158
168
|
### Locals
|
|
159
169
|
|
|
160
|
-
Set values on `req.locals`. Values can be static or functions that receive `(req, res)`.
|
|
170
|
+
Set values on `req.locals`. Values can be static or functions that receive `(req, res)`. Locals functions are called AFTER setup functions.
|
|
161
171
|
|
|
162
172
|
```typescript
|
|
163
173
|
import type { ExpressHandlerLocals } from "jaypie";
|
|
@@ -176,7 +186,7 @@ const handler = expressHandler(
|
|
|
176
186
|
{
|
|
177
187
|
locals: {
|
|
178
188
|
apiVersion: "v1", // Static value
|
|
179
|
-
user: getUser, // Function called
|
|
189
|
+
user: getUser, // Function called after setup
|
|
180
190
|
},
|
|
181
191
|
}
|
|
182
192
|
);
|
|
@@ -184,7 +194,7 @@ const handler = expressHandler(
|
|
|
184
194
|
|
|
185
195
|
## CORS Helper
|
|
186
196
|
|
|
187
|
-
|
|
197
|
+
Configures CORS middleware using the `cors` npm package with automatic origin validation.
|
|
188
198
|
|
|
189
199
|
```typescript
|
|
190
200
|
import { cors } from "jaypie";
|
|
@@ -199,17 +209,23 @@ app.use(cors({ origin: "*" }));
|
|
|
199
209
|
// Specific origin
|
|
200
210
|
app.use(cors({ origin: "https://example.com" }));
|
|
201
211
|
|
|
212
|
+
// Multiple origins
|
|
213
|
+
app.use(cors({ origin: ["https://example.com", "https://app.example.com"] }));
|
|
214
|
+
|
|
202
215
|
// Custom configuration
|
|
203
216
|
const corsConfig: CorsConfig = {
|
|
204
217
|
origin: "https://api.example.com",
|
|
205
|
-
|
|
218
|
+
overrides: {
|
|
219
|
+
// Additional options passed to the cors package
|
|
220
|
+
credentials: true,
|
|
221
|
+
},
|
|
206
222
|
};
|
|
207
223
|
app.use(cors(corsConfig));
|
|
208
224
|
```
|
|
209
225
|
|
|
210
226
|
Environment variables:
|
|
211
|
-
- `BASE_URL` or `PROJECT_BASE_URL`: Default allowed
|
|
212
|
-
- `PROJECT_ENV=sandbox` or `PROJECT_SANDBOX_MODE=true`: Allows localhost
|
|
227
|
+
- `BASE_URL` or `PROJECT_BASE_URL`: Default allowed origins
|
|
228
|
+
- `PROJECT_ENV=sandbox` or `PROJECT_SANDBOX_MODE=true`: Allows localhost origins (including ports)
|
|
213
229
|
|
|
214
230
|
## Pre-built Routes
|
|
215
231
|
|
|
@@ -319,6 +335,7 @@ import {
|
|
|
319
335
|
notFoundRoute,
|
|
320
336
|
NotFoundError,
|
|
321
337
|
ForbiddenError,
|
|
338
|
+
UnauthorizedError,
|
|
322
339
|
log,
|
|
323
340
|
} from "jaypie";
|
|
324
341
|
import type {
|
|
@@ -378,10 +395,13 @@ export default app;
|
|
|
378
395
|
|
|
379
396
|
## Response Headers
|
|
380
397
|
|
|
381
|
-
expressHandler automatically sets:
|
|
382
|
-
- `X-Powered-By: @jaypie/express`
|
|
383
|
-
- `X-Project-Handler: {name}` (
|
|
384
|
-
- `X-Project-Invocation: {uuid}` (request tracking ID)
|
|
398
|
+
expressHandler automatically sets these headers:
|
|
399
|
+
- `X-Powered-By: @jaypie/express` (always set, overrides Express default)
|
|
400
|
+
- `X-Project-Handler: {name}` (when name option is provided)
|
|
401
|
+
- `X-Project-Invocation: {uuid}` (request tracking ID, always set)
|
|
402
|
+
- `X-Project-Environment: {env}` (when PROJECT_ENV is set)
|
|
403
|
+
- `X-Project-Key: {key}` (when PROJECT_KEY is set)
|
|
404
|
+
- `X-Project-Version: {version}` (when PROJECT_VERSION is set or version option provided)
|
|
385
405
|
|
|
386
406
|
## Datadog Integration
|
|
387
407
|
|
|
@@ -1,68 +1,78 @@
|
|
|
1
1
|
---
|
|
2
2
|
trigger: model_decision
|
|
3
|
-
description:
|
|
3
|
+
description: Create a new Express application subpackage that runs as a serverless Lambda behind API Gateway using @jaypie/express utilities
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Jaypie Initialize Express on Lambda
|
|
6
|
+
# Jaypie Initialize Express Application on Lambda
|
|
7
|
+
|
|
8
|
+
Create an Express application subpackage that uses @jaypie/express to run as a serverless Lambda behind API Gateway. This prompt is for creating **application packages** (like packages/api or packages/backend), not the @jaypie/express library itself.
|
|
7
9
|
|
|
8
10
|
## Process
|
|
9
11
|
|
|
10
12
|
1. Follow Jaypie_Init_Project_Subpackage.md:
|
|
11
|
-
*
|
|
13
|
+
* Choose an appropriate package name (e.g., @project-org/api, @project-org/backend)
|
|
14
|
+
* Use packages/<package-name> for the directory (e.g., packages/api)
|
|
12
15
|
* This creates the basic subpackage structure with package.json, tsconfig.json, and vitest config files
|
|
13
16
|
|
|
14
|
-
2.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
2. Create Express application files using Templates_Express_Subpackage.md:
|
|
18
|
+
* Create `packages/<package-name>/index.ts` using the index.ts template
|
|
19
|
+
* Create `packages/<package-name>/src/app.ts` using the app.ts template
|
|
20
|
+
* Create `packages/<package-name>/src/handler.config.ts` using the handler.config.ts template
|
|
21
|
+
* Create `packages/<package-name>/src/routes/resource.router.ts` using the resource.router.ts template
|
|
22
|
+
* Create `packages/<package-name>/src/routes/resource/resourceGet.route.ts` using the resourceGet.route.ts template
|
|
23
|
+
* Create `packages/<package-name>/src/routes/resource/__tests__/resourceGet.route.spec.ts` using the test template
|
|
24
|
+
* Create `packages/<package-name>/src/types/express.ts` using the express types template
|
|
25
|
+
* All templates are documented in Templates_Express_Subpackage.md
|
|
22
26
|
|
|
23
27
|
3. Update package.json scripts:
|
|
24
|
-
*
|
|
28
|
+
* Add these scripts to the package.json:
|
|
25
29
|
* `"dev": "tsx watch index.ts"`
|
|
26
30
|
* `"start": "node dist/index.js"`
|
|
27
31
|
* `"build": "tsc"`
|
|
28
|
-
*
|
|
32
|
+
* Keep existing scripts from the template (test, lint, typecheck, format)
|
|
33
|
+
* Run `npm --workspace ./packages/<package-name> run format:package`
|
|
29
34
|
|
|
30
35
|
4. Install dependencies:
|
|
31
|
-
* `npm --workspace ./packages
|
|
32
|
-
* `npm --workspace ./packages
|
|
33
|
-
* Always
|
|
36
|
+
* `npm --workspace ./packages/<package-name> install jaypie express @codegenie/serverless-express`
|
|
37
|
+
* `npm --workspace ./packages/<package-name> install --save-dev @types/express @types/cors tsx`
|
|
38
|
+
* Always use npm install commands; never manually edit package.json dependencies
|
|
34
39
|
|
|
35
40
|
5. Update TypeScript configuration:
|
|
36
|
-
*
|
|
41
|
+
* Edit packages/<package-name>/tsconfig.json to include index.ts in the include array
|
|
42
|
+
* Change include to: `"include": ["src/**/*", "index.ts"]`
|
|
37
43
|
* Change exclude to: `"exclude": ["node_modules", "dist", "**/*.spec.ts"]`
|
|
38
|
-
* Test the build
|
|
39
|
-
*
|
|
44
|
+
* Test the build with `npm --workspace ./packages/<package-name> run build`
|
|
45
|
+
* Verify dist/ is in root .gitignore (it should already be there)
|
|
40
46
|
|
|
41
47
|
6. Update the top-level package.json:
|
|
42
|
-
* Add
|
|
43
|
-
*
|
|
44
|
-
*
|
|
48
|
+
* Add workspace-specific dev and start scripts
|
|
49
|
+
* Add `"dev:<package-name>": "npm --workspace packages/<package-name> run dev"`
|
|
50
|
+
* Add `"start:<package-name>": "npm --workspace packages/<package-name> run start"`
|
|
51
|
+
* If there is no standalone `dev` or `start` script, create them referencing the new package
|
|
52
|
+
* If `dev` or `start` scripts already exist, consider whether to update them based on project needs
|
|
45
53
|
|
|
46
54
|
## Pattern
|
|
47
55
|
|
|
48
56
|
- TypeScript with ES modules (`"type": "module"`)
|
|
49
57
|
- Handler pattern: configuration → lifecycle → processing → response
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
- Lambda-optimized Express configuration
|
|
58
|
+
- Use `handlerConfig` helper for shared configuration and lifecycle management
|
|
59
|
+
- Separation of concerns: routers, route handlers, and middleware
|
|
60
|
+
- Lambda-optimized Express configuration using @codegenie/serverless-express
|
|
61
|
+
- Development mode: Express listens on port 8080 when NODE_ENV=development
|
|
53
62
|
|
|
54
63
|
## Structure
|
|
55
64
|
|
|
56
65
|
```
|
|
57
|
-
|
|
66
|
+
<package-name>/
|
|
58
67
|
├── package.json
|
|
59
68
|
├── tsconfig.json
|
|
60
|
-
├──
|
|
61
|
-
├── vitest.
|
|
62
|
-
├──
|
|
69
|
+
├── vite.config.ts # From template
|
|
70
|
+
├── vitest.config.ts # From template
|
|
71
|
+
├── vitest.setup.ts # From template
|
|
72
|
+
├── index.ts # Lambda handler entry point
|
|
63
73
|
├── src/
|
|
64
|
-
│ ├── app.ts
|
|
65
|
-
│ ├── handler.config.ts
|
|
74
|
+
│ ├── app.ts # Express app configuration
|
|
75
|
+
│ ├── handler.config.ts # Shared handler configuration helper
|
|
66
76
|
│ ├── routes/
|
|
67
77
|
│ │ ├── resource.router.ts
|
|
68
78
|
│ │ └── resource/
|
|
@@ -70,18 +80,36 @@ express/
|
|
|
70
80
|
│ │ └── __tests__/
|
|
71
81
|
│ │ └── resourceGet.route.spec.ts
|
|
72
82
|
│ └── types/
|
|
73
|
-
│ └── express.ts
|
|
74
|
-
└── dist/
|
|
83
|
+
│ └── express.ts # Express type augmentation for req.locals
|
|
84
|
+
└── dist/ # Generated by tsc
|
|
75
85
|
```
|
|
76
86
|
|
|
77
87
|
## Local Development
|
|
78
88
|
|
|
79
|
-
|
|
89
|
+
The index.ts template checks `process.env.NODE_ENV === "development"` to enable local development mode. In this mode, Express listens on port 8080 (port 3000 is typically reserved for frontend applications).
|
|
90
|
+
|
|
91
|
+
Start local development with:
|
|
92
|
+
```bash
|
|
93
|
+
npm run dev:<package-name>
|
|
94
|
+
```
|
|
80
95
|
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
This runs `tsx watch index.ts`, which:
|
|
97
|
+
- Sets up the Express app
|
|
98
|
+
- Listens on port 8080
|
|
99
|
+
- Auto-reloads on file changes
|
|
100
|
+
- Does not invoke serverless-express wrapper
|
|
83
101
|
|
|
84
102
|
## Version Compatibility
|
|
85
103
|
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
- Express: 4.x (Express 5 upgrade not planned)
|
|
105
|
+
- Node: ES modules with TypeScript
|
|
106
|
+
- @codegenie/serverless-express: 4.x
|
|
107
|
+
- @types/express: Compatible with Express 4.x
|
|
108
|
+
|
|
109
|
+
## Context Files
|
|
110
|
+
|
|
111
|
+
Reference these files for additional guidance:
|
|
112
|
+
- `Jaypie_Init_Project_Subpackage.md` - Subpackage initialization process
|
|
113
|
+
- `Templates_Express_Subpackage.md` - Code templates for all files
|
|
114
|
+
- `Jaypie_Express_Package.md` - Documentation on @jaypie/express features
|
|
115
|
+
- `Jaypie_Core_Errors_and_Logging.md` - Error handling patterns
|