Skip to content

Commit 5442b21

Browse files
Merge branch 'master' into duplicate-prevention
2 parents c9e1ddf + 651f54a commit 5442b21

19 files changed

+92
-1096
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "medic",
3-
"version": "4.15.0",
3+
"version": "4.16.0",
44
"private": true,
55
"license": "AGPL-3.0-only",
66
"repository": {

scripts/build/index.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('fs');
22
const spawn = require('child_process').spawn;
33
const path = require('path');
4-
const rpn = require('request-promise-native');
54
const mustache = require('mustache');
65

76
const packageJson = require('../../package.json');
@@ -34,8 +33,18 @@ const getApiUrl = (pathname = '') => {
3433
const apiUrl = new URL(COUCH_URL);
3534
apiUrl.port = API_PORT || DEFAULT_API_PORT;
3635
apiUrl.pathname = pathname;
37-
38-
return apiUrl.toString();
36+
const basicAuth = btoa(`${apiUrl.username}:${apiUrl.password}`);
37+
apiUrl.username = '';
38+
apiUrl.password = '';
39+
40+
return {
41+
url: apiUrl.toString(),
42+
options: {
43+
headers: {
44+
Authorization: `Basic ${basicAuth}`,
45+
}
46+
}
47+
};
3948
};
4049

4150
const releaseName = TAG || versions.escapeBranchName(BRANCH) || `${packageJson.version}-local-development`;
@@ -157,24 +166,28 @@ const saveServiceTags = () => {
157166
fs.writeFileSync(tagsFilePath, JSON.stringify(tags));
158167
};
159168

160-
const updateServiceWorker = () => {
161-
const updateSWUrl = getApiUrl('/api/v2/upgrade/service-worker');
169+
const updateServiceWorker = async () => {
170+
const { url, options } = getApiUrl('/api/v2/upgrade/service-worker');
162171

163-
return rpn.get(updateSWUrl).catch(err => {
164-
if (err.status === 401) {
165-
throw new Error('Environment variable COUCH_URL has invalid authentication');
172+
try {
173+
const response = await fetch(url, options);
174+
if (response.ok) {
175+
return;
166176
}
167-
if (err.status === 403) {
168-
throw new Error('Environment variable COUCH_URL must have admin authentication');
177+
178+
throw response;
179+
} catch (err) {
180+
if (err.status === 401 || err.status === 403) {
181+
throw new Error('Environment variable COUCH_URL does not have valid authentication');
169182
}
170183

171-
if (err.error && err.error.code === 'ECONNREFUSED') {
184+
if (err.cause?.code === 'ECONNREFUSED') {
172185
console.warn('API could not be reached, so the service-worker has not been updated. ');
173186
return;
174187
}
175188

176189
throw err;
177-
});
190+
}
178191
};
179192

180193
const setDdocsVersion = () => {

scripts/bulk-password-update-export.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED=0;
33
const minimist = require('minimist');
44
const {promises: fsPromises} = require('fs');
55
const readline = require('readline');
6-
const rpn = require('request-promise-native');
76
const {randomInt} = require('crypto');
87
const csvSync = require('csv-parse/sync');
98

@@ -46,10 +45,10 @@ const user = argv.user;
4645
const password = argv.password;
4746

4847
const options = {
49-
uri: url.href,
50-
json: true,
48+
method: 'POST',
5149
headers: {
52-
'Authorization': 'Basic ' + Buffer.from(`${user}:${password}`).toString('base64')
50+
'Authorization': 'Basic ' + btoa(`${user}:${password}`),
51+
'Content-Type': 'application/json'
5352
}
5453
};
5554

@@ -73,18 +72,16 @@ Do you want to continue? [y/N]
7372

7473
const changeUserPass = async (user, options) => {
7574
const postOptions = {...options};
76-
postOptions.body = {
77-
'password': user.pass
78-
};
79-
postOptions.uri = `${options.uri}/${user.name}`;
75+
postOptions.body = JSON.stringify({ password: user.pass });
76+
const uri = `${url.href}/${user.name}`;
8077
try {
8178
if (admins.includes(user.name)) {
8279
throw new Error(`403 - Password change for "${user.name}" not allowed .`);
8380
}
8481
if (user.name.toString().trim() === '') {
8582
throw new Error(`404 - Username is blank - check CSV and run again.`);
8683
}
87-
await rpn.post(postOptions);
84+
await fetch(uri, postOptions);
8885
console.log('SUCCESS', user.name, user.pass);
8986
} catch (e) {
9087
console.log('ERROR', user.name, e.message);

scripts/generate-form-attachments/.eslintrc.json

-13
This file was deleted.

scripts/generate-form-attachments/README.md

-39
This file was deleted.

scripts/generate-form-attachments/package-lock.json

-13
This file was deleted.

scripts/generate-form-attachments/package.json

-12
This file was deleted.

scripts/generate-form-attachments/src/create-attachments.js

-163
This file was deleted.

scripts/generate-form-attachments/src/index.js

-17
This file was deleted.

0 commit comments

Comments
 (0)