@cley_faye/boilerplate 3.12.1 → 3.13.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/README.md +3 -1
- package/lib/express/logger.d.ts +3 -3
- package/lib/express/logger.js +15 -5
- package/lib/express/middlewares/bodylogger.d.ts +3 -3
- package/lib/express/pipelinebuilder.d.ts +9 -7
- package/lib/grunt/args.d.ts +5 -5
- package/lib/grunt/reactapp/pug.d.ts +1 -1
- package/lib/grunt/reactapp/util.d.ts +2 -2
- package/lib/grunt/reactapp.d.ts +1 -1
- package/lib/grunt/reactapp.js +1 -1
- package/lib/grunt/util.d.ts +2 -2
- package/lib/repl.d.ts +1 -1
- package/lib/util.js +3 -3
- package/lib/winston.d.ts +1 -1
- package/package.json +14 -12
package/README.md
CHANGED
|
@@ -407,9 +407,11 @@ router.post(
|
|
|
407
407
|
In addition to excluding properties from the body of a request and adding custom properties, it can
|
|
408
408
|
be useful to always identify a request coming from a logged-in user.
|
|
409
409
|
|
|
410
|
-
You can provide a `
|
|
410
|
+
You can provide a `authFromReq` property to the `options.log` configuration.
|
|
411
411
|
It should be a function that receive `req` as its argument and returns a string identifying the
|
|
412
412
|
logged-in user.
|
|
413
|
+
(this only work with the default log handler; if you define anything in `route` you can set this in
|
|
414
|
+
`dynamicMeta()`)
|
|
413
415
|
|
|
414
416
|
### Configuring global aspects of an Express App
|
|
415
417
|
|
package/lib/express/logger.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import expressWinston, { BaseLoggerOptions } from "express-winston";
|
|
2
2
|
import { Request, Router } from "express";
|
|
3
3
|
import { LogOptions, UserFromReqFunc } from "./pipelinebuilder.js";
|
|
4
|
-
export
|
|
4
|
+
export type LoggerOptions = expressWinston.BaseLoggerOptions | boolean;
|
|
5
5
|
interface ErrorLoggerConfiguration {
|
|
6
6
|
/** @deprecated Use collapseStacktrace */
|
|
7
7
|
collapseNodeModules?: boolean;
|
|
8
8
|
collapseStacktrace?: boolean;
|
|
9
9
|
extraFilter?: Array<RegExp> | RegExp;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export type ErrorLoggerOptions = ErrorLoggerConfiguration | boolean;
|
|
12
12
|
export interface LoggingData {
|
|
13
13
|
extraLoggingData?: Record<string, unknown>;
|
|
14
14
|
}
|
|
@@ -19,7 +19,7 @@ export interface RequestWithLoggingData extends Request {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
/** Return the default value for route logger is it is set as `true` */
|
|
22
|
-
export declare const defaultRouteLoggerConfig: (
|
|
22
|
+
export declare const defaultRouteLoggerConfig: (authFromReq?: UserFromReqFunc) => BaseLoggerOptions;
|
|
23
23
|
export declare const registerRouteLogger: (app: Router, logOptions?: LogOptions) => void;
|
|
24
24
|
export declare const registerErrorLogger: (app: Router, logOptions?: LogOptions) => void;
|
|
25
25
|
export {};
|
package/lib/express/logger.js
CHANGED
|
@@ -57,24 +57,34 @@ const customRouteFormat = (outputTimestamp) => winston_1.default.format.printf((
|
|
|
57
57
|
return (0, winston_js_1.prefixOutput)(info.level, finalMessage, outputTimestamp);
|
|
58
58
|
});
|
|
59
59
|
/** Return the default value for route logger is it is set as `true` */
|
|
60
|
-
const defaultRouteLoggerConfig = (
|
|
60
|
+
const defaultRouteLoggerConfig = (authFromReq) => ({
|
|
61
61
|
meta: true,
|
|
62
62
|
requestWhitelist: ["body"],
|
|
63
63
|
responseWhitelist: [],
|
|
64
64
|
dynamicMeta: (req) => {
|
|
65
65
|
const castReq = req;
|
|
66
66
|
const data = { ...castReq._cleyfayeLogging?.extraLoggingData };
|
|
67
|
-
if (
|
|
68
|
-
|
|
67
|
+
if (authFromReq) {
|
|
68
|
+
const value = authFromReq(req);
|
|
69
|
+
if (!value) {
|
|
70
|
+
data.auth = null;
|
|
71
|
+
}
|
|
72
|
+
else if (typeof value === "string") {
|
|
73
|
+
data.auth = value;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
Object.assign(data, value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
69
79
|
return data;
|
|
70
80
|
},
|
|
71
81
|
});
|
|
72
82
|
exports.defaultRouteLoggerConfig = defaultRouteLoggerConfig;
|
|
73
83
|
const registerRouteLogger = (app, logOptions) => {
|
|
74
|
-
const { route, timestamp, userFromReq } = logOptions ?? {};
|
|
84
|
+
const { route, timestamp, userFromReq, authFromReq } = logOptions ?? {};
|
|
75
85
|
let extraConfig;
|
|
76
86
|
if (typeof route === "boolean") {
|
|
77
|
-
extraConfig = (0, exports.defaultRouteLoggerConfig)(userFromReq);
|
|
87
|
+
extraConfig = (0, exports.defaultRouteLoggerConfig)(authFromReq ?? userFromReq);
|
|
78
88
|
}
|
|
79
89
|
else {
|
|
80
90
|
extraConfig = { ...route };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export type ExtraLoggingDataType = Record<string, unknown> | undefined;
|
|
3
|
+
export type ExtraLoggingDataFunc = (req: Request) => Promise<ExtraLoggingDataType> | ExtraLoggingDataType;
|
|
4
|
+
export type ExtraLoggingData = ExtraLoggingDataFunc | Record<string, unknown>;
|
|
5
5
|
export interface ExtraLoggingOptions {
|
|
6
6
|
/** Do not expose the "hidden" body props */
|
|
7
7
|
noHiddenBodyProps?: boolean;
|
|
@@ -2,36 +2,38 @@ import express, { Request } from "express";
|
|
|
2
2
|
import { OptionsJson, OptionsUrlencoded, OptionsText, Options as OptionsRaw } from "body-parser";
|
|
3
3
|
import winston from "winston";
|
|
4
4
|
import { LoggerOptions, ErrorLoggerOptions } from "./logger.js";
|
|
5
|
-
export
|
|
5
|
+
export type LogFunction = (...args: Array<string | number | Record<string, unknown>>) => void;
|
|
6
6
|
export interface MiddlewareOptions {
|
|
7
7
|
urlencoded?: boolean | OptionsUrlencoded;
|
|
8
8
|
text?: boolean | OptionsText;
|
|
9
9
|
raw?: boolean | OptionsRaw;
|
|
10
10
|
json?: boolean | OptionsJson;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type ComplexRouteHandler = express.RequestHandler | express.Router | Array<express.RequestHandler>;
|
|
13
13
|
export interface ComplexRouteDefinition {
|
|
14
14
|
route: string;
|
|
15
15
|
handler: ComplexRouteHandler;
|
|
16
16
|
method?: "get" | "post" | "put" | "options";
|
|
17
17
|
}
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
18
|
+
export type RouteDefinition = ComplexRouteDefinition | express.RequestHandler;
|
|
19
|
+
export type RouterDefinition = express.Router | RouteDefinition;
|
|
20
|
+
export type RouterWithNullDef = RouterDefinition | null | undefined;
|
|
21
21
|
export interface ComplexStaticDefinition {
|
|
22
22
|
root: string;
|
|
23
23
|
options?: Record<string, unknown>;
|
|
24
24
|
route?: string;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
27
|
-
export
|
|
26
|
+
export type StaticDefinition = ComplexStaticDefinition | string;
|
|
27
|
+
export type UserFromReqFunc = (req: Request) => string | Record<string, unknown> | undefined;
|
|
28
28
|
export interface LogOptions {
|
|
29
29
|
route?: LoggerOptions;
|
|
30
30
|
error?: ErrorLoggerOptions;
|
|
31
31
|
logger?: winston.Logger;
|
|
32
32
|
timestamp?: boolean;
|
|
33
33
|
extraStacktraceFilter?: Array<RegExp> | RegExp;
|
|
34
|
+
/** @deprecated Use `authFromReq` instead */
|
|
34
35
|
userFromReq?: UserFromReqFunc;
|
|
36
|
+
authFromReq?: UserFromReqFunc;
|
|
35
37
|
}
|
|
36
38
|
export interface DefaultErrorHandlerConfig {
|
|
37
39
|
/** Set to true to allow server errors without a code to be sent as-is in the response */
|
package/lib/grunt/args.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ export declare enum OptType {
|
|
|
6
6
|
/**
|
|
7
7
|
* Possible value type for options from command line
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type OptValue = string | number | boolean;
|
|
10
10
|
/**
|
|
11
11
|
* List of all configured options
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type Opts = Record<string, OptValue>;
|
|
14
14
|
/**
|
|
15
15
|
* Raw value type from command line
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export type RawOptValue = undefined | boolean | string;
|
|
18
18
|
/**
|
|
19
19
|
* Interface to an option provider (usually Grunt itself)
|
|
20
20
|
*/
|
|
@@ -61,11 +61,11 @@ export interface OptionDefinitionBoolean extends OptionDefinitionBase {
|
|
|
61
61
|
/**
|
|
62
62
|
* All possible option definition types
|
|
63
63
|
*/
|
|
64
|
-
export
|
|
64
|
+
export type OptionDefinition = OptionDefinitionString | OptionDefinitionNumber | OptionDefinitionBoolean;
|
|
65
65
|
/**
|
|
66
66
|
* Expected options from command line
|
|
67
67
|
*/
|
|
68
|
-
export
|
|
68
|
+
export type ConfigDefinition = Record<string, OptionDefinition>;
|
|
69
69
|
/**
|
|
70
70
|
* Display help to the user
|
|
71
71
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseOptions } from "../util.js";
|
|
2
2
|
import { HandlerFunctionResult } from "../reactapp.js";
|
|
3
3
|
import { GruntConfig } from "./util.js";
|
|
4
|
-
export
|
|
4
|
+
export type DynamicDataFunc = () => Promise<Record<string, unknown>>;
|
|
5
5
|
export interface PugOptions extends BaseOptions {
|
|
6
6
|
options?: Record<string, unknown>;
|
|
7
7
|
sourcePath?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type DynamicTaskFunc = () => Promise<void>;
|
|
2
|
+
export type GruntConfig = Record<string, Record<string, Record<string, unknown> | (() => void) | undefined>>;
|
|
3
3
|
/** Insert a new task in a grunt config object.
|
|
4
4
|
*
|
|
5
5
|
* @param gruntConfig
|
package/lib/grunt/reactapp.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface HandlerFunctionResult {
|
|
|
31
31
|
handledFiles: Array<string>;
|
|
32
32
|
watchTasks: Array<WatchTaskDef>;
|
|
33
33
|
}
|
|
34
|
-
export
|
|
34
|
+
export type HandlerFunction = (gruntConfig: GruntConfig, targetName: string, options: BaseOptions) => HandlerFunctionResult;
|
|
35
35
|
/** Insert necessary build step for a React/Web app.
|
|
36
36
|
*
|
|
37
37
|
* This function will add the following Grunt tasks:
|
package/lib/grunt/reactapp.js
CHANGED
|
@@ -111,7 +111,7 @@ const createWatchTasks = (gruntConfig, mergedResults, watchMode) => {
|
|
|
111
111
|
? ""
|
|
112
112
|
: "webres/";
|
|
113
113
|
if (cur.startsWith("!")) {
|
|
114
|
-
acc.push(`!${prefix}${cur.
|
|
114
|
+
acc.push(`!${prefix}${cur.substring(1)}`);
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
117
|
acc.push(`${prefix}${cur}`);
|
package/lib/grunt/util.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export interface BaseOptions {
|
|
2
2
|
disabled?: boolean;
|
|
3
3
|
}
|
|
4
|
-
export
|
|
5
|
-
export
|
|
4
|
+
export type ConfigValue = string | number | boolean | Record<string, unknown> | null;
|
|
5
|
+
export type GenericConfigObject = Record<string, ConfigValue>;
|
|
6
6
|
/** Set a value in a nested object
|
|
7
7
|
*
|
|
8
8
|
* This will set, for example, sourceObject.foo.bar = value by making copies of
|
package/lib/repl.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Function called when the REPL is closed */
|
|
2
|
-
export
|
|
2
|
+
export type ReplCloseFunc = () => void;
|
|
3
3
|
/** Mimic the required elements from a db object */
|
|
4
4
|
interface DBLikeObject {
|
|
5
5
|
/** db object can have a reference to an initialized sequelize instance */
|
package/lib/util.js
CHANGED
|
@@ -38,10 +38,10 @@ const trimWordEnd = 3;
|
|
|
38
38
|
*/
|
|
39
39
|
const camelToKebab = (camel) => camel.length === 0
|
|
40
40
|
? ""
|
|
41
|
-
: `${camel[0].toUpperCase()}${camel.
|
|
41
|
+
: `${camel[0].toUpperCase()}${camel.substring(1)}`
|
|
42
42
|
.replace(/[A-Z][A-Z0-9]+[a-z0-9]/ug, value => value[0]
|
|
43
|
-
+ value.
|
|
44
|
-
+ value.
|
|
43
|
+
+ value.substring(1, value.length - trimWordEnd + 1).toLowerCase()
|
|
44
|
+
+ value.substring(value.length - trimWordStart)).replace(/[A-Z][A-Z]+$/u, value => value[0] + value.substring(1).toLowerCase())
|
|
45
45
|
.split(/(?=[A-Z])/u)
|
|
46
46
|
.map(word => word.toLowerCase())
|
|
47
47
|
.join("-");
|
package/lib/winston.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ interface ExtendedErrorFields {
|
|
|
25
25
|
};
|
|
26
26
|
statusCode?: number;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
type ExtendedError = Error & ExtendedErrorFields;
|
|
29
29
|
/** Return a string with the full error and stacktrace, including causes */
|
|
30
30
|
export declare const filterError: (error: ExtendedError, collapseStacktrace?: boolean, extraFilter?: Array<RegExp> | RegExp) => string;
|
|
31
31
|
export declare const customFormat: (timestamp?: boolean, collapseStacktrace?: boolean, stacktraceFilter?: Array<RegExp> | RegExp) => Format;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cley_faye/boilerplate",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Boilerplate code generator for generic projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"prepack": "npm run grunt -- clean build",
|
|
11
|
+
"check": "tsc --noEmit && eslint .",
|
|
11
12
|
"grunt": "npx grunt --gruntfile Gruntfile.cjs"
|
|
12
13
|
},
|
|
13
14
|
"author": "Gabriel Paul \"Cley Faye\" Risterucci",
|
|
@@ -17,25 +18,26 @@
|
|
|
17
18
|
},
|
|
18
19
|
"homepage": "https://github.com/CleyFaye/boilerplate#readme",
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"@keeex/eslint-config": "^1.
|
|
21
|
-
"@types/express": "^4.17.
|
|
21
|
+
"@keeex/eslint-config": "^1.9.2",
|
|
22
|
+
"@types/express": "^4.17.17",
|
|
22
23
|
"@types/grunt": "^0.4.27",
|
|
23
24
|
"@types/http-errors": "^2.0.1",
|
|
24
|
-
"@types/node": "^18.11.
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
26
|
-
"@typescript-eslint/parser": "^5.
|
|
27
|
-
"eslint": "^8.
|
|
28
|
-
"eslint-plugin-
|
|
25
|
+
"@types/node": "^18.11.19",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^5.50.0",
|
|
27
|
+
"@typescript-eslint/parser": "^5.50.0",
|
|
28
|
+
"eslint": "^8.33.0",
|
|
29
|
+
"eslint-plugin-deprecation": "^1.3.3",
|
|
30
|
+
"eslint-plugin-import": "^2.27.5",
|
|
29
31
|
"eslint-plugin-promise": "^6.1.1",
|
|
30
32
|
"eslint-webpack-plugin": "^3.2.0",
|
|
31
33
|
"express-winston": "^4.2.0",
|
|
32
|
-
"grunt": "^1.
|
|
34
|
+
"grunt": "^1.6.1",
|
|
33
35
|
"grunt-banner": "^0.6.0",
|
|
34
36
|
"grunt-contrib-clean": "^2.0.1",
|
|
35
37
|
"grunt-run": "^0.8.1",
|
|
36
38
|
"load-grunt-tasks": "^5.1.0",
|
|
37
39
|
"logform": "^2.4.2",
|
|
38
|
-
"typescript": "^4.
|
|
40
|
+
"typescript": "^4.9.5",
|
|
39
41
|
"winston": "^3.8.2"
|
|
40
42
|
},
|
|
41
43
|
"peerDependencies": {
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
"grunt-contrib-watch": "1.x",
|
|
56
58
|
"grunt-sass": "3.x",
|
|
57
59
|
"grunt-webpack": "5.x",
|
|
58
|
-
"resolve-typescript-plugin": "2.
|
|
60
|
+
"resolve-typescript-plugin": "^2.0.0",
|
|
59
61
|
"sass": "1.x",
|
|
60
62
|
"ts-loader": "^9.4.1",
|
|
61
63
|
"winston": "3.x"
|
|
@@ -110,7 +112,7 @@
|
|
|
110
112
|
"optional": true
|
|
111
113
|
},
|
|
112
114
|
"resolve-typescript-plugin": {
|
|
113
|
-
"optional":
|
|
115
|
+
"optional": false
|
|
114
116
|
},
|
|
115
117
|
"sass": {
|
|
116
118
|
"optional": true
|