locize-cli 7.14.15 → 7.15.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/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  Project versioning adheres to [Semantic Versioning](http://semver.org/).
6
6
  Change log format is based on [Keep a Changelog](http://keepachangelog.com/).
7
7
 
8
+ ## [7.15.1](https://github.com/locize/locize-cli/compare/v7.15.0...v7.15.1) - 2023-12-19
9
+
10
+ - refactor retriable requests handling
11
+
12
+ ## [7.15.0](https://github.com/locize/locize-cli/compare/v7.14.15...v7.15.0) - 2023-12-18
13
+
14
+ - locize sync: show publish mode advice if necessary
15
+
8
16
  ## [7.14.15](https://github.com/locize/locize-cli/compare/v7.14.14...v7.14.15) - 2023-12-18
9
17
 
10
18
  - fix sync for private published translations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "7.14.15",
3
+ "version": "7.15.1",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
package/request.js CHANGED
@@ -8,6 +8,28 @@ cacheable.install(https.globalAgent);
8
8
 
9
9
  const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || process.env.https_proxy || process.env.HTTPS_PROXY;
10
10
 
11
+ const isRetriableError = (err) => {
12
+ return err && err.message && (
13
+ err.message.indexOf('ETIMEDOUT') > -1 || // on timeout retry
14
+ // on dns errors
15
+ err.message.indexOf('ENOTFOUND') > -1 ||
16
+ err.message.indexOf('ENODATA') > -1 ||
17
+ err.message.indexOf('ENOENT') > -1 // Windows: name exists, but not this record type
18
+ );
19
+ };
20
+
21
+ const isJSONResponse = (res) => res.headers.get('content-type') && res.headers.get('content-type').indexOf('json') > 0;
22
+
23
+ const handleResponse = (res) => {
24
+ if (isJSONResponse(res)) {
25
+ return new Promise((resolve, reject) => res.json().then((obj) => resolve({ res, obj })).catch(reject));
26
+ } else {
27
+ return { res };
28
+ }
29
+ };
30
+
31
+ const handleSuccessful = (callback) => (ret) => callback(null, ret.res, ret.obj);
32
+
11
33
  module.exports = (url, options, callback) => {
12
34
  if (httpProxy) {
13
35
  const httpsProxyAgent = new HttpsProxyAgent(httpProxy);
@@ -25,31 +47,16 @@ module.exports = (url, options, callback) => {
25
47
  }
26
48
  }
27
49
  if (options.headers['Authorization'] === undefined) delete options.headers['Authorization'];
28
- fetch(url, options).then((res) => {
29
- if (res.headers.get('content-type') && res.headers.get('content-type').indexOf('json') > 0) {
30
- return new Promise((resolve, reject) => res.json().then((obj) => resolve({ res, obj })).catch(reject));
31
- } else {
32
- return { res };
33
- }
34
- }).then((ret) => callback(null, ret.res, ret.obj)).catch((err) => {
35
- if (err && err.message && (
36
- err.message.indexOf('ETIMEDOUT') > -1 || // on timeout retry
37
- // on dns errors
38
- err.message.indexOf('ENOTFOUND') > -1 ||
39
- err.message.indexOf('ENODATA') > -1 ||
40
- err.message.indexOf('ENOENT') > -1 // Windows: name exists, but not this record type
41
- )) {
50
+
51
+ function retriableFetch(maxRetries) {
52
+ fetch(url, options).then(handleResponse).then(handleSuccessful(callback)).catch((err) => {
53
+ if (maxRetries < 1) return callback(err);
54
+ if (!isRetriableError(err)) return callback(err);
42
55
  setTimeout(() => {
43
- fetch(url, options).then((res) => {
44
- if (res.headers.get('content-type') && res.headers.get('content-type').indexOf('json') > 0) {
45
- return new Promise((resolve, reject) => res.json().then((obj) => resolve({ res, obj })).catch(reject));
46
- } else {
47
- return { res };
48
- }
49
- }).then((ret) => callback(null, ret.res, ret.obj)).catch(callback);
56
+ retriableFetch(--maxRetries);
50
57
  }, 5000);
51
- return;
52
- }
53
- callback(err);
54
- });
58
+ });
59
+ }
60
+
61
+ retriableFetch(3);
55
62
  };
package/sync.js CHANGED
@@ -270,6 +270,11 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
270
270
  }
271
271
  }, (err, res, obj) => {
272
272
  if (err) return clb(err);
273
+ const cliInfo = res.headers.get('x-cli-info');
274
+ if (cliInfo && cliInfo !== opt.lastShownCliInfo) {
275
+ console.log(colors.yellow(cliInfo));
276
+ opt.lastShownCliInfo = cliInfo;
277
+ }
273
278
  if (res.status === 504 && !isRetrying) {
274
279
  return setTimeout(() => send(d, so, clb, true), 3000);
275
280
  }