@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
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { createId } from "@paralleldrive/cuid2";
|
|
2
|
-
import { NextFunction, Response } from "express";
|
|
3
|
-
import { ILogger } from "@alanszp/logger";
|
|
4
|
-
import { Audit } from "@alanszp/audit";
|
|
5
|
-
import { appIdentifier } from "@alanszp/core";
|
|
6
|
-
import { GenericRequest } from "../types/GenericRequest";
|
|
7
|
-
import { SharedContext } from "@alanszp/shared-context";
|
|
8
|
-
import { compact } from "lodash";
|
|
9
|
-
|
|
10
|
-
export function createContext(
|
|
11
|
-
sharedContext: SharedContext,
|
|
12
|
-
baseLogger: ILogger,
|
|
13
|
-
audit: Audit
|
|
14
|
-
) {
|
|
15
|
-
return (req: GenericRequest, res: Response, next: NextFunction): void => {
|
|
16
|
-
req.context = req.context || {};
|
|
17
|
-
|
|
18
|
-
const receivedChain =
|
|
19
|
-
req.header("x-lifecycle-chain") || req.body?.detail?.lch;
|
|
20
|
-
const lifecycleChain = compact([receivedChain, appIdentifier()]).join(",");
|
|
21
|
-
|
|
22
|
-
const lifecycleId =
|
|
23
|
-
req.header("x-lifecycle-id") || req.body?.detail?.lid || createId();
|
|
24
|
-
|
|
25
|
-
const contextId = createId();
|
|
26
|
-
|
|
27
|
-
res.setHeader("x-lifecycle-id", lifecycleId);
|
|
28
|
-
res.setHeader("x-context-id", contextId);
|
|
29
|
-
|
|
30
|
-
sharedContext.run(
|
|
31
|
-
(context) => {
|
|
32
|
-
req.context.authenticated = [];
|
|
33
|
-
req.context.lifecycleId = context.lifecycleId;
|
|
34
|
-
req.context.lifecycleChain = context.lifecycleChain;
|
|
35
|
-
req.context.contextId = context.contextId;
|
|
36
|
-
req.context.log = context.logger;
|
|
37
|
-
req.context.audit = context.audit;
|
|
38
|
-
next();
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
logger: baseLogger,
|
|
42
|
-
audit: audit.withState(),
|
|
43
|
-
lifecycleId,
|
|
44
|
-
lifecycleChain,
|
|
45
|
-
contextId,
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Response } from "express";
|
|
2
|
-
import { GenericRequest } from "../types/GenericRequest";
|
|
3
|
-
import { render401Error } from "../helpers/renderErrorJson";
|
|
4
|
-
|
|
5
|
-
function response401(res: Response): void {
|
|
6
|
-
res.status(401).json(render401Error(["permissions"]));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function hasRoles(
|
|
10
|
-
roles: string | string[]
|
|
11
|
-
): (req: GenericRequest, res: Response, next: NextFunction) => void {
|
|
12
|
-
return (req: GenericRequest, res: Response, next: NextFunction) => {
|
|
13
|
-
const { jwtUser } = req.context;
|
|
14
|
-
if (!jwtUser) {
|
|
15
|
-
return response401(res);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (jwtUser.hasRoles(roles)) {
|
|
19
|
-
return next();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
response401(res);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { json, OptionsJson } from "body-parser";
|
|
2
|
-
import { NextFunction, Response } from "express";
|
|
3
|
-
import { GenericRequest } from "../types/GenericRequest";
|
|
4
|
-
import { render400Error } from "../helpers/renderErrorJson";
|
|
5
|
-
|
|
6
|
-
export function jsonBodyParser(options?: OptionsJson) {
|
|
7
|
-
const bodyParser = json({ limit: "1mb", ...options });
|
|
8
|
-
return function jsonBodyParserMiddleware(
|
|
9
|
-
req: GenericRequest,
|
|
10
|
-
res: Response,
|
|
11
|
-
next: NextFunction
|
|
12
|
-
): void {
|
|
13
|
-
try {
|
|
14
|
-
bodyParser(req, res, (error?: unknown) => {
|
|
15
|
-
if (!error) return next();
|
|
16
|
-
res.status(400).json(render400Error("Malformed JSON"));
|
|
17
|
-
});
|
|
18
|
-
} catch (error: unknown) {
|
|
19
|
-
res.status(400).json(render400Error("Malformed JSON"));
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ErrorRequestHandler, NextFunction, Response } from "express";
|
|
2
|
-
import { InternalServerError } from "@alanszp/errors";
|
|
3
|
-
import { GenericRequest } from "../types/GenericRequest";
|
|
4
|
-
import { ILogger } from "@alanszp/logger";
|
|
5
|
-
|
|
6
|
-
export type GetInternalServerErrorMiddleware = (
|
|
7
|
-
getLogger: () => ILogger
|
|
8
|
-
) => ErrorRequestHandler;
|
|
9
|
-
|
|
10
|
-
export const returnInternalServerError: GetInternalServerErrorMiddleware =
|
|
11
|
-
(getLogger: () => ILogger) =>
|
|
12
|
-
(error: unknown, req: GenericRequest, res: Response, _next: NextFunction) => {
|
|
13
|
-
res.status(500).json(new InternalServerError(error).toView());
|
|
14
|
-
getLogger().error("error_to_client", { error });
|
|
15
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Response } from "express";
|
|
2
|
-
import { GenericRequest } from "../types/GenericRequest";
|
|
3
|
-
import { render404Error } from "../helpers/renderErrorJson";
|
|
4
|
-
|
|
5
|
-
export function returnNotFound(
|
|
6
|
-
_req: GenericRequest,
|
|
7
|
-
res: Response,
|
|
8
|
-
_next: NextFunction
|
|
9
|
-
): void {
|
|
10
|
-
res.status(404).json(render404Error());
|
|
11
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ApiKeyOptions,
|
|
3
|
-
AuthMethods,
|
|
4
|
-
BothMethodsOptions,
|
|
5
|
-
JWTOptions,
|
|
6
|
-
} from "../../middlewares/authenticateUser";
|
|
7
|
-
|
|
8
|
-
export const jwtAuthOptions = {
|
|
9
|
-
jwtVerifyOptions: {
|
|
10
|
-
publicKey: "publicKey",
|
|
11
|
-
issuer: "issuer",
|
|
12
|
-
audience: "audience",
|
|
13
|
-
},
|
|
14
|
-
types: [AuthMethods.JWT],
|
|
15
|
-
} as any as JWTOptions;
|
|
16
|
-
|
|
17
|
-
export const verifyOptions = {
|
|
18
|
-
issuer: "issuer",
|
|
19
|
-
audience: "audience",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const apiKeyAuthOptions: ApiKeyOptions = {
|
|
23
|
-
validApiKeys: ["token", "tooooken"],
|
|
24
|
-
types: [AuthMethods.API_KEY],
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const bothMethodsAuthOptions: BothMethodsOptions = {
|
|
28
|
-
jwtVerifyOptions: {
|
|
29
|
-
publicKey: "publicKey",
|
|
30
|
-
issuer: "issuer",
|
|
31
|
-
audience: "audience",
|
|
32
|
-
},
|
|
33
|
-
validApiKeys: ["token", "tooooken"],
|
|
34
|
-
types: [AuthMethods.API_KEY, AuthMethods.JWT],
|
|
35
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { GenericRequest } from "../../types/GenericRequest";
|
|
2
|
-
|
|
3
|
-
export const mockRequest = (
|
|
4
|
-
authorization: string,
|
|
5
|
-
otherHeaders?: Record<string, unknown>
|
|
6
|
-
): GenericRequest => {
|
|
7
|
-
const headers = { authorization, ...otherHeaders };
|
|
8
|
-
return {
|
|
9
|
-
headers,
|
|
10
|
-
context: { jwtUser: undefined, authenticated: [] },
|
|
11
|
-
header: (name: string) => headers[name],
|
|
12
|
-
} as any as GenericRequest;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const mockRequestWithBody = (
|
|
16
|
-
authorization: string,
|
|
17
|
-
otherHeaders?: Record<string, unknown>,
|
|
18
|
-
body: Record<string, unknown> = {}
|
|
19
|
-
): GenericRequest => {
|
|
20
|
-
return {
|
|
21
|
-
...mockRequest(authorization, otherHeaders),
|
|
22
|
-
body,
|
|
23
|
-
} as any as GenericRequest;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const mockResponse = () => {
|
|
27
|
-
const res = {} as any;
|
|
28
|
-
res.status = jest.fn().mockReturnValue(res);
|
|
29
|
-
res.json = jest.fn().mockReturnValue(res);
|
|
30
|
-
return res;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const mockNext = () => jest.fn();
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { JWTUser } from "@alanszp/jwt";
|
|
2
|
-
|
|
3
|
-
export const userJwtUserMock: JWTUser = new JWTUser({
|
|
4
|
-
id: "1",
|
|
5
|
-
employeeReference: "1",
|
|
6
|
-
organizationReference: "test",
|
|
7
|
-
roles: [],
|
|
8
|
-
permissions: "MA==",
|
|
9
|
-
segmentReference: null,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export const laraJwtUserMock: JWTUser = new JWTUser({
|
|
13
|
-
id: "0",
|
|
14
|
-
employeeReference: "0",
|
|
15
|
-
organizationReference: "lara",
|
|
16
|
-
roles: [],
|
|
17
|
-
permissions: "MA==",
|
|
18
|
-
segmentReference: null,
|
|
19
|
-
});
|
package/src/test/setup.test.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { now } from "../helpers/now";
|
|
2
|
-
|
|
3
|
-
jest.mock("@/helpers/now");
|
|
4
|
-
|
|
5
|
-
describe("Timezones", () => {
|
|
6
|
-
it("should always be UTC", () => {
|
|
7
|
-
expect(new Date().getTimezoneOffset()).toBe(0);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("now() is mocked", () => {
|
|
11
|
-
(now as jest.Mock).mockReturnValue(new Date("2021-01-01T12:30:43"));
|
|
12
|
-
|
|
13
|
-
expect(now()).toEqual(new Date("2021-01-01T12:30:43"));
|
|
14
|
-
});
|
|
15
|
-
});
|
package/src/test/setup.ts
DELETED
package/src/types/AuthMethod.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
-
export type DistributiveOmit<T, K extends keyof any> = T extends any
|
|
3
|
-
? Omit<T, K>
|
|
4
|
-
: never;
|
|
5
|
-
|
|
6
|
-
export type Overwrite<T, U> = DistributiveOmit<T, keyof U> & U;
|
|
7
|
-
|
|
8
|
-
type GenerateStringUnion<T> = Extract<
|
|
9
|
-
{
|
|
10
|
-
[Key in keyof T]: true extends T[Key] ? Key : never;
|
|
11
|
-
}[keyof T],
|
|
12
|
-
string
|
|
13
|
-
>;
|
|
14
|
-
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
type OverridableStringUnion<
|
|
17
|
-
T extends string | number,
|
|
18
|
-
U = {}
|
|
19
|
-
> = GenerateStringUnion<Overwrite<Record<T, true>, U>>;
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
22
|
-
export interface AuthMethodsOverride {}
|
|
23
|
-
|
|
24
|
-
export type AuthMethod = OverridableStringUnion<
|
|
25
|
-
"jwt" | "api_key",
|
|
26
|
-
AuthMethodsOverride
|
|
27
|
-
>;
|
package/src/types/custom.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ILogger } from "@alanszp/logger";
|
|
2
|
-
import { AuditWithState } from "@alanszp/audit";
|
|
3
|
-
import { JWTUser } from "@alanszp/jwt";
|
|
4
|
-
import { AuthMethod } from "./AuthMethod";
|
|
5
|
-
|
|
6
|
-
declare global {
|
|
7
|
-
namespace Express {
|
|
8
|
-
export interface Request {
|
|
9
|
-
context: {
|
|
10
|
-
lifecycleId: string;
|
|
11
|
-
lifecycleChain: string;
|
|
12
|
-
contextId: string;
|
|
13
|
-
authenticated: AuthMethod[];
|
|
14
|
-
log: ILogger;
|
|
15
|
-
audit: AuditWithState;
|
|
16
|
-
jwtUser?: JWTUser;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|