@naturalcycles/backend-lib 4.20.1 → 4.21.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.
@@ -7,7 +7,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
7
7
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
8
8
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
9
9
  const APP_YAML_DEFAULT = () => ({
10
- runtime: 'nodejs18',
10
+ runtime: 'nodejs20',
11
11
  service: 'default',
12
12
  inbound_services: ['warmup'],
13
13
  instance_class: 'F1',
@@ -9,10 +9,8 @@ const deployPrepare_1 = require("./deployPrepare");
9
9
  async function deployGae(opt = {}) {
10
10
  const { logOnFailure, logOnSuccess } = opt;
11
11
  // 1. build-prod
12
- // await execCommand(`yarn`, [`build-prod`])
13
12
  (0, dev_lib_1.buildProdCommand)();
14
13
  // 2. deploy-prepare
15
- // await execCommand(`yarn`, ['deploy-prepare'])
16
14
  const deployInfo = await (0, deployPrepare_1.deployPrepare)();
17
15
  const targetDir = './tmp/deploy';
18
16
  const appYamlPath = `${targetDir}/app.yaml`;
@@ -22,6 +20,7 @@ async function deployGae(opt = {}) {
22
20
  gaeService,
23
21
  gaeVersion,
24
22
  });
23
+ (0, nodejs_lib_1.appendToGithubSummary)(`[versionUrl](${versionUrl})`);
25
24
  await (0, js_lib_1.pRetry)(async () => {
26
25
  try {
27
26
  (0, nodejs_lib_1.execVoidCommandSync)(`gcloud app deploy ${appYamlPath} --project ${gaeProject} --version ${gaeVersion} --quiet --no-promote`, [], { shell: true });
@@ -36,6 +35,8 @@ async function deployGae(opt = {}) {
36
35
  name: 'deploy',
37
36
  maxAttempts: 2,
38
37
  delay: 30000,
38
+ // todo: this doesn't work, as the error is different from what is logged.
39
+ // We shoud somehow capture the logged text
39
40
  predicate: err => (0, js_lib_1._anyToError)(err).message.includes('operation is already in progress'),
40
41
  });
41
42
  // Health check (versionUrl)
@@ -90,7 +90,7 @@ class SentrySharedService {
90
90
  // It will log additional "breadcrumb object" before the error
91
91
  // It's a Breadcrumb, not a console.log, because console.log are NOT automatically attached as Breadcrumbs in cron-job environments (outside of Express)
92
92
  this.sentry().addBreadcrumb({
93
- message: (0, nodejs_lib_1.inspectAny)(err, INSPECT_OPT),
93
+ message: (0, nodejs_lib_1._inspect)(err, INSPECT_OPT),
94
94
  });
95
95
  return this.sentry().captureException(err);
96
96
  }
@@ -116,7 +116,7 @@ class SentrySharedService {
116
116
  log: () => { },
117
117
  warn: () => { },
118
118
  error: (...args) => {
119
- const message = args.map(arg => (0, nodejs_lib_1.inspectAny)(arg, INSPECT_OPT)).join(' ');
119
+ const message = args.map(arg => (0, nodejs_lib_1._inspect)(arg, INSPECT_OPT)).join(' ');
120
120
  this.sentry().addBreadcrumb({
121
121
  message,
122
122
  });
@@ -44,7 +44,7 @@ function logToDev(requestId, args) {
44
44
  // Run on local machine
45
45
  console.log([
46
46
  requestId ? [(0, nodejs_lib_1.dimGrey)(`[${requestId}]`)] : [],
47
- ...args.map(a => (0, nodejs_lib_1.inspectAny)(a, { includeErrorStack: true, colors: true })),
47
+ ...args.map(a => (0, nodejs_lib_1._inspect)(a, { includeErrorStack: true, colors: true })),
48
48
  ].join(' '));
49
49
  }
50
50
  /**
@@ -52,7 +52,7 @@ function logToDev(requestId, args) {
52
52
  * This is to not confuse e.g Sentry when it picks up messages with colors
53
53
  */
54
54
  function logToCI(args) {
55
- console.log(args.map(a => (0, nodejs_lib_1.inspectAny)(a, { includeErrorStack: true, colors: false })).join(' '));
55
+ console.log(args.map(a => (0, nodejs_lib_1._inspect)(a, { includeErrorStack: true, colors: false })).join(' '));
56
56
  }
57
57
  function appEngineLogMiddleware() {
58
58
  if (!isGAE || !GOOGLE_CLOUD_PROJECT) {
@@ -27,7 +27,7 @@ function simpleRequestLoggerMiddleware(_cfg = {}) {
27
27
  (0, request_log_util_1.logRequest)(req, res.statusCode, (0, nodejs_lib_1.dimGrey)((0, js_lib_1._since)(started)));
28
28
  // Avoid logging twice. It was previously logged by genericErrorHandler
29
29
  // if (res.__err) {
30
- // logRequest(req, res.statusCode, dimGrey(_since(started)), inspectAny(res.__err))
30
+ // logRequest(req, res.statusCode, dimGrey(_since(started)), _inspect(res.__err))
31
31
  // } else {
32
32
  // logRequest(req, res.statusCode, dimGrey(_since(started)))
33
33
  // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "4.20.1",
3
+ "version": "4.21.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "serve": "APP_ENV=dev nodemon",
@@ -6,7 +6,7 @@ import { BackendCfg } from './backend.cfg.util'
6
6
  import { AppYaml, DeployInfo } from './deploy.model'
7
7
 
8
8
  const APP_YAML_DEFAULT = (): AppYaml => ({
9
- runtime: 'nodejs18',
9
+ runtime: 'nodejs20',
10
10
  service: 'default',
11
11
  inbound_services: ['warmup'],
12
12
  instance_class: 'F1',
@@ -1,6 +1,6 @@
1
1
  import { buildProdCommand } from '@naturalcycles/dev-lib'
2
2
  import { _anyToError, _objectAssign, pRetry } from '@naturalcycles/js-lib'
3
- import { execVoidCommandSync } from '@naturalcycles/nodejs-lib'
3
+ import { appendToGithubSummary, execVoidCommandSync } from '@naturalcycles/nodejs-lib'
4
4
  import { deployHealthCheck, DeployHealthCheckOptions } from './deployHealthCheck'
5
5
  import { deployPrepare, DeployPrepareOptions } from './deployPrepare'
6
6
 
@@ -11,12 +11,10 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
11
11
 
12
12
  // 1. build-prod
13
13
 
14
- // await execCommand(`yarn`, [`build-prod`])
15
14
  buildProdCommand()
16
15
 
17
16
  // 2. deploy-prepare
18
17
 
19
- // await execCommand(`yarn`, ['deploy-prepare'])
20
18
  const deployInfo = await deployPrepare()
21
19
 
22
20
  const targetDir = './tmp/deploy'
@@ -29,6 +27,8 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
29
27
  gaeVersion,
30
28
  })
31
29
 
30
+ appendToGithubSummary(`[versionUrl](${versionUrl})`)
31
+
32
32
  await pRetry(
33
33
  async () => {
34
34
  try {
@@ -48,6 +48,8 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
48
48
  name: 'deploy',
49
49
  maxAttempts: 2,
50
50
  delay: 30_000,
51
+ // todo: this doesn't work, as the error is different from what is logged.
52
+ // We shoud somehow capture the logged text
51
53
  predicate: err => _anyToError(err).message.includes('operation is already in progress'),
52
54
  },
53
55
  )
@@ -5,7 +5,7 @@ import {
5
5
  CommonLogger,
6
6
  CommonLogLevel,
7
7
  } from '@naturalcycles/js-lib'
8
- import { inspectAny, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
8
+ import { _inspect, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
9
9
  // eslint-disable-next-line import/no-duplicates
10
10
  import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
11
11
  // eslint-disable-next-line import/no-duplicates
@@ -115,7 +115,7 @@ export class SentrySharedService {
115
115
  // It will log additional "breadcrumb object" before the error
116
116
  // It's a Breadcrumb, not a console.log, because console.log are NOT automatically attached as Breadcrumbs in cron-job environments (outside of Express)
117
117
  this.sentry().addBreadcrumb({
118
- message: inspectAny(err, INSPECT_OPT),
118
+ message: _inspect(err, INSPECT_OPT),
119
119
  })
120
120
 
121
121
  return this.sentry().captureException(err)
@@ -145,7 +145,7 @@ export class SentrySharedService {
145
145
  log: () => {}, // noop
146
146
  warn: () => {}, // noop
147
147
  error: (...args) => {
148
- const message = args.map(arg => inspectAny(arg, INSPECT_OPT)).join(' ')
148
+ const message = args.map(arg => _inspect(arg, INSPECT_OPT)).join(' ')
149
149
 
150
150
  this.sentry().addBreadcrumb({
151
151
  message,
@@ -1,6 +1,6 @@
1
1
  import { inspect } from 'node:util'
2
2
  import { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
3
- import { dimGrey, inspectAny } from '@naturalcycles/nodejs-lib'
3
+ import { dimGrey, _inspect } from '@naturalcycles/nodejs-lib'
4
4
  import { BackendRequestHandler } from './server.model'
5
5
 
6
6
  const { GOOGLE_CLOUD_PROJECT, GAE_INSTANCE } = process.env
@@ -53,7 +53,7 @@ function logToDev(requestId: string | null, args: any[]): void {
53
53
  console.log(
54
54
  [
55
55
  requestId ? [dimGrey(`[${requestId}]`)] : [],
56
- ...args.map(a => inspectAny(a, { includeErrorStack: true, colors: true })),
56
+ ...args.map(a => _inspect(a, { includeErrorStack: true, colors: true })),
57
57
  ].join(' '),
58
58
  )
59
59
  }
@@ -63,7 +63,7 @@ function logToDev(requestId: string | null, args: any[]): void {
63
63
  * This is to not confuse e.g Sentry when it picks up messages with colors
64
64
  */
65
65
  function logToCI(args: any[]): void {
66
- console.log(args.map(a => inspectAny(a, { includeErrorStack: true, colors: false })).join(' '))
66
+ console.log(args.map(a => _inspect(a, { includeErrorStack: true, colors: false })).join(' '))
67
67
  }
68
68
 
69
69
  export function appEngineLogMiddleware(): BackendRequestHandler {
@@ -44,7 +44,7 @@ export function simpleRequestLoggerMiddleware(
44
44
 
45
45
  // Avoid logging twice. It was previously logged by genericErrorHandler
46
46
  // if (res.__err) {
47
- // logRequest(req, res.statusCode, dimGrey(_since(started)), inspectAny(res.__err))
47
+ // logRequest(req, res.statusCode, dimGrey(_since(started)), _inspect(res.__err))
48
48
  // } else {
49
49
  // logRequest(req, res.statusCode, dimGrey(_since(started)))
50
50
  // }