@hello.nrfcloud.com/nrfcloud-api-helpers 1.1.4 → 1.2.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.
@@ -1,29 +1,15 @@
1
1
  import { SSMClient } from '@aws-sdk/client-ssm';
2
2
  import { get } from '@bifravst/aws-ssm-settings-helpers';
3
- import { getAccountsFromAllSettings } from './getAllAccounts.js';
4
- import { validateSettings } from './settings.js';
5
3
  import { NRFCLOUD_ACCOUNT_SCOPE } from './scope.js';
4
+ import { groupByAccount } from './groupByAccount.js';
5
+ import { validateSettings } from './settings.js';
6
6
  /**
7
7
  * Returns settings for all accounts
8
8
  */
9
- export const getAllAccountsSettings = async ({ ssm, stackName, }) => {
10
- const allSettings = await get(ssm)({
11
- stackName,
12
- scope: NRFCLOUD_ACCOUNT_SCOPE,
13
- })();
14
- const accounts = getAccountsFromAllSettings(allSettings);
15
- return [...accounts].reduce((allAccountSettings, account) => ({
16
- ...allAccountSettings,
17
- [account]: validateSettings(Object.entries(allSettings)
18
- .filter(([k]) => k.startsWith(`${account}/`))
19
- .map(([k, v]) => [
20
- k.replace(new RegExp(`^${account}/`), ''),
21
- v,
22
- ])
23
- .reduce((s, [k, v]) => ({ ...s, [k]: v }), {})),
24
- }), {});
25
- };
26
- console.log(await getAllAccountsSettings({
27
- ssm: new SSMClient(),
28
- stackName: 'hello-nrfcloud-backend',
29
- }));
9
+ export const getAllAccountsSettings = async ({ ssm, stackName, }) => Object.entries(groupByAccount(await get(ssm)({
10
+ stackName,
11
+ scope: NRFCLOUD_ACCOUNT_SCOPE,
12
+ })())).reduce((allSettings, [account, settings]) => ({
13
+ ...allSettings,
14
+ [account]: validateSettings(settings),
15
+ }), {});
@@ -0,0 +1 @@
1
+ export declare const groupByAccount: (allSettings: Record<string, string>) => Record<string, Record<string, string>>;
@@ -0,0 +1,14 @@
1
+ import { getAccountsFromAllSettings } from './getAllAccounts.js';
2
+ export const groupByAccount = (allSettings) => {
3
+ const accounts = getAccountsFromAllSettings(allSettings);
4
+ return [...accounts].reduce((allAccountSettings, account) => ({
5
+ ...allAccountSettings,
6
+ [account]: Object.entries(allSettings)
7
+ .filter(([k]) => k.startsWith(`${account}/`))
8
+ .map(([k, v]) => [
9
+ k.replace(new RegExp(`^${account}/`), ''),
10
+ v,
11
+ ])
12
+ .reduce((s, [k, v]) => ({ ...s, [k]: v }), {}),
13
+ }), {});
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import { it, describe } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { groupByAccount } from './groupByAccount.js';
4
+ void describe('groupByAccount()', () => {
5
+ void it('should group settings by account', () => assert.deepEqual(groupByAccount({
6
+ 'elite/accountDeviceClientId': 'account-4db55163-7593-4d63-9679-d16fbc2d464f',
7
+ 'elite/healthCheckModel': 'PCA20035+solar',
8
+ 'acme/mqttEndpoint': 'mqtt.nrfcloud.com',
9
+ 'acme/teamId': 'f4ba6ede-7867-43eb-a495-7e0de108f52e',
10
+ }), {
11
+ acme: {
12
+ mqttEndpoint: 'mqtt.nrfcloud.com',
13
+ teamId: 'f4ba6ede-7867-43eb-a495-7e0de108f52e',
14
+ },
15
+ elite: {
16
+ accountDeviceClientId: 'account-4db55163-7593-4d63-9679-d16fbc2d464f',
17
+ healthCheckModel: 'PCA20035+solar',
18
+ },
19
+ }));
20
+ });
@@ -3,3 +3,4 @@ export * from './scope.js';
3
3
  export * from './initializeAccount.js';
4
4
  export * from './getAllAccounts.js';
5
5
  export * from './getAllAccountsSettings.js';
6
+ export * from './groupByAccount.js';
@@ -3,3 +3,4 @@ export * from './scope.js';
3
3
  export * from './initializeAccount.js';
4
4
  export * from './getAllAccounts.js';
5
5
  export * from './getAllAccountsSettings.js';
6
+ export * from './groupByAccount.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/nrfcloud-api-helpers",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "Helper functions for integrating nRF Cloud APIs in AWS lambdas written in TypeScript.",
5
5
  "exports": {
6
6
  "./*": {