@naturalcycles/nodejs-lib 12.100.0 → 12.101.1

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.
@@ -53,24 +53,27 @@ exports.json2env = json2env;
53
53
  function appendToBashEnv(obj, prefix = '') {
54
54
  const { BASH_ENV } = process.env;
55
55
  if (BASH_ENV) {
56
- fs.appendFileSync(BASH_ENV, objectToShellExport(obj, prefix));
57
- console.log(`BASH_ENV file appended (${(0, colors_1.dimGrey)(BASH_ENV)})`);
56
+ const data = objectToShellExport(obj, prefix);
57
+ fs.appendFileSync(BASH_ENV, data);
58
+ console.log(`BASH_ENV file appended (${(0, colors_1.dimGrey)(BASH_ENV)})\n${data}`);
58
59
  }
59
60
  }
60
61
  exports.appendToBashEnv = appendToBashEnv;
61
62
  function appendToGithubEnv(obj, prefix = '') {
62
63
  const { GITHUB_ENV } = process.env;
63
64
  if (GITHUB_ENV) {
64
- fs.appendFileSync(GITHUB_ENV, objectToGithubActionsEnv(obj, prefix));
65
- console.log(`GITHUB_ENV file appended (${(0, colors_1.dimGrey)(GITHUB_ENV)})`);
65
+ const data = objectToGithubActionsEnv(obj, prefix);
66
+ fs.appendFileSync(GITHUB_ENV, data);
67
+ console.log(`GITHUB_ENV file appended (${(0, colors_1.dimGrey)(GITHUB_ENV)})\n${data}`);
66
68
  }
67
69
  }
68
70
  exports.appendToGithubEnv = appendToGithubEnv;
69
71
  function appendToGithubOutput(obj, prefix = '') {
70
72
  const { GITHUB_OUTPUT } = process.env;
71
73
  if (GITHUB_OUTPUT) {
72
- fs.appendFileSync(GITHUB_OUTPUT, objectToGithubActionsEnv(obj, prefix));
73
- console.log(`GITHUB_OUTPUT file appended (${(0, colors_1.dimGrey)(GITHUB_OUTPUT)})`);
74
+ const data = objectToGithubActionsEnv(obj, prefix);
75
+ fs.appendFileSync(GITHUB_OUTPUT, data);
76
+ console.log(`GITHUB_OUTPUT file appended (${(0, colors_1.dimGrey)(GITHUB_OUTPUT)})\n${data}`);
74
77
  }
75
78
  }
76
79
  exports.appendToGithubOutput = appendToGithubOutput;
@@ -14,6 +14,7 @@ import { SlackAttachmentField, SlackMessage, SlackServiceCfg } from './slack.ser
14
14
  */
15
15
  export declare class SlackService<CTX = any> {
16
16
  constructor(cfg: Partial<SlackServiceCfg<CTX>>);
17
+ private fetcher;
17
18
  cfg: SlackServiceCfg<CTX>;
18
19
  /**
19
20
  * Allows to "log" many things at once, similar to `console.log(one, two, three).
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.slackDefaultMessagePrefixHook = exports.SlackService = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const got_1 = require("got");
6
5
  const __1 = require("..");
7
6
  const GAE = !!process.env['GAE_INSTANCE'];
8
7
  const DEFAULTS = {
@@ -38,6 +37,9 @@ class SlackService {
38
37
  ...cfg.inspectOptions,
39
38
  },
40
39
  };
40
+ this.fetcher = (0, js_lib_1.getFetcher)({
41
+ timeoutSeconds: 90,
42
+ });
41
43
  }
42
44
  /**
43
45
  * Allows to "log" many things at once, similar to `console.log(one, two, three).
@@ -89,13 +91,12 @@ class SlackService {
89
91
  // Text with Prefix
90
92
  text: [prefix.join(': '), text].filter(Boolean).join('\n'),
91
93
  }, ['items', 'ctx']);
92
- await got_1.default
93
- .post(webhookUrl, {
94
+ await this.fetcher
95
+ .postVoid(webhookUrl, {
94
96
  json,
95
- responseType: 'text',
96
- timeout: 90000,
97
97
  })
98
98
  .catch(err => {
99
+ // console.log(err)
99
100
  // ignore (unless throwOnError is set)
100
101
  if (msg.throwOnError)
101
102
  throw err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.100.0",
3
+ "version": "12.101.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -93,24 +93,27 @@ export function json2env(opt: Json2EnvOptions): void {
93
93
  export function appendToBashEnv(obj: AnyObject, prefix = ''): void {
94
94
  const { BASH_ENV } = process.env
95
95
  if (BASH_ENV) {
96
- fs.appendFileSync(BASH_ENV, objectToShellExport(obj, prefix))
97
- console.log(`BASH_ENV file appended (${dimGrey(BASH_ENV)})`)
96
+ const data = objectToShellExport(obj, prefix)
97
+ fs.appendFileSync(BASH_ENV, data)
98
+ console.log(`BASH_ENV file appended (${dimGrey(BASH_ENV)})\n${data}`)
98
99
  }
99
100
  }
100
101
 
101
102
  export function appendToGithubEnv(obj: AnyObject, prefix = ''): void {
102
103
  const { GITHUB_ENV } = process.env
103
104
  if (GITHUB_ENV) {
104
- fs.appendFileSync(GITHUB_ENV, objectToGithubActionsEnv(obj, prefix))
105
- console.log(`GITHUB_ENV file appended (${dimGrey(GITHUB_ENV)})`)
105
+ const data = objectToGithubActionsEnv(obj, prefix)
106
+ fs.appendFileSync(GITHUB_ENV, data)
107
+ console.log(`GITHUB_ENV file appended (${dimGrey(GITHUB_ENV)})\n${data}`)
106
108
  }
107
109
  }
108
110
 
109
111
  export function appendToGithubOutput(obj: AnyObject, prefix = ''): void {
110
112
  const { GITHUB_OUTPUT } = process.env
111
113
  if (GITHUB_OUTPUT) {
112
- fs.appendFileSync(GITHUB_OUTPUT, objectToGithubActionsEnv(obj, prefix))
113
- console.log(`GITHUB_OUTPUT file appended (${dimGrey(GITHUB_OUTPUT)})`)
114
+ const data = objectToGithubActionsEnv(obj, prefix)
115
+ fs.appendFileSync(GITHUB_OUTPUT, data)
116
+ console.log(`GITHUB_OUTPUT file appended (${dimGrey(GITHUB_OUTPUT)})\n${data}`)
114
117
  }
115
118
  }
116
119
 
@@ -4,10 +4,11 @@ import {
4
4
  CommonLogger,
5
5
  commonLoggerMinLevel,
6
6
  CommonLogLevel,
7
+ Fetcher,
8
+ getFetcher,
7
9
  localTime,
8
10
  PQueue,
9
11
  } from '@naturalcycles/js-lib'
10
- import got from 'got'
11
12
  import { inspectAny, InspectAnyOptions } from '..'
12
13
  import {
13
14
  SlackApiBody,
@@ -53,8 +54,14 @@ export class SlackService<CTX = any> {
53
54
  ...cfg.inspectOptions,
54
55
  },
55
56
  }
57
+
58
+ this.fetcher = getFetcher({
59
+ timeoutSeconds: 90,
60
+ })
56
61
  }
57
62
 
63
+ private fetcher: Fetcher
64
+
58
65
  cfg!: SlackServiceCfg<CTX>
59
66
 
60
67
  /**
@@ -120,13 +127,12 @@ export class SlackService<CTX = any> {
120
127
  ['items', 'ctx'],
121
128
  )
122
129
 
123
- await got
124
- .post(webhookUrl, {
130
+ await this.fetcher
131
+ .postVoid(webhookUrl, {
125
132
  json,
126
- responseType: 'text',
127
- timeout: 90_000,
128
133
  })
129
134
  .catch(err => {
135
+ // console.log(err)
130
136
  // ignore (unless throwOnError is set)
131
137
  if (msg.throwOnError) throw err
132
138
  })