locize-cli 7.12.5 → 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 +4 -0
- package/getRemoteNamespace.js +55 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ 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
|
+
|
|
8
12
|
## [7.12.5](https://github.com/locize/locize-cli/compare/v7.12.4...v7.12.5) - 2022-08-25
|
|
9
13
|
|
|
10
14
|
- update dependencies
|
package/getRemoteNamespace.js
CHANGED
|
@@ -4,20 +4,21 @@ const sortFlatResources = require('./sortFlatResources');
|
|
|
4
4
|
|
|
5
5
|
const getRandomDelay = (delayFrom, delayTo) => Math.floor(Math.random() * delayTo) + delayFrom;
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
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(), {
|
|
9
10
|
method: 'get',
|
|
10
|
-
headers:
|
|
11
|
+
headers: {
|
|
11
12
|
'Authorization': opt.apiKey
|
|
12
|
-
}
|
|
13
|
+
}
|
|
13
14
|
}, (err, res, obj) => {
|
|
14
15
|
if (err) return cb(err);
|
|
15
16
|
if (res.status >= 300) {
|
|
16
17
|
retry = retry || 0;
|
|
17
18
|
if (retry < 3 && res.status !== 401) {
|
|
18
19
|
setTimeout(() => {
|
|
19
|
-
|
|
20
|
-
},
|
|
20
|
+
pullNamespacePaged(opt, lng, ns, cb, next, retry + 1);
|
|
21
|
+
}, getRandomDelay(3000, 10000));
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
24
|
if (obj && (obj.errorMessage || obj.message)) {
|
|
@@ -25,6 +26,54 @@ const getRemoteNamespace = (opt, lng, ns, cb, retry) => {
|
|
|
25
26
|
}
|
|
26
27
|
return cb(new Error(res.statusText + ' (' + res.status + ')'));
|
|
27
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
|
+
|
|
61
|
+
const getRemoteNamespace = (opt, lng, ns, cb) => {
|
|
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(), {
|
|
65
|
+
method: 'get',
|
|
66
|
+
headers: opt.isPrivate ? {
|
|
67
|
+
'Authorization': opt.apiKey
|
|
68
|
+
} : undefined
|
|
69
|
+
}, (err, res, obj) => {
|
|
70
|
+
if (err) return cb(err);
|
|
71
|
+
if (res.status >= 300) {
|
|
72
|
+
if (obj && (obj.errorMessage || obj.message)) {
|
|
73
|
+
return cb(new Error((obj.errorMessage || obj.message)));
|
|
74
|
+
}
|
|
75
|
+
return cb(new Error(res.statusText + ' (' + res.status + ')'));
|
|
76
|
+
}
|
|
28
77
|
cb(null, sortFlatResources(flatten(obj)), res.headers.get('last-modified') ? new Date(res.headers.get('last-modified')) : undefined);
|
|
29
78
|
});
|
|
30
79
|
};
|