@creator.co/wapi 1.2.1-beta5 → 1.2.2
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/.github/workflows/npmpublish.yml +11 -19
- package/.github/workflows/prs.yml +13 -0
- package/jest.config.ts +39 -0
- package/package.json +15 -4
- package/src/API/Request.ts +120 -10
- package/src/API/Response.ts +236 -8
- package/src/API/Utils.ts +56 -1
- package/src/BaseEvent/EventProcessor.ts +84 -11
- package/src/BaseEvent/Process.ts +62 -1
- package/src/BaseEvent/Transaction.ts +5 -8
- package/src/Config/Configuration.ts +111 -5
- package/src/Config/EnvironmentVar.ts +90 -1
- package/src/Crypto/Crypto.ts +77 -18
- package/src/Crypto/JWT.ts +49 -3
- package/src/Globals.ts +141 -3
- package/src/Logger/Logger.ts +173 -19
- package/src/Mailer/Mailer.ts +95 -0
- package/src/Publisher/Publisher.ts +50 -4
- package/src/Server/RouteResolver.ts +142 -0
- package/src/Server/Router.ts +77 -0
- package/src/Server/lib/ContainerServer.ts +48 -1
- package/src/Server/lib/Server.ts +78 -38
- package/src/Server/lib/container/GenericHandler.ts +7 -5
- package/src/Server/lib/container/GenericHandlerEvent.ts +59 -17
- package/src/Server/lib/container/HealthHandler.ts +1 -1
- package/src/Server/lib/container/Proxy.ts +92 -11
- package/src/Server/lib/container/Utils.ts +16 -25
- package/src/Validation/Validator.ts +18 -2
- package/tests/API/Request.test.ts +263 -0
- package/tests/API/Response.test.ts +372 -0
- package/tests/API/Utils.test.ts +157 -0
- package/tests/BaseEvent/EventProcessor.test.ts +278 -0
- package/tests/BaseEvent/Process.test.ts +49 -0
- package/tests/BaseEvent/Transaction.test.ts +231 -0
- package/tests/Config/Config.test.ts +193 -0
- package/tests/Config/EnvironmentVar.test.ts +223 -0
- package/tests/Crypto/Crypto.test.ts +90 -0
- package/tests/Crypto/JWT.test.ts +92 -0
- package/tests/Logger/Logger.test.ts +108 -0
- package/tests/Mailer/Mailer.test.ts +67 -0
- package/tests/Publisher/Publisher.test.ts +60 -0
- package/tests/Server/RouteResolver.test.ts +106 -0
- package/tests/Server/Router.test.ts +38 -0
- package/tests/Server/lib/ContainerServer.test.ts +329 -0
- package/tests/Server/lib/Server.test.ts +12 -0
- package/tests/Server/lib/container/GenericHandler.test.ts +141 -0
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
- package/tests/Server/lib/container/Proxy.test.ts +278 -0
- package/tests/Server/lib/container/Utils.test.ts +48 -0
- package/tests/Test.utils.ts +95 -0
- package/tests/Validation/Validator.test.ts +88 -0
- package/tests/main.test.ts +15 -0
- package/tsconfig.json +1 -0
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -24
- package/dist/index.js.map +0 -1
- package/dist/package.json +0 -53
- package/dist/src/API/Request.d.ts +0 -21
- package/dist/src/API/Request.js +0 -86
- package/dist/src/API/Request.js.map +0 -1
- package/dist/src/API/Response.d.ts +0 -39
- package/dist/src/API/Response.js +0 -232
- package/dist/src/API/Response.js.map +0 -1
- package/dist/src/API/Utils.d.ts +0 -8
- package/dist/src/API/Utils.js +0 -49
- package/dist/src/API/Utils.js.map +0 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +0 -13
- package/dist/src/BaseEvent/EventProcessor.js +0 -151
- package/dist/src/BaseEvent/EventProcessor.js.map +0 -1
- package/dist/src/BaseEvent/Process.d.ts +0 -12
- package/dist/src/BaseEvent/Process.js +0 -114
- package/dist/src/BaseEvent/Process.js.map +0 -1
- package/dist/src/BaseEvent/Transaction.d.ts +0 -29
- package/dist/src/BaseEvent/Transaction.js +0 -248
- package/dist/src/BaseEvent/Transaction.js.map +0 -1
- package/dist/src/Config/Configuration.d.ts +0 -34
- package/dist/src/Config/Configuration.js +0 -93
- package/dist/src/Config/Configuration.js.map +0 -1
- package/dist/src/Config/EnvironmentVar.d.ts +0 -17
- package/dist/src/Config/EnvironmentVar.js +0 -152
- package/dist/src/Config/EnvironmentVar.js.map +0 -1
- package/dist/src/Crypto/Crypto.d.ts +0 -8
- package/dist/src/Crypto/Crypto.js +0 -84
- package/dist/src/Crypto/Crypto.js.map +0 -1
- package/dist/src/Crypto/JWT.d.ts +0 -16
- package/dist/src/Crypto/JWT.js +0 -49
- package/dist/src/Crypto/JWT.js.map +0 -1
- package/dist/src/Globals.d.ts +0 -21
- package/dist/src/Globals.js +0 -35
- package/dist/src/Globals.js.map +0 -1
- package/dist/src/Logger/Logger.d.ts +0 -34
- package/dist/src/Logger/Logger.js +0 -345
- package/dist/src/Logger/Logger.js.map +0 -1
- package/dist/src/Mailer/Mailer.d.ts +0 -12
- package/dist/src/Mailer/Mailer.js +0 -234
- package/dist/src/Mailer/Mailer.js.map +0 -1
- package/dist/src/Publisher/Publisher.d.ts +0 -10
- package/dist/src/Publisher/Publisher.js +0 -109
- package/dist/src/Publisher/Publisher.js.map +0 -1
- package/dist/src/Server/Router.d.ts +0 -27
- package/dist/src/Server/Router.js +0 -22
- package/dist/src/Server/Router.js.map +0 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +0 -11
- package/dist/src/Server/lib/ContainerServer.js +0 -103
- package/dist/src/Server/lib/ContainerServer.js.map +0 -1
- package/dist/src/Server/lib/Server.d.ts +0 -9
- package/dist/src/Server/lib/Server.js +0 -141
- package/dist/src/Server/lib/Server.js.map +0 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +0 -4
- package/dist/src/Server/lib/container/GenericHandler.js +0 -136
- package/dist/src/Server/lib/container/GenericHandler.js.map +0 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +0 -14
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +0 -164
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +0 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +0 -3
- package/dist/src/Server/lib/container/HealthHandler.js +0 -44
- package/dist/src/Server/lib/container/HealthHandler.js.map +0 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +0 -15
- package/dist/src/Server/lib/container/Proxy.js +0 -157
- package/dist/src/Server/lib/container/Proxy.js.map +0 -1
- package/dist/src/Server/lib/container/Utils.d.ts +0 -6
- package/dist/src/Server/lib/container/Utils.js +0 -109
- package/dist/src/Server/lib/container/Utils.js.map +0 -1
- package/dist/src/Validation/Validator.d.ts +0 -5
- package/dist/src/Validation/Validator.js +0 -31
- package/dist/src/Validation/Validator.js.map +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { expect } from "chai"
|
|
2
|
+
|
|
3
|
+
import Response from "../../src/API/Response"
|
|
4
|
+
import Globals from "../../src/Globals"
|
|
5
|
+
import Validator from "../../src/Validation/Validator"
|
|
6
|
+
import { ViewSchema } from "../Test.utils"
|
|
7
|
+
|
|
8
|
+
function expectFullFailure(validationResult, c = 4) {
|
|
9
|
+
expect(validationResult).to.be.an.instanceof(Response)
|
|
10
|
+
if (validationResult instanceof Response) {
|
|
11
|
+
expect(validationResult.getBody()).is.not.null
|
|
12
|
+
expect(validationResult.getBody()).to.have.property(
|
|
13
|
+
"err",
|
|
14
|
+
Globals.ErrorResponseValidationFail,
|
|
15
|
+
)
|
|
16
|
+
expect(validationResult.getBody()).to.have.property(
|
|
17
|
+
"errCode",
|
|
18
|
+
Globals.ErrorCode_InvalidInput,
|
|
19
|
+
)
|
|
20
|
+
expect(validationResult.getBody()).to.have.property("validationFailure")
|
|
21
|
+
expect(validationResult.getBody()["validationFailure"]).to.have.lengthOf(c)
|
|
22
|
+
expect(validationResult.getCode()).is.equals(400)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("Validates unsuccessfully", () => {
|
|
27
|
+
test("Fails to validate async", () => {
|
|
28
|
+
const validationResult = Validator.validateSchema(
|
|
29
|
+
async () => {},
|
|
30
|
+
ViewSchema,
|
|
31
|
+
)
|
|
32
|
+
expectFullFailure(validationResult, 1)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test("Fails to validate null", () => {
|
|
36
|
+
const validationResult = Validator.validateSchema(null, ViewSchema)
|
|
37
|
+
expectFullFailure(validationResult, 1)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test("Fails to validate empty string", () => {
|
|
41
|
+
const validationResult = Validator.validateSchema("", ViewSchema)
|
|
42
|
+
expectFullFailure(validationResult, 1)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test("Fails to validate empty object", () => {
|
|
46
|
+
const validationResult = Validator.validateSchema({}, ViewSchema)
|
|
47
|
+
expectFullFailure(validationResult)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test("Fails to validate object with wrong keys", () => {
|
|
51
|
+
const validationResult = Validator.validateSchema(
|
|
52
|
+
{ name: "Joe" },
|
|
53
|
+
ViewSchema,
|
|
54
|
+
)
|
|
55
|
+
expectFullFailure(validationResult)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test("Fails to validate object with wrong key types", () => {
|
|
59
|
+
const validationResult = Validator.validateSchema({ id: 123 }, ViewSchema)
|
|
60
|
+
expectFullFailure(validationResult)
|
|
61
|
+
if (validationResult instanceof Response) {
|
|
62
|
+
console.log(validationResult.getBody()["validationFailure"])
|
|
63
|
+
expect(
|
|
64
|
+
validationResult.getBody()["validationFailure"].filter((f) => {
|
|
65
|
+
return f.message == "Expected string, received number"
|
|
66
|
+
}),
|
|
67
|
+
).to.have.lengthOf(1)
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe("Validates successfully", () => {
|
|
73
|
+
test("Succeeds to validate", () => {
|
|
74
|
+
const validationResult = Validator.validateSchema(
|
|
75
|
+
{
|
|
76
|
+
id: "123",
|
|
77
|
+
content: "123",
|
|
78
|
+
createdAt: new Date(),
|
|
79
|
+
updatedAt: new Date(),
|
|
80
|
+
},
|
|
81
|
+
ViewSchema,
|
|
82
|
+
)
|
|
83
|
+
expect(validationResult).to.not.be.an.instanceof(Response)
|
|
84
|
+
expect(validationResult).to.be.true
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
export {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// requireActual ensures you get the real file
|
|
2
|
+
// instead of an automock
|
|
3
|
+
// we use import type and <typeof ...> to still get types
|
|
4
|
+
// import type * as Silly from "../silly"
|
|
5
|
+
// const { sillyFunction } = jest.requireActual<typeof Silly>("../silly")
|
|
6
|
+
|
|
7
|
+
describe("silly function", () => {
|
|
8
|
+
test("guaranteed random", () => {
|
|
9
|
+
expect(4).toBe(4)
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
// required with this small example
|
|
14
|
+
// to make the isolatedModules config happy
|
|
15
|
+
export {}
|
package/tsconfig.json
CHANGED
package/dist/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Response from "./src/API/Response";
|
|
2
|
-
import Utils from "./src/API/Utils";
|
|
3
|
-
import EventProcessor from "./src/BaseEvent/EventProcessor";
|
|
4
|
-
import Process from "./src/BaseEvent/Process";
|
|
5
|
-
import Transaction from "./src/BaseEvent/Transaction";
|
|
6
|
-
import Configuration from "./src/Config/Configuration";
|
|
7
|
-
import Crypto from "./src/Crypto/Crypto";
|
|
8
|
-
import JWT from "./src/Crypto/JWT";
|
|
9
|
-
import Mailer from "./src/Mailer/Mailer";
|
|
10
|
-
import Router, { Route } from "./src/Server/Router";
|
|
11
|
-
export { Transaction, Process, EventProcessor, Router, Mailer, Crypto, JWT, Configuration, Response, Utils, Route, };
|
package/dist/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Utils = exports.Response = exports.Configuration = exports.JWT = exports.Crypto = exports.Mailer = exports.Router = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
|
|
4
|
-
var Response_1 = require("./src/API/Response");
|
|
5
|
-
exports.Response = Response_1.default;
|
|
6
|
-
var Utils_1 = require("./src/API/Utils");
|
|
7
|
-
exports.Utils = Utils_1.default;
|
|
8
|
-
var EventProcessor_1 = require("./src/BaseEvent/EventProcessor");
|
|
9
|
-
exports.EventProcessor = EventProcessor_1.default;
|
|
10
|
-
var Process_1 = require("./src/BaseEvent/Process");
|
|
11
|
-
exports.Process = Process_1.default;
|
|
12
|
-
var Transaction_1 = require("./src/BaseEvent/Transaction");
|
|
13
|
-
exports.Transaction = Transaction_1.default;
|
|
14
|
-
var Configuration_1 = require("./src/Config/Configuration");
|
|
15
|
-
exports.Configuration = Configuration_1.default;
|
|
16
|
-
var Crypto_1 = require("./src/Crypto/Crypto");
|
|
17
|
-
exports.Crypto = Crypto_1.default;
|
|
18
|
-
var JWT_1 = require("./src/Crypto/JWT");
|
|
19
|
-
exports.JWT = JWT_1.default;
|
|
20
|
-
var Mailer_1 = require("./src/Mailer/Mailer");
|
|
21
|
-
exports.Mailer = Mailer_1.default;
|
|
22
|
-
var Router_1 = require("./src/Server/Router");
|
|
23
|
-
exports.Router = Router_1.default;
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAuBvC,mBAvBK,kBAAQ,CAuBL;AAtBV,yCAAmC;AAwBjC,gBAxBK,eAAK,CAwBL;AAvBP,iEAA2D;AAazD,yBAbK,wBAAc,CAaL;AAZhB,mDAA6C;AAW3C,kBAXK,iBAAO,CAWL;AAVT,2DAAqD;AASnD,sBATK,qBAAW,CASL;AARb,4DAAsD;AAgBpD,wBAhBK,uBAAa,CAgBL;AAff,8CAAwC;AAatC,iBAbK,gBAAM,CAaL;AAZR,wCAAkC;AAahC,cAbK,aAAG,CAaL;AAZL,8CAAwC;AAUtC,iBAVK,gBAAM,CAUL;AATR,8CAAmD;AAOjD,iBAPK,gBAAM,CAOL"}
|
package/dist/package.json
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "1.2.1-beta5",
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"type": "commonjs",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "npm run lint && tsc --build",
|
|
10
|
-
"clean": "tsc --build --clean",
|
|
11
|
-
"lint": "eslint . --ext .ts --fix"
|
|
12
|
-
},
|
|
13
|
-
"author": "",
|
|
14
|
-
"license": "ISC",
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"@aws-sdk/client-kms": "^3.427.0",
|
|
17
|
-
"@aws-sdk/client-secrets-manager": "^3.427.0",
|
|
18
|
-
"@aws-sdk/client-ses": "^3.414.0",
|
|
19
|
-
"@aws-sdk/client-sns": "^3.398.0",
|
|
20
|
-
"@aws-sdk/client-ssm": "^3.427.0",
|
|
21
|
-
"@aws-sdk/credential-provider-node": "^3.414.0",
|
|
22
|
-
"@types/email-templates": "^10.0.1",
|
|
23
|
-
"@types/nodemailer": "^6.4.10",
|
|
24
|
-
"abind": "^1.0.5",
|
|
25
|
-
"cors": "^2.8.5",
|
|
26
|
-
"cuid": "^3.0.0",
|
|
27
|
-
"dotenv": "^16.3.1",
|
|
28
|
-
"email-templates": "^11.1.1",
|
|
29
|
-
"express": "^4.18.2",
|
|
30
|
-
"json-stringify-safe": "^5.0.1",
|
|
31
|
-
"jsonwebtoken": "^9.0.2",
|
|
32
|
-
"node-cache": "^5.1.2",
|
|
33
|
-
"parse-duration": "^1.1.0",
|
|
34
|
-
"sha1": "^1.1.1",
|
|
35
|
-
"stack-trace": "0.0.10",
|
|
36
|
-
"unflatten": "^1.0.4",
|
|
37
|
-
"zod": "^3.22.4"
|
|
38
|
-
},
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@types/aws-lambda": "^8.10.119",
|
|
41
|
-
"@types/express": "^4.17.19",
|
|
42
|
-
"@types/jsonwebtoken": "^9.0.3",
|
|
43
|
-
"@types/node": "^20.5.7",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
45
|
-
"@typescript-eslint/parser": "^6.5.0",
|
|
46
|
-
"aws-lambda": "^1.0.7",
|
|
47
|
-
"eslint": "^8.48.0",
|
|
48
|
-
"eslint-config-prettier": "^9.0.0",
|
|
49
|
-
"eslint-plugin-import": "^2.28.1",
|
|
50
|
-
"eslint-plugin-prettier": "^5.0.0",
|
|
51
|
-
"prettier": "^3.0.3"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Context, APIGatewayEvent } from "aws-lambda";
|
|
2
|
-
import Logger from "../Logger/Logger";
|
|
3
|
-
export default class Request<InputType> {
|
|
4
|
-
private requestEvent;
|
|
5
|
-
private context;
|
|
6
|
-
constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger);
|
|
7
|
-
containsQueryParam(paramName: string): boolean;
|
|
8
|
-
getQueryParam(paramName: string): string | null;
|
|
9
|
-
getHeader(headerName: string): string | null;
|
|
10
|
-
getContextParam(cxtParam: string): any | null;
|
|
11
|
-
containsPathParam(paramName: string): boolean;
|
|
12
|
-
getPathParam(paramName: string): string | null;
|
|
13
|
-
getBody(): InputType;
|
|
14
|
-
getPath(): string;
|
|
15
|
-
getMethod(): string;
|
|
16
|
-
getPathParams(): object | null;
|
|
17
|
-
getAuthorizationHeader(): string | null;
|
|
18
|
-
getRequestID(): string;
|
|
19
|
-
getOriginIP(): string;
|
|
20
|
-
setFixedPathParams(keys: any[], result: any[]): void;
|
|
21
|
-
}
|
package/dist/src/API/Request.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var Utils_1 = require("./Utils");
|
|
4
|
-
//
|
|
5
|
-
var Request = /** @class */ (function () {
|
|
6
|
-
function Request(requestEvent, context, logger) {
|
|
7
|
-
this.requestEvent = requestEvent;
|
|
8
|
-
this.context = context;
|
|
9
|
-
logger.debug("Request info:", JSON.stringify(requestEvent));
|
|
10
|
-
logger.debug("Request context:", JSON.stringify(context));
|
|
11
|
-
}
|
|
12
|
-
//query
|
|
13
|
-
Request.prototype.containsQueryParam = function (paramName) {
|
|
14
|
-
var val = this.getQueryParam(paramName);
|
|
15
|
-
return !!val && (Utils_1.default.isValidString(val) || Utils_1.default.isValidNumber(val));
|
|
16
|
-
};
|
|
17
|
-
Request.prototype.getQueryParam = function (paramName) {
|
|
18
|
-
return Utils_1.default.caseInsensitiveObjectForKey(this.requestEvent.queryStringParameters, paramName);
|
|
19
|
-
};
|
|
20
|
-
//header
|
|
21
|
-
Request.prototype.getHeader = function (headerName) {
|
|
22
|
-
return Utils_1.default.caseInsensitiveObjectForKey(this.requestEvent.headers, headerName);
|
|
23
|
-
};
|
|
24
|
-
//context params
|
|
25
|
-
Request.prototype.getContextParam = function (cxtParam) {
|
|
26
|
-
return Utils_1.default.caseInsensitiveObjectForKey(this.requestEvent.requestContext, cxtParam);
|
|
27
|
-
};
|
|
28
|
-
//path param
|
|
29
|
-
Request.prototype.containsPathParam = function (paramName) {
|
|
30
|
-
var val = this.getPathParam(paramName);
|
|
31
|
-
return !!val && (Utils_1.default.isValidString(val) || Utils_1.default.isValidNumber(val));
|
|
32
|
-
};
|
|
33
|
-
Request.prototype.getPathParam = function (paramName) {
|
|
34
|
-
return Utils_1.default.caseInsensitiveObjectForKey(this.requestEvent.pathParameters, paramName);
|
|
35
|
-
};
|
|
36
|
-
//body
|
|
37
|
-
Request.prototype.getBody = function () {
|
|
38
|
-
var b = null;
|
|
39
|
-
try {
|
|
40
|
-
b = this.requestEvent.body;
|
|
41
|
-
if (typeof b === "string" || b instanceof String)
|
|
42
|
-
b = JSON.parse(b);
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
console.error("Error while getting request body!", e);
|
|
46
|
-
}
|
|
47
|
-
return b;
|
|
48
|
-
};
|
|
49
|
-
Request.prototype.getPath = function () {
|
|
50
|
-
return this.requestEvent.path;
|
|
51
|
-
};
|
|
52
|
-
Request.prototype.getMethod = function () {
|
|
53
|
-
return this.requestEvent.httpMethod;
|
|
54
|
-
};
|
|
55
|
-
Request.prototype.getPathParams = function () {
|
|
56
|
-
return this.requestEvent.pathParameters;
|
|
57
|
-
};
|
|
58
|
-
//Shortcuts
|
|
59
|
-
Request.prototype.getAuthorizationHeader = function () {
|
|
60
|
-
return this.getHeader("Authorization");
|
|
61
|
-
};
|
|
62
|
-
Request.prototype.getRequestID = function () {
|
|
63
|
-
if (this.context.awsRequestId)
|
|
64
|
-
return this.context.awsRequestId;
|
|
65
|
-
return this.requestEvent.requestContext
|
|
66
|
-
? this.requestEvent.requestContext.requestId
|
|
67
|
-
: "unknown";
|
|
68
|
-
};
|
|
69
|
-
Request.prototype.getOriginIP = function () {
|
|
70
|
-
var _a;
|
|
71
|
-
var origin = (_a = this.getContextParam("identity")) === null || _a === void 0 ? void 0 : _a.sourceIp;
|
|
72
|
-
var hOrigin = this.getHeader("X-Forwarded-For");
|
|
73
|
-
return origin ? origin : hOrigin ? hOrigin : "unknow";
|
|
74
|
-
};
|
|
75
|
-
//ugly fix
|
|
76
|
-
Request.prototype.setFixedPathParams = function (keys, result) {
|
|
77
|
-
var _this = this;
|
|
78
|
-
this.requestEvent.pathParameters = {};
|
|
79
|
-
keys.forEach(function (key, index) {
|
|
80
|
-
return (_this.requestEvent.pathParameters[key.name] = result[index + 1]);
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
return Request;
|
|
84
|
-
}());
|
|
85
|
-
exports.default = Request;
|
|
86
|
-
//# sourceMappingURL=Request.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/API/Request.ts"],"names":[],"mappings":";;AAEA,iCAA2B;AAE3B,EA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,UAAU,CAAC,0CAAE,QAAQ,CAAA;QACzD,IAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAA;QACjD,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAA;IACvD,CAAC;IAED,UAAU;IACH,oCAAkB,GAAzB,UAA0B,IAAW,EAAE,MAAa;QAApD,iBAMC;QALC,IAAI,CAAC,YAAY,CAAC,cAAc,GAAG,EAAE,CAAA;QACrC,IAAI,CAAC,OAAO,CACV,UAAC,GAAG,EAAE,KAAK;YACT,OAAA,CAAC,KAAI,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAAhE,CAAgE,CACnE,CAAA;IACH,CAAC;IACH,cAAC;AAAD,CAAC,AA3FD,IA2FC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Context } from "aws-lambda";
|
|
2
|
-
import Transaction from "../BaseEvent/Transaction";
|
|
3
|
-
export type ResponseErrorType = {
|
|
4
|
-
err: string;
|
|
5
|
-
errCode?: string;
|
|
6
|
-
};
|
|
7
|
-
export default class Response<BodyType = null> {
|
|
8
|
-
private _statusCode;
|
|
9
|
-
private _body;
|
|
10
|
-
private _isPipingOut;
|
|
11
|
-
private _headers;
|
|
12
|
-
readonly shouldStream: boolean;
|
|
13
|
-
readonly rawBody: boolean;
|
|
14
|
-
readonly throwOnErrors: boolean;
|
|
15
|
-
readonly disableTransactionID: boolean;
|
|
16
|
-
constructor(statusCode: number, body: BodyType, optBehaviour?: {
|
|
17
|
-
shouldStream?: boolean;
|
|
18
|
-
rawBody?: boolean;
|
|
19
|
-
throwOnErrors?: boolean;
|
|
20
|
-
disableTransactionID?: boolean;
|
|
21
|
-
} | undefined);
|
|
22
|
-
getCode(): number;
|
|
23
|
-
getBody(): BodyType;
|
|
24
|
-
appendIntoBody(key: string, value: any): void;
|
|
25
|
-
appendHeader(key: string, value: any): void;
|
|
26
|
-
build(context: Context, transaction: Transaction<any, any, any>, _optDoNotCallContext: boolean): Promise<void>;
|
|
27
|
-
private _pipe;
|
|
28
|
-
private _rawContext;
|
|
29
|
-
static MissingParamResponse(paramName: string): Response<ResponseErrorType>;
|
|
30
|
-
static MissingQueryResponse(paramName: string): Response<ResponseErrorType>;
|
|
31
|
-
static BadRequestResponse(msg?: string, errCode?: string, optBody?: any): Response<ResponseErrorType>;
|
|
32
|
-
static BadRequestResponseWithRollback(msg: string, errCode: string, optBody?: any): Response<ResponseErrorType>;
|
|
33
|
-
static UnauthorizedResponse(msg: string, errCode: string): Response<ResponseErrorType>;
|
|
34
|
-
static SuccessResponse<BodyType>(body: BodyType): Response<BodyType>;
|
|
35
|
-
static RedirectResponse(url: string): Response<null>;
|
|
36
|
-
static SuccessNoContentResponse(): Response<null>;
|
|
37
|
-
static SuccessStreamResponse(stream: any, contentType: string): Response;
|
|
38
|
-
static SimpleResponse<BodyType>(body: BodyType, optionalCode?: number): Response<BodyType>;
|
|
39
|
-
}
|
package/dist/src/API/Response.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
var Globals_1 = require("../Globals");
|
|
66
|
-
//
|
|
67
|
-
var CustomError = /** @class */ (function (_super) {
|
|
68
|
-
__extends(CustomError, _super);
|
|
69
|
-
function CustomError(body) {
|
|
70
|
-
var _this = this;
|
|
71
|
-
var msg = body && body.message ? body.message : "Unknown error!";
|
|
72
|
-
_this = _super.call(this, msg) || this;
|
|
73
|
-
_this.name = body && body.error ? body.error : "UnknownError";
|
|
74
|
-
return _this;
|
|
75
|
-
}
|
|
76
|
-
return CustomError;
|
|
77
|
-
}(Error));
|
|
78
|
-
//
|
|
79
|
-
var Response = /** @class */ (function () {
|
|
80
|
-
//
|
|
81
|
-
function Response(statusCode, body, optBehaviour) {
|
|
82
|
-
// response
|
|
83
|
-
this._statusCode = statusCode;
|
|
84
|
-
this._body = body;
|
|
85
|
-
this._headers = {
|
|
86
|
-
"Access-Control-Allow-Origin": "*",
|
|
87
|
-
"Access-Control-Allow-Credentials": true,
|
|
88
|
-
"Content-Type": "application/json",
|
|
89
|
-
};
|
|
90
|
-
// behaviour
|
|
91
|
-
this._isPipingOut = false; //internal -- flag to indicate streaming out has started and avoid double stream call
|
|
92
|
-
// options
|
|
93
|
-
this.shouldStream = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.shouldStream); //
|
|
94
|
-
this.rawBody = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.rawBody);
|
|
95
|
-
this.throwOnErrors = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.throwOnErrors);
|
|
96
|
-
this.disableTransactionID = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.disableTransactionID);
|
|
97
|
-
}
|
|
98
|
-
Response.prototype.getCode = function () {
|
|
99
|
-
return this._statusCode;
|
|
100
|
-
};
|
|
101
|
-
Response.prototype.getBody = function () {
|
|
102
|
-
return this._body;
|
|
103
|
-
};
|
|
104
|
-
Response.prototype.appendIntoBody = function (key, value) {
|
|
105
|
-
this._body[key] = value;
|
|
106
|
-
};
|
|
107
|
-
Response.prototype.appendHeader = function (key, value) {
|
|
108
|
-
this._headers[key] = value;
|
|
109
|
-
};
|
|
110
|
-
Response.prototype.build = function (context, transaction, _optDoNotCallContext) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
-
var b;
|
|
113
|
-
return __generator(this, function (_a) {
|
|
114
|
-
switch (_a.label) {
|
|
115
|
-
case 0:
|
|
116
|
-
//Stream support
|
|
117
|
-
if (this._isPipingOut)
|
|
118
|
-
return [2 /*return*/];
|
|
119
|
-
if (this.shouldStream)
|
|
120
|
-
return [2 /*return*/, this._pipe(context)
|
|
121
|
-
//append default fields
|
|
122
|
-
];
|
|
123
|
-
//append default fields
|
|
124
|
-
if (transaction.request.getRequestID() &&
|
|
125
|
-
this._body &&
|
|
126
|
-
!this.disableTransactionID)
|
|
127
|
-
this.appendIntoBody("transactionID", transaction.request.getRequestID()); //append transaction ID
|
|
128
|
-
//Raw response support
|
|
129
|
-
if (this.rawBody)
|
|
130
|
-
return [2 /*return*/, this._rawContext(context, transaction)
|
|
131
|
-
//build response
|
|
132
|
-
];
|
|
133
|
-
b = __assign({ statusCode: this._statusCode, headers: this._headers }, (this._body ? { body: JSON.stringify(this._body) } : {}));
|
|
134
|
-
//log response and respond to context
|
|
135
|
-
transaction.logger.debug(b);
|
|
136
|
-
if (!transaction.responseProxy) return [3 /*break*/, 2];
|
|
137
|
-
return [4 /*yield*/, transaction.responseProxy(this)
|
|
138
|
-
//Batch does not succeed directly just on upper transaction (which will should be a batch)
|
|
139
|
-
];
|
|
140
|
-
case 1:
|
|
141
|
-
_a.sent();
|
|
142
|
-
_a.label = 2;
|
|
143
|
-
case 2:
|
|
144
|
-
//Batch does not succeed directly just on upper transaction (which will should be a batch)
|
|
145
|
-
if (!_optDoNotCallContext)
|
|
146
|
-
context.succeed(b);
|
|
147
|
-
return [2 /*return*/];
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
Response.prototype._pipe = function (context) {
|
|
153
|
-
//Check if not streaming
|
|
154
|
-
if (this._isPipingOut)
|
|
155
|
-
return;
|
|
156
|
-
this._isPipingOut = true;
|
|
157
|
-
//build response
|
|
158
|
-
var b = {
|
|
159
|
-
statusCode: this._statusCode,
|
|
160
|
-
body: this._body,
|
|
161
|
-
headers: this._headers,
|
|
162
|
-
};
|
|
163
|
-
//log response and respond to context
|
|
164
|
-
context.succeed(b);
|
|
165
|
-
};
|
|
166
|
-
Response.prototype._rawContext = function (context, transaction) {
|
|
167
|
-
//log response and respond to context
|
|
168
|
-
transaction.logger.debug(this._body);
|
|
169
|
-
if (this.getCode() <= 200 && this.getCode() <= 299)
|
|
170
|
-
context.succeed(this._body);
|
|
171
|
-
else {
|
|
172
|
-
if (!this.throwOnErrors)
|
|
173
|
-
context.fail(new CustomError(this._body));
|
|
174
|
-
else
|
|
175
|
-
throw new CustomError(this._body);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
/* Shortcuts */
|
|
179
|
-
Response.MissingParamResponse = function (paramName) {
|
|
180
|
-
console.warn("Invalid request - Path parameter ".concat(paramName, " is missing."));
|
|
181
|
-
return new Response(400, {
|
|
182
|
-
err: "Invalid request. Path parameter ".concat(paramName, " is missing."),
|
|
183
|
-
errCode: Globals_1.default.ErrorCode_MissingParam,
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
Response.MissingQueryResponse = function (paramName) {
|
|
187
|
-
console.warn("Invalid request - Query parameter ".concat(paramName, " is missing."));
|
|
188
|
-
return new Response(400, {
|
|
189
|
-
err: "Invalid request. Query parameter ".concat(paramName, " is missing."),
|
|
190
|
-
errCode: Globals_1.default.ErrorCode_MissingParam,
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
Response.BadRequestResponse = function (msg, errCode, optBody) {
|
|
194
|
-
console.warn("Bad request - ".concat(msg));
|
|
195
|
-
return new Response(400, __assign(__assign({ err: msg }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
|
|
196
|
-
};
|
|
197
|
-
Response.BadRequestResponseWithRollback = function (msg, errCode, optBody) {
|
|
198
|
-
console.warn("Bad request - ".concat(msg));
|
|
199
|
-
return new Response(400, __assign(__assign({ err: msg, rollback: true }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
|
|
200
|
-
};
|
|
201
|
-
Response.UnauthorizedResponse = function (msg, errCode) {
|
|
202
|
-
console.warn("Denying request - ".concat(msg));
|
|
203
|
-
return new Response(401, __assign({ err: msg }, (errCode ? { errCode: errCode } : {})));
|
|
204
|
-
};
|
|
205
|
-
Response.SuccessResponse = function (body) {
|
|
206
|
-
return new Response(200, (body ? body : {}));
|
|
207
|
-
};
|
|
208
|
-
Response.RedirectResponse = function (url) {
|
|
209
|
-
var resp = new Response(302, null);
|
|
210
|
-
resp.appendHeader("Location", url);
|
|
211
|
-
return resp;
|
|
212
|
-
};
|
|
213
|
-
Response.SuccessNoContentResponse = function () {
|
|
214
|
-
return new Response(204, null);
|
|
215
|
-
};
|
|
216
|
-
Response.SuccessStreamResponse = function (stream, contentType) {
|
|
217
|
-
var resp = new Response(200, stream ? stream : {}, {
|
|
218
|
-
shouldStream: true,
|
|
219
|
-
});
|
|
220
|
-
resp.appendHeader("Connection", "keep-alive");
|
|
221
|
-
if (contentType)
|
|
222
|
-
resp.appendHeader("Content-type", contentType);
|
|
223
|
-
return resp;
|
|
224
|
-
};
|
|
225
|
-
Response.SimpleResponse = function (body, optionalCode) {
|
|
226
|
-
var resp = new Response(optionalCode || 200, body);
|
|
227
|
-
return resp;
|
|
228
|
-
};
|
|
229
|
-
return Response;
|
|
230
|
-
}());
|
|
231
|
-
exports.default = Response;
|
|
232
|
-
//# sourceMappingURL=Response.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sCAAgC;AAChC,EAAE;AACF;IAA0B,+BAAK;IAC7B,qBAAY,IAAS;QAArB,iBAIC;QAHC,IAAM,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAA;gBAClE,kBAAM,GAAG,CAAC;QACV,KAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAA;;IAC9D,CAA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C;IACa,yBAAgB,GAA9B,UAA+B,GAAW;QACxC,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;QAC1C,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;IACa,iCAAwB,GAAtC;QACE,OAAO,IAAI,QAAQ,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC;IACa,8BAAqB,GAAnC,UACE,MAAW,EACX,WAAmB;QAEnB,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;YACnD,YAAY,EAAE,IAAI;SACnB,CAAC,CAAA;QACF,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;QAC7C,IAAI,WAAW;YAAE,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAA;IACb,CAAC;IACa,uBAAc,GAA5B,UACE,IAAc,EACd,YAAqB;QAErB,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAW,YAAY,IAAI,GAAG,EAAE,IAAI,CAAC,CAAA;QAC9D,OAAO,IAAI,CAAA;IACb,CAAC;IACH,eAAC;AAAD,CAAC,AAhMD,IAgMC"}
|
package/dist/src/API/Utils.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default class Utils {
|
|
2
|
-
static isHybridlessContainer(): boolean;
|
|
3
|
-
static isValidString(string: string): boolean;
|
|
4
|
-
static parseIntNullIfNaN(string: string): number | null;
|
|
5
|
-
static parseObjectNullIfEmpty(string: string): any | null;
|
|
6
|
-
static isValidNumber(number: string): boolean;
|
|
7
|
-
static caseInsensitiveObjectForKey(obj: any, key: string): any | null;
|
|
8
|
-
}
|