Skip to content

Commit

Permalink
Merge branch 'master' into duplicate-prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinHairSaintClair authored Jan 15, 2025
2 parents 9eb471f + 651f54a commit 4728a2c
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 1,096 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic",
"version": "4.15.0",
"version": "4.16.0",
"private": true,
"license": "AGPL-3.0-only",
"repository": {
Expand Down
37 changes: 25 additions & 12 deletions scripts/build/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('fs');
const spawn = require('child_process').spawn;
const path = require('path');
const rpn = require('request-promise-native');
const mustache = require('mustache');

const packageJson = require('../../package.json');
Expand Down Expand Up @@ -34,8 +33,18 @@ const getApiUrl = (pathname = '') => {
const apiUrl = new URL(COUCH_URL);
apiUrl.port = API_PORT || DEFAULT_API_PORT;
apiUrl.pathname = pathname;

return apiUrl.toString();
const basicAuth = btoa(`${apiUrl.username}:${apiUrl.password}`);
apiUrl.username = '';
apiUrl.password = '';

return {
url: apiUrl.toString(),
options: {
headers: {
Authorization: `Basic ${basicAuth}`,
}
}
};
};

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

const updateServiceWorker = () => {
const updateSWUrl = getApiUrl('/api/v2/upgrade/service-worker');
const updateServiceWorker = async () => {
const { url, options } = getApiUrl('/api/v2/upgrade/service-worker');

return rpn.get(updateSWUrl).catch(err => {
if (err.status === 401) {
throw new Error('Environment variable COUCH_URL has invalid authentication');
try {
const response = await fetch(url, options);
if (response.ok) {
return;
}
if (err.status === 403) {
throw new Error('Environment variable COUCH_URL must have admin authentication');

throw response;
} catch (err) {
if (err.status === 401 || err.status === 403) {
throw new Error('Environment variable COUCH_URL does not have valid authentication');
}

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

throw err;
});
}
};

const setDdocsVersion = () => {
Expand Down
15 changes: 6 additions & 9 deletions scripts/bulk-password-update-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED=0;
const minimist = require('minimist');
const {promises: fsPromises} = require('fs');
const readline = require('readline');
const rpn = require('request-promise-native');
const {randomInt} = require('crypto');
const csvSync = require('csv-parse/sync');

Expand Down Expand Up @@ -46,10 +45,10 @@ const user = argv.user;
const password = argv.password;

const options = {
uri: url.href,
json: true,
method: 'POST',
headers: {
'Authorization': 'Basic ' + Buffer.from(`${user}:${password}`).toString('base64')
'Authorization': 'Basic ' + btoa(`${user}:${password}`),
'Content-Type': 'application/json'
}
};

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

const changeUserPass = async (user, options) => {
const postOptions = {...options};
postOptions.body = {
'password': user.pass
};
postOptions.uri = `${options.uri}/${user.name}`;
postOptions.body = JSON.stringify({ password: user.pass });
const uri = `${url.href}/${user.name}`;
try {
if (admins.includes(user.name)) {
throw new Error(`403 - Password change for "${user.name}" not allowed .`);
}
if (user.name.toString().trim() === '') {
throw new Error(`404 - Username is blank - check CSV and run again.`);
}
await rpn.post(postOptions);
await fetch(uri, postOptions);
console.log('SUCCESS', user.name, user.pass);
} catch (e) {
console.log('ERROR', user.name, e.message);
Expand Down
13 changes: 0 additions & 13 deletions scripts/generate-form-attachments/.eslintrc.json

This file was deleted.

39 changes: 0 additions & 39 deletions scripts/generate-form-attachments/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/generate-form-attachments/package-lock.json

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/generate-form-attachments/package.json

This file was deleted.

163 changes: 0 additions & 163 deletions scripts/generate-form-attachments/src/create-attachments.js

This file was deleted.

17 changes: 0 additions & 17 deletions scripts/generate-form-attachments/src/index.js

This file was deleted.

Loading

0 comments on commit 4728a2c

Please sign in to comment.