From 04019b3f6a2e1e8fc6cdfda5e31255a7a26356f3 Mon Sep 17 00:00:00 2001 From: eyelidlessness Date: Thu, 21 Apr 2022 12:22:59 -0700 Subject: [PATCH] Prepare to release 2.1.3 (#148) --- CHANGELOG.md | 6 + docs/api.js.html | 174 ++++--- docs/global.html | 2 +- docs/index.html | 45 +- docs/language.js.html | 50 +- docs/markdown.js.html | 107 ++-- docs/module-api.html | 2 +- docs/module-markdown.html | 18 +- docs/module-transformer.html | 40 +- docs/transformer.js.html | 504 ++++++++++-------- docs/url.js.html | 30 +- package-lock.json | 974 +++++++++++++++++++---------------- package.json | 22 +- 13 files changed, 1072 insertions(+), 902 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a597a2..81a00c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2.1.3] - 2022-04-21 + +##### Changed + +- Code style/formatting: Prettier + Airbnb ESLint preset (#146) + ## [2.1.2] - 2022-02-01 ##### Fixed diff --git a/docs/api.js.html b/docs/api.js.html index 0186918..1b8c86d 100644 --- a/docs/api.js.html +++ b/docs/api.js.html @@ -58,81 +58,93 @@

api.js

* PRs are very welcome! */ -const request = require( 'request' ); -const express = require( 'express' ); +const request = require('request'); +const express = require('express'); + const router = express.Router(); -const transformer = require( './transformer' ); +const transformer = require('./transformer'); router - .all( '/', ( req, res, next ) => { - if ( req.app.get( 'secure' ) ) { - res.status( 405 ).send( 'Not Allowed' ); - } else if ( !req.query.xform ) { - res.status( 400 ).send( 'Bad Request.' ); + .all('/', (req, res, next) => { + if (req.app.get('secure')) { + res.status(405).send('Not Allowed'); + } else if (!req.query.xform) { + res.status(400).send('Bad Request.'); } else { // allow requests from anywhere - res.set( 'Access-Control-Allow-Origin', '*' ); + res.set('Access-Control-Allow-Origin', '*'); next(); } - } ) - .get( '/', ( req, res ) => { - _request( { + }) + .get('/', (req, res) => { + _request({ method: 'get', - url: req.query.xform - } ) - .then( xform => transformer.transform( { - xform, - theme: req.query.theme, - openclinica: req.query.openclinica === 'true', - markdown: req.query.markdown !== 'false' - } ) ) - .then( result => { - res.json( result ); - } ) - .catch( error => { + url: req.query.xform, + }) + .then((xform) => + transformer.transform({ + xform, + theme: req.query.theme, + openclinica: req.query.openclinica === 'true', + markdown: req.query.markdown !== 'false', + }) + ) + .then((result) => { + res.json(result); + }) + .catch((error) => { error.status = error.status || 500; error.message = error.message || 'Unknown error.'; - res.status( error.status ).send( `${error.message} (stack: ${error.stack})` ); - } ); - } ) - .post( '/', ( req, res ) => { - transformer.transform( { - xform: req.body.xform, - theme: req.body.theme, - media: req.body.media, - openclinica: req.body.openclinica === 'true', - markdown: req.body.markdown !== 'false' - } ) - .then( result => { - res.json( result ); - } ) - .catch( error => { + res.status(error.status).send( + `${error.message} (stack: ${error.stack})` + ); + }); + }) + .post('/', (req, res) => { + transformer + .transform({ + xform: req.body.xform, + theme: req.body.theme, + media: req.body.media, + openclinica: req.body.openclinica === 'true', + markdown: req.body.markdown !== 'false', + }) + .then((result) => { + res.json(result); + }) + .catch((error) => { error.status = error.status || 500; error.message = error.message || 'Unknown error.'; - res.status( error.status ).send( `${error.message} (stack: ${error.stack})` ); - } ); - } ) + res.status(error.status).send( + `${error.message} (stack: ${error.stack})` + ); + }); + }) // for development purposes, to return HTML that can be easily inspected in the developer console - .get( '/htmlform', ( req, res ) => { - _request( { + .get('/htmlform', (req, res) => { + _request({ method: 'get', - url: req.query.xform - } ) - .then( xform => transformer.transform( { - xform, - theme: req.query.theme, - openclinica: req.query.openclinica === 'true', - markdown: req.query.markdown !== 'false' - } ) ) - .then( result => { - res.send( result.form ); - } ) - .catch( error => { + url: req.query.xform, + }) + .then((xform) => + transformer.transform({ + xform, + theme: req.query.theme, + openclinica: req.query.openclinica === 'true', + markdown: req.query.markdown !== 'false', + }) + ) + .then((result) => { + res.send(result.form); + }) + .catch((error) => { error.status = error.status || 500; error.message = error.message || 'Unknown error.'; - res.status( error.status ).send( `${error.message} (stack: ${error.stack})` ); - } ); - } ); + res.status(error.status).send( + `${error.message} (stack: ${error.stack})` + ); + }); + }); /** * Sends a request to an OpenRosa server. Only for basic retrieval of @@ -141,35 +153,41 @@

api.js

* @param { {url: string, method: string} } options - Request options object. * @return { Promise<Error|object> } a promise that resolves in request body. */ -function _request( options ) { +function _request(options) { options.headers = options.headers || {}; - options.headers[ 'X-OpenRosa-Version' ] = '1.0'; + options.headers['X-OpenRosa-Version'] = '1.0'; const method = options.method || 'get'; - return new Promise( ( resolve, reject ) => { - request[ method ]( options, ( error, response, body ) => { - if ( error ) { - console.error( `Error occurred when requesting ${options.url}`, error ); - reject( error ); - } else if ( response.statusCode === 401 ) { - const error = new Error( 'Forbidden. Authorization Required.' ); + return new Promise((resolve, reject) => { + request[method](options, (error, response, body) => { + if (error) { + console.error( + `Error occurred when requesting ${options.url}`, + error + ); + reject(error); + } else if (response.statusCode === 401) { + const error = new Error('Forbidden. Authorization Required.'); error.status = response.statusCode; - reject( error ); - } else if ( response.statusCode < 200 || response.statusCode >= 300 ) { - const error = new Error( `Request to ${options.url} failed.` ); + reject(error); + } else if ( + response.statusCode < 200 || + response.statusCode >= 300 + ) { + const error = new Error(`Request to ${options.url} failed.`); error.status = response.statusCode; - reject( error ); + reject(error); } else { - //console.log( `response of request to ${options.url} has status code: `, response.statusCode ); - resolve( body ); + // console.log( `response of request to ${options.url} has status code: `, response.statusCode ); + resolve(body); } - } ); - } ); + }); + }); } -module.exports = app => { - app.use( '/transform', router ); +module.exports = (app) => { + app.use('/transform', router); }; diff --git a/docs/global.html b/docs/global.html index 9844dc2..38dd9b8 100644 --- a/docs/global.html +++ b/docs/global.html @@ -291,7 +291,7 @@

getMediaP
Source:
diff --git a/docs/index.html b/docs/index.html index 4e8984c..3c734c6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -77,26 +77,28 @@

Install as module

Use as module

const transformer = require('enketo-transformer');
-const xform = fs.readFileSync( 'path/to/xform.xml' );
-
-transformer.transform( {
-    // required string of XForm
-    xform: xform,
-    // optional string, to add theme if no theme is defined in the XForm
-    theme: 'sometheme',
-    // optional map, to replace jr://..../myfile.png URLs
-    media: {
-        'myfile.png' : '/path/to/somefile.png',
-        'myfile.mp3' : '/another/path/to/2.mp3'
-    },
-    // optional ability to disable markdown rendering (default is true)
-    markdown: false,
-    // optional preprocess function that transforms the XForm (as libXMLJs object) to
-    // e.g. correct incompatible XForm syntax before Enketo's transformation takes place
-    preprocess: doc => doc,
-} ).then(function( result ){
-    // do something with result
-});
+const xform = fs.readFileSync('path/to/xform.xml');
+
+transformer
+    .transform({
+        // required string of XForm
+        xform: xform,
+        // optional string, to add theme if no theme is defined in the XForm
+        theme: 'sometheme',
+        // optional map, to replace jr://..../myfile.png URLs
+        media: {
+            'myfile.png': '/path/to/somefile.png',
+            'myfile.mp3': '/another/path/to/2.mp3',
+        },
+        // optional ability to disable markdown rendering (default is true)
+        markdown: false,
+        // optional preprocess function that transforms the XForm (as libXMLJs object) to
+        // e.g. correct incompatible XForm syntax before Enketo's transformation takes place
+        preprocess: (doc) => doc,
+    })
+    .then(function (result) {
+        // do something with result
+    });
 

Install as app (web API)

    @@ -117,12 +119,11 @@

    Use as app (web API)

    Response format

    {
    -    "form" : "<form>.....</form>",
    +    "form": "<form>.....</form>",
         "model": "<model>...</model>",
         "transformerVersion": "1.13.0",
         "languageMap": { "Français": "fr", "English": "en" }
     }
    -
     

    Test