@bifravst/aws-ssm-settings-helpers 1.0.0 → 1.0.1
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.d.ts +8 -4
- package/dist/settings.js +22 -15
- package/dist/settings.spec.js +10 -5
- package/package.json +1 -1
package/dist/settings.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { SSMClient } from '@aws-sdk/client-ssm';
|
|
2
|
-
export declare const settingsPath: ({ stackName, scope, property, }: {
|
|
2
|
+
export declare const settingsPath: ({ stackName, scope, context, property, }: {
|
|
3
3
|
stackName: string;
|
|
4
4
|
scope: string;
|
|
5
|
+
context: string;
|
|
5
6
|
property?: string | undefined;
|
|
6
7
|
}) => string;
|
|
7
|
-
export declare const getSettings: <Settings extends Record<string, string>>({ ssm, stackName, scope, }: {
|
|
8
|
+
export declare const getSettings: <Settings extends Record<string, string>>({ ssm, stackName, scope, context, }: {
|
|
8
9
|
ssm: SSMClient;
|
|
9
10
|
stackName: string;
|
|
10
11
|
scope: string;
|
|
12
|
+
context: string;
|
|
11
13
|
}) => () => Promise<Settings>;
|
|
12
|
-
export declare const putSettings: ({ ssm, stackName, scope, }: {
|
|
14
|
+
export declare const putSettings: ({ ssm, stackName, scope, context, }: {
|
|
13
15
|
ssm: SSMClient;
|
|
14
16
|
stackName: string;
|
|
15
17
|
scope: string;
|
|
18
|
+
context: string;
|
|
16
19
|
}) => ({ property, value, deleteBeforeUpdate, }: {
|
|
17
20
|
property: string;
|
|
18
21
|
value: string;
|
|
@@ -23,10 +26,11 @@ export declare const putSettings: ({ ssm, stackName, scope, }: {
|
|
|
23
26
|
}) => Promise<{
|
|
24
27
|
name: string;
|
|
25
28
|
}>;
|
|
26
|
-
export declare const deleteSettings: ({ ssm, stackName, scope, }: {
|
|
29
|
+
export declare const deleteSettings: ({ ssm, stackName, scope, context, }: {
|
|
27
30
|
ssm: SSMClient;
|
|
28
31
|
stackName: string;
|
|
29
32
|
scope: string;
|
|
33
|
+
context: string;
|
|
30
34
|
}) => ({ property }: {
|
|
31
35
|
property: string;
|
|
32
36
|
}) => Promise<{
|
package/dist/settings.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { DeleteParameterCommand, GetParametersByPathCommand, PutParameterCommand, SSMClient, } from '@aws-sdk/client-ssm';
|
|
2
2
|
import { paginate } from './paginate.js';
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
const nameRx = /^[a-zA-Z0-9_.-]+$/;
|
|
4
|
+
export const settingsPath = ({ stackName, scope, context, property, }) => {
|
|
5
|
+
if (!nameRx.test(stackName))
|
|
6
|
+
throw new Error(`Invalid stackName value: ${stackName}!`);
|
|
7
|
+
if (!nameRx.test(scope))
|
|
8
|
+
throw new Error(`Invalid scope value: ${scope}!`);
|
|
9
|
+
if (!nameRx.test(context))
|
|
10
|
+
throw new Error(`Invalid context value: ${context}!`);
|
|
11
|
+
const parts = [stackName, scope, context];
|
|
12
|
+
if (property !== undefined) {
|
|
13
|
+
if (!nameRx.test(property))
|
|
14
|
+
throw new Error(`Invalid property value: ${property}!`);
|
|
15
|
+
parts.push(property);
|
|
16
|
+
}
|
|
17
|
+
return `/${parts.join('/')}`;
|
|
10
18
|
};
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const Path = settingsPath({ stackName, scope });
|
|
19
|
+
export const getSettings = ({ ssm, stackName, scope, context, }) => async () => {
|
|
20
|
+
const Path = settingsPath({ stackName, scope, context });
|
|
14
21
|
const Parameters = [];
|
|
15
22
|
await paginate({
|
|
16
23
|
paginator: async (NextToken) => ssm
|
|
@@ -26,7 +33,7 @@ export const getSettings = ({ ssm, stackName, scope, }) => async () => {
|
|
|
26
33
|
}),
|
|
27
34
|
});
|
|
28
35
|
if (Parameters.length === 0)
|
|
29
|
-
throw new Error(`
|
|
36
|
+
throw new Error(`context not configured: ${Path}!`);
|
|
30
37
|
return Parameters.map(({ Name, ...rest }) => ({
|
|
31
38
|
...rest,
|
|
32
39
|
Name: Name?.replace(`${Path}/`, ''),
|
|
@@ -35,8 +42,8 @@ export const getSettings = ({ ssm, stackName, scope, }) => async () => {
|
|
|
35
42
|
[Name ?? '']: Value ?? '',
|
|
36
43
|
}), {});
|
|
37
44
|
};
|
|
38
|
-
export const putSettings = ({ ssm, stackName, scope, }) => async ({ property, value, deleteBeforeUpdate, }) => {
|
|
39
|
-
const Name =
|
|
45
|
+
export const putSettings = ({ ssm, stackName, scope, context, }) => async ({ property, value, deleteBeforeUpdate, }) => {
|
|
46
|
+
const Name = settingsPath({ stackName, scope, context, property });
|
|
40
47
|
if (deleteBeforeUpdate ?? false) {
|
|
41
48
|
try {
|
|
42
49
|
await ssm.send(new DeleteParameterCommand({
|
|
@@ -55,8 +62,8 @@ export const putSettings = ({ ssm, stackName, scope, }) => async ({ property, va
|
|
|
55
62
|
}));
|
|
56
63
|
return { name: Name };
|
|
57
64
|
};
|
|
58
|
-
export const deleteSettings = ({ ssm, stackName, scope, }) => async ({ property }) => {
|
|
59
|
-
const Name =
|
|
65
|
+
export const deleteSettings = ({ ssm, stackName, scope, context, }) => async ({ property }) => {
|
|
66
|
+
const Name = settingsPath({ stackName, scope, context, property });
|
|
60
67
|
try {
|
|
61
68
|
await ssm.send(new DeleteParameterCommand({
|
|
62
69
|
Name,
|
package/dist/settings.spec.js
CHANGED
|
@@ -8,7 +8,8 @@ void describe('getSettingsOptional()', () => {
|
|
|
8
8
|
send: async () => Promise.resolve({ Parameters: undefined }),
|
|
9
9
|
},
|
|
10
10
|
stackName: 'STACK_NAME',
|
|
11
|
-
scope: 'stack
|
|
11
|
+
scope: 'stack',
|
|
12
|
+
context: 'context',
|
|
12
13
|
});
|
|
13
14
|
const result = await stackConfig({});
|
|
14
15
|
assert.deepEqual(result, {});
|
|
@@ -16,18 +17,21 @@ void describe('getSettingsOptional()', () => {
|
|
|
16
17
|
});
|
|
17
18
|
void describe('settingsPath()', () => {
|
|
18
19
|
void it('should produce a fully qualified parameter name', () => assert.equal(settingsPath({
|
|
19
|
-
scope: 'stack
|
|
20
|
+
scope: 'stack',
|
|
21
|
+
context: 'context',
|
|
20
22
|
stackName: 'hello-nrfcloud',
|
|
21
23
|
property: 'someProperty',
|
|
22
24
|
}), '/hello-nrfcloud/stack/context/someProperty'));
|
|
23
25
|
void it('should produce a fully qualified parameter name for valid string scope', () => assert.equal(settingsPath({
|
|
24
|
-
scope: 'thirdParty
|
|
26
|
+
scope: 'thirdParty',
|
|
27
|
+
context: 'elite',
|
|
25
28
|
stackName: 'hello-nrfcloud',
|
|
26
29
|
property: 'someProperty',
|
|
27
30
|
}), '/hello-nrfcloud/thirdParty/elite/someProperty'));
|
|
28
31
|
void it('should error for invalid string scope', () => {
|
|
29
32
|
assert.throws(() => settingsPath({
|
|
30
|
-
scope: '
|
|
33
|
+
scope: 'thirdParty',
|
|
34
|
+
context: 'el ite',
|
|
31
35
|
stackName: 'hello-nrfcloud',
|
|
32
36
|
property: 'someProperty',
|
|
33
37
|
}));
|
|
@@ -54,7 +58,8 @@ void describe('getSettings()', () => {
|
|
|
54
58
|
send: async () => Promise.resolve({ Parameters: returnedValues }),
|
|
55
59
|
},
|
|
56
60
|
stackName: 'hello-nrfcloud',
|
|
57
|
-
scope: 'stack
|
|
61
|
+
scope: 'stack',
|
|
62
|
+
context: 'context',
|
|
58
63
|
});
|
|
59
64
|
const result = await stackConfig();
|
|
60
65
|
assert.deepEqual(result, {
|
package/package.json
CHANGED