@venturekit/runtime 0.0.0-dev.20260307234057

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/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2025 VentureKit Contributors
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * VentureKit Request Context
3
+ *
4
+ * Provides typed access to request metadata, user info, and tenant context.
5
+ * Extensible for future auth/tenancy modules.
6
+ */
7
+ import type { APIGatewayProxyEventV2 } from 'aws-lambda';
8
+ /**
9
+ * User information extracted from JWT claims
10
+ */
11
+ export interface UserContext {
12
+ /** User ID (Cognito sub) */
13
+ id: string;
14
+ /** User email */
15
+ email?: string;
16
+ /** User's OAuth scopes */
17
+ scopes: string[];
18
+ /** Custom claims from JWT */
19
+ claims: Record<string, unknown>;
20
+ }
21
+ /**
22
+ * Tenant context for multi-tenant applications
23
+ * (Populated by @venturekit/tenancy when enabled)
24
+ */
25
+ export interface TenantContext {
26
+ /** Tenant ID */
27
+ id: string;
28
+ /** Tenant slug/subdomain */
29
+ slug?: string;
30
+ /** Tenant-specific metadata */
31
+ metadata: Record<string, unknown>;
32
+ }
33
+ /**
34
+ * Request context passed to all handlers
35
+ */
36
+ export interface RequestContext {
37
+ /** Unique request ID for tracing */
38
+ requestId: string;
39
+ /** Request timestamp */
40
+ timestamp: Date;
41
+ /** HTTP method */
42
+ method: string;
43
+ /** Request path */
44
+ path: string;
45
+ /** Source IP address */
46
+ sourceIp: string;
47
+ /** User agent */
48
+ userAgent: string;
49
+ /** User context (populated for authenticated requests) */
50
+ user: UserContext | null;
51
+ /** Tenant context (populated when tenancy is enabled) */
52
+ tenant: TenantContext | null;
53
+ /** Request locale (from Accept-Language or default) */
54
+ locale: string;
55
+ /** Raw AWS event (for advanced use cases) */
56
+ rawEvent: APIGatewayProxyEventV2;
57
+ /** Query params from the request */
58
+ queryParams?: Record<string, string | undefined>;
59
+ /**
60
+ * Database transaction (populated when handler has transactional: true)
61
+ * Use tx.query() to run all queries within the same transaction.
62
+ * The transaction is auto-committed on success, rolled back on error.
63
+ */
64
+ tx?: unknown;
65
+ /**
66
+ * Infrastructure intent outputs (populated after infra provisioning).
67
+ * Provides access to provisioned resource endpoints, ARNs, etc.
68
+ * Hydrated from the VENTURE_INTENT_OUTPUTS environment variable.
69
+ */
70
+ intentOutputs?: Record<string, unknown>;
71
+ }
72
+ /**
73
+ * Extract user context from JWT claims in API Gateway event
74
+ */
75
+ export declare function extractUserContext(event: APIGatewayProxyEventV2): UserContext | null;
76
+ /**
77
+ * Extract locale from Accept-Language header
78
+ */
79
+ export declare function extractLocale(event: APIGatewayProxyEventV2, supportedLocales: string[], defaultLocale: string): string;
80
+ /**
81
+ * Build request context from API Gateway event
82
+ */
83
+ export declare function buildContext(event: APIGatewayProxyEventV2, options: {
84
+ supportedLocales: string[];
85
+ defaultLocale: string;
86
+ }): RequestContext;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /**
3
+ * VentureKit Request Context
4
+ *
5
+ * Provides typed access to request metadata, user info, and tenant context.
6
+ * Extensible for future auth/tenancy modules.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.extractUserContext = extractUserContext;
10
+ exports.extractLocale = extractLocale;
11
+ exports.buildContext = buildContext;
12
+ /**
13
+ * Extract user context from JWT claims in API Gateway event
14
+ */
15
+ function extractUserContext(event) {
16
+ const claims = event.requestContext?.authorizer?.jwt?.claims;
17
+ if (!claims) {
18
+ return null;
19
+ }
20
+ const sub = claims.sub;
21
+ if (!sub) {
22
+ return null;
23
+ }
24
+ // Extract scopes from 'scope' claim (space-separated)
25
+ const scopeString = claims.scope;
26
+ const scopes = scopeString ? scopeString.split(' ') : [];
27
+ return {
28
+ id: sub,
29
+ email: claims.email,
30
+ scopes,
31
+ claims: claims,
32
+ };
33
+ }
34
+ /**
35
+ * Extract locale from Accept-Language header
36
+ */
37
+ function extractLocale(event, supportedLocales, defaultLocale) {
38
+ const acceptLanguage = event.headers?.['accept-language'] || '';
39
+ // Parse Accept-Language header (simplified)
40
+ const requested = acceptLanguage.split(',')[0]?.split('-')[0]?.toLowerCase();
41
+ if (requested && supportedLocales.includes(requested)) {
42
+ return requested;
43
+ }
44
+ return defaultLocale;
45
+ }
46
+ /**
47
+ * Build request context from API Gateway event
48
+ */
49
+ function buildContext(event, options) {
50
+ // Hydrate intent outputs from env var (set by infra layer after provisioning)
51
+ let intentOutputs;
52
+ try {
53
+ const raw = process.env.VENTURE_INTENT_OUTPUTS;
54
+ if (raw) {
55
+ intentOutputs = JSON.parse(raw);
56
+ }
57
+ }
58
+ catch {
59
+ // Ignore parse errors — intentOutputs stays undefined
60
+ }
61
+ return {
62
+ requestId: event.requestContext?.requestId || crypto.randomUUID(),
63
+ timestamp: new Date(),
64
+ method: event.requestContext?.http?.method || 'UNKNOWN',
65
+ path: event.requestContext?.http?.path || '/',
66
+ sourceIp: event.requestContext?.http?.sourceIp || 'unknown',
67
+ userAgent: event.headers?.['user-agent'] || 'unknown',
68
+ user: extractUserContext(event),
69
+ tenant: null, // Populated by @venturekit/tenancy
70
+ locale: extractLocale(event, options.supportedLocales, options.defaultLocale),
71
+ rawEvent: event,
72
+ queryParams: event.queryStringParameters,
73
+ intentOutputs,
74
+ };
75
+ }
76
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9jb250ZXh0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7R0FLRzs7QUFzRkgsZ0RBc0JDO0FBS0Qsc0NBZUM7QUFLRCxvQ0FnQ0M7QUFsRkQ7O0dBRUc7QUFDSCxTQUFnQixrQkFBa0IsQ0FBQyxLQUE2QjtJQUM5RCxNQUFNLE1BQU0sR0FBSSxLQUFLLENBQUMsY0FBc0IsRUFBRSxVQUFVLEVBQUUsR0FBRyxFQUFFLE1BQU0sQ0FBQztJQUV0RSxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUM7UUFDWixPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7SUFFRCxNQUFNLEdBQUcsR0FBRyxNQUFNLENBQUMsR0FBeUIsQ0FBQztJQUM3QyxJQUFJLENBQUMsR0F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gICAgcmVxdWVzdElkOiBldmVudC5yZXF1ZXN0Q29udGV4dD8ucmVxdWVzdElkIHx8IGNyeXB0by5yYW5kb21VVUlEKCksXG4gICAgdGltZXN0YW1wOiBuZXcgRGF0ZSgpLFxuICAgIG1ldGhvZDogZXZlbnQucmVxdWVzdENvbnRleHQ/Lmh0dHA/Lm1ldGhvZCB8fCAnVU5LTk9XTicsXG4gICAgcGF0aDogZXZlbnQucmVxdWVzdENvbnRleHQ/Lmh0dHA/LnBhdGggfHwgJy8nLFxuICAgIHNvdXJjZUlwOiBldmVudC5yZXF1ZXN0Q29udGV4dD8uaHR0cD8uc291cmNlSXAgfHwgJ3Vua25vd24nLFxuICAgIHVzZXJBZ2VudDogZXZlbnQuaGVhZGVycz8uWyd1c2VyLWFnZW50J10gfHwgJ3Vua25vd24nLFxuICAgIHVzZXI6IGV4dHJhY3RVc2VyQ29udGV4dChldmVudCksXG4gICAgdGVuYW50OiBudWxsLCAvLyBQb3B1bGF0ZWQgYnkgQHZlbnR1cmVraXQvdGVuYW5jeVxuICAgIGxvY2FsZTogZXh0cmFjdExvY2FsZShldmVudCwgb3B0aW9ucy5zdXBwb3J0ZWRMb2NhbGVzLCBvcHRpb25zLmRlZmF1bHRMb2NhbGUpLFxuICAgIHJhd0V2ZW50OiBldmVudCxcbiAgICBxdWVyeVBhcmFtczogZXZlbnQucXVlcnlTdHJpbmdQYXJhbWV0ZXJzIGFzIFJlY29yZDxzdHJpbmcsIHN0cmluZyB8IHVuZGVmaW5lZD4gfCB1bmRlZmluZWQsXG4gICAgaW50ZW50T3V0cHV0cyxcbiAgfTtcbn1cbiJdfQ==
@@ -0,0 +1,80 @@
1
+ /**
2
+ * VentureKit Runtime Errors
3
+ *
4
+ * Standardized error types for consistent error handling across handlers.
5
+ */
6
+ /**
7
+ * Base error class for all VentureKit errors
8
+ */
9
+ export declare class VentureError extends Error {
10
+ readonly code: string;
11
+ readonly statusCode: number;
12
+ readonly details?: Record<string, unknown> | undefined;
13
+ constructor(code: string, message: string, statusCode?: number, details?: Record<string, unknown> | undefined);
14
+ toJSON(): {
15
+ error: {
16
+ details?: Record<string, unknown> | undefined;
17
+ code: string;
18
+ message: string;
19
+ };
20
+ };
21
+ }
22
+ /**
23
+ * 400 Bad Request - Invalid input
24
+ */
25
+ export declare class BadRequestError extends VentureError {
26
+ constructor(message: string, details?: Record<string, unknown>);
27
+ }
28
+ /**
29
+ * 401 Unauthorized - Missing or invalid authentication
30
+ */
31
+ export declare class UnauthorizedError extends VentureError {
32
+ constructor(message?: string);
33
+ }
34
+ /**
35
+ * 403 Forbidden - Authenticated but not allowed
36
+ */
37
+ export declare class ForbiddenError extends VentureError {
38
+ constructor(message?: string);
39
+ }
40
+ /**
41
+ * 404 Not Found - Resource doesn't exist
42
+ */
43
+ export declare class NotFoundError extends VentureError {
44
+ constructor(resource: string, id?: string);
45
+ }
46
+ /**
47
+ * 409 Conflict - Resource already exists or state conflict
48
+ */
49
+ export declare class ConflictError extends VentureError {
50
+ constructor(message: string, details?: Record<string, unknown>);
51
+ }
52
+ /**
53
+ * 422 Unprocessable Entity - Validation failed
54
+ */
55
+ export declare class ValidationError extends VentureError {
56
+ readonly fieldErrors: Record<string, string[]>;
57
+ constructor(message: string, fieldErrors: Record<string, string[]>);
58
+ }
59
+ /**
60
+ * 429 Too Many Requests - Rate limited
61
+ */
62
+ export declare class RateLimitError extends VentureError {
63
+ constructor(retryAfterSec?: number);
64
+ }
65
+ /**
66
+ * 500 Internal Server Error - Unexpected error
67
+ */
68
+ export declare class InternalError extends VentureError {
69
+ constructor(message?: string);
70
+ }
71
+ /**
72
+ * 503 Service Unavailable - Dependency failure
73
+ */
74
+ export declare class ServiceUnavailableError extends VentureError {
75
+ constructor(service: string);
76
+ }
77
+ /**
78
+ * Check if an error is a VentureError
79
+ */
80
+ export declare function isVentureError(error: unknown): error is VentureError;
package/dist/errors.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /**
3
+ * VentureKit Runtime Errors
4
+ *
5
+ * Standardized error types for consistent error handling across handlers.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ServiceUnavailableError = exports.InternalError = exports.RateLimitError = exports.ValidationError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.VentureError = void 0;
9
+ exports.isVentureError = isVentureError;
10
+ /**
11
+ * Base error class for all VentureKit errors
12
+ */
13
+ class VentureError extends Error {
14
+ code;
15
+ statusCode;
16
+ details;
17
+ constructor(code, message, statusCode = 500, details) {
18
+ super(message);
19
+ this.code = code;
20
+ this.statusCode = statusCode;
21
+ this.details = details;
22
+ this.name = 'VentureError';
23
+ }
24
+ toJSON() {
25
+ return {
26
+ error: {
27
+ code: this.code,
28
+ message: this.message,
29
+ ...(this.details && { details: this.details }),
30
+ },
31
+ };
32
+ }
33
+ }
34
+ exports.VentureError = VentureError;
35
+ /**
36
+ * 400 Bad Request - Invalid input
37
+ */
38
+ class BadRequestError extends VentureError {
39
+ constructor(message, details) {
40
+ super('BAD_REQUEST', message, 400, details);
41
+ this.name = 'BadRequestError';
42
+ }
43
+ }
44
+ exports.BadRequestError = BadRequestError;
45
+ /**
46
+ * 401 Unauthorized - Missing or invalid authentication
47
+ */
48
+ class UnauthorizedError extends VentureError {
49
+ constructor(message = 'Authentication required') {
50
+ super('UNAUTHORIZED', message, 401);
51
+ this.name = 'UnauthorizedError';
52
+ }
53
+ }
54
+ exports.UnauthorizedError = UnauthorizedError;
55
+ /**
56
+ * 403 Forbidden - Authenticated but not allowed
57
+ */
58
+ class ForbiddenError extends VentureError {
59
+ constructor(message = 'Access denied') {
60
+ super('FORBIDDEN', message, 403);
61
+ this.name = 'ForbiddenError';
62
+ }
63
+ }
64
+ exports.ForbiddenError = ForbiddenError;
65
+ /**
66
+ * 404 Not Found - Resource doesn't exist
67
+ */
68
+ class NotFoundError extends VentureError {
69
+ constructor(resource, id) {
70
+ const message = id ? `${resource} '${id}' not found` : `${resource} not found`;
71
+ super('NOT_FOUND', message, 404, { resource, id });
72
+ this.name = 'NotFoundError';
73
+ }
74
+ }
75
+ exports.NotFoundError = NotFoundError;
76
+ /**
77
+ * 409 Conflict - Resource already exists or state conflict
78
+ */
79
+ class ConflictError extends VentureError {
80
+ constructor(message, details) {
81
+ super('CONFLICT', message, 409, details);
82
+ this.name = 'ConflictError';
83
+ }
84
+ }
85
+ exports.ConflictError = ConflictError;
86
+ /**
87
+ * 422 Unprocessable Entity - Validation failed
88
+ */
89
+ class ValidationError extends VentureError {
90
+ fieldErrors;
91
+ constructor(message, fieldErrors) {
92
+ super('VALIDATION_ERROR', message, 422, { fields: fieldErrors });
93
+ this.fieldErrors = fieldErrors;
94
+ this.name = 'ValidationError';
95
+ }
96
+ }
97
+ exports.ValidationError = ValidationError;
98
+ /**
99
+ * 429 Too Many Requests - Rate limited
100
+ */
101
+ class RateLimitError extends VentureError {
102
+ constructor(retryAfterSec) {
103
+ super('RATE_LIMITED', 'Too many requests', 429, retryAfterSec ? { retryAfterSec } : undefined);
104
+ this.name = 'RateLimitError';
105
+ }
106
+ }
107
+ exports.RateLimitError = RateLimitError;
108
+ /**
109
+ * 500 Internal Server Error - Unexpected error
110
+ */
111
+ class InternalError extends VentureError {
112
+ constructor(message = 'Internal server error') {
113
+ super('INTERNAL_ERROR', message, 500);
114
+ this.name = 'InternalError';
115
+ }
116
+ }
117
+ exports.InternalError = InternalError;
118
+ /**
119
+ * 503 Service Unavailable - Dependency failure
120
+ */
121
+ class ServiceUnavailableError extends VentureError {
122
+ constructor(service) {
123
+ super('SERVICE_UNAVAILABLE', `${service} is currently unavailable`, 503, { service });
124
+ this.name = 'ServiceUnavailableError';
125
+ }
126
+ }
127
+ exports.ServiceUnavailableError = ServiceUnavailableError;
128
+ /**
129
+ * Check if an error is a VentureError
130
+ */
131
+ function isVentureError(error) {
132
+ return error instanceof VentureError;
133
+ }
134
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxl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cmVcbiAqL1xuZXhwb3J0IGNsYXNzIFNlcnZpY2VVbmF2YWlsYWJsZUVycm9yIGV4dGVuZHMgVmVudHVyZUVycm9yIHtcbiAgY29uc3RydWN0b3Ioc2VydmljZTogc3RyaW5nKSB7XG4gICAgc3VwZXIoJ1NFUlZJQ0VfVU5BVkFJTEFCTEUnLCBgJHtzZXJ2aWNlfSBpcyBjdXJyZW50bHkgdW5hdmFpbGFibGVgLCA1MDMsIHsgc2VydmljZSB9KTtcbiAgICB0aGlzLm5hbWUgPSAnU2VydmljZVVuYXZhaWxhYmxlRXJyb3InO1xuICB9XG59XG5cbi8qKlxuICogQ2hlY2sgaWYgYW4gZXJyb3IgaXMgYSBWZW50dXJlRXJyb3JcbiAqL1xuZXhwb3J0IGZ1bmN0aW9uIGlzVmVudHVyZUVycm9yKGVycm9yOiB1bmtub3duKTogZXJyb3IgaXMgVmVudHVyZUVycm9yIHtcbiAgcmV0dXJuIGVycm9yIGluc3RhbmNlb2YgVmVudHVyZUVycm9yO1xufVxuIl19
@@ -0,0 +1,71 @@
1
+ /**
2
+ * VentureKit Handler
3
+ *
4
+ * Single unified Lambda handler that adapts to context:
5
+ * - No scopes = public endpoint
6
+ * - With scopes = authenticated + scope check
7
+ * - Status code auto-detected from HTTP method or explicitly set
8
+ */
9
+ import type { APIGatewayProxyEventV2, APIGatewayProxyResultV2, Context } from 'aws-lambda';
10
+ import { RequestContext } from './context';
11
+ import { Logger } from './logger';
12
+ import { Middleware } from './middleware';
13
+ /**
14
+ * Handler function signature
15
+ */
16
+ export type HandlerFn<TBody = unknown, TResult = unknown> = (body: TBody, ctx: RequestContext, logger: Logger) => Promise<TResult>;
17
+ /**
18
+ * HTTP Status codes
19
+ */
20
+ export type StatusCode = 200 | 201 | 204;
21
+ /**
22
+ * Handler configuration
23
+ */
24
+ export interface HandlerConfig {
25
+ /**
26
+ * Required OAuth scopes
27
+ * - Empty array or undefined = public endpoint (no auth)
28
+ * - Non-empty array = authenticated + scope check
29
+ */
30
+ scopes?: string[];
31
+ /**
32
+ * Response status code
33
+ * - undefined = auto-detect from HTTP method (GET/PUT=200, POST=201, DELETE=204)
34
+ * - number = explicit status code
35
+ */
36
+ status?: StatusCode;
37
+ /** Custom middleware to apply */
38
+ middleware?: Middleware[];
39
+ /** Log level */
40
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
41
+ /**
42
+ * Wrap the entire handler execution in a database transaction.
43
+ * When true, a transaction is started before the handler runs
44
+ * and is available via ctx.tx. It auto-commits on success
45
+ * and auto-rolls-back on error.
46
+ * Requires @venturekit/data to be installed.
47
+ */
48
+ transactional?: boolean;
49
+ }
50
+ /**
51
+ * VentureKit unified handler
52
+ *
53
+ * Adapts to context with smart defaults:
54
+ * - No scopes = public endpoint
55
+ * - With scopes = authenticated + scope check
56
+ * - Status: GET/PUT → 200, POST → 201, DELETE → 204 (or set explicitly)
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // Public endpoint
61
+ * export const main = handler(async (body, ctx, log) => {
62
+ * return { status: 'ok' };
63
+ * });
64
+ *
65
+ * // Authenticated endpoint
66
+ * export const main = handler(async (body, ctx, log) => {
67
+ * return { id: '123' };
68
+ * }, { scopes: ['projects.write'] });
69
+ * ```
70
+ */
71
+ export declare function handler<TBody = unknown, TResult = unknown>(fn: HandlerFn<TBody, TResult>, config?: HandlerConfig): (event: APIGatewayProxyEventV2, context: Context) => Promise<APIGatewayProxyResultV2>;