@alanszp/express 12.0.2 → 13.0.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/helpers/getRequestBaseLog.d.ts +2 -0
- package/dist/helpers/getRequestBaseLog.js +9 -0
- package/dist/helpers/getRequestBaseLog.js.map +1 -0
- package/dist/helpers/renderErrorJson.d.ts +1 -0
- package/dist/helpers/renderErrorJson.js +10 -1
- package/dist/helpers/renderErrorJson.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/middlewares/errorRequestHandlerMiddleware.d.ts +4 -0
- package/dist/middlewares/errorRequestHandlerMiddleware.js +68 -0
- package/dist/middlewares/errorRequestHandlerMiddleware.js.map +1 -0
- package/dist/middlewares/hasPermissions.d.ts +20 -0
- package/dist/middlewares/hasPermissions.js +90 -0
- package/dist/middlewares/hasPermissions.js.map +1 -0
- package/dist/middlewares/hasRoles.js +4 -4
- package/dist/middlewares/hasRoles.js.map +1 -1
- package/package.json +9 -10
- package/.gitignore +0 -3
- package/.npmignore +0 -3
- package/dist/middlewares/returnInternalServerError.d.ts +0 -4
- package/dist/middlewares/returnInternalServerError.js +0 -10
- package/dist/middlewares/returnInternalServerError.js.map +0 -1
- package/node_modules/@jest/expect-utils/LICENSE +0 -21
- package/node_modules/@jest/expect-utils/README.md +0 -5
- package/node_modules/@jest/expect-utils/build/index.d.ts +0 -93
- package/node_modules/@jest/expect-utils/build/index.js +0 -37
- package/node_modules/@jest/expect-utils/build/jasmineUtils.js +0 -282
- package/node_modules/@jest/expect-utils/build/types.js +0 -1
- package/node_modules/@jest/expect-utils/build/utils.js +0 -457
- package/node_modules/@jest/expect-utils/package.json +0 -33
- package/node_modules/@jest/types/LICENSE +0 -21
- package/node_modules/@jest/types/README.md +0 -30
- package/node_modules/@jest/types/build/Circus.js +0 -1
- package/node_modules/@jest/types/build/Config.js +0 -1
- package/node_modules/@jest/types/build/Global.js +0 -1
- package/node_modules/@jest/types/build/TestResult.js +0 -1
- package/node_modules/@jest/types/build/Transform.js +0 -1
- package/node_modules/@jest/types/build/index.d.ts +0 -1166
- package/node_modules/@jest/types/build/index.js +0 -1
- package/node_modules/@jest/types/package.json +0 -38
- package/node_modules/@types/jest/LICENSE +0 -21
- package/node_modules/@types/jest/README.md +0 -17
- package/node_modules/@types/jest/index.d.ts +0 -1608
- package/node_modules/@types/jest/package.json +0 -159
- package/node_modules/@types/node/LICENSE +0 -21
- package/node_modules/@types/node/README.md +0 -15
- package/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/assert.d.ts +0 -996
- package/node_modules/@types/node/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/buffer.d.ts +0 -2362
- package/node_modules/@types/node/child_process.d.ts +0 -1540
- package/node_modules/@types/node/cluster.d.ts +0 -432
- package/node_modules/@types/node/console.d.ts +0 -415
- package/node_modules/@types/node/constants.d.ts +0 -19
- package/node_modules/@types/node/crypto.d.ts +0 -4487
- package/node_modules/@types/node/dgram.d.ts +0 -596
- package/node_modules/@types/node/diagnostics_channel.d.ts +0 -545
- package/node_modules/@types/node/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/dns.d.ts +0 -809
- package/node_modules/@types/node/dom-events.d.ts +0 -122
- package/node_modules/@types/node/domain.d.ts +0 -170
- package/node_modules/@types/node/events.d.ts +0 -879
- package/node_modules/@types/node/fs/promises.d.ts +0 -1239
- package/node_modules/@types/node/fs.d.ts +0 -4311
- package/node_modules/@types/node/globals.d.ts +0 -411
- package/node_modules/@types/node/globals.global.d.ts +0 -1
- package/node_modules/@types/node/http.d.ts +0 -1887
- package/node_modules/@types/node/http2.d.ts +0 -2382
- package/node_modules/@types/node/https.d.ts +0 -550
- package/node_modules/@types/node/index.d.ts +0 -88
- package/node_modules/@types/node/inspector.d.ts +0 -2747
- package/node_modules/@types/node/module.d.ts +0 -315
- package/node_modules/@types/node/net.d.ts +0 -949
- package/node_modules/@types/node/os.d.ts +0 -478
- package/node_modules/@types/node/package.json +0 -229
- package/node_modules/@types/node/path.d.ts +0 -191
- package/node_modules/@types/node/perf_hooks.d.ts +0 -645
- package/node_modules/@types/node/process.d.ts +0 -1561
- package/node_modules/@types/node/punycode.d.ts +0 -117
- package/node_modules/@types/node/querystring.d.ts +0 -141
- package/node_modules/@types/node/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/readline.d.ts +0 -539
- package/node_modules/@types/node/repl.d.ts +0 -430
- package/node_modules/@types/node/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/stream/web.d.ts +0 -366
- package/node_modules/@types/node/stream.d.ts +0 -1701
- package/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/test.d.ts +0 -1465
- package/node_modules/@types/node/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/timers.d.ts +0 -240
- package/node_modules/@types/node/tls.d.ts +0 -1210
- package/node_modules/@types/node/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
- package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2362
- package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
- package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
- package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
- package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4487
- package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -596
- package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -545
- package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
- package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
- package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
- package/node_modules/@types/node/ts4.8/events.d.ts +0 -879
- package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1239
- package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4311
- package/node_modules/@types/node/ts4.8/globals.d.ts +0 -411
- package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/http.d.ts +0 -1887
- package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
- package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
- package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
- package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
- package/node_modules/@types/node/ts4.8/module.d.ts +0 -315
- package/node_modules/@types/node/ts4.8/net.d.ts +0 -949
- package/node_modules/@types/node/ts4.8/os.d.ts +0 -478
- package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -645
- package/node_modules/@types/node/ts4.8/process.d.ts +0 -1561
- package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
- package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
- package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
- package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -366
- package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
- package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/ts4.8/test.d.ts +0 -1465
- package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
- package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
- package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
- package/node_modules/@types/node/ts4.8/url.d.ts +0 -927
- package/node_modules/@types/node/ts4.8/util.d.ts +0 -2183
- package/node_modules/@types/node/ts4.8/v8.d.ts +0 -764
- package/node_modules/@types/node/ts4.8/vm.d.ts +0 -903
- package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -179
- package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
- package/node_modules/@types/node/tty.d.ts +0 -208
- package/node_modules/@types/node/url.d.ts +0 -927
- package/node_modules/@types/node/util.d.ts +0 -2183
- package/node_modules/@types/node/v8.d.ts +0 -764
- package/node_modules/@types/node/vm.d.ts +0 -903
- package/node_modules/@types/node/wasi.d.ts +0 -179
- package/node_modules/@types/node/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/zlib.d.ts +0 -517
- package/src/helpers/getIp.ts +0 -5
- package/src/helpers/getRequestLogger.ts +0 -6
- package/src/helpers/now.ts +0 -3
- package/src/helpers/renderErrorJson.ts +0 -29
- package/src/index.ts +0 -10
- package/src/middlewares/accessLogger.ts +0 -34
- package/src/middlewares/auditLog.ts +0 -52
- package/src/middlewares/authedForOrg.ts +0 -50
- package/src/middlewares/authenticateUser.test.ts +0 -403
- package/src/middlewares/authenticateUser.ts +0 -171
- package/src/middlewares/createContext.test.ts +0 -85
- package/src/middlewares/createContext.ts +0 -49
- package/src/middlewares/hasRoles.ts +0 -24
- package/src/middlewares/jsonBodyParser.ts +0 -22
- package/src/middlewares/returnInternalServerError.ts +0 -15
- package/src/middlewares/returnNotFound.ts +0 -11
- package/src/test/mocks/authOptionsMocks.ts +0 -35
- package/src/test/mocks/expressMocks.ts +0 -33
- package/src/test/mocks/jwtUserMocks.ts +0 -19
- package/src/test/setup.test.ts +0 -15
- package/src/test/setup.ts +0 -3
- package/src/types/AuthMethod.ts +0 -27
- package/src/types/GenericRequest.ts +0 -3
- package/src/types/custom.d.ts +0 -20
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRequestBaseLog = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
function getRequestBaseLog(req) {
|
|
6
|
+
return `${(0, lodash_1.snakeCase)(req.path)}.${(0, lodash_1.snakeCase)(req.method)}`;
|
|
7
|
+
}
|
|
8
|
+
exports.getRequestBaseLog = getRequestBaseLog;
|
|
9
|
+
//# sourceMappingURL=getRequestBaseLog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRequestBaseLog.js","sourceRoot":"","sources":["../../src/helpers/getRequestBaseLog.ts"],"names":[],"mappings":";;;AACA,mCAAmC;AAEnC,SAAgB,iBAAiB,CAAC,GAAY;IAC5C,OAAO,GAAG,IAAA,kBAAS,EAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAA,kBAAS,EAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;AAC3D,CAAC;AAFD,8CAEC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RenderableView } from "@alanszp/errors";
|
|
2
2
|
export declare function render401Error(requiredChecks: string[]): RenderableView;
|
|
3
|
+
export declare function render403Error(): RenderableView;
|
|
3
4
|
export declare function render404Error(): RenderableView;
|
|
4
5
|
export declare function render400Error(message: string): RenderableView;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.render400Error = exports.render404Error = exports.render401Error = void 0;
|
|
3
|
+
exports.render400Error = exports.render404Error = exports.render403Error = exports.render401Error = void 0;
|
|
4
4
|
const core_1 = require("@alanszp/core");
|
|
5
5
|
function render401Error(requiredChecks) {
|
|
6
6
|
return {
|
|
@@ -11,6 +11,15 @@ function render401Error(requiredChecks) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
exports.render401Error = render401Error;
|
|
14
|
+
function render403Error() {
|
|
15
|
+
return {
|
|
16
|
+
code: "forbidden",
|
|
17
|
+
message: "Forbidden",
|
|
18
|
+
context: {},
|
|
19
|
+
origin: (0, core_1.appIdentifier)(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.render403Error = render403Error;
|
|
14
23
|
function render404Error() {
|
|
15
24
|
return {
|
|
16
25
|
code: "not_found",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderErrorJson.js","sourceRoot":"","sources":["../../src/helpers/renderErrorJson.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAG9C,SAAgB,cAAc,CAAC,cAAwB;IACrD,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,oBAAoB;QAC7B,OAAO,EAAE,EAAE,cAAc,EAAE;QAC3B,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC;AAED,SAAgB,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW;QACpB,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC;AAED,SAAgB,cAAc,CAAC,OAAe;IAC5C,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,OAAO;QACP,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC"}
|
|
1
|
+
{"version":3,"file":"renderErrorJson.js","sourceRoot":"","sources":["../../src/helpers/renderErrorJson.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAG9C,SAAgB,cAAc,CAAC,cAAwB;IACrD,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,oBAAoB;QAC7B,OAAO,EAAE,EAAE,cAAc,EAAE;QAC3B,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC;AAED,SAAgB,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW;QACpB,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC;AAED,SAAgB,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW;QACpB,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC;AAED,SAAgB,cAAc,CAAC,OAAe;IAC5C,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,OAAO;QACP,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export * from "./middlewares/accessLogger";
|
|
|
4
4
|
export * from "./middlewares/authedForOrg";
|
|
5
5
|
export * from "./middlewares/createContext";
|
|
6
6
|
export * from "./middlewares/authenticateUser";
|
|
7
|
-
export * from "./middlewares/
|
|
7
|
+
export * from "./middlewares/errorRequestHandlerMiddleware";
|
|
8
8
|
export * from "./middlewares/returnNotFound";
|
|
9
9
|
export * from "./middlewares/jsonBodyParser";
|
|
10
10
|
export * from "./middlewares/hasRoles";
|
|
11
|
+
export * from "./middlewares/hasPermissions";
|
|
12
|
+
export * from "./helpers/getRequestBaseLog";
|
package/dist/index.js
CHANGED
|
@@ -16,8 +16,10 @@ __exportStar(require("./middlewares/accessLogger"), exports);
|
|
|
16
16
|
__exportStar(require("./middlewares/authedForOrg"), exports);
|
|
17
17
|
__exportStar(require("./middlewares/createContext"), exports);
|
|
18
18
|
__exportStar(require("./middlewares/authenticateUser"), exports);
|
|
19
|
-
__exportStar(require("./middlewares/
|
|
19
|
+
__exportStar(require("./middlewares/errorRequestHandlerMiddleware"), exports);
|
|
20
20
|
__exportStar(require("./middlewares/returnNotFound"), exports);
|
|
21
21
|
__exportStar(require("./middlewares/jsonBodyParser"), exports);
|
|
22
22
|
__exportStar(require("./middlewares/hasRoles"), exports);
|
|
23
|
+
__exportStar(require("./middlewares/hasPermissions"), exports);
|
|
24
|
+
__exportStar(require("./helpers/getRequestBaseLog"), exports);
|
|
23
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAmC;AACnC,yDAAuC;AACvC,6DAA2C;AAC3C,6DAA2C;AAC3C,8DAA4C;AAC5C,iEAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAmC;AACnC,yDAAuC;AACvC,6DAA2C;AAC3C,6DAA2C;AAC3C,8DAA4C;AAC5C,iEAA+C;AAC/C,8EAA4D;AAC5D,+DAA6C;AAC7C,+DAA6C;AAC7C,yDAAuC;AACvC,+DAA6C;AAC7C,8DAA4C"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ErrorRequestHandler } from "express";
|
|
2
|
+
import { ILogger } from "@alanszp/logger";
|
|
3
|
+
export declare type ErrorRequestHandlerMiddleware = (getLogger: () => ILogger) => ErrorRequestHandler;
|
|
4
|
+
export declare const errorRequestHandlerMiddleware: ErrorRequestHandlerMiddleware;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorRequestHandlerMiddleware = void 0;
|
|
4
|
+
const errors_1 = require("@alanszp/errors");
|
|
5
|
+
const getRequestBaseLog_1 = require("../helpers/getRequestBaseLog");
|
|
6
|
+
const typeorm_1 = require("typeorm");
|
|
7
|
+
const renderErrorJson_1 = require("../helpers/renderErrorJson");
|
|
8
|
+
const errorRequestHandlerMiddleware = (getLogger) => (error, req, res, _next) => {
|
|
9
|
+
const logger = getLogger();
|
|
10
|
+
const baseLog = (0, getRequestBaseLog_1.getRequestBaseLog)(req);
|
|
11
|
+
try {
|
|
12
|
+
if (error instanceof errors_1.RenderableError) {
|
|
13
|
+
const statusCode = error instanceof errors_1.HttpRenderableError ? error.httpCode() : 500;
|
|
14
|
+
if (statusCode >= 500) {
|
|
15
|
+
logger.error(`${baseLog}.error.${error.code()}`, {
|
|
16
|
+
statusCode,
|
|
17
|
+
error,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
logger.info(`${baseLog}.error.${error.code()}`, {
|
|
22
|
+
statusCode,
|
|
23
|
+
error,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
res.status(statusCode).json(error.toView());
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (error instanceof typeorm_1.EntityNotFoundError) {
|
|
30
|
+
logger.info(`${baseLog}.error.typeorm.entity_not_found`, {
|
|
31
|
+
error,
|
|
32
|
+
});
|
|
33
|
+
res.status(404).json((0, renderErrorJson_1.render404Error)());
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (error instanceof typeorm_1.QueryFailedError) {
|
|
37
|
+
if (error.code === "23505") {
|
|
38
|
+
logger.info(`${baseLog}.error.typeorm.query_error.duplicate`, {
|
|
39
|
+
error,
|
|
40
|
+
});
|
|
41
|
+
res.status(400).json((0, renderErrorJson_1.render400Error)("Entity already exists"));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
logger.error(`${baseLog}.error.typeorm.query_error.unknown`, {
|
|
45
|
+
error,
|
|
46
|
+
});
|
|
47
|
+
res.status(500).json(new errors_1.InternalServerError(error).toView());
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
res.status(500).json(new errors_1.InternalServerError(error).toView());
|
|
52
|
+
logger.error(`${baseLog}.error.return_internal_server_error.error_to_client`, { error });
|
|
53
|
+
}
|
|
54
|
+
catch (errorOfError) {
|
|
55
|
+
try {
|
|
56
|
+
// Try one last time to log the error
|
|
57
|
+
logger.error(`${baseLog}.error.return_internal_server_error.error_rendering_error_to_client`, { error: errorOfError });
|
|
58
|
+
}
|
|
59
|
+
catch (_error) { }
|
|
60
|
+
res.status(500).json({
|
|
61
|
+
code: "internal_server_error",
|
|
62
|
+
message: "Internal server error",
|
|
63
|
+
context: {},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.errorRequestHandlerMiddleware = errorRequestHandlerMiddleware;
|
|
68
|
+
//# sourceMappingURL=errorRequestHandlerMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorRequestHandlerMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/errorRequestHandlerMiddleware.ts"],"names":[],"mappings":";;;AACA,4CAIyB;AAGzB,oEAAiE;AACjE,qCAAgE;AAChE,gEAA4E;AAMrE,MAAM,6BAA6B,GACxC,CAAC,SAAwB,EAAE,EAAE,CAC7B,CAAC,KAAc,EAAE,GAAmB,EAAE,GAAa,EAAE,KAAmB,EAAE,EAAE;IAC1E,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,IAAA,qCAAiB,EAAC,GAAG,CAAC,CAAC;IAEvC,IAAI;QACF,IAAI,KAAK,YAAY,wBAAe,EAAE;YACpC,MAAM,UAAU,GACd,KAAK,YAAY,4BAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;YAEhE,IAAI,UAAU,IAAI,GAAG,EAAE;gBACrB,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,UAAU,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE;oBAC/C,UAAU;oBACV,KAAK;iBACN,CAAC,CAAC;aACJ;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,UAAU,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE;oBAC9C,UAAU;oBACV,KAAK;iBACN,CAAC,CAAC;aACJ;YAED,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC5C,OAAO;SACR;QAED,IAAI,KAAK,YAAY,6BAAmB,EAAE;YACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,iCAAiC,EAAE;gBACvD,KAAK;aACN,CAAC,CAAC;YACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,GAAE,CAAC,CAAC;YACvC,OAAO;SACR;QAED,IAAI,KAAK,YAAY,0BAAgB,EAAE;YACrC,IAAK,KAAqC,CAAC,IAAI,KAAK,OAAO,EAAE;gBAC3D,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,sCAAsC,EAAE;oBAC5D,KAAK;iBACN,CAAC,CAAC;gBACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,EAAC,uBAAuB,CAAC,CAAC,CAAC;aAC/D;iBAAM;gBACL,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,oCAAoC,EAAE;oBAC3D,KAAK;iBACN,CAAC,CAAC;gBACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,4BAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;aAC/D;YACD,OAAO;SACR;QAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,4BAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9D,MAAM,CAAC,KAAK,CACV,GAAG,OAAO,qDAAqD,EAC/D,EAAE,KAAK,EAAE,CACV,CAAC;KACH;IAAC,OAAO,YAAqB,EAAE;QAC9B,IAAI;YACF,qCAAqC;YACrC,MAAM,CAAC,KAAK,CACV,GAAG,OAAO,qEAAqE,EAC/E,EAAE,KAAK,EAAE,YAAY,EAAE,CACxB,CAAC;SACH;QAAC,OAAO,MAAe,EAAE,GAAE;QAE5B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,uBAAuB;YAC7B,OAAO,EAAE,uBAAuB;YAChC,OAAO,EAAE,EAAE;SACZ,CAAC,CAAC;KACJ;AACH,CAAC,CAAC;AAtES,QAAA,6BAA6B,iCAsEtC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NextFunction, Response } from "express";
|
|
2
|
+
import { GenericRequest } from "../types/GenericRequest";
|
|
3
|
+
/**
|
|
4
|
+
* Check if the jwtUser has a single permission
|
|
5
|
+
* If not, check if the jwtUser has the required roles (to maintain backwards compatibility)
|
|
6
|
+
* When neither permissions nor roles requirements are met, throw a NoPermissionError
|
|
7
|
+
*/
|
|
8
|
+
export declare function hasPermission(permission: string, oldRoleCodes?: string | string[]): (req: GenericRequest, res: Response, next: NextFunction) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Check if the jwtUser has at least one permission
|
|
11
|
+
* If not, check if the jwtUser has the required roles (to maintain backwards compatibility)
|
|
12
|
+
* When neither permissions nor roles requirements are met, throw a NoPermissionError
|
|
13
|
+
*/
|
|
14
|
+
export declare function hasSomePermission(permissions: string[], oldRoleCodes?: string | string[]): (req: GenericRequest, res: Response, next: NextFunction) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Check if the jwtUser has all permissions
|
|
17
|
+
* If not, check if the jwtUser has the required roles (to maintain backwards compatibility)
|
|
18
|
+
* When neither permissions nor roles requirements are met, throw a NoPermissionError
|
|
19
|
+
*/
|
|
20
|
+
export declare function hasEveryPermission(permissions: string[], oldRoleCodes?: string | string[]): (req: GenericRequest, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.hasEveryPermission = exports.hasSomePermission = exports.hasPermission = void 0;
|
|
13
|
+
const hasRoles_1 = require("./hasRoles");
|
|
14
|
+
const renderErrorJson_1 = require("../helpers/renderErrorJson");
|
|
15
|
+
function response401(res) {
|
|
16
|
+
res.status(401).json((0, renderErrorJson_1.render401Error)(["jwt"]));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check if the jwtUser has a single permission
|
|
20
|
+
* If not, check if the jwtUser has the required roles (to maintain backwards compatibility)
|
|
21
|
+
* When neither permissions nor roles requirements are met, throw a NoPermissionError
|
|
22
|
+
*/
|
|
23
|
+
function hasPermission(permission, oldRoleCodes) {
|
|
24
|
+
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
const { jwtUser } = req.context;
|
|
27
|
+
if (!jwtUser) {
|
|
28
|
+
return response401(res);
|
|
29
|
+
}
|
|
30
|
+
yield jwtUser.validatePermission(permission);
|
|
31
|
+
next();
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (oldRoleCodes) {
|
|
35
|
+
return (0, hasRoles_1.hasRoles)(oldRoleCodes)(req, res, next);
|
|
36
|
+
}
|
|
37
|
+
next(error);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.hasPermission = hasPermission;
|
|
42
|
+
/**
|
|
43
|
+
* Check if the jwtUser has at least one permission
|
|
44
|
+
* If not, check if the jwtUser has the required roles (to maintain backwards compatibility)
|
|
45
|
+
* When neither permissions nor roles requirements are met, throw a NoPermissionError
|
|
46
|
+
*/
|
|
47
|
+
function hasSomePermission(permissions, oldRoleCodes) {
|
|
48
|
+
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
try {
|
|
50
|
+
const { jwtUser } = req.context;
|
|
51
|
+
if (!jwtUser) {
|
|
52
|
+
return response401(res);
|
|
53
|
+
}
|
|
54
|
+
yield jwtUser.validateSomePermission(permissions);
|
|
55
|
+
next();
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (oldRoleCodes) {
|
|
59
|
+
return (0, hasRoles_1.hasRoles)(oldRoleCodes)(req, res, next);
|
|
60
|
+
}
|
|
61
|
+
next(error);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.hasSomePermission = hasSomePermission;
|
|
66
|
+
/**
|
|
67
|
+
* Check if the jwtUser has all permissions
|
|
68
|
+
* If not, check if the jwtUser has the required roles (to maintain backwards compatibility)
|
|
69
|
+
* When neither permissions nor roles requirements are met, throw a NoPermissionError
|
|
70
|
+
*/
|
|
71
|
+
function hasEveryPermission(permissions, oldRoleCodes) {
|
|
72
|
+
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
try {
|
|
74
|
+
const { jwtUser } = req.context;
|
|
75
|
+
if (!jwtUser) {
|
|
76
|
+
return response401(res);
|
|
77
|
+
}
|
|
78
|
+
yield jwtUser.validateEveryPermission(permissions);
|
|
79
|
+
next();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (oldRoleCodes) {
|
|
83
|
+
return (0, hasRoles_1.hasRoles)(oldRoleCodes)(req, res, next);
|
|
84
|
+
}
|
|
85
|
+
next(error);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.hasEveryPermission = hasEveryPermission;
|
|
90
|
+
//# sourceMappingURL=hasPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasPermissions.js","sourceRoot":"","sources":["../../src/middlewares/hasPermissions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAAsC;AACtC,gEAA4E;AAE5E,SAAS,WAAW,CAAC,GAAa;IAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,EAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,UAAkB,EAClB,YAAgC;IAEhC,OAAO,CAAO,GAAmB,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACtE,IAAI;YACF,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;YAChC,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;aACzB;YAED,MAAM,OAAO,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;YAC7C,IAAI,EAAE,CAAC;SACR;QAAC,OAAO,KAAc,EAAE;YACvB,IAAI,YAAY,EAAE;gBAChB,OAAO,IAAA,mBAAQ,EAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;aAC/C;YACD,IAAI,CAAC,KAAK,CAAC,CAAC;SACb;IACH,CAAC,CAAA,CAAC;AACJ,CAAC;AApBD,sCAoBC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,WAAqB,EACrB,YAAgC;IAEhC,OAAO,CAAO,GAAmB,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACtE,IAAI;YACF,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;YAChC,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;aACzB;YAED,MAAM,OAAO,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC;YAClD,IAAI,EAAE,CAAC;SACR;QAAC,OAAO,KAAc,EAAE;YACvB,IAAI,YAAY,EAAE;gBAChB,OAAO,IAAA,mBAAQ,EAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;aAC/C;YACD,IAAI,CAAC,KAAK,CAAC,CAAC;SACb;IACH,CAAC,CAAA,CAAC;AACJ,CAAC;AApBD,8CAoBC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAChC,WAAqB,EACrB,YAAgC;IAEhC,OAAO,CAAO,GAAmB,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACtE,IAAI;YACF,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;YAChC,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;aACzB;YAED,MAAM,OAAO,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;YACnD,IAAI,EAAE,CAAC;SACR;QAAC,OAAO,KAAc,EAAE;YACvB,IAAI,YAAY,EAAE;gBAChB,OAAO,IAAA,mBAAQ,EAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;aAC/C;YACD,IAAI,CAAC,KAAK,CAAC,CAAC;SACb;IACH,CAAC,CAAA,CAAC;AACJ,CAAC;AApBD,gDAoBC"}
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasRoles = void 0;
|
|
4
4
|
const renderErrorJson_1 = require("../helpers/renderErrorJson");
|
|
5
|
-
function
|
|
6
|
-
res.status(
|
|
5
|
+
function response403(res) {
|
|
6
|
+
res.status(403).json((0, renderErrorJson_1.render403Error)());
|
|
7
7
|
}
|
|
8
8
|
function hasRoles(roles) {
|
|
9
9
|
return (req, res, next) => {
|
|
10
10
|
const { jwtUser } = req.context;
|
|
11
11
|
if (!jwtUser) {
|
|
12
|
-
return
|
|
12
|
+
return response403(res);
|
|
13
13
|
}
|
|
14
14
|
if (jwtUser.hasRoles(roles)) {
|
|
15
15
|
return next();
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
response403(res);
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
exports.hasRoles = hasRoles;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasRoles.js","sourceRoot":"","sources":["../../src/middlewares/hasRoles.ts"],"names":[],"mappings":";;;AAEA,gEAA4D;AAE5D,SAAS,WAAW,CAAC,GAAa;IAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,
|
|
1
|
+
{"version":3,"file":"hasRoles.js","sourceRoot":"","sources":["../../src/middlewares/hasRoles.ts"],"names":[],"mappings":";;;AAEA,gEAA4D;AAE5D,SAAS,WAAW,CAAC,GAAa;IAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,GAAE,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,QAAQ,CACtB,KAAwB;IAExB,OAAO,CAAC,GAAmB,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAChE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;SACzB;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO,IAAI,EAAE,CAAC;SACf;QAED,WAAW,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC;AAfD,4BAeC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
4
4
|
"description": "Alan's express utils and middlewares.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"files": [
|
|
9
|
-
"**/*"
|
|
10
|
-
],
|
|
11
8
|
"publishConfig": {
|
|
12
9
|
"access": "public"
|
|
13
10
|
},
|
|
@@ -21,7 +18,8 @@
|
|
|
21
18
|
},
|
|
22
19
|
"peerDependencies": {
|
|
23
20
|
"@alanszp/errors": ">=12.0.0",
|
|
24
|
-
"express": "^4.17.1"
|
|
21
|
+
"express": "^4.17.1",
|
|
22
|
+
"typeorm": "^0.2.41"
|
|
25
23
|
},
|
|
26
24
|
"devDependencies": {
|
|
27
25
|
"@types/body-parser": "^1.19.1",
|
|
@@ -33,17 +31,18 @@
|
|
|
33
31
|
"jest": "^29.7.0",
|
|
34
32
|
"ts-node": "^10.0.0",
|
|
35
33
|
"tslint": "^6.1.3",
|
|
34
|
+
"typeorm": "^0.2.41",
|
|
36
35
|
"typescript": "^4.3.4"
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|
|
39
|
-
"@alanszp/audit": "^
|
|
40
|
-
"@alanszp/jwt": "^
|
|
41
|
-
"@alanszp/logger": "^
|
|
42
|
-
"@alanszp/shared-context": "^
|
|
38
|
+
"@alanszp/audit": "^13.0.0",
|
|
39
|
+
"@alanszp/jwt": "^13.0.0",
|
|
40
|
+
"@alanszp/logger": "^13.0.0",
|
|
41
|
+
"@alanszp/shared-context": "^13.0.0",
|
|
43
42
|
"@babel/core": "^7.23.9",
|
|
44
43
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
45
44
|
"body-parser": "^1.20.2",
|
|
46
45
|
"lodash": "^4.17.21"
|
|
47
46
|
},
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "a9643f1301fe2e704611805b65e64de2ee5186cd"
|
|
49
48
|
}
|
package/.gitignore
DELETED
package/.npmignore
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ErrorRequestHandler } from "express";
|
|
2
|
-
import { ILogger } from "@alanszp/logger";
|
|
3
|
-
export declare type GetInternalServerErrorMiddleware = (getLogger: () => ILogger) => ErrorRequestHandler;
|
|
4
|
-
export declare const returnInternalServerError: GetInternalServerErrorMiddleware;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.returnInternalServerError = void 0;
|
|
4
|
-
const errors_1 = require("@alanszp/errors");
|
|
5
|
-
const returnInternalServerError = (getLogger) => (error, req, res, _next) => {
|
|
6
|
-
res.status(500).json(new errors_1.InternalServerError(error).toView());
|
|
7
|
-
getLogger().error("error_to_client", { error });
|
|
8
|
-
};
|
|
9
|
-
exports.returnInternalServerError = returnInternalServerError;
|
|
10
|
-
//# sourceMappingURL=returnInternalServerError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"returnInternalServerError.js","sourceRoot":"","sources":["../../src/middlewares/returnInternalServerError.ts"],"names":[],"mappings":";;;AACA,4CAAsD;AAQ/C,MAAM,yBAAyB,GACpC,CAAC,SAAwB,EAAE,EAAE,CAC7B,CAAC,KAAc,EAAE,GAAmB,EAAE,GAAa,EAAE,KAAmB,EAAE,EAAE;IAC1E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,4BAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9D,SAAS,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC,CAAC;AALS,QAAA,yBAAyB,6BAKlC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Facebook, Inc. and its affiliates.
|
|
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.
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# `@jest/expect-utils`
|
|
2
|
-
|
|
3
|
-
This module exports some utils for the `expect` function used in [Jest](https://jestjs.io/).
|
|
4
|
-
|
|
5
|
-
You probably don't want to use this package directly. E.g. if you're writing [custom matcher](https://jestjs.io/docs/expect#expectextendmatchers), you should use the injected [`this.equals`](https://jestjs.io/docs/expect#thisequalsa-b).
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
export declare const arrayBufferEquality: (
|
|
8
|
-
a: unknown,
|
|
9
|
-
b: unknown,
|
|
10
|
-
) => boolean | undefined;
|
|
11
|
-
|
|
12
|
-
export declare function emptyObject(obj: unknown): boolean;
|
|
13
|
-
|
|
14
|
-
export declare const equals: EqualsFunction;
|
|
15
|
-
|
|
16
|
-
export declare type EqualsFunction = (
|
|
17
|
-
a: unknown,
|
|
18
|
-
b: unknown,
|
|
19
|
-
customTesters?: Array<Tester>,
|
|
20
|
-
strictCheck?: boolean,
|
|
21
|
-
) => boolean;
|
|
22
|
-
|
|
23
|
-
export declare const getObjectSubset: (
|
|
24
|
-
object: any,
|
|
25
|
-
subset: any,
|
|
26
|
-
seenReferences?: WeakMap<object, boolean>,
|
|
27
|
-
) => any;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
31
|
-
*
|
|
32
|
-
* This source code is licensed under the MIT license found in the
|
|
33
|
-
* LICENSE file in the root directory of this source tree.
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
declare type GetPath = {
|
|
37
|
-
hasEndProp?: boolean;
|
|
38
|
-
endPropIsDefined?: boolean;
|
|
39
|
-
lastTraversedObject: unknown;
|
|
40
|
-
traversedPath: Array<string>;
|
|
41
|
-
value?: unknown;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export declare const getPath: (
|
|
45
|
-
object: Record<string, any>,
|
|
46
|
-
propertyPath: string | Array<string>,
|
|
47
|
-
) => GetPath;
|
|
48
|
-
|
|
49
|
-
export declare function isA(typeName: string, value: unknown): boolean;
|
|
50
|
-
|
|
51
|
-
export declare const isError: (value: unknown) => value is Error;
|
|
52
|
-
|
|
53
|
-
export declare const isOneline: (
|
|
54
|
-
expected: unknown,
|
|
55
|
-
received: unknown,
|
|
56
|
-
) => boolean;
|
|
57
|
-
|
|
58
|
-
export declare const iterableEquality: (
|
|
59
|
-
a: any,
|
|
60
|
-
b: any,
|
|
61
|
-
aStack?: Array<any>,
|
|
62
|
-
bStack?: Array<any>,
|
|
63
|
-
) => boolean | undefined;
|
|
64
|
-
|
|
65
|
-
export declare const partition: <T>(
|
|
66
|
-
items: T[],
|
|
67
|
-
predicate: (arg: T) => boolean,
|
|
68
|
-
) => [T[], T[]];
|
|
69
|
-
|
|
70
|
-
export declare const pathAsArray: (propertyPath: string) => Array<any>;
|
|
71
|
-
|
|
72
|
-
export declare const sparseArrayEquality: (
|
|
73
|
-
a: unknown,
|
|
74
|
-
b: unknown,
|
|
75
|
-
) => boolean | undefined;
|
|
76
|
-
|
|
77
|
-
export declare const subsetEquality: (
|
|
78
|
-
object: unknown,
|
|
79
|
-
subset: unknown,
|
|
80
|
-
) => boolean | undefined;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
84
|
-
*
|
|
85
|
-
* This source code is licensed under the MIT license found in the
|
|
86
|
-
* LICENSE file in the root directory of this source tree.
|
|
87
|
-
*
|
|
88
|
-
*/
|
|
89
|
-
export declare type Tester = (a: any, b: any) => boolean | undefined;
|
|
90
|
-
|
|
91
|
-
export declare const typeEquality: (a: any, b: any) => boolean | undefined;
|
|
92
|
-
|
|
93
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
equals: true,
|
|
8
|
-
isA: true
|
|
9
|
-
};
|
|
10
|
-
Object.defineProperty(exports, 'equals', {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _jasmineUtils.equals;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, 'isA', {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return _jasmineUtils.isA;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
var _jasmineUtils = require('./jasmineUtils');
|
|
24
|
-
|
|
25
|
-
var _utils = require('./utils');
|
|
26
|
-
|
|
27
|
-
Object.keys(_utils).forEach(function (key) {
|
|
28
|
-
if (key === 'default' || key === '__esModule') return;
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
30
|
-
if (key in exports && exports[key] === _utils[key]) return;
|
|
31
|
-
Object.defineProperty(exports, key, {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return _utils[key];
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|