@temporary-name/standard-server-aws-lambda 1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309
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 +21 -0
- package/README.md +3 -0
- package/dist/index.d.mts +66 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.mjs +131 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Stainless
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Stream, { Readable } from 'node:stream';
|
|
2
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
|
|
3
|
+
import { ToNodeHttpBodyOptions } from '@temporary-name/standard-server-node';
|
|
4
|
+
export { ToEventStreamOptions, toAbortSignal, toEventStream } from '@temporary-name/standard-server-node';
|
|
5
|
+
import { ToEventIteratorOptions as ToEventIteratorOptions$1 } from '@temporary-name/standard-server-fetch';
|
|
6
|
+
|
|
7
|
+
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
8
|
+
}
|
|
9
|
+
declare function toEventIterator(body: string | undefined, options?: ToEventIteratorOptions): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
10
|
+
|
|
11
|
+
interface APIGatewayProxyEventHeaders {
|
|
12
|
+
[name: string]: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
interface APIGatewayProxyEventPathParameters {
|
|
15
|
+
[name: string]: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
interface APIGatewayProxyEventQueryStringParameters {
|
|
18
|
+
[name: string]: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
interface APIGatewayProxyEventStageVariables {
|
|
21
|
+
[name: string]: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
interface APIGatewayProxyEventV2 {
|
|
24
|
+
version: string;
|
|
25
|
+
routeKey: string;
|
|
26
|
+
rawPath: string;
|
|
27
|
+
rawQueryString: string;
|
|
28
|
+
cookies?: string[];
|
|
29
|
+
headers: APIGatewayProxyEventHeaders;
|
|
30
|
+
queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
|
|
31
|
+
requestContext: {
|
|
32
|
+
domainName: string;
|
|
33
|
+
http: {
|
|
34
|
+
method: string;
|
|
35
|
+
path: string;
|
|
36
|
+
protocol: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
body?: string;
|
|
40
|
+
pathParameters?: APIGatewayProxyEventPathParameters;
|
|
41
|
+
isBase64Encoded: boolean;
|
|
42
|
+
stageVariables?: APIGatewayProxyEventStageVariables;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
46
|
+
}
|
|
47
|
+
declare function toStandardBody(event: APIGatewayProxyEventV2, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
48
|
+
interface ToLambdaBodyOptions extends ToNodeHttpBodyOptions {
|
|
49
|
+
}
|
|
50
|
+
declare function toLambdaBody(standardBody: StandardBody, standardHeaders: StandardHeaders, options?: ToLambdaBodyOptions): [body: undefined | string | Readable, headers: StandardHeaders];
|
|
51
|
+
|
|
52
|
+
declare function toStandardHeaders(headers: APIGatewayProxyEventHeaders, cookies: string[] | undefined): StandardHeaders;
|
|
53
|
+
declare function toLambdaHeaders(standard: StandardHeaders): [headers: APIGatewayProxyEventHeaders, setCookies: string[]];
|
|
54
|
+
|
|
55
|
+
declare function toStandardLazyRequest(event: APIGatewayProxyEventV2, responseStream: Stream.Writable): StandardLazyRequest;
|
|
56
|
+
|
|
57
|
+
interface SendStandardResponseOptions extends ToLambdaBodyOptions {
|
|
58
|
+
}
|
|
59
|
+
declare function sendStandardResponse(responseStream: Stream.Writable, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
60
|
+
|
|
61
|
+
declare function toStandardUrl(event: APIGatewayProxyEventV2): URL;
|
|
62
|
+
|
|
63
|
+
type ResponseStream = Stream.Writable;
|
|
64
|
+
|
|
65
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
|
66
|
+
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions, ToEventIteratorOptions, ToLambdaBodyOptions, ToStandardBodyOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Stream, { Readable } from 'node:stream';
|
|
2
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
|
|
3
|
+
import { ToNodeHttpBodyOptions } from '@temporary-name/standard-server-node';
|
|
4
|
+
export { ToEventStreamOptions, toAbortSignal, toEventStream } from '@temporary-name/standard-server-node';
|
|
5
|
+
import { ToEventIteratorOptions as ToEventIteratorOptions$1 } from '@temporary-name/standard-server-fetch';
|
|
6
|
+
|
|
7
|
+
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
8
|
+
}
|
|
9
|
+
declare function toEventIterator(body: string | undefined, options?: ToEventIteratorOptions): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
10
|
+
|
|
11
|
+
interface APIGatewayProxyEventHeaders {
|
|
12
|
+
[name: string]: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
interface APIGatewayProxyEventPathParameters {
|
|
15
|
+
[name: string]: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
interface APIGatewayProxyEventQueryStringParameters {
|
|
18
|
+
[name: string]: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
interface APIGatewayProxyEventStageVariables {
|
|
21
|
+
[name: string]: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
interface APIGatewayProxyEventV2 {
|
|
24
|
+
version: string;
|
|
25
|
+
routeKey: string;
|
|
26
|
+
rawPath: string;
|
|
27
|
+
rawQueryString: string;
|
|
28
|
+
cookies?: string[];
|
|
29
|
+
headers: APIGatewayProxyEventHeaders;
|
|
30
|
+
queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
|
|
31
|
+
requestContext: {
|
|
32
|
+
domainName: string;
|
|
33
|
+
http: {
|
|
34
|
+
method: string;
|
|
35
|
+
path: string;
|
|
36
|
+
protocol: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
body?: string;
|
|
40
|
+
pathParameters?: APIGatewayProxyEventPathParameters;
|
|
41
|
+
isBase64Encoded: boolean;
|
|
42
|
+
stageVariables?: APIGatewayProxyEventStageVariables;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
46
|
+
}
|
|
47
|
+
declare function toStandardBody(event: APIGatewayProxyEventV2, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
48
|
+
interface ToLambdaBodyOptions extends ToNodeHttpBodyOptions {
|
|
49
|
+
}
|
|
50
|
+
declare function toLambdaBody(standardBody: StandardBody, standardHeaders: StandardHeaders, options?: ToLambdaBodyOptions): [body: undefined | string | Readable, headers: StandardHeaders];
|
|
51
|
+
|
|
52
|
+
declare function toStandardHeaders(headers: APIGatewayProxyEventHeaders, cookies: string[] | undefined): StandardHeaders;
|
|
53
|
+
declare function toLambdaHeaders(standard: StandardHeaders): [headers: APIGatewayProxyEventHeaders, setCookies: string[]];
|
|
54
|
+
|
|
55
|
+
declare function toStandardLazyRequest(event: APIGatewayProxyEventV2, responseStream: Stream.Writable): StandardLazyRequest;
|
|
56
|
+
|
|
57
|
+
interface SendStandardResponseOptions extends ToLambdaBodyOptions {
|
|
58
|
+
}
|
|
59
|
+
declare function sendStandardResponse(responseStream: Stream.Writable, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
60
|
+
|
|
61
|
+
declare function toStandardUrl(event: APIGatewayProxyEventV2): URL;
|
|
62
|
+
|
|
63
|
+
type ResponseStream = Stream.Writable;
|
|
64
|
+
|
|
65
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
|
66
|
+
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions, ToEventIteratorOptions, ToLambdaBodyOptions, ToStandardBodyOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { runWithSpan, parseEmptyableJSON, toArray, once } from '@temporary-name/shared';
|
|
2
|
+
import { getFilenameFromContentDisposition, flattenHeader } from '@temporary-name/standard-server';
|
|
3
|
+
import { toNodeHttpBody, toAbortSignal } from '@temporary-name/standard-server-node';
|
|
4
|
+
export { toAbortSignal, toEventStream } from '@temporary-name/standard-server-node';
|
|
5
|
+
import { Buffer } from 'node:buffer';
|
|
6
|
+
import { toEventIterator as toEventIterator$1 } from '@temporary-name/standard-server-fetch';
|
|
7
|
+
|
|
8
|
+
function toEventIterator(body, options = {}) {
|
|
9
|
+
const stream = body ? new Blob([body]).stream() : null;
|
|
10
|
+
return toEventIterator$1(stream, options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function toStandardBody(event, options = {}) {
|
|
14
|
+
return runWithSpan({ name: "parse_standard_body", signal: options.signal }, async () => {
|
|
15
|
+
const contentType = event.headers["content-type"];
|
|
16
|
+
const contentDisposition = event.headers["content-disposition"];
|
|
17
|
+
if (typeof contentDisposition === "string") {
|
|
18
|
+
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
19
|
+
return _parseAsFile(event.body, event.isBase64Encoded, fileName, contentType ?? "");
|
|
20
|
+
}
|
|
21
|
+
if (!contentType || contentType.startsWith("application/json")) {
|
|
22
|
+
const text = _parseAsString(event.body, event.isBase64Encoded);
|
|
23
|
+
return parseEmptyableJSON(text);
|
|
24
|
+
}
|
|
25
|
+
if (contentType.startsWith("multipart/form-data")) {
|
|
26
|
+
return _parseAsFormData(event.body, event.isBase64Encoded, contentType);
|
|
27
|
+
}
|
|
28
|
+
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
|
29
|
+
return new URLSearchParams(_parseAsString(event.body, event.isBase64Encoded));
|
|
30
|
+
}
|
|
31
|
+
if (contentType.startsWith("text/event-stream")) {
|
|
32
|
+
return toEventIterator(_parseAsString(event.body, event.isBase64Encoded), options);
|
|
33
|
+
}
|
|
34
|
+
if (contentType.startsWith("text/plain")) {
|
|
35
|
+
return _parseAsString(event.body, event.isBase64Encoded);
|
|
36
|
+
}
|
|
37
|
+
return _parseAsFile(event.body, event.isBase64Encoded, "blob", contentType);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function toLambdaBody(standardBody, standardHeaders, options = {}) {
|
|
41
|
+
standardHeaders = { ...standardHeaders };
|
|
42
|
+
const body = toNodeHttpBody(standardBody, standardHeaders, options);
|
|
43
|
+
return [body, standardHeaders];
|
|
44
|
+
}
|
|
45
|
+
function _parseAsFile(body, isBase64Encoded, fileName, contentType) {
|
|
46
|
+
return new File(
|
|
47
|
+
body === void 0 ? [] : [isBase64Encoded ? Buffer.from(body, "base64") : body],
|
|
48
|
+
fileName,
|
|
49
|
+
{ type: contentType }
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
function _parseAsString(body, isBase64Encoded) {
|
|
53
|
+
return isBase64Encoded && body !== void 0 ? Buffer.from(body, "base64").toString() : body;
|
|
54
|
+
}
|
|
55
|
+
function _parseAsFormData(body, isBase64Encoded, contentType) {
|
|
56
|
+
const blobPart = isBase64Encoded && body !== void 0 ? Buffer.from(body, "base64") : body;
|
|
57
|
+
const response = new Response(blobPart, {
|
|
58
|
+
headers: {
|
|
59
|
+
"content-type": contentType
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return response.formData();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toStandardHeaders(headers, cookies) {
|
|
66
|
+
return {
|
|
67
|
+
...headers,
|
|
68
|
+
"set-cookie": cookies
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function toLambdaHeaders(standard) {
|
|
72
|
+
const headers = {};
|
|
73
|
+
const setCookies = [];
|
|
74
|
+
for (const key in standard) {
|
|
75
|
+
const value = standard[key];
|
|
76
|
+
if (value === void 0) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (key === "set-cookie") {
|
|
80
|
+
setCookies.push(...toArray(value));
|
|
81
|
+
} else {
|
|
82
|
+
headers[key] = flattenHeader(value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return [headers, setCookies];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function toStandardUrl(event) {
|
|
89
|
+
return new URL(`https://${event.requestContext.domainName}${event.rawPath}?${event.rawQueryString}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function toStandardLazyRequest(event, responseStream) {
|
|
93
|
+
const signal = toAbortSignal(responseStream);
|
|
94
|
+
return {
|
|
95
|
+
url: toStandardUrl(event),
|
|
96
|
+
method: event.requestContext.http.method,
|
|
97
|
+
headers: toStandardHeaders(event.headers, event.cookies),
|
|
98
|
+
signal,
|
|
99
|
+
body: once(() => toStandardBody(event, { signal }))
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function sendStandardResponse(responseStream, standardResponse, options = {}) {
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
responseStream.once("error", reject);
|
|
106
|
+
responseStream.once("close", resolve);
|
|
107
|
+
const [body, standardHeaders] = toLambdaBody(standardResponse.body, standardResponse.headers, options);
|
|
108
|
+
const [headers, setCookies] = toLambdaHeaders(standardHeaders);
|
|
109
|
+
globalThis.awslambda.HttpResponseStream.from(responseStream, {
|
|
110
|
+
statusCode: standardResponse.status,
|
|
111
|
+
headers,
|
|
112
|
+
cookies: setCookies
|
|
113
|
+
});
|
|
114
|
+
if (body === void 0) {
|
|
115
|
+
responseStream.end();
|
|
116
|
+
} else if (typeof body === "string") {
|
|
117
|
+
responseStream.write(body);
|
|
118
|
+
responseStream.end();
|
|
119
|
+
} else {
|
|
120
|
+
responseStream.once("close", () => {
|
|
121
|
+
if (!body.closed) {
|
|
122
|
+
body.destroy(responseStream.errored ?? void 0);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
body.once("error", (error) => responseStream.destroy(error));
|
|
126
|
+
body.pipe(responseStream);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@temporary-name/standard-server-aws-lambda",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://www.stainless.com/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/stainless-api/krusty.git",
|
|
10
|
+
"directory": "packages/standard-server-aws-lambda"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"krusty"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@temporary-name/shared": "1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309",
|
|
27
|
+
"@temporary-name/standard-server": "1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309",
|
|
28
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309",
|
|
29
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/aws-lambda": "^8.10.153",
|
|
33
|
+
"@types/node": "^22.15.30"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "unbuild",
|
|
37
|
+
"build:watch": "pnpm run build --watch",
|
|
38
|
+
"type:check": "tsc -b"
|
|
39
|
+
}
|
|
40
|
+
}
|