sst-http 0.4.0 → 0.7.0
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/index.cjs +14 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +13 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
Res: () => Res,
|
|
39
39
|
configureRoutes: () => configureRoutes,
|
|
40
40
|
createHandler: () => createHandler,
|
|
41
|
+
handleError: () => handleError,
|
|
41
42
|
json: () => json,
|
|
42
43
|
noContent: () => noContent,
|
|
43
44
|
text: () => text
|
|
@@ -165,6 +166,7 @@ function normalizeRoutePath(path) {
|
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
// src/runtime.ts
|
|
169
|
+
var HTTP_ERROR_MARKER = Symbol.for("sst-http.HttpError");
|
|
168
170
|
var HttpError = class extends Error {
|
|
169
171
|
statusCode;
|
|
170
172
|
headers;
|
|
@@ -172,6 +174,7 @@ var HttpError = class extends Error {
|
|
|
172
174
|
constructor(statusCode, message, options2) {
|
|
173
175
|
super(message);
|
|
174
176
|
this.name = "HttpError";
|
|
177
|
+
Object.defineProperty(this, HTTP_ERROR_MARKER, { value: true });
|
|
175
178
|
this.statusCode = statusCode;
|
|
176
179
|
this.headers = options2?.headers;
|
|
177
180
|
this.details = options2?.details;
|
|
@@ -407,8 +410,17 @@ function extractAuthClaims(event, entry) {
|
|
|
407
410
|
const claims = ctxV2?.authorizer?.jwt?.claims || ctxV1?.authorizer?.claims;
|
|
408
411
|
return claims ?? void 0;
|
|
409
412
|
}
|
|
413
|
+
function isHttpError(error) {
|
|
414
|
+
if (!error || typeof error !== "object") {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
const marker = error[HTTP_ERROR_MARKER] === true;
|
|
418
|
+
const named = error.name === "HttpError";
|
|
419
|
+
const status = typeof error.statusCode === "number";
|
|
420
|
+
return status && (marker || named);
|
|
421
|
+
}
|
|
410
422
|
function handleError(error, preferV2) {
|
|
411
|
-
if (error
|
|
423
|
+
if (isHttpError(error)) {
|
|
412
424
|
return formatResponse({
|
|
413
425
|
statusCode: error.statusCode,
|
|
414
426
|
headers: {
|
|
@@ -561,6 +573,7 @@ function Res() {
|
|
|
561
573
|
Res,
|
|
562
574
|
configureRoutes,
|
|
563
575
|
createHandler,
|
|
576
|
+
handleError,
|
|
564
577
|
json,
|
|
565
578
|
noContent,
|
|
566
579
|
text
|
package/dist/index.d.cts
CHANGED
|
@@ -19,6 +19,7 @@ declare function noContent(headers?: Record<string, string>): ResponseLike;
|
|
|
19
19
|
type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
20
20
|
type LambdaResult = APIGatewayProxyResult | APIGatewayProxyResultV2;
|
|
21
21
|
declare function createHandler(): (event: LambdaEvent, lambdaContext: unknown) => Promise<LambdaResult>;
|
|
22
|
+
declare function handleError(error: unknown, preferV2: boolean): LambdaResult;
|
|
22
23
|
|
|
23
24
|
type LegacyDecorator = (target: unknown, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => void;
|
|
24
25
|
type LegacyParameterDecorator = (target: unknown, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -40,4 +41,4 @@ declare function Res(): LegacyParameterDecorator;
|
|
|
40
41
|
|
|
41
42
|
declare function configureRoutes(next?: RouteOptions): void;
|
|
42
43
|
|
|
43
|
-
export { Auth, Body, Delete, FirebaseAuth, FirebaseAuthOptions, Get, Head, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, ResponseLike, RouteOptions, configureRoutes, createHandler, json, noContent, text };
|
|
44
|
+
export { Auth, Body, Delete, FirebaseAuth, FirebaseAuthOptions, Get, Head, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, ResponseLike, RouteOptions, configureRoutes, createHandler, handleError, json, noContent, text };
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ declare function noContent(headers?: Record<string, string>): ResponseLike;
|
|
|
19
19
|
type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
20
20
|
type LambdaResult = APIGatewayProxyResult | APIGatewayProxyResultV2;
|
|
21
21
|
declare function createHandler(): (event: LambdaEvent, lambdaContext: unknown) => Promise<LambdaResult>;
|
|
22
|
+
declare function handleError(error: unknown, preferV2: boolean): LambdaResult;
|
|
22
23
|
|
|
23
24
|
type LegacyDecorator = (target: unknown, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => void;
|
|
24
25
|
type LegacyParameterDecorator = (target: unknown, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -40,4 +41,4 @@ declare function Res(): LegacyParameterDecorator;
|
|
|
40
41
|
|
|
41
42
|
declare function configureRoutes(next?: RouteOptions): void;
|
|
42
43
|
|
|
43
|
-
export { Auth, Body, Delete, FirebaseAuth, FirebaseAuthOptions, Get, Head, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, ResponseLike, RouteOptions, configureRoutes, createHandler, json, noContent, text };
|
|
44
|
+
export { Auth, Body, Delete, FirebaseAuth, FirebaseAuthOptions, Get, Head, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, ResponseLike, RouteOptions, configureRoutes, createHandler, handleError, json, noContent, text };
|
package/dist/index.js
CHANGED
|
@@ -119,6 +119,7 @@ function normalizeRoutePath(path) {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// src/runtime.ts
|
|
122
|
+
var HTTP_ERROR_MARKER = Symbol.for("sst-http.HttpError");
|
|
122
123
|
var HttpError = class extends Error {
|
|
123
124
|
statusCode;
|
|
124
125
|
headers;
|
|
@@ -126,6 +127,7 @@ var HttpError = class extends Error {
|
|
|
126
127
|
constructor(statusCode, message, options2) {
|
|
127
128
|
super(message);
|
|
128
129
|
this.name = "HttpError";
|
|
130
|
+
Object.defineProperty(this, HTTP_ERROR_MARKER, { value: true });
|
|
129
131
|
this.statusCode = statusCode;
|
|
130
132
|
this.headers = options2?.headers;
|
|
131
133
|
this.details = options2?.details;
|
|
@@ -361,8 +363,17 @@ function extractAuthClaims(event, entry) {
|
|
|
361
363
|
const claims = ctxV2?.authorizer?.jwt?.claims || ctxV1?.authorizer?.claims;
|
|
362
364
|
return claims ?? void 0;
|
|
363
365
|
}
|
|
366
|
+
function isHttpError(error) {
|
|
367
|
+
if (!error || typeof error !== "object") {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
const marker = error[HTTP_ERROR_MARKER] === true;
|
|
371
|
+
const named = error.name === "HttpError";
|
|
372
|
+
const status = typeof error.statusCode === "number";
|
|
373
|
+
return status && (marker || named);
|
|
374
|
+
}
|
|
364
375
|
function handleError(error, preferV2) {
|
|
365
|
-
if (error
|
|
376
|
+
if (isHttpError(error)) {
|
|
366
377
|
return formatResponse({
|
|
367
378
|
statusCode: error.statusCode,
|
|
368
379
|
headers: {
|
|
@@ -514,6 +525,7 @@ export {
|
|
|
514
525
|
Res,
|
|
515
526
|
configureRoutes,
|
|
516
527
|
createHandler,
|
|
528
|
+
handleError,
|
|
517
529
|
json,
|
|
518
530
|
noContent,
|
|
519
531
|
text
|