@skillswaveca/nova-shared-libraries 3.5.16 → 3.6.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.
@@ -6,8 +6,10 @@ jobs:
6
6
  run-tests:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
- - name: Install pnpm
10
- run: npm install -g pnpm
9
+ - uses: pnpm/action-setup@v4
10
+ name: Install pnpm
11
+ with:
12
+ version: 9
11
13
  - uses: actions/checkout@v4
12
14
  - name: Overwrite git protocol to https
13
15
  run: git config --global url."https://github.com".insteadOf git://github.com
@@ -17,7 +19,7 @@ jobs:
17
19
  cache: 'pnpm'
18
20
 
19
21
  - name: Install deps
20
- run: pnpm install
22
+ run: pnpm install --frozen-lockfile
21
23
 
22
24
  - name: Run unit tests and linting
23
25
  run: pnpm recursive run test
@@ -10,8 +10,10 @@ jobs:
10
10
  runs-on: ubuntu-latest
11
11
 
12
12
  steps:
13
- - name: Install pnpm
14
- run: npm install -g pnpm
13
+ - uses: pnpm/action-setup@v4
14
+ name: Install pnpm
15
+ with:
16
+ version: 9
15
17
 
16
18
  - name: Checkout repository
17
19
  uses: actions/checkout@v4
@@ -26,7 +28,7 @@ jobs:
26
28
  registry-url: 'https://registry.npmjs.org/'
27
29
 
28
30
  - name: Install dependencies
29
- run: pnpm install
31
+ run: pnpm install --frozen-lockfile
30
32
 
31
33
  - name: Initialize mandatory git config
32
34
  run: |
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="https://github.com/SkillsWave/nova-shared-libraries/assets/1350855/edc19764-ebce-4eab-a813-28edcf5e84fc" width="400"/>
2
+ <img src="https://github.com/SkillsWave/nova-shared-libraries/assets/1350855/3e7683f6-227c-4948-aaed-b9ee4d2400d7" width="400"/>
3
3
  </p>
4
4
 
5
5
  # Nova shared libraries
@@ -1,25 +1,25 @@
1
1
  export const packageInfo = [
2
2
  {
3
3
  "name": "@skillswaveca/nova-utils",
4
- "version": "3.5.15",
4
+ "version": "3.5.17",
5
5
  "description": "A collection of random utils used in nova repos",
6
6
  "docsPath": "./nova-utils/index.html"
7
7
  },
8
8
  {
9
9
  "name": "@skillswaveca/nova-model",
10
- "version": "3.5.15",
10
+ "version": "3.5.17",
11
11
  "description": "Nova model stuff",
12
12
  "docsPath": "./nova-model/index.html"
13
13
  },
14
14
  {
15
15
  "name": "@skillswaveca/nova-middleware",
16
- "version": "3.5.15",
16
+ "version": "3.5.17",
17
17
  "description": "A collection of middleware used by nova projects",
18
18
  "docsPath": "./nova-middleware/index.html"
19
19
  },
20
20
  {
21
21
  "name": "@skillswaveca/nova-drivers",
22
- "version": "3.5.15",
22
+ "version": "3.5.17",
23
23
  "description": "Some helper drivers for AWS services",
24
24
  "docsPath": "./drivers/index.html"
25
25
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-shared-libraries",
4
4
  "description": "A monorepo of shared libraries for Nova projects.",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.5.16",
6
+ "version": "3.6.0",
7
7
  "main": "index.js",
8
8
  "license": "MIT",
9
9
  "keywords": [],
@@ -43,7 +43,6 @@
43
43
  "eslint-plugin-jsdoc": "^48.2.5",
44
44
  "eslint-plugin-mocha": "^10.4.3",
45
45
  "glob": "^10.3.15",
46
- "glob-promise": "^6.0.5",
47
46
  "live-server": "^1.2.2",
48
47
  "mocha": "^10.4.0",
49
48
  "rollup": "^4.17.2",
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-drivers",
4
4
  "description": "Some helper drivers for AWS services",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.5.16",
6
+ "version": "3.6.0",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "pre-release": "pnpm run create-index",
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-middleware",
4
4
  "description": "A collection of middleware used by nova projects",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.5.16",
6
+ "version": "3.6.0",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "pre-release": "pnpm run create-index",
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-model",
4
4
  "description": "Nova model stuff",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.5.16",
6
+ "version": "3.6.0",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "pre-release": "pnpm run create-index",
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-utils",
4
4
  "description": "A collection of random utils used in nova repos",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.5.16",
6
+ "version": "3.6.0",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "pre-release": "pnpm run create-index",
@@ -1,6 +1,5 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
-
4
3
  import yn from 'yn';
5
4
  import { log } from './logger.js';
6
5
 
@@ -12,14 +11,16 @@ import { log } from './logger.js';
12
11
  * @returns {Object} - The resulting merged object.
13
12
  */
14
13
  export const deepMerge = (obj1, obj2) => {
15
- const output = Object.assign({}, obj1);
14
+ const output = { ...obj1 }; // Use spread syntax for shallow copy
16
15
  for (const key in obj2) {
17
- if (obj2[key]) {
16
+ if (obj2[key] !== undefined && obj2[key] !== null) {
18
17
  if (typeof obj2[key] === 'object' && obj2[key] !== null && obj1[key]) {
19
18
  output[key] = deepMerge(obj1[key], obj2[key]);
20
19
  } else {
21
20
  output[key] = obj2[key];
22
21
  }
22
+ } else if (obj2[key] === null) {
23
+ output[key] = obj2[key];
23
24
  }
24
25
  }
25
26
  return output;
@@ -184,7 +185,11 @@ const readJsonFiles = dir => {
184
185
  return fs.readdirSync(dir)
185
186
  .filter(file => path.extname(file) === '.json')
186
187
  .reduce((acc, file) => {
187
- acc[path.basename(file, '.json')] = JSON.parse(fs.readFileSync(path.join(dir, file), 'utf8'));
188
+ try {
189
+ acc[path.basename(file, '.json')] = JSON.parse(fs.readFileSync(path.join(dir, file), 'utf8'));
190
+ } catch (err) {
191
+ log.error({ message: err.message }, `Error reading JSON file: ${file}`);
192
+ }
188
193
  return acc;
189
194
  }, {});
190
195
  };
@@ -199,10 +204,16 @@ export class NovaStageConfig {
199
204
  *
200
205
  * @param {Object} baseConfig - The default configuration object that will be used as the base.
201
206
  * @param stageConfig - The stage configuration object or the path to the directory containing stage-specific JSON files.
207
+ * @param accountConfig - The account configuration object or the path to the directory containing account-specific JSON files.
202
208
  */
203
- constructor(baseConfig, stageConfig) {
209
+ constructor(baseConfig, stageConfig, accountConfig) {
204
210
  this.baseConfig = baseConfig;
205
211
  this.stages = typeof stageConfig === 'string' ? readJsonFiles(stageConfig) : stageConfig;
212
+ if (accountConfig && typeof accountConfig === 'string') {
213
+ this.accounts = readJsonFiles(accountConfig);
214
+ } else {
215
+ log.info('No account configuration provided.');
216
+ }
206
217
  if (!this.baseConfig) {
207
218
  throw new Error('NovaConfig requires a base configuration object to be provided.');
208
219
  }
@@ -218,11 +229,19 @@ export class NovaStageConfig {
218
229
  *
219
230
  * @param {string} stage - The stage for which the configuration is needed, typically corresponds
220
231
  * to different deployment environments (e.g., 'prod', 'dev').
232
+ * @param region - The region for which the configuration is needed.
221
233
  * @returns {Object} - The merged configuration object that combines the default settings with
222
234
  * any stage-specific overrides.
223
235
  */
224
- createConfigForStage(stage) {
236
+ createConfigForStage(stage, region) {
237
+ const baseConfig = this.baseConfig(stage);
225
238
  const stageConfig = this.stages[stage] || this.stages.dev;
226
- return deepMerge(this.baseConfig(stage), stageConfig);
239
+ const awsAccount = stageConfig?.awsAccount || baseConfig?.awsAccount;
240
+ const accountConfig = this.accounts ? this.accounts[awsAccount] : {};
241
+ const regionConfig = region ? this.stages[`${stage}.${region}`] : {};
242
+ let ret = deepMerge(baseConfig, accountConfig);
243
+ ret = deepMerge(ret, stageConfig);
244
+ ret = deepMerge(ret, regionConfig);
245
+ return ret;
227
246
  }
228
247
  }