@kununu/phraseapp-cli 3.1.0-beta.1 → 3.1.0-beta.2

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.
Files changed (2) hide show
  1. package/index.js +29 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -90,14 +90,13 @@ const getFilePath = (path, filePrefix, localeId) =>
90
90
  `${path}${getFileName(filePrefix, localeId)}`;
91
91
 
92
92
  function getPhraseAppDownloadUrl(
93
- accessToken,
94
93
  projectId,
95
94
  localeId,
96
95
  tags,
97
96
  fallbackLocaleId,
98
97
  branch,
99
98
  ) {
100
- return `https://${accessToken}@api.phraseapp.com/api/v2/projects/${projectId}/locales/${localeId}/download?${getPhraseAppQueryParams(tags, fallbackLocaleId, branch)}`;
99
+ return `https://api.phraseapp.com/api/v2/projects/${projectId}/locales/${localeId}/download?${getPhraseAppQueryParams(tags, fallbackLocaleId, branch)}`;
101
100
  }
102
101
 
103
102
  function downloadLocaleFile(phrase, locale) {
@@ -120,7 +119,6 @@ function downloadLocaleFile(phrase, locale) {
120
119
 
121
120
  return new Promise((resolve, reject) => {
122
121
  const url = getPhraseAppDownloadUrl(
123
- accessToken,
124
122
  projectId,
125
123
  localeId,
126
124
  tags,
@@ -128,27 +126,39 @@ function downloadLocaleFile(phrase, locale) {
128
126
  branch,
129
127
  );
130
128
 
131
- fetch(url, (error, response, body) => {
132
- if (!error && response.statusCode === 200) {
133
- fs.writeFileSync(filepath, body);
129
+ const headers = new Headers({
130
+ Authorization: `Basic ${btoa(accessToken)}`,
131
+ });
132
+
133
+ fetch(url, {headers})
134
+ .then(response => {
135
+ if (!response.ok) {
136
+ throw new Error(response);
137
+ }
138
+ return response.json();
139
+ })
140
+ .then(data => {
141
+ // Handle the JSON response
142
+ fs.writeFileSync(filepath, JSON.stringify(data));
134
143
  console.info(
135
144
  `Success: locale file ${getFileName(filePrefix, localeId)} was updated`
136
145
  .green.bold,
137
146
  );
138
147
  return resolve();
139
- }
140
-
141
- if (response.statusCode === 401) {
142
- console.error('Error: Please check your access_token'.red.bold);
143
- } else {
144
- console.error(
145
- `Error: locale file ${getFileName(filePrefix, localeId)}. Message: ${JSON.parse(body).message}`
146
- .red,
147
- );
148
- }
149
-
150
- return reject(response);
151
- });
148
+ })
149
+ .catch(error => {
150
+ if (error.status === 401) {
151
+ console.error('Error: Please check your access_token'.red.bold);
152
+ } else {
153
+ // Handle any errors
154
+ console.error(
155
+ `Error: locale file ${getFileName(filePrefix, localeId)}. Message: ${error.json()}`
156
+ .red,
157
+ );
158
+ }
159
+
160
+ return reject();
161
+ });
152
162
  });
153
163
  }
154
164
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kununu/phraseapp-cli",
3
- "version": "3.1.0-beta.1",
3
+ "version": "3.1.0-beta.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "kununu",