zgrzyt 2.0.3 → 2.1.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.
package/index.js CHANGED
@@ -17,8 +17,17 @@ main(apis).catch(e => {
17
17
  });
18
18
 
19
19
  async function main(apis) {
20
- const results = await Promise.all(apis.map(zgrzyt));
21
- const { exitCode, lines } = report(results);
20
+ const promises = await Promise.allSettled(apis.map(zgrzyt));
21
+ const results = [];
22
+ const errors = [];
23
+ promises.forEach(p => {
24
+ if (p.status === 'fulfilled') {
25
+ results.push(p.value);
26
+ } else {
27
+ errors.push(p.reason);
28
+ }
29
+ });
30
+ const { exitCode, lines } = report(results, errors);
22
31
  console.log(lines.join('\n'));
23
32
  await onExit();
24
33
  process.exit(exitCode);
package/lib/cloudflare.js CHANGED
@@ -11,13 +11,13 @@ class CloudflareError extends Error {
11
11
  }
12
12
  }
13
13
 
14
- function client({ token }) {
14
+ function client({ token, timeout = 4000, retry = 2 }) {
15
15
  const cf = got.extend({
16
16
  prefixUrl: 'https://api.cloudflare.com/client/v4',
17
17
  resolveBodyOnly: true,
18
18
  responseType: 'json',
19
- timeout: { request: 4000 },
20
- retry: { limit: 2 },
19
+ timeout: { request: timeout },
20
+ retry: { limit: retry },
21
21
  headers: {
22
22
  'Authorization': `Bearer ${token}`
23
23
  }
@@ -85,7 +85,7 @@ function client({ token }) {
85
85
  }
86
86
 
87
87
  debug('Listing zones...');
88
- for (let page = 1; await getPage(page); page++) {}
88
+ for (let page = 1; await getPage(page); page++) { }
89
89
  debug('Listing zones done.');
90
90
 
91
91
  return zones;
package/lib/config.js CHANGED
@@ -21,10 +21,16 @@ function prepareConfig(config) {
21
21
  cluster = {}
22
22
  } = config;
23
23
 
24
- if (!cloudflare || !cloudflare.token) {
24
+ if (!cloudflare?.token) {
25
25
  console.error('Cloudflare API token not configured');
26
26
  return;
27
27
  }
28
+ if (typeof cloudflare.timeout === 'string') {
29
+ cloudflare.timeout = parseInt(cloudflare.timeout);
30
+ }
31
+ if (typeof cloudflare.retry === 'string') {
32
+ cloudflare.retry = parseInt(cloudflare.retry);
33
+ }
28
34
 
29
35
  // collect all APIs
30
36
  const apis = [
package/lib/report.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import sprintf from 'sprintfjs';
2
2
 
3
- export function report(results) {
3
+ export function report(results, errors) {
4
4
  const collected = results.reduce(collect, {
5
5
  missing: [],
6
6
  switched: [],
7
7
  noops: []
8
8
  });
9
- return reportAll(collected);
9
+ return reportAll(collected, errors.map(formatError));
10
10
  }
11
11
 
12
12
  function collect(context, { url, domain, record, good, switched }) {
@@ -22,7 +22,12 @@ function collect(context, { url, domain, record, good, switched }) {
22
22
  return context;
23
23
  }
24
24
 
25
- function reportAll(collected) {
25
+ function formatError(err) {
26
+ console.error(err);
27
+ return err.toString();
28
+ }
29
+
30
+ function reportAll(collected, errors) {
26
31
  const {
27
32
  missing,
28
33
  noops,
@@ -43,6 +48,10 @@ function reportAll(collected) {
43
48
  if (noops.length > 0) {
44
49
  lines.push('No changes:\n', ...noops, '\n');
45
50
  }
51
+ if (errors.length) {
52
+ lines.push('Errors:\n', ...errors, `\n`);
53
+ exitCode = -1;
54
+ }
46
55
 
47
56
  return { exitCode, lines: lines.slice(0, -1) };
48
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zgrzyt",
3
- "version": "2.0.3",
3
+ "version": "2.1.1",
4
4
  "description": "Poor man's load balancing DNS switcher.",
5
5
  "type": "module",
6
6
  "author": {
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "debug": "~4",
30
- "got": "~13",
31
- "parse-domain": "~7",
30
+ "got": "~14",
31
+ "parse-domain": "~8",
32
32
  "rc": "^1.2.8",
33
33
  "sprintfjs": "^1.2.16"
34
34
  },