@allthings/cloud-toolkit 5.0.0 → 5.1.0-beta.2
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/README.md +2 -2
- package/dist/lib.cjs.js +58 -6
- package/dist/lib.esm.mjs +50 -7
- package/dist/src/base64.d.ts +2 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/utils.d.ts +6 -0
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ Standardizes the setup of aws, Datadog and other things
|
|
|
30
30
|
| batchWriteItems | table<br/>items | Creates multiple item in a defined table |
|
|
31
31
|
| deleteItem | table<br/>key<br/>options (optional) | Deletes database item from defined table by given key |
|
|
32
32
|
| getItem | table<br/>key<br/>options (optional) | Returns item from Database by defined table and key |
|
|
33
|
-
| putItem | table<br/>
|
|
33
|
+
| putItem | table<br/>item | Creates one item in defined table |
|
|
34
34
|
| queryTable | table<br/>options (optional) | Returns result items of query |
|
|
35
35
|
| scanTable | table<br/>options (optional) | Returns result items of scan |
|
|
36
36
|
| updateItem | table<br/>key<br/>options (optional) | Updates item in database by provided table and given key |
|
|
@@ -42,7 +42,7 @@ Standardizes the setup of aws, Datadog and other things
|
|
|
42
42
|
| deleteQueueItem | queueUrl<br/>receiptHandle | Deletes item from queue |
|
|
43
43
|
| getQueueItems | queueUrl<br/>maxNumberOfMessages (optional) | Retrieves items from queue |
|
|
44
44
|
| getQueueUrl | queueName | Returns queue url which is needed for all other requests |
|
|
45
|
-
| sendMessage | queueUrl<br/>message<br/>messageAttributes(optional)<br/>messageDelay(optional) | Creates an item in the queue |
|
|
45
|
+
| sendMessage | queueUrl<br/>message<br/>fifoSettings(optional)<br/>messageAttributes(optional)<br/>messageDelay(optional) | Creates an item in the queue |
|
|
46
46
|
|
|
47
47
|
### logger
|
|
48
48
|
|
package/dist/lib.cjs.js
CHANGED
|
@@ -703,6 +703,30 @@ const until = async (predicate, transformer, initialValue, iterationCount = 0) =
|
|
|
703
703
|
? transformed
|
|
704
704
|
: until(predicate, transformer, transformed, iterationCount + 1);
|
|
705
705
|
};
|
|
706
|
+
const partial = (function_, ...partialArguments) => (...arguments_) => function_(...partialArguments, ...arguments_);
|
|
707
|
+
const times = (function_, n) => Array.from({ length: n }, (_, index) => function_(index, index));
|
|
708
|
+
const deepFlatten = (arrayOfArrays) => arrayOfArrays.reduce((flatArray, currentArray) => [
|
|
709
|
+
...flatArray,
|
|
710
|
+
...(Array.isArray(currentArray)
|
|
711
|
+
?
|
|
712
|
+
currentArray.some(Array.isArray)
|
|
713
|
+
? deepFlatten(currentArray)
|
|
714
|
+
: currentArray
|
|
715
|
+
: [currentArray]),
|
|
716
|
+
], []);
|
|
717
|
+
const flatten = (arrayOfArrays, depth = 1) => arrayOfArrays.reduce((flatArray, currentArray) => [
|
|
718
|
+
...flatArray,
|
|
719
|
+
...(Array.isArray(currentArray)
|
|
720
|
+
?
|
|
721
|
+
currentArray.some(Array.isArray) && depth > 1
|
|
722
|
+
? flatten(currentArray, depth - 1)
|
|
723
|
+
: currentArray
|
|
724
|
+
: [currentArray]),
|
|
725
|
+
], []);
|
|
726
|
+
const asyncReduce = async (iterable, reducer, initialValue) => iterable.reduce(async (accumulatorPromise, value, index, array) => {
|
|
727
|
+
const accumulator = await accumulatorPromise;
|
|
728
|
+
return reducer(accumulator, value, index, array);
|
|
729
|
+
}, Promise.resolve(initialValue));
|
|
706
730
|
|
|
707
731
|
const DEFAULT_BATCH_ITEMS_MAX_RETRIES = 50;
|
|
708
732
|
let queue;
|
|
@@ -943,16 +967,32 @@ const getSecrets = async (ssm, config, parameters_, defaultValues) => {
|
|
|
943
967
|
return defaultValues;
|
|
944
968
|
}
|
|
945
969
|
};
|
|
970
|
+
const fetchParameterValue = async (ssm, config, parameter_) => {
|
|
971
|
+
const parameter = await ssm.send(new clientSsm.GetParameterCommand({
|
|
972
|
+
Name: `${config.prefix ?? ''}${parameter_}`,
|
|
973
|
+
WithDecryption: true,
|
|
974
|
+
}));
|
|
975
|
+
return parameter?.Parameter?.Value;
|
|
976
|
+
};
|
|
977
|
+
const getRequiredSecret = async (ssm, config, parameter_) => {
|
|
978
|
+
const value = await fetchParameterValue(ssm, config, parameter_);
|
|
979
|
+
if (value === undefined) {
|
|
980
|
+
throw new Error(`Could not retrieve parameter ${parameter_} from AWS SSM parameter store`);
|
|
981
|
+
}
|
|
982
|
+
return value;
|
|
983
|
+
};
|
|
946
984
|
const getSecret = async (ssm, config, parameter_, defaultValue) => {
|
|
985
|
+
if (defaultValue === undefined) {
|
|
986
|
+
if (config.onlyDefault) {
|
|
987
|
+
throw new Error(`Cannot retrieve parameter ${parameter_}: onlyDefault is enabled and no default value was provided`);
|
|
988
|
+
}
|
|
989
|
+
return getRequiredSecret(ssm, config, parameter_);
|
|
990
|
+
}
|
|
947
991
|
if (config.onlyDefault) {
|
|
948
992
|
return defaultValue;
|
|
949
993
|
}
|
|
950
994
|
try {
|
|
951
|
-
|
|
952
|
-
Name: `${config.prefix ?? ''}${parameter_}`,
|
|
953
|
-
WithDecryption: true,
|
|
954
|
-
}));
|
|
955
|
-
return parameter?.Parameter?.Value ?? defaultValue;
|
|
995
|
+
return (await fetchParameterValue(ssm, config, parameter_)) ?? defaultValue;
|
|
956
996
|
}
|
|
957
997
|
catch (error) {
|
|
958
998
|
if (config.logger) {
|
|
@@ -968,7 +1008,7 @@ const parameterStore = (userConfig) => {
|
|
|
968
1008
|
};
|
|
969
1009
|
const ssm = new clientSsm.SSMClient(clientConfig);
|
|
970
1010
|
return {
|
|
971
|
-
getSecret: (parameter, defaultValue
|
|
1011
|
+
getSecret: (parameter, defaultValue) => getSecret(ssm, config, parameter, defaultValue),
|
|
972
1012
|
getSecrets: (parameters, defaultValues = []) => getSecrets(ssm, config, parameters, defaultValues),
|
|
973
1013
|
};
|
|
974
1014
|
};
|
|
@@ -1119,6 +1159,9 @@ const sqs = (userConfig) => {
|
|
|
1119
1159
|
};
|
|
1120
1160
|
};
|
|
1121
1161
|
|
|
1162
|
+
const btoa = (stringToEncode) => Buffer.from(stringToEncode).toString('base64');
|
|
1163
|
+
const atob = (stringToDecode) => Buffer.from(stringToDecode, 'base64').toString('utf8');
|
|
1164
|
+
|
|
1122
1165
|
const logger = (config) => {
|
|
1123
1166
|
const loggerConfig = {
|
|
1124
1167
|
defaultMeta: {
|
|
@@ -1158,9 +1201,18 @@ exports.DEFAULT_PARAMETER_STORE_CLIENT_CONFIG = DEFAULT_CLIENT_CONFIG$1;
|
|
|
1158
1201
|
exports.DEFAULT_SES_CLIENT_CONFIG = DEFAULT_CLIENT_CONFIG;
|
|
1159
1202
|
exports.ServerError = ServerError;
|
|
1160
1203
|
exports.alagarr = alagarr;
|
|
1204
|
+
exports.asyncReduce = asyncReduce;
|
|
1205
|
+
exports.atob = atob;
|
|
1206
|
+
exports.btoa = btoa;
|
|
1207
|
+
exports.deepFlatten = deepFlatten;
|
|
1161
1208
|
exports.dynamodb = dynamodb;
|
|
1209
|
+
exports.flatten = flatten;
|
|
1162
1210
|
exports.lambda = lambda;
|
|
1163
1211
|
exports.logger = logger;
|
|
1164
1212
|
exports.parameterStore = parameterStore;
|
|
1213
|
+
exports.partial = partial;
|
|
1165
1214
|
exports.ses = ses;
|
|
1215
|
+
exports.splitEvery = splitEvery;
|
|
1166
1216
|
exports.sqs = sqs;
|
|
1217
|
+
exports.times = times;
|
|
1218
|
+
exports.until = until;
|
package/dist/lib.esm.mjs
CHANGED
|
@@ -681,6 +681,30 @@ const until = async (predicate, transformer, initialValue, iterationCount = 0) =
|
|
|
681
681
|
? transformed
|
|
682
682
|
: until(predicate, transformer, transformed, iterationCount + 1);
|
|
683
683
|
};
|
|
684
|
+
const partial = (function_, ...partialArguments) => (...arguments_) => function_(...partialArguments, ...arguments_);
|
|
685
|
+
const times = (function_, n) => Array.from({ length: n }, (_, index) => function_(index, index));
|
|
686
|
+
const deepFlatten = (arrayOfArrays) => arrayOfArrays.reduce((flatArray, currentArray) => [
|
|
687
|
+
...flatArray,
|
|
688
|
+
...(Array.isArray(currentArray)
|
|
689
|
+
?
|
|
690
|
+
currentArray.some(Array.isArray)
|
|
691
|
+
? deepFlatten(currentArray)
|
|
692
|
+
: currentArray
|
|
693
|
+
: [currentArray]),
|
|
694
|
+
], []);
|
|
695
|
+
const flatten = (arrayOfArrays, depth = 1) => arrayOfArrays.reduce((flatArray, currentArray) => [
|
|
696
|
+
...flatArray,
|
|
697
|
+
...(Array.isArray(currentArray)
|
|
698
|
+
?
|
|
699
|
+
currentArray.some(Array.isArray) && depth > 1
|
|
700
|
+
? flatten(currentArray, depth - 1)
|
|
701
|
+
: currentArray
|
|
702
|
+
: [currentArray]),
|
|
703
|
+
], []);
|
|
704
|
+
const asyncReduce = async (iterable, reducer, initialValue) => iterable.reduce(async (accumulatorPromise, value, index, array) => {
|
|
705
|
+
const accumulator = await accumulatorPromise;
|
|
706
|
+
return reducer(accumulator, value, index, array);
|
|
707
|
+
}, Promise.resolve(initialValue));
|
|
684
708
|
|
|
685
709
|
const DEFAULT_BATCH_ITEMS_MAX_RETRIES = 50;
|
|
686
710
|
let queue;
|
|
@@ -921,16 +945,32 @@ const getSecrets = async (ssm, config, parameters_, defaultValues) => {
|
|
|
921
945
|
return defaultValues;
|
|
922
946
|
}
|
|
923
947
|
};
|
|
948
|
+
const fetchParameterValue = async (ssm, config, parameter_) => {
|
|
949
|
+
const parameter = await ssm.send(new GetParameterCommand({
|
|
950
|
+
Name: `${config.prefix ?? ''}${parameter_}`,
|
|
951
|
+
WithDecryption: true,
|
|
952
|
+
}));
|
|
953
|
+
return parameter?.Parameter?.Value;
|
|
954
|
+
};
|
|
955
|
+
const getRequiredSecret = async (ssm, config, parameter_) => {
|
|
956
|
+
const value = await fetchParameterValue(ssm, config, parameter_);
|
|
957
|
+
if (value === undefined) {
|
|
958
|
+
throw new Error(`Could not retrieve parameter ${parameter_} from AWS SSM parameter store`);
|
|
959
|
+
}
|
|
960
|
+
return value;
|
|
961
|
+
};
|
|
924
962
|
const getSecret = async (ssm, config, parameter_, defaultValue) => {
|
|
963
|
+
if (defaultValue === undefined) {
|
|
964
|
+
if (config.onlyDefault) {
|
|
965
|
+
throw new Error(`Cannot retrieve parameter ${parameter_}: onlyDefault is enabled and no default value was provided`);
|
|
966
|
+
}
|
|
967
|
+
return getRequiredSecret(ssm, config, parameter_);
|
|
968
|
+
}
|
|
925
969
|
if (config.onlyDefault) {
|
|
926
970
|
return defaultValue;
|
|
927
971
|
}
|
|
928
972
|
try {
|
|
929
|
-
|
|
930
|
-
Name: `${config.prefix ?? ''}${parameter_}`,
|
|
931
|
-
WithDecryption: true,
|
|
932
|
-
}));
|
|
933
|
-
return parameter?.Parameter?.Value ?? defaultValue;
|
|
973
|
+
return (await fetchParameterValue(ssm, config, parameter_)) ?? defaultValue;
|
|
934
974
|
}
|
|
935
975
|
catch (error) {
|
|
936
976
|
if (config.logger) {
|
|
@@ -946,7 +986,7 @@ const parameterStore = (userConfig) => {
|
|
|
946
986
|
};
|
|
947
987
|
const ssm = new SSMClient(clientConfig);
|
|
948
988
|
return {
|
|
949
|
-
getSecret: (parameter, defaultValue
|
|
989
|
+
getSecret: (parameter, defaultValue) => getSecret(ssm, config, parameter, defaultValue),
|
|
950
990
|
getSecrets: (parameters, defaultValues = []) => getSecrets(ssm, config, parameters, defaultValues),
|
|
951
991
|
};
|
|
952
992
|
};
|
|
@@ -1097,6 +1137,9 @@ const sqs = (userConfig) => {
|
|
|
1097
1137
|
};
|
|
1098
1138
|
};
|
|
1099
1139
|
|
|
1140
|
+
const btoa = (stringToEncode) => Buffer.from(stringToEncode).toString('base64');
|
|
1141
|
+
const atob = (stringToDecode) => Buffer.from(stringToDecode, 'base64').toString('utf8');
|
|
1142
|
+
|
|
1100
1143
|
const logger = (config) => {
|
|
1101
1144
|
const loggerConfig = {
|
|
1102
1145
|
defaultMeta: {
|
|
@@ -1127,4 +1170,4 @@ const logger = (config) => {
|
|
|
1127
1170
|
});
|
|
1128
1171
|
};
|
|
1129
1172
|
|
|
1130
|
-
export { ClientError, DEFAULT_CLIENT_CONFIG$1 as DEFAULT_PARAMETER_STORE_CLIENT_CONFIG, DEFAULT_CLIENT_CONFIG as DEFAULT_SES_CLIENT_CONFIG, ServerError, alagarr, dynamodb, lambda, logger, parameterStore, ses, sqs };
|
|
1173
|
+
export { ClientError, DEFAULT_CLIENT_CONFIG$1 as DEFAULT_PARAMETER_STORE_CLIENT_CONFIG, DEFAULT_CLIENT_CONFIG as DEFAULT_SES_CLIENT_CONFIG, ServerError, alagarr, asyncReduce, atob, btoa, deepFlatten, dynamodb, flatten, lambda, logger, parameterStore, partial, ses, splitEvery, sqs, times, until };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { Alagarr, default as alagarr, ClientError, HandlerFunction, IInterfaceAlagarrOptions, IInterfaceHeaders, IInterfaceQueryParameters, IInterfaceRequest, IInterfaceResponse, ServerError, } from './alagarr';
|
|
2
2
|
export { DEFAULT_PARAMETER_STORE_CLIENT_CONFIG, DEFAULT_SES_CLIENT_CONFIG, dynamodb, IDynamoDBConfig, IDynamoDBInstance, IEmailAttachment, IEmailOptions, ILambda, ILambdaInstance, IParameterStore, IParameterStoreInstance, ISES, ISESInstance, ISQS, ISQSInstance, IUnprocessedItems, lambda, parameterStore, ses, sqs, TBatchWriteItems, TDeleteItem, TDeleteQueueItem, TGetItem, TGetQueueItems, TGetQueueUrl, TGetSecret, TGetSecrets, TInvokeLambda, TPutItem, TQueryTable, TScanTable, TSendMail, TSendMessage, TUpdateItem, } from './aws';
|
|
3
|
+
export { atob, btoa } from './base64';
|
|
3
4
|
export { default as logger } from './logger/logger';
|
|
5
|
+
export { asyncReduce, deepFlatten, flatten, List, partial, splitEvery, times, until, } from './utils';
|
|
4
6
|
export type { APIGatewayEvent, APIGatewayProxyEventV2, Context, } from 'aws-lambda';
|
|
5
7
|
export { Logger } from 'winston';
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
export type List<T> = readonly T[];
|
|
1
2
|
export declare const splitEvery: <T>(every: number, list: readonly T[]) => T[][];
|
|
2
3
|
export declare const until: <A, B>(predicate: (value: B, iteration: number) => boolean | Promise<boolean>, transformer: (value: A | B | undefined, iteration: number) => B | Promise<B>, initialValue?: A | B, iterationCount?: number) => Promise<B>;
|
|
4
|
+
export declare const partial: (function_: (...arguments_: any[]) => any | Promise<any>, ...partialArguments: any[]) => (...arguments_: any[]) => any;
|
|
5
|
+
export declare const times: <T>(function_: (item: number, index: number) => T, n: number) => List<T>;
|
|
6
|
+
export declare const deepFlatten: <T>(arrayOfArrays: readonly (readonly T[])[]) => readonly T[];
|
|
7
|
+
export declare const flatten: <T>(arrayOfArrays: readonly (readonly T[])[], depth?: number) => readonly T[];
|
|
8
|
+
export declare const asyncReduce: <I, O>(iterable: List<I>, reducer: (previousValue: O, currentValue: I, currentIndex: number, iterable: List<I>) => Promise<O>, initialValue: O) => Promise<O>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allthings/cloud-toolkit",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.1.0-beta.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Allthings GmbH",
|
|
6
6
|
"keywords": [
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"node": ">=24",
|
|
18
18
|
"npm": ">=10"
|
|
19
19
|
},
|
|
20
|
-
"packageManager": "yarn@4.
|
|
20
|
+
"packageManager": "yarn@4.18.0",
|
|
21
21
|
"main": "dist/lib.cjs.js",
|
|
22
22
|
"module": "dist/lib.esm.mjs",
|
|
23
23
|
"types": "dist/src/index.d.ts",
|
|
@@ -76,22 +76,22 @@
|
|
|
76
76
|
"winston": "^3.19.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@allthings/eslint-config": "5.
|
|
80
|
-
"@commitlint/cli": "21.2.
|
|
81
|
-
"@commitlint/config-conventional": "21.2.
|
|
79
|
+
"@allthings/eslint-config": "5.2.0",
|
|
80
|
+
"@commitlint/cli": "21.2.2",
|
|
81
|
+
"@commitlint/config-conventional": "21.2.2",
|
|
82
82
|
"@rollup/plugin-node-resolve": "16.0.3",
|
|
83
83
|
"@types/node": "24.13.3",
|
|
84
84
|
"@types/nodemailer": "8.0.1",
|
|
85
85
|
"@vitest/coverage-v8": "4.1.10",
|
|
86
86
|
"aws-sdk-client-mock": "4.1.0",
|
|
87
87
|
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
88
|
-
"eslint": "10.
|
|
88
|
+
"eslint": "10.8.1",
|
|
89
89
|
"husky": "9.1.7",
|
|
90
|
-
"lint-staged": "17.
|
|
91
|
-
"prettier": "3.9.
|
|
90
|
+
"lint-staged": "17.3.0",
|
|
91
|
+
"prettier": "3.9.6",
|
|
92
92
|
"rimraf": "6.1.3",
|
|
93
|
-
"rollup": "4.62.
|
|
94
|
-
"semantic-release": "25.0.
|
|
93
|
+
"rollup": "4.62.4",
|
|
94
|
+
"semantic-release": "25.0.9",
|
|
95
95
|
"typescript": "6.0.3",
|
|
96
96
|
"vitest": "4.1.10"
|
|
97
97
|
},
|