@naturalcycles/backend-lib 4.8.2 → 4.9.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/cfg/tsconfig.json +2 -2
- package/dist/admin/adminMiddleware.d.ts +1 -1
- package/dist/admin/adminMiddleware.js +1 -1
- package/dist/db/httpDB.js +2 -2
- package/dist/deploy/deploy.util.js +1 -1
- package/dist/deploy/deployHealthCheck.js +3 -3
- package/dist/paths.cnst.js +1 -1
- package/dist/server/appEngineLogMiddleware.js +2 -2
- package/dist/server/asyncLocalStorageMiddleware.js +2 -2
- package/dist/server/createDefaultApp.model.d.ts +1 -1
- package/dist/server/deployInfo.util.js +1 -1
- package/dist/server/server.model.d.ts +5 -5
- package/dist/server/server.util.d.ts +1 -1
- package/dist/server/startServer.d.ts +1 -1
- package/dist/server/startServer.model.d.ts +1 -1
- package/package.json +3 -7
- package/src/admin/adminMiddleware.ts +1 -1
- package/src/db/httpDB.ts +1 -1
- package/src/deploy/deploy.util.ts +1 -1
- package/src/deploy/deployHealthCheck.ts +1 -1
- package/src/paths.cnst.ts +1 -1
- package/src/server/appEngineLogMiddleware.ts +1 -1
- package/src/server/asyncLocalStorageMiddleware.ts +1 -1
- package/src/server/deployInfo.util.ts +1 -1
- package/src/server/server.util.ts +2 -2
- package/src/server/startServer.model.ts +1 -1
- package/src/server/startServer.ts +1 -1
- package/src/testing/express.test.service.ts +2 -2
package/cfg/tsconfig.json
CHANGED
|
@@ -18,7 +18,7 @@ export interface RequireAdminCfg {
|
|
|
18
18
|
*/
|
|
19
19
|
autoLogin?: boolean;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type AdminMiddleware = (reqPermissions?: string[], cfg?: RequireAdminCfg) => BackendRequestHandler;
|
|
22
22
|
export declare function createAdminMiddleware(adminService: BaseAdminService, cfgDefaults?: RequireAdminCfg): AdminMiddleware;
|
|
23
23
|
/**
|
|
24
24
|
* Require Admin permission.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLoginHtmlRedirect = exports.loginHtml = exports.requireAdminPermissions = exports.createAdminMiddleware = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const ejs = require("ejs");
|
|
7
7
|
function createAdminMiddleware(adminService, cfgDefaults = {}) {
|
package/dist/db/httpDB.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpDB = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
5
|
const db_lib_1 = require("@naturalcycles/db-lib");
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
7
|
/**
|
|
@@ -91,7 +91,7 @@ class HttpDB extends db_lib_1.BaseCommonDB {
|
|
|
91
91
|
}
|
|
92
92
|
streamQuery(_q, _opt) {
|
|
93
93
|
console.warn(`streamQuery not implemented`);
|
|
94
|
-
return
|
|
94
|
+
return node_stream_1.Readable.from([]);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
exports.HttpDB = HttpDB;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateGAEServiceName = exports.createAppYaml = exports.createAndSaveAppYaml = exports.createDeployInfo = exports.createAndSaveDeployInfo = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
7
7
|
const yaml = require("js-yaml");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deployHealthCheck = exports.deployHealthCheckYargsOptions = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_util_1 = require("node:util");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
7
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
@@ -83,7 +83,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
83
83
|
}
|
|
84
84
|
async function makeAttempt() {
|
|
85
85
|
attempt++;
|
|
86
|
-
console.log([`>>`, (0, colors_1.dimGrey)(url), (0,
|
|
86
|
+
console.log([`>>`, (0, colors_1.dimGrey)(url), (0, node_util_1.inspect)({ attempt }, inspectOpt)].join(' '));
|
|
87
87
|
const started = Date.now();
|
|
88
88
|
const { statusCode } = await got(url, {
|
|
89
89
|
responseType: 'json',
|
|
@@ -120,7 +120,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
120
120
|
`<< HTTP`,
|
|
121
121
|
(0, request_log_util_1.coloredHttpCode)(statusCode),
|
|
122
122
|
(0, colors_1.dimGrey)((0, js_lib_1._since)(started)),
|
|
123
|
-
(0,
|
|
123
|
+
(0, node_util_1.inspect)((0, js_lib_1._filterFalsyValues)({ countHealthy, countUnhealthy }), inspectOpt),
|
|
124
124
|
].join(' '));
|
|
125
125
|
if (attempt >= maxTries) {
|
|
126
126
|
doneReason = `reached maxTries of ${maxTries}`;
|
package/dist/paths.cnst.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.testDir = exports.srcDir = exports.resourcesDir = exports.projectDir = void 0;
|
|
4
|
-
const path = require("path");
|
|
4
|
+
const path = require("node:path");
|
|
5
5
|
exports.projectDir = path.join(__dirname, '/..');
|
|
6
6
|
exports.resourcesDir = `${exports.projectDir}/resources`;
|
|
7
7
|
exports.srcDir = `${exports.projectDir}/src`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.appEngineLogMiddleware = exports.ciLogger = exports.devLogger = exports.gaeLogger = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_util_1 = require("node:util");
|
|
5
5
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
7
|
const { GOOGLE_CLOUD_PROJECT, GAE_INSTANCE } = process.env;
|
|
@@ -37,7 +37,7 @@ exports.ciLogger = {
|
|
|
37
37
|
// Documented here: https://cloud.google.com/logging/docs/structured-logging
|
|
38
38
|
function logToAppEngine(meta, args) {
|
|
39
39
|
console.log(JSON.stringify({
|
|
40
|
-
message: args.map(a => (typeof a === 'string' ? a : (0,
|
|
40
|
+
message: args.map(a => (typeof a === 'string' ? a : (0, node_util_1.inspect)(a))).join(' '),
|
|
41
41
|
...meta,
|
|
42
42
|
}));
|
|
43
43
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.requestLogger = exports.getRequestLogger = exports.getRequest = exports.asyncLocalStorageMiddleware = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const appEngineLogMiddleware_1 = require("./appEngineLogMiddleware");
|
|
7
7
|
const { GAE_INSTANCE, CI } = process.env;
|
|
@@ -9,7 +9,7 @@ const isGAE = !!GAE_INSTANCE;
|
|
|
9
9
|
const isCI = !!CI;
|
|
10
10
|
// Singleton, for simplicity
|
|
11
11
|
// Create it lazily (on demand)
|
|
12
|
-
const storage = (0, js_lib_1._lazyValue)(() => new
|
|
12
|
+
const storage = (0, js_lib_1._lazyValue)(() => new node_async_hooks_1.AsyncLocalStorage());
|
|
13
13
|
function asyncLocalStorageMiddleware() {
|
|
14
14
|
return (req, res, next) => {
|
|
15
15
|
const store = {
|
|
@@ -7,7 +7,7 @@ import { GenericErrorMiddlewareCfg } from './genericErrorMiddleware';
|
|
|
7
7
|
* Plain RequestHandler can be provided - then it's mounted to /
|
|
8
8
|
* Otherwise `path` can be provided to specify mounting point.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export type BackendRequestHandlerCfg = BackendRequestHandler | BackendRequestHandlerWithPath;
|
|
11
11
|
export interface BackendRequestHandlerWithPath {
|
|
12
12
|
path: string;
|
|
13
13
|
handler: BackendRequestHandler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDeployInfo = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
exports.getDeployInfo = (0, js_lib_1._memoFn)((projectDir) => {
|
|
7
7
|
const deployInfoPath = `${projectDir}/deployInfo.json`;
|
|
@@ -20,11 +20,11 @@ export interface BackendRequest extends Request {
|
|
|
20
20
|
requestTimeout?: NodeJS.Timeout;
|
|
21
21
|
bodyParserTimeout?: NodeJS.Timeout;
|
|
22
22
|
}
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
26
|
-
export
|
|
27
|
-
export
|
|
23
|
+
export type BackendResponse = Response;
|
|
24
|
+
export type BackendRequestHandler = (req: BackendRequest, res: BackendResponse, next: NextFunction) => void;
|
|
25
|
+
export type BackendErrorRequestHandler = (err: any, req: BackendRequest, res: BackendResponse, next: NextFunction) => void;
|
|
26
|
+
export type BackendRouter = IRouter;
|
|
27
|
+
export type BackendApplication = Application;
|
|
28
28
|
declare module 'http' {
|
|
29
29
|
interface IncomingMessage {
|
|
30
30
|
log: CommonLogFunction;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Server } from 'http';
|
|
2
|
+
import { Server } from 'node:http';
|
|
3
3
|
import { SentrySharedService } from '../sentry/sentry.shared.service';
|
|
4
4
|
import { DefaultAppCfg } from './createDefaultApp.model';
|
|
5
5
|
import { BackendApplication } from './server.model';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/backend-lib",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install && patch-package",
|
|
6
6
|
"serve": "APP_ENV=dev nodemon",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"express": "^4.16.4",
|
|
31
31
|
"express-promise-router": "^4.0.0",
|
|
32
32
|
"firebase-admin": "^11.0.0",
|
|
33
|
-
"fs-extra": "^
|
|
33
|
+
"fs-extra": "^11.0.0",
|
|
34
34
|
"helmet": "^6.0.0",
|
|
35
35
|
"js-yaml": "^4.0.0",
|
|
36
36
|
"on-finished": "^2.3.0",
|
|
@@ -49,14 +49,10 @@
|
|
|
49
49
|
"jest": "^29.0.1",
|
|
50
50
|
"nodemon": "^2.0.14",
|
|
51
51
|
"patch-package": "^6.2.1",
|
|
52
|
-
"prettier": "^2.0.0",
|
|
53
52
|
"vue-class-component": "^7.2.6",
|
|
54
53
|
"vuepress": "^1.7.1",
|
|
55
54
|
"vuepress-plugin-typescript": "^0.3.1"
|
|
56
55
|
},
|
|
57
|
-
"resolutions": {
|
|
58
|
-
"prettier": "^2.0.0"
|
|
59
|
-
},
|
|
60
56
|
"files": [
|
|
61
57
|
"dist",
|
|
62
58
|
"cfg",
|
|
@@ -82,7 +78,7 @@
|
|
|
82
78
|
"url": "https://github.com/NaturalCycles/backend-lib"
|
|
83
79
|
},
|
|
84
80
|
"engines": {
|
|
85
|
-
"node": ">=
|
|
81
|
+
"node": ">=16.10.0"
|
|
86
82
|
},
|
|
87
83
|
"type": "commonjs",
|
|
88
84
|
"description": "Standard library for making Express.js / AppEngine based backend services",
|
package/src/db/httpDB.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inspect, InspectOptions } from 'util'
|
|
1
|
+
import { inspect, InspectOptions } from 'node:util'
|
|
2
2
|
import { pDelay, _filterFalsyValues, _ms, _since } from '@naturalcycles/js-lib'
|
|
3
3
|
import { getGot } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import { dimGrey, red } from '@naturalcycles/nodejs-lib/dist/colors'
|
package/src/paths.cnst.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'async_hooks'
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
2
|
import { _lazyValue, CommonLogger } from '@naturalcycles/js-lib'
|
|
3
3
|
import { BackendRequest, BackendRequestHandler } from './server.model'
|
|
4
4
|
import { gaeLogger, devLogger, ciLogger } from './appEngineLogMiddleware'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Server } from 'http'
|
|
2
|
-
import { AddressInfo } from 'net'
|
|
1
|
+
import { Server } from 'node:http'
|
|
2
|
+
import { AddressInfo } from 'node:net'
|
|
3
3
|
import { getGot, GetGotOptions, Got } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import { BackendApplication, createDefaultApp, DefaultAppCfg } from '../index'
|
|
5
5
|
import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model'
|