aws-service-stack 0.18.438 → 0.18.440
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/controller/controller-request.d.ts.map +1 -1
- package/dist/controller/controller-request.js +2 -1
- package/dist/controller/controller-request.js.map +1 -1
- package/dist/model/http.model.d.ts +2 -1
- package/dist/model/http.model.d.ts.map +1 -1
- package/dist/model/http.model.js +1 -0
- package/dist/model/http.model.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-request.d.ts","sourceRoot":"","sources":["../../src/controller/controller-request.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,kBAAkB,EAKnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"controller-request.d.ts","sourceRoot":"","sources":["../../src/controller/controller-request.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,kBAAkB,EAKnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,EAAE,cAAc,EAA8B,MAAM,iBAAiB,CAAC;AAG7E,8BAAsB,iBAAiB,CAAC,CAAC,GAAG,GAAG;IAC7C,SAAS,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IACrC,SAAS,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACtC,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAEtC,QAAQ,EAAE,cAAc,EAAE;IAIhC,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IAUxE,qBAAqB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC;IAUhF,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC;IAEnF,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,GAAG,CAAC;YAEvE,aAAa;IAuC3B,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,cAAc;CAYvB"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ControllerRequest = void 0;
|
|
4
4
|
const index_1 = require("../index");
|
|
5
5
|
const exception_1 = require("../exception");
|
|
6
|
+
const types_1 = require("../model/index.js");
|
|
6
7
|
const string_util_1 = require("../utils/string.util");
|
|
7
8
|
class ControllerRequest {
|
|
8
9
|
policies;
|
|
@@ -21,7 +22,7 @@ class ControllerRequest {
|
|
|
21
22
|
try {
|
|
22
23
|
if (!Array.isArray(this.policies) || this.policies.length === 0)
|
|
23
24
|
throw new exception_1.ErrorHttp(exception_1.HTTP.INTERNAL_SERVER_ERROR, "No policies defined for this controller");
|
|
24
|
-
const policy = this.policies.find((p) => p.method === method && (0, string_util_1.trimSpecialChar)(p.path) === (0, string_util_1.trimSpecialChar)(path));
|
|
25
|
+
const policy = this.policies.find((p) => (p.method === method || p.method === types_1.HttpMethod.ANY) && (0, string_util_1.trimSpecialChar)(p.path) === (0, string_util_1.trimSpecialChar)(path));
|
|
25
26
|
if (!policy) {
|
|
26
27
|
throw new exception_1.ErrorHttp(exception_1.HTTP.NOT_FOUND, "No matching policy found for this endpoint");
|
|
27
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-request.js","sourceRoot":"","sources":["../../src/controller/controller-request.ts"],"names":[],"mappings":";;;AAAA,oCAOkB;AAElB,4CAAgE;
|
|
1
|
+
{"version":3,"file":"controller-request.js","sourceRoot":"","sources":["../../src/controller/controller-request.ts"],"names":[],"mappings":";;;AAAA,oCAO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,KAAK,EAAE,CAAC;YACf,MAAM,eAAe,GAAG,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC;YAC5C,MAAM,IAAI,qBAAS,CAAC,gBAAI,CAAC,WAAW,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,QAAa,EAAE,cAA8B;QAClE,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAA,oBAAY,EAAC,QAAQ,EAAE,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;QAChF,CAAC;QAED,IAAI,QAAQ,EAAE,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,QAAQ,CAAC,KAAK,GAAG,IAAA,oBAAY,EAAC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;YAC9F,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,OAAO,IAAA,oBAAY,EAAC,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACrF,CAAC;CACF;AA7FD,8CA6FC","sourcesContent":["import {\n APIResponse,\n APIResponseOptions,\n createApiResponse,\n formatErrors,\n removeFields,\n validateWithSchema,\n} from \"../index\";\nimport { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from \"aws-lambda\";\nimport { ErrorHttp, HTTP, refineHttpError } from \"../exception\";\nimport { EndpointPolicy, HttpMethod, ResponseFields } from \"@chinggis/types\";\nimport { trimSpecialChar } from \"../utils/string.util\";\n\nexport abstract class ControllerRequest<R = any> {\n protected policies: EndpointPolicy[];\n protected options: APIResponseOptions;\n protected responseHeaders: Record<string, string>;\n\n constructor(policies: EndpointPolicy[]) {\n this.policies = policies;\n }\n\n async resolveRequestRestApi(event: APIGatewayProxyEvent): Promise<APIResponse> {\n return this.handleRequest(\n event,\n event.httpMethod,\n event.resource,\n event.body,\n this.processRequestRestApi.bind(this),\n );\n }\n\n async resolveRequestHttpApi(event: APIGatewayProxyEventV2): Promise<APIResponse> {\n return this.handleRequest(\n event,\n event.requestContext.http.method,\n event.rawPath,\n event.body,\n this.processRequestHttpApi.bind(this),\n );\n }\n\n protected abstract processRequestRestApi(event: APIGatewayProxyEvent): Promise<any>;\n\n protected abstract processRequestHttpApi(event: APIGatewayProxyEventV2): Promise<any>;\n\n private async handleRequest(\n event: any,\n method: string,\n path: string,\n validationTarget: any,\n processor: (event: any) => Promise<any>,\n ): Promise<APIResponse> {\n try {\n if (!Array.isArray(this.policies) || this.policies.length === 0)\n throw new ErrorHttp(HTTP.INTERNAL_SERVER_ERROR, \"No policies defined for this controller\");\n\n const policy = this.policies.find(\n (p) =>\n (p.method === method || p.method === HttpMethod.ANY) && trimSpecialChar(p.path) === trimSpecialChar(path),\n );\n\n if (!policy) {\n throw new ErrorHttp(HTTP.NOT_FOUND, \"No matching policy found for this endpoint\");\n }\n\n validationTarget = validationTarget ? JSON.parse(validationTarget) : {};\n\n this.validateRequest(validationTarget, policy);\n\n const response = await processor(event);\n\n const filteredResponse = policy.response ? this.filterResponse(response, policy.response) : response;\n\n return createApiResponse(200, filteredResponse, this.options, this.responseHeaders);\n } catch (err) {\n const error = refineHttpError(err);\n\n if (error.statusCode >= 500) log.error(error);\n else if (error.statusCode >= 400) log.warn(error);\n\n return createApiResponse(error.statusCode, error.content);\n }\n }\n\n private validateRequest(body: any, policy: EndpointPolicy): void {\n try {\n validateWithSchema(policy.validator, body);\n } catch (error) {\n const formattedErrors = formatErrors(error);\n throw new ErrorHttp(HTTP.BAD_REQUEST, undefined, formattedErrors);\n }\n }\n\n private filterResponse(response: any, responsePolicy: ResponseFields): any {\n if (Array.isArray(response)) {\n return removeFields(response, responsePolicy.include, responsePolicy.exclude);\n }\n\n if (response?.items && Array.isArray(response.items)) {\n response.items = removeFields(response.items, responsePolicy.include, responsePolicy.exclude);\n return response;\n }\n\n return removeFields([response], responsePolicy.include, responsePolicy.exclude)[0];\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.model.d.ts","sourceRoot":"","sources":["../../src/model/http.model.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,MAAM,WAAW;
|
|
1
|
+
{"version":3,"file":"http.model.d.ts","sourceRoot":"","sources":["../../src/model/http.model.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,GAAG,QAAQ;CACZ;AAED,oBAAY,SAAS;IACnB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AAED,oBAAY,MAAM;IAChB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB"}
|
package/dist/model/http.model.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.model.js","sourceRoot":"","sources":["../../src/model/http.model.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"http.model.js","sourceRoot":"","sources":["../../src/model/http.model.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,6BAAe,CAAA;IACf,+BAAiB,CAAA;IACjB,yBAAW,CAAA;AACb,CAAC,EAPW,UAAU,0BAAV,UAAU,QAOrB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,0BAAa,CAAA;AACf,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAED,IAAY,MAKX;AALD,WAAY,MAAM;IAChB,2BAAiB,CAAA;IACjB,uBAAa,CAAA;IACb,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;AACnB,CAAC,EALW,MAAM,sBAAN,MAAM,QAKjB","sourcesContent":["export enum HttpMethod {\n GET = \"GET\",\n POST = \"POST\",\n PUT = \"PUT\",\n PATCH = \"PATCH\",\n DELETE = \"DELETE\",\n ANY = \"ANY\",\n}\n\nexport enum SortOrder {\n ASC = \"asc\",\n DESC = \"desc\",\n}\n\nexport enum Action {\n CREATE = \"CREATE\",\n READ = \"READ\",\n UPDATE = \"UPDATE\",\n DELETE = \"DELETE\",\n}\n"]}
|