cht-conf 3.22.0 → 4.0.0

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.
@@ -0,0 +1,11 @@
1
+ sonar.sources=.
2
+ # Can have multiple comma-separated entries
3
+ sonar.exclusions=test/**/*
4
+
5
+ sonar.tests=.
6
+ # Can have multiple comma-separated entries
7
+ sonar.test.inclusions=test/**/*
8
+
9
+ sonar.issue.ignore.block=e1
10
+ sonar.issue.ignore.block.e1.beginBlockRegexp=NOSONAR_BEGIN
11
+ sonar.issue.ignore.block.e1.endBlockRegexp=NOSONAR_END
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ # [4.0.0](https://github.com/medic/cht-conf/compare/v3.23.0...v4.0.0) (2024-07-01)
2
+
3
+
4
+ ### Performance Improvements
5
+
6
+ * **#600:** drop support for Node versions < 18 ([#619](https://github.com/medic/cht-conf/issues/619)) ([496d074](https://github.com/medic/cht-conf/commit/496d0742890f1347557caecc1241bdd590c774c0)), closes [#600](https://github.com/medic/cht-conf/issues/600)
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * **#600:** Dropping support for NodeJS versions < 18
12
+
13
+ # [3.23.0](https://github.com/medic/cht-conf/compare/v3.22.0...v3.23.0) (2024-06-20)
14
+
15
+
16
+ ### Features
17
+
18
+ * session token authentication ([efbc9cf](https://github.com/medic/cht-conf/commit/efbc9cfc5dc972f355fa07b3a394c63d84b352de))
19
+
1
20
  # [3.22.0](https://github.com/medic/cht-conf/compare/v3.21.5...v3.22.0) (2024-04-29)
2
21
 
3
22
 
package/README.md CHANGED
@@ -5,8 +5,8 @@ CHT Conf is a command-line interface tool to manage and configure your apps buil
5
5
 
6
6
  # Requirements
7
7
 
8
- * nodejs 8 or later
9
- * python 2.7
8
+ * nodejs 18 or later
9
+ * python 3
10
10
  * or Docker
11
11
 
12
12
  # Installation
@@ -106,6 +106,12 @@ If a different username is required, add the `--user` switch:
106
106
 
107
107
  **NB** - When specifying the URL with `--url`, be sure not to specify the CouchDB database name in the URL. The CHT API will find the correct database.
108
108
 
109
+ ### Using a session token for authentication
110
+
111
+ CHT Conf supports authentication using a session token by adding `--session-token` parameter:
112
+
113
+ cht --url=https://example.com:12345 --session-token=*my_token*
114
+
109
115
  ### Into an archive to be uploaded later
110
116
 
111
117
  cht --archive
@@ -343,7 +349,7 @@ Builds brought to you courtesy of GitHub actions.
343
349
 
344
350
  # Copyright
345
351
 
346
- Copyright 2013-2023 Medic Mobile, Inc. <hello@medic.org>
352
+ Copyright 2013-2024 Medic Mobile, Inc. <hello@medic.org>
347
353
 
348
354
  # License
349
355
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "cht-conf",
3
- "version": "3.22.0",
3
+ "version": "4.0.0",
4
4
  "description": "Configure CHT deployments",
5
5
  "main": "./src/lib/main.js",
6
6
  "engines": {
7
- "node": ">=8.10.0"
7
+ "node": ">=18.0.0"
8
8
  },
9
9
  "scripts": {
10
10
  "clean": "rm -rf ./build/",
@@ -58,6 +58,7 @@
58
58
  "pouchdb-adapter-http": "^7.2.2",
59
59
  "pouchdb-core": "^7.2.2",
60
60
  "pouchdb-mapreduce": "^7.2.2",
61
+ "pouchdb-session-authentication": "^1.3.0",
61
62
  "properties": "^1.2.1",
62
63
  "queue-promise": "^2.2.1",
63
64
  "readline-sync": "^1.4.10",
package/src/lib/api.js CHANGED
@@ -7,8 +7,34 @@ const log = require('./log');
7
7
  const url = require('url');
8
8
 
9
9
  const cache = new Map();
10
+ const sessionCookieName = 'AuthSession';
11
+
12
+ // Helper function to create request headers with session token (if available)
13
+ const withSessionCookie = (...args) => {
14
+ const options = typeof args[0] === 'object' ? Object.assign({}, args[0]) : { url: args[0] };
15
+
16
+ if (args.length > 1) {
17
+ // Merge remaining arguments
18
+ Object.assign(options, ...args.slice(1));
19
+ }
20
+
21
+ const sessionToken = environment.sessionToken;
22
+ if (sessionToken || options.headers) {
23
+ options.headers = Object.assign(
24
+ {},
25
+ options.headers || {},
26
+ sessionToken ? { Cookie: `${sessionCookieName}=${sessionToken}` } : {}
27
+ );
28
+ }
29
+
30
+ return options;
31
+ };
32
+
33
+ const _request = (method) => (...args) => {
34
+ const requestOptions = withSessionCookie(...args);
35
+ return retry(() => rpn[method](requestOptions), { retries: 5, randomize: false, factor: 1.5 });
36
+ };
10
37
 
11
- const _request = (method) => (...args) => retry(() => rpn[method](...args), { retries: 5, randomize: false, factor: 1.5 });
12
38
  const request = {
13
39
  get: _request('get'),
14
40
  post: _request('post'),
package/src/lib/db.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const PouchDB = require('pouchdb-core');
2
2
  PouchDB.plugin(require('pouchdb-adapter-http'));
3
3
  PouchDB.plugin(require('pouchdb-mapreduce'));
4
+ PouchDB.plugin(require('pouchdb-session-authentication'));
4
5
 
5
6
  const ArchivingDB = require('./archiving-db');
6
7
  const environment = require('./environment');
@@ -10,6 +11,7 @@ module.exports = () => {
10
11
  return new ArchivingDB(environment.archiveDestination);
11
12
  }
12
13
 
13
- return new PouchDB(environment.apiUrl, { ajax: { timeout: 60000 } });
14
+ return new PouchDB(environment.apiUrl, {
15
+ session: environment.sessionToken,
16
+ });
14
17
  };
15
-
@@ -13,7 +13,8 @@ const initialize = (
13
13
  apiUrl,
14
14
  force,
15
15
  skipTranslationCheck,
16
- skipValidate
16
+ skipValidate,
17
+ sessionToken
17
18
  ) => {
18
19
  if (state.initialized) {
19
20
  throw Error('environment is already initialized');
@@ -28,7 +29,8 @@ const initialize = (
28
29
  pathToProject,
29
30
  force,
30
31
  skipTranslationCheck,
31
- skipValidate
32
+ skipValidate,
33
+ sessionToken
32
34
  });
33
35
  };
34
36
 
@@ -54,6 +56,7 @@ module.exports = {
54
56
  get force() { return getState('force'); },
55
57
  get skipTranslationCheck() { return getState('skipTranslationCheck'); },
56
58
  get skipValidate() { return getState('skipValidate'); },
59
+ get sessionToken() { return getState('sessionToken'); },
57
60
 
58
61
  /**
59
62
  * Return `true` if the environment **seems** to be production.
package/src/lib/main.js CHANGED
@@ -160,7 +160,8 @@ module.exports = async (argv, env) => {
160
160
  apiUrl,
161
161
  cmdArgs.force,
162
162
  cmdArgs['skip-translation-check'],
163
- skipValidate
163
+ skipValidate,
164
+ cmdArgs['session-token'],
164
165
  );
165
166
 
166
167
  if (requiresInstance && apiUrl) {