Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit 3cef358

Browse files
authored
Merge pull request #697 from OpenClinica/revert-694-revert-691-merge/6.2.0
Revert "Revert "Merge/6.2.0""
2 parents d4dc69f + e109715 commit 3cef358

File tree

110 files changed

+2826
-1193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2826
-1193
lines changed

.eslintrc.json

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,27 @@
99
"structuredClone": true
1010
},
1111
"extends": ["airbnb", "prettier"],
12-
"plugins": ["chai-friendly", "jsdoc", "prettier", "unicorn"],
12+
"plugins": [
13+
"chai-friendly",
14+
"jsdoc",
15+
"prettier",
16+
"unicorn",
17+
"@typescript-eslint"
18+
],
19+
"parser": "@typescript-eslint/parser",
1320
"parserOptions": {
1421
"sourceType": "module",
1522
"ecmaVersion": 2021
1623
},
1724
"settings": {
25+
"import/parsers": {
26+
"@typescript-eslint/parser": [".js", ".ts", ".tsx"]
27+
},
28+
"import/resolver": {
29+
"typescript": {
30+
"alwaysTryTypes": true
31+
}
32+
},
1833
"jsdoc": {
1934
"tagNamePreference": {
2035
"returns": "return"
@@ -31,7 +46,8 @@
3146
"enketo/widgets",
3247
"enketo/translator",
3348
"enketo/dialog",
34-
"enketo/file-manager"
49+
"enketo/file-manager",
50+
"enketo-transformer/web"
3551
]
3652
}
3753
],

CHANGELOG.md

+29

Gruntfile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = (grunt) => {
66
'!.nyc_output',
77
'!**/node_modules/**',
88
'!test/client/forms/forms.js',
9-
'!public/js/build/*',
9+
'!public/js/build/**',
1010
'!docs/**',
1111
'!test-coverage/**',
1212
];
@@ -105,7 +105,7 @@ module.exports = (grunt) => {
105105
'find locales -name "translation-combined.json" -delete && rm -fr locales/??',
106106
},
107107
'clean-js': {
108-
command: 'rm -f public/js/build/* && rm -f public/js/*.js',
108+
command: 'rm -rf public/js/build/* && rm -f public/js/*.js',
109109
},
110110
translation: {
111111
command:

README.md

+6-4

app/controllers/media-controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const request = require('request');
88
const express = require('express');
99

1010
const router = express.Router();
11-
const debug = require('debug')('media-controller');
11+
const debug = require('debug')('enketo:media-controller');
1212
const {
1313
RequestFilteringHttpAgent,
1414
RequestFilteringHttpsAgent,

app/controllers/transformation-controller.js

+14-65
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const transformer = require('enketo-transformer');
66
const communicator = require('../lib/communicator');
7-
const { TranslatedError } = require('../lib/custom-error');
7+
const { ResponseError, TranslatedError } = require('../lib/custom-error');
88
const surveyModel = require('../models/survey-model');
99
const cacheModel = require('../models/cache-model');
1010
const account = require('../models/account-model');
@@ -13,7 +13,6 @@ const config = require('../models/config-model').server;
1313
const utils = require('../lib/utils');
1414
const routerUtils = require('../lib/router-utils');
1515
const express = require('express');
16-
const url = require('url');
1716
const mediaLib = require('../lib/media');
1817

1918
const router = express.Router();
@@ -101,27 +100,15 @@ async function getSurveyParts(req, res, next) {
101100
/** @type {string | null} */
102101
let formId = null;
103102

104-
/** @type {string | null} */
105-
let formFileName = null;
106-
107103
try {
108104
let survey = await _getSurveyParams(req);
109105

110-
// A request with "xformUrl" body parameter was used (unlaunched form)
111-
if (survey.info != null) {
112-
formFileName = survey.info.downloadUrl.replace(
113-
/.*\/([^/]+)$/,
114-
'$1'
115-
);
116-
survey = await _getFormDirectly(survey);
117-
118-
_respond(res, survey);
106+
formId = survey.openRosaId;
119107

120-
return;
108+
if (formId == null) {
109+
throw new ResponseError(404);
121110
}
122111

123-
formId = survey.openRosaId;
124-
125112
const authenticated = await _authenticate(survey);
126113
const cached = await _getFormFromCache(authenticated);
127114

@@ -142,14 +129,10 @@ async function getSurveyParts(req, res, next) {
142129
});
143130
} catch (error) {
144131
if (error.status === 403) {
145-
const notFoundError =
146-
formId == null
147-
? new TranslatedError('error.notfounddirectformurl', {
148-
formFileName,
149-
})
150-
: new TranslatedError('error.notfoundinformlist', {
151-
formId,
152-
});
132+
const notFoundError = new TranslatedError(
133+
'error.notfoundinformlist',
134+
{ formId }
135+
);
153136

154137
notFoundError.status = 404;
155138

@@ -183,17 +166,6 @@ function getSurveyHash(req, res, next) {
183166
.catch(next);
184167
}
185168

186-
/**
187-
* @param {module:survey-model~SurveyObject} survey - survey object
188-
*
189-
* @return { Promise<module:survey-model~SurveyObject> } a Promise resolving with survey object with form transformation result
190-
*
191-
*/
192-
function _getFormDirectly(survey) {
193-
survey.openclinica = true;
194-
return communicator.getXForm(survey).then(transformer.transform);
195-
}
196-
197169
/**
198170
* @param {module:survey-model~SurveyObject} survey - survey object
199171
*
@@ -233,8 +205,11 @@ function _updateCache(survey) {
233205
delete survey.mediaHash;
234206
delete survey.mediaUrlHash;
235207
delete survey.formHash;
236-
237-
return _getFormDirectly(survey).then(cacheModel.set);
208+
survey.openclinica = true;
209+
return communicator
210+
.getXForm(survey)
211+
.then(transformer.transform)
212+
.then(cacheModel.set);
238213
}
239214

240215
return survey;
@@ -359,7 +334,6 @@ function _setCookieAndCredentials(survey, req) {
359334
* @return { Promise<module:survey-model~SurveyObject> } a Promise resolving with survey object
360335
*/
361336
function _getSurveyParams(req) {
362-
const params = req.body;
363337
const customParamName = req.app.get(
364338
'query parameter to pass to submission'
365339
);
@@ -376,32 +350,7 @@ function _getSurveyParams(req) {
376350
return _setCookieAndCredentials(survey, req);
377351
});
378352
}
379-
if (params.xformUrl) {
380-
const urlObj = url.parse(params.xformUrl);
381-
if (!urlObj || !urlObj.protocol || !urlObj.host) {
382-
const error = new Error('Bad Request. Form URL is invalid.');
383-
error.status = 400;
384-
throw error;
385-
}
386-
const xUrl = `${urlObj.protocol}//${urlObj.host}${urlObj.pathname}`;
387-
388-
return account
389-
.check({
390-
openRosaServer: xUrl,
391-
})
392-
.then(
393-
(
394-
survey // no need to check quota
395-
) =>
396-
Promise.resolve({
397-
info: {
398-
downloadUrl: params.xformUrl,
399-
},
400-
account: survey.account,
401-
})
402-
)
403-
.then((survey) => _setCookieAndCredentials(survey, req));
404-
}
353+
405354
const error = new Error('Bad Request. Survey information not complete.');
406355
error.status = 400;
407356
throw error;

app/lib/communicator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const request = require('request');
66
const { Auth } = require('request/lib/auth');
77
const TError = require('./custom-error').TranslatedError;
88
const config = require('../models/config-model').server;
9-
const debug = require('debug')('openrosa-communicator');
9+
const debug = require('debug')('enketo:openrosa-communicator');
1010
const Xml2Js = require('xml2js');
1111

1212
const parser = new Xml2Js.Parser();

app/lib/pdf.js

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ async function get(
121121
},
122122
scale,
123123
printBackground: true,
124+
timeout,
124125
});
125126
} catch (e) {
126127
e.status = e.status || 400;

app/models/cache-model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const utils = require('../lib/utils');
99

1010
const prefix = 'ca:';
1111
const expiry = 30 * 24 * 60 * 60;
12-
const debug = require('debug')('cache-model');
12+
const debug = require('debug')('enketo:cache-model');
1313

1414
const clientGet = promisify(cacheClient.get).bind(cacheClient);
1515
const clientSet = promisify(cacheClient.set).bind(cacheClient);

app/models/survey-model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const TError = require('../lib/custom-error').TranslatedError;
88
const config = require('./config-model').server;
99

1010
const pending = {};
11-
const debug = require('debug')('survey-model');
11+
const debug = require('debug')('enketo:survey-model');
1212

1313
/**
1414
* @typedef {import('./account-model').AccountObj} AccountObj

app/views/index.pug

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ block content
5757
li= t("langs.sv")
5858
when "lo"
5959
li= t("langs.lo")
60+
when "uk"
61+
li= t("langs.uk")
6062
when "sk"
6163
li= t("langs.sk")
6264
when "tr"

app/views/surveys/webform.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ block style
2020

2121
block script
2222
- var suffix = (type && type !== 'single') ? '-' + (type === 'full' || type === 'preview' || type === 'fieldsubmission' ? 'oc' : type): ''
23-
script#main-script(defer, module, src=`${basePath}${offlinePath || ''}/js/build/enketo-webform${suffix}.js`)
23+
script#main-script(defer, type='module', src=`${basePath}${offlinePath || ''}/js/build/enketo-webform${suffix}.js`)
2424

2525
-// load jini stuff asynchronously (OC)
2626
if jini && !headless

config/build.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
const alias = require('esbuild-plugin-alias');
1+
// @ts-check
2+
23
const path = require('path');
34
const pkg = require('../package.json');
45

56
const cwd = process.cwd();
67

78
const entryPoints = pkg.entries.map((entry) => path.resolve(cwd, entry));
89

9-
const isProduction = process.env.NODE_ENV === 'production';
10-
11-
module.exports = {
10+
module.exports = /** @satisfies {import('esbuild').BuildOptions} */ ({
11+
alias: Object.fromEntries(
12+
Object.entries(pkg.browser).map(([key, value]) => [
13+
key,
14+
path.resolve(cwd, `${value}.js`),
15+
])
16+
),
1217
bundle: true,
18+
chunkNames: 'chunks/[name]-[hash]',
1319
entryPoints,
14-
format: 'iife',
15-
minify: isProduction,
20+
entryNames: '[name]',
21+
external: ['crypto', 'libxslt'],
22+
format: 'esm',
23+
minify: true,
1624
outdir: path.resolve(cwd, './public/js/build'),
17-
plugins: [
18-
alias(
19-
Object.fromEntries(
20-
Object.entries(pkg.browser).map(([key, value]) => [
21-
key,
22-
path.resolve(cwd, `${value}.js`),
23-
])
24-
)
25-
),
26-
],
27-
sourcemap: isProduction ? false : 'inline',
25+
sourcemap: true,
26+
splitting: true,
2827
target: ['chrome89', 'edge89', 'firefox90', 'safari13'],
29-
};
28+
});

config/express.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const errorHandler = require('../app/controllers/error-handler');
1414

1515
const controllersPath = path.join(__dirname, '../app/controllers');
1616
const app = express();
17-
const debug = require('debug')('express');
17+
const debug = require('debug')('enketo:express');
1818
const config = require('../app/models/config-model');
1919

2020
// general

docs/app_controllers_api-controller.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_api-v1-controller.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_api-v2-controller.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_authentication-controller.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_error-handler.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_media-controller.js.html

+2-2
Large diffs are not rendered by default.

docs/app_controllers_offline-controller.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_pages-controller.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_submission-controller.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_survey-controller.js.html

+1-1
Large diffs are not rendered by default.

docs/app_controllers_transformation-controller.js.html

+14-64
Large diffs are not rendered by default.

docs/app_lib_communicator.js.html

+2-2
Large diffs are not rendered by default.

docs/app_lib_custom-error.js.html

+1-1
Large diffs are not rendered by default.

docs/app_lib_media.js.html

+1-1
Large diffs are not rendered by default.

docs/app_lib_pdf.js.html

+2-1
Large diffs are not rendered by default.

docs/app_lib_router-utils.js.html

+1-1
Large diffs are not rendered by default.

docs/app_lib_utils.js.html

+1-1
Large diffs are not rendered by default.

docs/app_models_account-model.js.html

+1-1
Large diffs are not rendered by default.

docs/app_models_cache-model.js.html

+2-2
Large diffs are not rendered by default.

docs/app_models_config-model.js.html

+1-1
Large diffs are not rendered by default.

docs/app_models_instance-model.js.html

+1-1
Large diffs are not rendered by default.

docs/app_models_record-model.js.html

+1-1
Large diffs are not rendered by default.

docs/app_models_submission-model.js.html

+1-1
Large diffs are not rendered by default.

docs/app_models_survey-model.js.html

+2-2
Large diffs are not rendered by default.

docs/app_models_user-model.js.html

+1-1
Large diffs are not rendered by default.

docs/global.html

+1-1
Large diffs are not rendered by default.

docs/index.html

+6-5
Large diffs are not rendered by default.

docs/module-account-model.html

+1-1
Large diffs are not rendered by default.

docs/module-api-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-api-v1-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-api-v2-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-authentication-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-cache-model.html

+1-1
Large diffs are not rendered by default.

docs/module-communicator.html

+1-1
Large diffs are not rendered by default.

docs/module-config-model.html

+1-1
Large diffs are not rendered by default.

docs/module-custom-error.html

+1-1
Large diffs are not rendered by default.

docs/module-duplicates.html

+1-1
Large diffs are not rendered by default.

docs/module-error-handler.html

+1-1
Large diffs are not rendered by default.

docs/module-instance-model.html

+1-1
Large diffs are not rendered by default.

docs/module-media-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-offline-resources-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-pages-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-pdf.html

+1-1
Large diffs are not rendered by default.

docs/module-router-utils.html

+1-1
Large diffs are not rendered by default.

docs/module-submission-model.html

+1-1
Large diffs are not rendered by default.

docs/module-submissions-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-survey-controller.html

+1-1
Large diffs are not rendered by default.

docs/module-survey-model.html

+1-1
Large diffs are not rendered by default.

docs/module-transformation-controller.html

+12-166
Large diffs are not rendered by default.

docs/module-user-model.html

+1-1
Large diffs are not rendered by default.

docs/module-utils.html

+1-1
Large diffs are not rendered by default.

docs/tools_duplicates.js.html

+1-1
Large diffs are not rendered by default.

docs/tutorial-00-getting-started.html

+5-1
Large diffs are not rendered by default.

docs/tutorial-02-heroku.html

+1-1
Large diffs are not rendered by default.

docs/tutorial-10-configure.html

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)