locize-cli 7.12.3 → 7.12.6

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,19 @@ 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.12.6](https://github.com/locize/locize-cli/compare/v7.12.5...v7.12.6) - 2022-08-26
9
+
10
+ - internal optimization of unpublished download workflow
11
+
12
+ ## [7.12.5](https://github.com/locize/locize-cli/compare/v7.12.4...v7.12.5) - 2022-08-25
13
+
14
+ - update dependencies
15
+
16
+ ## [7.12.4](https://github.com/locize/locize-cli/compare/v7.12.3...v7.12.4) - 2022-07-20
17
+
18
+ - optimize update handling
19
+ - update dependencies
20
+
8
21
  ## [7.12.3](https://github.com/locize/locize-cli/compare/v7.12.2...v7.12.3) - 2022-07-20
9
22
 
10
23
  - update dependencies
@@ -2,10 +2,68 @@ const request = require('./request');
2
2
  const flatten = require('flat');
3
3
  const sortFlatResources = require('./sortFlatResources');
4
4
 
5
+ const getRandomDelay = (delayFrom, delayTo) => Math.floor(Math.random() * delayTo) + delayFrom;
6
+
7
+ const pullNamespacePaged = (opt, lng, ns, cb, next, retry) => {
8
+ next = next || '';
9
+ request(opt.apiPath + '/pull/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?' + 'next=' + next + '&ts=' + Date.now(), {
10
+ method: 'get',
11
+ headers: {
12
+ 'Authorization': opt.apiKey
13
+ }
14
+ }, (err, res, obj) => {
15
+ if (err) return cb(err);
16
+ if (res.status >= 300) {
17
+ retry = retry || 0;
18
+ if (retry < 3 && res.status !== 401) {
19
+ setTimeout(() => {
20
+ pullNamespacePaged(opt, lng, ns, cb, next, retry + 1);
21
+ }, getRandomDelay(3000, 10000));
22
+ return;
23
+ }
24
+ if (obj && (obj.errorMessage || obj.message)) {
25
+ return cb(new Error((obj.errorMessage || obj.message)));
26
+ }
27
+ return cb(new Error(res.statusText + ' (' + res.status + ')'));
28
+ }
29
+
30
+ cb(null, {
31
+ result: sortFlatResources(flatten(obj)),
32
+ next: res.headers.get('x-next-page'),
33
+ lastModified: res.headers.get('last-modified') ? new Date(res.headers.get('last-modified')) : undefined
34
+ });
35
+ });
36
+ };
37
+
38
+ const pullNamespace = (opt, lng, ns, cb) => {
39
+ var ret = {};
40
+ var lastModified = new Date(2000, 0, 1);
41
+ (function nextPage(next) {
42
+ pullNamespacePaged(opt, lng, ns, (err, info) => {
43
+ if (err) return cb(err);
44
+
45
+ Object.keys(info.result).forEach((k) => {
46
+ ret[k] = info.result[k];
47
+ });
48
+
49
+ if (info.lastModified.getTime() > lastModified.getTime()) {
50
+ lastModified = info.lastModified;
51
+ }
52
+
53
+ if (info.next) {
54
+ return nextPage(info.next);
55
+ }
56
+ cb(null, ret, lastModified);
57
+ }, next);
58
+ })();
59
+ };
60
+
5
61
  const getRemoteNamespace = (opt, lng, ns, cb) => {
6
- request(opt.apiPath + (opt.isPrivate ? '/private' : opt.unpublished ? '/pull' : '') + '/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?ts=' + Date.now(), {
62
+ if (opt.unpublished) return pullNamespace(opt, lng, ns, cb);
63
+
64
+ request(opt.apiPath + (opt.isPrivate ? '/private' : '') + '/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?ts=' + Date.now(), {
7
65
  method: 'get',
8
- headers: (opt.isPrivate || opt.unpublished) ? {
66
+ headers: opt.isPrivate ? {
9
67
  'Authorization': opt.apiKey
10
68
  } : undefined
11
69
  }, (err, res, obj) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "7.12.3",
3
+ "version": "7.12.6",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "@js.properties/properties": "0.5.4",
11
11
  "android-string-resource": "2.3.4",
12
12
  "async": "3.2.4",
13
- "cacheable-lookup": "6.0.4",
13
+ "cacheable-lookup": "6.1.0",
14
14
  "colors": "1.4.0",
15
15
  "commander": "9.4.0",
16
16
  "csvjson": "5.1.0",
@@ -19,7 +19,7 @@
19
19
  "fluent_conv": "3.1.0",
20
20
  "gettext-converter": "1.2.3",
21
21
  "https-proxy-agent": "5.0.1",
22
- "ini": "3.0.0",
22
+ "ini": "3.0.1",
23
23
  "js-yaml": "4.1.0",
24
24
  "laravelphp": "2.0.3",
25
25
  "lodash.clonedeep": "4.5.0",
@@ -33,7 +33,7 @@
33
33
  "xlsx": "0.18.5"
34
34
  },
35
35
  "devDependencies": {
36
- "eslint": "8.20.0",
36
+ "eslint": "8.22.0",
37
37
  "gh-release": "6.0.4",
38
38
  "pkg": "5.8.0"
39
39
  },
package/sync.js CHANGED
@@ -254,14 +254,15 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
254
254
  ns.diff.toUpdate.forEach((k) => data[k] = ns.content[k]);
255
255
  }
256
256
 
257
- if (Object.keys(data).length === 0) return cb(null);
257
+ var keysToSend = Object.keys(data).length;
258
+ if (keysToSend === 0) return cb(null);
258
259
 
259
260
  if (opt.dry) return cb(null);
260
261
 
261
262
  var payloadKeysLimit = 1000;
262
263
 
263
- function send(d, clb, isRetrying) {
264
- request(opt.apiPath + '/update/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace + (shouldOmit ? '?omitstatsgeneration=true' : ''), {
264
+ function send(d, so, clb, isRetrying) {
265
+ request(opt.apiPath + '/update/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace + (so ? '?omitstatsgeneration=true' : ''), {
265
266
  method: 'post',
266
267
  body: d,
267
268
  headers: {
@@ -270,7 +271,7 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
270
271
  }, (err, res, obj) => {
271
272
  if (err) return clb(err);
272
273
  if (res.status === 504 && !isRetrying) {
273
- return setTimeout(() => send(d, clb, true), 3000);
274
+ return setTimeout(() => send(d, so, clb, true), 3000);
274
275
  }
275
276
  if (res.status >= 300 && res.status !== 412) {
276
277
  if (obj && (obj.errorMessage || obj.message)) {
@@ -282,7 +283,7 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
282
283
  });
283
284
  }
284
285
 
285
- if (Object.keys(data).length > payloadKeysLimit) {
286
+ if (keysToSend > payloadKeysLimit) {
286
287
  var tasks = [];
287
288
  var keysInObj = Object.keys(data);
288
289
 
@@ -290,7 +291,8 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
290
291
  (function() {
291
292
  var pagedData = {};
292
293
  keysInObj.splice(0, payloadKeysLimit).forEach((k) => pagedData[k] = data[k]);
293
- tasks.push((c) => send(pagedData, c));
294
+ var hasMoreKeys = keysInObj.length > 0;
295
+ tasks.push((c) => send(pagedData, hasMoreKeys ? true : shouldOmit, c));
294
296
  })();
295
297
  }
296
298
 
@@ -298,13 +300,13 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
298
300
 
299
301
  var finalPagedData = {};
300
302
  keysInObj.splice(0, keysInObj.length).forEach((k) => finalPagedData[k] = data[k]);
301
- tasks.push((c) => send(finalPagedData, c));
303
+ tasks.push((c) => send(finalPagedData, shouldOmit, c));
302
304
 
303
305
  async.series(tasks, cb);
304
306
  return;
305
307
  }
306
308
 
307
- send(data, cb);
309
+ send(data, shouldOmit, cb);
308
310
  };
309
311
 
310
312
  const cleanupLanguages = (opt, remoteLanguages) => {