@naturalcycles/backend-lib 4.10.1 → 4.10.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.
@@ -41,6 +41,7 @@ class BaseAdminService {
41
41
  /**
42
42
  * To be extended.
43
43
  */
44
+ // eslint-disable-next-line max-params
44
45
  async onPermissionCheck(req, email, reqPermissions, required, granted, meta = {}) {
45
46
  req.log(`${(0, colors_1.dimGrey)(email)} ${required ? 'required' : 'optional'} permissions check [${(0, colors_1.dimGrey)(reqPermissions.join(', '))}]: ${granted ? (0, colors_1.green)('GRANTED') : (0, colors_1.red)('DENIED')}`, meta);
46
47
  }
@@ -70,7 +71,7 @@ class BaseAdminService {
70
71
  * Override if needed.
71
72
  */
72
73
  async getAdminToken(req) {
73
- return ((req.cookies || {})[this.cfg.adminTokenKey] ||
74
+ return (req.cookies?.[this.cfg.adminTokenKey] ||
74
75
  req.header(this.cfg.adminTokenKey) ||
75
76
  req.header('x-admin-token'));
76
77
  }
@@ -16,7 +16,7 @@ export declare class HttpDB extends BaseCommonDB implements CommonDB {
16
16
  getTables(): Promise<string[]>;
17
17
  getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
18
18
  resetCache(table?: string): Promise<void>;
19
- getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
19
+ getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], opt?: CommonDBOptions): Promise<ROW[]>;
20
20
  runQuery<ROW extends ObjectWithId>(query: DBQuery<ROW>, opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
21
21
  runQueryCount<ROW extends ObjectWithId>(query: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>;
22
22
  saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
@@ -72,10 +72,10 @@ function httpDBRequestHandler(db) {
72
72
  res.end();
73
73
  });
74
74
  // deleteByIds
75
- router.put('/deleteByIds', (0, __1.reqValidation)('body', getByIdsInputSchema), async (req, res) => {
76
- const { table, ids, opt } = req.body;
77
- res.json(await db.deleteByIds(table, ids, opt));
78
- });
75
+ // router.put('/deleteByIds', reqValidation('body', getByIdsInputSchema), async (req, res) => {
76
+ // const { table, ids, opt } = req.body as GetByIdsInput
77
+ // res.json(await db.deleteByIds(table, ids, opt))
78
+ // })
79
79
  // deleteByQuery
80
80
  router.put('/deleteByQuery', (0, __1.reqValidation)('body', runQueryInputSchema), async (req, res) => {
81
81
  const { query, opt } = req.body;
@@ -86,7 +86,7 @@ class SentrySharedService {
86
86
  }),
87
87
  // data: (err as AppError).data, // included in message
88
88
  });
89
- return this.sentry().captureException((0, js_lib_1._anyToError)(err, Error, {
89
+ return this.sentry().captureException((0, js_lib_1._anyToError)(err, Error, {}, {
90
90
  stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
91
91
  }));
92
92
  }
@@ -121,7 +121,7 @@ class SentrySharedService {
121
121
  this.sentry().addBreadcrumb({
122
122
  message,
123
123
  });
124
- this.sentry().captureException((0, js_lib_1._anyToError)(args.length === 1 ? args[0] : args, Error, {
124
+ this.sentry().captureException((0, js_lib_1._anyToError)(args.length === 1 ? args[0] : args, Error, {}, {
125
125
  stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
126
126
  }));
127
127
  },
@@ -42,7 +42,7 @@ function respondWithError(req, res, err) {
42
42
  else {
43
43
  req.error(err);
44
44
  }
45
- const originalError = (0, js_lib_1._anyToError)(err, Error, {
45
+ const originalError = (0, js_lib_1._anyToError)(err, Error, {}, {
46
46
  stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
47
47
  });
48
48
  let errorId;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Server } from 'node:http';
3
3
  export interface DestroyableServer extends Server {
4
- destroy(): Promise<void>;
4
+ destroy: () => Promise<void>;
5
5
  }
6
6
  /**
7
7
  * Based on: https://github.com/isaacs/server-destroy/blob/master/index.js
@@ -2,7 +2,7 @@ import { GetGotOptions, Got } from '@naturalcycles/nodejs-lib';
2
2
  import { BackendApplication, DefaultAppCfg } from '../index';
3
3
  import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model';
4
4
  export interface ExpressApp extends Got {
5
- close(): Promise<void>;
5
+ close: () => Promise<void>;
6
6
  }
7
7
  declare class ExpressTestService {
8
8
  createAppFromResource(resource: BackendRequestHandlerCfg, opt?: GetGotOptions, defaultAppCfg?: DefaultAppCfg): ExpressApp;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "4.10.1",
3
+ "version": "4.10.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install && patch-package",
6
6
  "serve": "APP_ENV=dev nodemon",
7
- "docs-serve": "vuepress dev docs",
8
- "docs-build": "vuepress build docs",
7
+ "docs-serve": "NODE_OPTIONS=--openssl-legacy-provider vuepress dev docs",
8
+ "docs-build": "NODE_OPTIONS=--openssl-legacy-provider vuepress build docs",
9
9
  "deploy-gae": "yarn tsn ./src/bin/deploy-gae.ts",
10
10
  "deploy-prepare": "yarn tsn ./src/bin/deploy-prepare.ts",
11
11
  "deploy-prepare-debug": "AA=AA1 BB=BB1 yarn tsn ./src/bin/deploy-prepare.ts --projectDir ./src/test/project",
@@ -78,7 +78,7 @@
78
78
  "url": "https://github.com/NaturalCycles/backend-lib"
79
79
  },
80
80
  "engines": {
81
- "node": ">=16.10.0"
81
+ "node": ">=16.15.0"
82
82
  },
83
83
  "type": "commonjs",
84
84
  "description": "Standard library for making Express.js / AppEngine based backend services",
@@ -68,6 +68,7 @@ export class BaseAdminService {
68
68
  /**
69
69
  * To be extended.
70
70
  */
71
+ // eslint-disable-next-line max-params
71
72
  protected async onPermissionCheck(
72
73
  req: BackendRequest,
73
74
  email: string,
@@ -113,7 +114,7 @@ export class BaseAdminService {
113
114
  */
114
115
  async getAdminToken(req: BackendRequest): Promise<string | undefined> {
115
116
  return (
116
- (req.cookies || {})[this.cfg.adminTokenKey] ||
117
+ req.cookies?.[this.cfg.adminTokenKey] ||
117
118
  req.header(this.cfg.adminTokenKey) ||
118
119
  req.header('x-admin-token')
119
120
  )
package/src/db/httpDB.ts CHANGED
@@ -50,7 +50,7 @@ export class HttpDB extends BaseCommonDB implements CommonDB {
50
50
 
51
51
  override async getByIds<ROW extends ObjectWithId>(
52
52
  table: string,
53
- ids: string[],
53
+ ids: ROW['id'][],
54
54
  opt?: CommonDBOptions,
55
55
  ): Promise<ROW[]> {
56
56
  return await this.got
@@ -106,7 +106,7 @@ export class HttpDB extends BaseCommonDB implements CommonDB {
106
106
  })
107
107
  }
108
108
 
109
- override async deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number> {
109
+ async deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number> {
110
110
  return await this.got
111
111
  .put(`deleteByIds`, {
112
112
  json: {
@@ -111,10 +111,10 @@ export function httpDBRequestHandler(db: CommonDB): BackendRouter {
111
111
  })
112
112
 
113
113
  // deleteByIds
114
- router.put('/deleteByIds', reqValidation('body', getByIdsInputSchema), async (req, res) => {
115
- const { table, ids, opt } = req.body as GetByIdsInput
116
- res.json(await db.deleteByIds(table, ids, opt))
117
- })
114
+ // router.put('/deleteByIds', reqValidation('body', getByIdsInputSchema), async (req, res) => {
115
+ // const { table, ids, opt } = req.body as GetByIdsInput
116
+ // res.json(await db.deleteByIds(table, ids, opt))
117
+ // })
118
118
 
119
119
  // deleteByQuery
120
120
  router.put('/deleteByQuery', reqValidation('body', runQueryInputSchema), async (req, res) => {
@@ -100,9 +100,14 @@ export class SentrySharedService {
100
100
  })
101
101
 
102
102
  return this.sentry().captureException(
103
- _anyToError(err, Error, {
104
- stringifyFn: inspectAnyStringifyFn,
105
- }),
103
+ _anyToError(
104
+ err,
105
+ Error,
106
+ {},
107
+ {
108
+ stringifyFn: inspectAnyStringifyFn,
109
+ },
110
+ ),
106
111
  )
107
112
  }
108
113
 
@@ -144,9 +149,14 @@ export class SentrySharedService {
144
149
  })
145
150
 
146
151
  this.sentry().captureException(
147
- _anyToError(args.length === 1 ? args[0] : args, Error, {
148
- stringifyFn: inspectAnyStringifyFn,
149
- }),
152
+ _anyToError(
153
+ args.length === 1 ? args[0] : args,
154
+ Error,
155
+ {},
156
+ {
157
+ stringifyFn: inspectAnyStringifyFn,
158
+ },
159
+ ),
150
160
  )
151
161
  },
152
162
  }
@@ -73,9 +73,14 @@ export function respondWithError(req: BackendRequest, res: BackendResponse, err:
73
73
  req.error(err)
74
74
  }
75
75
 
76
- const originalError = _anyToError(err, Error, {
77
- stringifyFn: inspectAnyStringifyFn,
78
- })
76
+ const originalError = _anyToError(
77
+ err,
78
+ Error,
79
+ {},
80
+ {
81
+ stringifyFn: inspectAnyStringifyFn,
82
+ },
83
+ )
79
84
 
80
85
  let errorId: string | undefined
81
86
 
@@ -3,7 +3,7 @@ import { Socket } from 'node:net'
3
3
  import { StringMap } from '@naturalcycles/js-lib'
4
4
 
5
5
  export interface DestroyableServer extends Server {
6
- destroy(): Promise<void>
6
+ destroy: () => Promise<void>
7
7
  }
8
8
 
9
9
  /**
@@ -5,7 +5,7 @@ import { BackendApplication, createDefaultApp, DefaultAppCfg } from '../index'
5
5
  import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model'
6
6
 
7
7
  export interface ExpressApp extends Got {
8
- close(): Promise<void>
8
+ close: () => Promise<void>
9
9
  }
10
10
 
11
11
  // Example: