@hello.nrfcloud.com/nrfcloud-api-helpers 1.1.3 → 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.
- package/dist/settings/getAllAccountsSettings.js +9 -23
- package/dist/settings/groupByAccount.d.ts +1 -0
- package/dist/settings/groupByAccount.js +14 -0
- package/dist/settings/groupByAccount.spec.d.ts +1 -0
- package/dist/settings/groupByAccount.spec.js +20 -0
- package/dist/settings/index.d.ts +2 -0
- package/dist/settings/index.js +2 -0
- package/package.json +1 -1
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
});
|
package/dist/settings/index.d.ts
CHANGED
package/dist/settings/index.js
CHANGED