cht-conf 3.21.4 → 3.22.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [3.22.0](https://github.com/medic/cht-conf/compare/v3.21.5...v3.22.0) (2024-04-29)
2
+
3
+
4
+ ### Features
5
+
6
+ * **#615:** add support for `assetlinks.json` when compiling app settings ([#616](https://github.com/medic/cht-conf/issues/616)) ([f39d22a](https://github.com/medic/cht-conf/commit/f39d22a59816a18e9b2777067330193ce336b7a0)), closes [#615](https://github.com/medic/cht-conf/issues/615)
7
+
8
+ ## [3.21.5](https://github.com/medic/cht-conf/compare/v3.21.4...v3.21.5) (2024-02-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **#26:** add warning if jsonDir contains file when running csv-to-doc command ([#603](https://github.com/medic/cht-conf/issues/603)) ([e445c9b](https://github.com/medic/cht-conf/commit/e445c9b44be94b3a7492a471c5c709857509076e)), closes [#26](https://github.com/medic/cht-conf/issues/26)
14
+
1
15
  ## [3.21.4](https://github.com/medic/cht-conf/compare/v3.21.3...v3.21.4) (2024-01-31)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cht-conf",
3
- "version": "3.21.4",
3
+ "version": "3.22.0",
4
4
  "description": "Configure CHT deployments",
5
5
  "main": "./src/lib/main.js",
6
6
  "engines": {
@@ -95,6 +95,15 @@ const compileAppSettingsForProject = async (projectDir, options) => {
95
95
  }
96
96
  appSettings.schedules = scheduleSettings;
97
97
  }
98
+
99
+ const assetlinks = readOptionalJson(path.join(projectDir, 'app_settings/assetlinks.json'));
100
+ if (assetlinks) {
101
+ const validate = validateAppSettings.validateAssetlinks(assetlinks);
102
+ if (!validate.valid) {
103
+ throw new Error(`Invalid assetlinks: ${validate.error}`);
104
+ }
105
+ appSettings.assetlinks = assetlinks;
106
+ }
98
107
  } else {
99
108
  warn(`app_settings.json file should not be edited directly.
100
109
  Please create a base_settings.json file in app_settings folder and move any manually defined configurations there.`);
@@ -29,6 +29,10 @@ const execute = () => {
29
29
  const jsonDir = `${environment.pathToProject}/json_docs`;
30
30
  fs.mkdir(jsonDir);
31
31
 
32
+ const warningMsg = `There are already docs in ${jsonDir}.
33
+ New json files will be created along side these existing docs.`;
34
+ fs.warnIfDirectoryIsNotEmpty(jsonDir, warningMsg);
35
+
32
36
  const saveJsonDoc = doc => fs.write(`${jsonDir}/${doc._id}.doc.json`, safeStringify(doc) + '\n');
33
37
 
34
38
  const model = {
@@ -262,5 +266,5 @@ module.exports = {
262
266
  int,
263
267
  setCol,
264
268
  parseColumn,
265
- removeExcludedField
269
+ removeExcludedField,
266
270
  };
@@ -4,6 +4,7 @@ const mkdirp = require('mkdirp').sync;
4
4
  const os = require('os');
5
5
  const path = require('path');
6
6
  const trace = require('../lib/log').trace;
7
+ const userPrompt = require('../lib/user-prompt');
7
8
  const warn = require('../lib/log').warn;
8
9
 
9
10
  function read(path) {
@@ -80,12 +81,27 @@ function copy(from, to, { overwrite=true }={}) {
80
81
  }
81
82
  }
82
83
 
84
+ function isDirectoryEmpty(dir) {
85
+ return !fs.readdirSync(dir).length;
86
+ }
87
+
88
+ function warnIfDirectoryIsNotEmpty(dir, warningMsg) {
89
+ if (!isDirectoryEmpty(dir)) {
90
+ warn(warningMsg);
91
+
92
+ if (!userPrompt.keyInYN('Are you sure you want to continue?')) {
93
+ throw new Error('User aborted execution.');
94
+ }
95
+ }
96
+ }
97
+
83
98
  module.exports = {
84
99
  copy,
85
100
  dirs,
86
101
  exists: fs.existsSync,
87
102
  extension,
88
103
  fs,
104
+ isDirectoryEmpty,
89
105
  mkdir: path => { try { mkdirp(path); } catch(e) { warn(e); } },
90
106
  mkdtemp: () => fs.mkdtempSync(`${os.tmpdir()}/cht-conf`),
91
107
  path,
@@ -98,6 +114,7 @@ module.exports = {
98
114
  deleteFilesInFolder: folderPath => recurseFiles(folderPath).forEach(filePath => fs.unlinkSync(filePath)),
99
115
  readdir: fs.readdirSync,
100
116
  statSync: fs.statSync,
117
+ warnIfDirectoryIsNotEmpty,
101
118
  withoutExtension,
102
119
  write: (path, data, options = 'utf8') => fs.writeFileSync(path, data, options),
103
120
  writeBinary: (path, content) => fs.writeFileSync(path, content),
@@ -64,6 +64,19 @@ const ScheduleSchema = joi.array().items(
64
64
  })
65
65
  );
66
66
 
67
+ const AssetlinksSchema = joi.array().items(
68
+ joi.object({
69
+ relation: joi.array().items(
70
+ joi.string().valid('delegate_permission/common.handle_all_urls').required()
71
+ ).length(1).required(),
72
+ target: joi.object({
73
+ namespace: joi.string().valid('android_app').required(),
74
+ package_name: joi.string().required(),
75
+ sha256_cert_fingerprints: joi.array().items(joi.string().required()).min(1).required(),
76
+ }).required(),
77
+ }),
78
+ ).min(1);
79
+
67
80
  module.exports = {
68
81
  validateFormsSchema: (formsObject) => {
69
82
  const { error } = FormsSchema.validate(formsObject);
@@ -72,5 +85,9 @@ module.exports = {
72
85
  validateScheduleSchema: (scheduleObject) => {
73
86
  const { error } = ScheduleSchema.validate(scheduleObject);
74
87
  return error ? { valid: false, error } : { valid: true };
88
+ },
89
+ validateAssetlinks: (assetlinksObject) => {
90
+ const { error } = AssetlinksSchema.validate(assetlinksObject);
91
+ return error ? { valid: false, error } : { valid: true };
75
92
  }
76
93
  };