@aligent/microservice-util-lib 0.2.2 → 1.1.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/README.md +2 -2
- package/docs/classes/S3Dao.md +102 -107
- package/docs/functions/apiKeyAuthMiddleware.md +37 -0
- package/docs/functions/basicAuthMiddleware.md +37 -0
- package/docs/functions/chunkBy.md +43 -0
- package/docs/functions/fetchSsmParams.md +61 -0
- package/docs/functions/getAwsIdFromArn.md +37 -0
- package/docs/functions/hasDefinedProperties.md +57 -0
- package/docs/functions/oAuth10aAuthMiddleware.md +43 -0
- package/docs/functions/oAuth20AuthMiddleware.md +37 -0
- package/docs/functions/remap.md +71 -0
- package/docs/functions/retryWrapper.md +46 -0
- package/docs/interfaces/ApiKey.md +44 -0
- package/docs/interfaces/Basic.md +32 -0
- package/docs/interfaces/OAuth10a.md +93 -0
- package/docs/interfaces/OAuth20.md +44 -0
- package/docs/interfaces/RetryConfig.md +53 -42
- package/docs/modules.md +21 -267
- package/docs/type-aliases/ObjectMap.md +13 -0
- package/docs/type-aliases/Remap.md +21 -0
- package/package.json +15 -40
- package/{dist/chunkBy/chunkBy.js → src/chunk-by/chunk-by.js} +3 -4
- package/{dist/fetchSsmParams/fetchSsmParams.d.ts → src/fetch-ssm-params/fetch-ssm-params.d.ts} +2 -2
- package/src/fetch-ssm-params/fetch-ssm-params.js +28 -0
- package/src/get-aws-id-from-arn/get-aws-id-from-arn.d.ts +12 -0
- package/src/get-aws-id-from-arn/get-aws-id-from-arn.js +20 -0
- package/{dist/hasPropertiesDefined/hasPropertiesDefined.js → src/has-properties-defined/has-properties-defined.js} +2 -8
- package/src/index.d.ts +10 -0
- package/src/index.js +24 -0
- package/src/openapi-fetch-middlewares/authentications.d.ts +66 -0
- package/src/openapi-fetch-middlewares/authentications.js +96 -0
- package/src/openapi-fetch-middlewares/oauth10a/oauth10a.d.ts +12 -0
- package/src/openapi-fetch-middlewares/oauth10a/oauth10a.js +209 -0
- package/src/openapi-fetch-middlewares/types/authentications.d.ts +71 -0
- package/src/openapi-fetch-middlewares/types/authentications.js +2 -0
- package/{dist → src}/remap/remap.d.ts +6 -6
- package/src/remap/remap.js +97 -0
- package/{dist/retryWrapper/retryWrapper.d.ts → src/retry-wrapper/retry-wrapper.d.ts} +1 -1
- package/src/retry-wrapper/retry-wrapper.js +56 -0
- package/{dist → src}/s3/s3.d.ts +3 -6
- package/src/s3/s3.js +86 -0
- package/dist/chunkBy/chunkBy.js.map +0 -1
- package/dist/chunkBy/chunkBy.test.d.ts +0 -1
- package/dist/chunkBy/chunkBy.test.js +0 -17
- package/dist/chunkBy/chunkBy.test.js.map +0 -1
- package/dist/fetchSsmParams/fetchSsmParams.js +0 -80
- package/dist/fetchSsmParams/fetchSsmParams.js.map +0 -1
- package/dist/fetchSsmParams/fetchSsmParams.test.d.ts +0 -1
- package/dist/fetchSsmParams/fetchSsmParams.test.js +0 -110
- package/dist/fetchSsmParams/fetchSsmParams.test.js.map +0 -1
- package/dist/hasPropertiesDefined/hasPropertiesDefined.js.map +0 -1
- package/dist/hasPropertiesDefined/hasPropertiesDefined.test.d.ts +0 -1
- package/dist/hasPropertiesDefined/hasPropertiesDefined.test.js +0 -37
- package/dist/hasPropertiesDefined/hasPropertiesDefined.test.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -19
- package/dist/index.js.map +0 -1
- package/dist/remap/remap.js +0 -50
- package/dist/remap/remap.js.map +0 -1
- package/dist/remap/remap.test.d.ts +0 -1
- package/dist/remap/remap.test.js +0 -65
- package/dist/remap/remap.test.js.map +0 -1
- package/dist/retryWrapper/retryWrapper.js +0 -121
- package/dist/retryWrapper/retryWrapper.js.map +0 -1
- package/dist/retryWrapper/retryWrapper.test.d.ts +0 -1
- package/dist/retryWrapper/retryWrapper.test.js +0 -234
- package/dist/retryWrapper/retryWrapper.test.js.map +0 -1
- package/dist/s3/s3.js +0 -192
- package/dist/s3/s3.js.map +0 -1
- /package/{dist/chunkBy/chunkBy.d.ts → src/chunk-by/chunk-by.d.ts} +0 -0
- /package/{dist/hasPropertiesDefined/hasPropertiesDefined.d.ts → src/has-properties-defined/has-properties-defined.d.ts} +0 -0
package/docs/modules.md
CHANGED
|
@@ -1,281 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
**@aligent/microservice-util-lib**
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
***
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# @aligent/microservice-util-lib
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Classes
|
|
8
8
|
|
|
9
9
|
- [S3Dao](classes/S3Dao.md)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Interfaces
|
|
12
12
|
|
|
13
|
+
- [ApiKey](interfaces/ApiKey.md)
|
|
14
|
+
- [Basic](interfaces/Basic.md)
|
|
15
|
+
- [OAuth10a](interfaces/OAuth10a.md)
|
|
16
|
+
- [OAuth20](interfaces/OAuth20.md)
|
|
13
17
|
- [RetryConfig](interfaces/RetryConfig.md)
|
|
14
18
|
|
|
15
|
-
### Type Aliases
|
|
16
|
-
|
|
17
|
-
- [ObjectMap](modules.md#objectmap)
|
|
18
|
-
- [Remap](modules.md#remap)
|
|
19
|
-
|
|
20
|
-
### Functions
|
|
21
|
-
|
|
22
|
-
- [chunkBy](modules.md#chunkby)
|
|
23
|
-
- [fetchSsmParams](modules.md#fetchssmparams)
|
|
24
|
-
- [hasDefinedProperties](modules.md#hasdefinedproperties)
|
|
25
|
-
- [remap](modules.md#remap-1)
|
|
26
|
-
- [retryWrapper](modules.md#retrywrapper)
|
|
27
|
-
|
|
28
19
|
## Type Aliases
|
|
29
20
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Ƭ **ObjectMap**: readonly readonly [`string`, `string`, Function?][]
|
|
33
|
-
|
|
34
|
-
A list of keys to keys, with an optional transformer function
|
|
35
|
-
|
|
36
|
-
#### Defined in
|
|
37
|
-
|
|
38
|
-
[remap/remap.ts:15](https://bitbucket.org/aligent/microservice-util-lib/src/c978f6c/src/remap/remap.ts#lines-15)
|
|
39
|
-
|
|
40
|
-
___
|
|
41
|
-
|
|
42
|
-
### <a id="remap" name="remap"></a> Remap
|
|
43
|
-
|
|
44
|
-
Ƭ **Remap**<`MapArray`, `Original`\>: `SimplifyIntersection`<`ConstructTypeFromProperties`<`MapArray`, `Original`\>\>
|
|
45
|
-
|
|
46
|
-
#### Type parameters
|
|
47
|
-
|
|
48
|
-
| Name | Type |
|
|
49
|
-
| :------ | :------ |
|
|
50
|
-
| `MapArray` | extends [`ObjectMap`](modules.md#objectmap) |
|
|
51
|
-
| `Original` | extends `Object` |
|
|
52
|
-
|
|
53
|
-
#### Defined in
|
|
54
|
-
|
|
55
|
-
[remap/remap.ts:159](https://bitbucket.org/aligent/microservice-util-lib/src/c978f6c/src/remap/remap.ts#lines-159)
|
|
21
|
+
- [ObjectMap](type-aliases/ObjectMap.md)
|
|
22
|
+
- [Remap](type-aliases/Remap.md)
|
|
56
23
|
|
|
57
24
|
## Functions
|
|
58
25
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
#### Type parameters
|
|
72
|
-
|
|
73
|
-
| Name |
|
|
74
|
-
| :------ |
|
|
75
|
-
| `ArrayItem` |
|
|
76
|
-
|
|
77
|
-
#### Parameters
|
|
78
|
-
|
|
79
|
-
| Name | Type | Description |
|
|
80
|
-
| :------ | :------ | :------ |
|
|
81
|
-
| `source` | `ArrayItem`[] | the array to split up |
|
|
82
|
-
| `chunkSize` | `number` | the size of each chunk. (The final chunk will be whatever is remaining) |
|
|
83
|
-
|
|
84
|
-
#### Returns
|
|
85
|
-
|
|
86
|
-
`ArrayItem`[][]
|
|
87
|
-
|
|
88
|
-
#### Defined in
|
|
89
|
-
|
|
90
|
-
[chunkBy/chunkBy.ts:10](https://bitbucket.org/aligent/microservice-util-lib/src/c978f6c/src/chunkBy/chunkBy.ts#lines-10)
|
|
91
|
-
|
|
92
|
-
___
|
|
93
|
-
|
|
94
|
-
### <a id="fetchssmparams" name="fetchssmparams"></a> fetchSsmParams
|
|
95
|
-
|
|
96
|
-
▸ **fetchSsmParams**(`param`): `Promise`<`Parameter`\>
|
|
97
|
-
|
|
98
|
-
Fetch one SSM parameter
|
|
99
|
-
|
|
100
|
-
#### Parameters
|
|
101
|
-
|
|
102
|
-
| Name | Type | Description |
|
|
103
|
-
| :------ | :------ | :------ |
|
|
104
|
-
| `param` | `string` | key of the parameter to fetch |
|
|
105
|
-
|
|
106
|
-
#### Returns
|
|
107
|
-
|
|
108
|
-
`Promise`<`Parameter`\>
|
|
109
|
-
|
|
110
|
-
#### Defined in
|
|
111
|
-
|
|
112
|
-
[fetchSsmParams/fetchSsmParams.ts:14](https://bitbucket.org/aligent/microservice-util-lib/src/c978f6c/src/fetchSsmParams/fetchSsmParams.ts#lines-14)
|
|
113
|
-
|
|
114
|
-
▸ **fetchSsmParams**(`...params`): `Promise`<`Parameter`[]\>
|
|
115
|
-
|
|
116
|
-
Fetch a list of SSM parameters
|
|
117
|
-
|
|
118
|
-
#### Parameters
|
|
119
|
-
|
|
120
|
-
| Name | Type | Description |
|
|
121
|
-
| :------ | :------ | :------ |
|
|
122
|
-
| `...params` | `string`[] | list of parameter keys to fetch |
|
|
123
|
-
|
|
124
|
-
#### Returns
|
|
125
|
-
|
|
126
|
-
`Promise`<`Parameter`[]\>
|
|
127
|
-
|
|
128
|
-
#### Defined in
|
|
129
|
-
|
|
130
|
-
[fetchSsmParams/fetchSsmParams.ts:21](https://bitbucket.org/aligent/microservice-util-lib/src/c978f6c/src/fetchSsmParams/fetchSsmParams.ts#lines-21)
|
|
131
|
-
|
|
132
|
-
___
|
|
133
|
-
|
|
134
|
-
### <a id="hasdefinedproperties" name="hasdefinedproperties"></a> hasDefinedProperties
|
|
135
|
-
|
|
136
|
-
▸ **hasDefinedProperties**<`T`, `K`\>(`obj`, `...keys`): obj is SimplifyIntersection<Required<Pick<T, K\>\> & Omit<T, K\>\>
|
|
137
|
-
|
|
138
|
-
Ensure that the given properties are defined on the object.
|
|
139
|
-
|
|
140
|
-
**`Example`**
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
type Foo = { a?: number; b?: number };
|
|
144
|
-
const foo: Foo = { a: 1, b: 2 };
|
|
145
|
-
if (hasDefinedProperties(foo, 'a')) {
|
|
146
|
-
console.log(foo);
|
|
147
|
-
// ^? const bar: {
|
|
148
|
-
// a: number;
|
|
149
|
-
// b?: number;
|
|
150
|
-
// }
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
#### Type parameters
|
|
155
|
-
|
|
156
|
-
| Name | Type |
|
|
157
|
-
| :------ | :------ |
|
|
158
|
-
| `T` | extends `Object` |
|
|
159
|
-
| `K` | extends `string` \| `number` \| `symbol` |
|
|
160
|
-
|
|
161
|
-
#### Parameters
|
|
162
|
-
|
|
163
|
-
| Name | Type | Description |
|
|
164
|
-
| :------ | :------ | :------ |
|
|
165
|
-
| `obj` | `object` \| `T` | The object to check. |
|
|
166
|
-
| `...keys` | `K`[] | The keys to check. |
|
|
167
|
-
|
|
168
|
-
#### Returns
|
|
169
|
-
|
|
170
|
-
obj is SimplifyIntersection<Required<Pick<T, K\>\> & Omit<T, K\>\>
|
|
171
|
-
|
|
172
|
-
`true` if the object has the given properties defined, `false` otherwise.
|
|
173
|
-
|
|
174
|
-
#### Defined in
|
|
175
|
-
|
|
176
|
-
[hasPropertiesDefined/hasPropertiesDefined.ts:22](https://bitbucket.org/aligent/microservice-util-lib/src/c978f6c/src/hasPropertiesDefined/hasPropertiesDefined.ts#lines-22)
|
|
177
|
-
|
|
178
|
-
___
|
|
179
|
-
|
|
180
|
-
### <a id="remap-1" name="remap-1"></a> remap
|
|
181
|
-
|
|
182
|
-
▸ **remap**<`Original`, `MapArray`\>(`object`, `map`): [`Remap`](modules.md#remap)<`MapArray`, `Original`\>
|
|
183
|
-
|
|
184
|
-
Map one object's values to another structure
|
|
185
|
-
|
|
186
|
-
**`Example`**
|
|
187
|
-
|
|
188
|
-
without a transformer function
|
|
189
|
-
```ts
|
|
190
|
-
const map = [
|
|
191
|
-
['foo', 'baz'],
|
|
192
|
-
['bar', 'qux.0']
|
|
193
|
-
] as const;
|
|
194
|
-
const obj = { foo: 'hi', bar: 7 }
|
|
195
|
-
remap(obj, map); // { baz: 'hi', qux: [7] }
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
**`Example`**
|
|
199
|
-
|
|
200
|
-
with a transformer function
|
|
201
|
-
```ts
|
|
202
|
-
const map = [
|
|
203
|
-
['foo', 'baz'],
|
|
204
|
-
['bar', 'qux.0', (x: number) => x + 1]
|
|
205
|
-
] as const;
|
|
206
|
-
const obj = { foo: 'hi', bar: 7 }
|
|
207
|
-
remap(obj, map); // { baz: 'hi', qux: [8] }
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
**`Example`**
|
|
211
|
-
|
|
212
|
-
with an empty initial key
|
|
213
|
-
```ts
|
|
214
|
-
const map = [
|
|
215
|
-
['', 'baz', (x: { foo: number, bar: number }) => x.foo + x.bar]
|
|
216
|
-
]
|
|
217
|
-
const obj = { foo: 3, bar: 7 }
|
|
218
|
-
remap(obj, map); // { baz: 10 }
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
#### Type parameters
|
|
222
|
-
|
|
223
|
-
| Name | Type |
|
|
224
|
-
| :------ | :------ |
|
|
225
|
-
| `Original` | extends `Object` |
|
|
226
|
-
| `MapArray` | extends readonly readonly [`string`, `string`, (...`args`: `any`[]) => `any`][] |
|
|
227
|
-
|
|
228
|
-
#### Parameters
|
|
229
|
-
|
|
230
|
-
| Name | Type | Description |
|
|
231
|
-
| :------ | :------ | :------ |
|
|
232
|
-
| `object` | `Original` | the object to map from |
|
|
233
|
-
| `map` | `MapArray` | the keys for the mapping |
|
|
234
|
-
|
|
235
|
-
#### Returns
|
|
236
|
-
|
|
237
|
-
[`Remap`](modules.md#remap)<`MapArray`, `Original`\>
|
|
238
|
-
|
|
239
|
-
the remapped object
|
|
240
|
-
|
|
241
|
-
#### Defined in
|
|
242
|
-
|
|
243
|
-
[remap/remap.ts:198](https://bitbucket.org/aligent/microservice-util-lib/src/c978f6c/src/remap/remap.ts#lines-198)
|
|
244
|
-
|
|
245
|
-
___
|
|
246
|
-
|
|
247
|
-
### <a id="retrywrapper" name="retrywrapper"></a> retryWrapper
|
|
248
|
-
|
|
249
|
-
▸ **retryWrapper**<`T`\>(`fn`, `config`): `Promise`<`T`\>
|
|
250
|
-
|
|
251
|
-
Retry an async function if it fails
|
|
252
|
-
|
|
253
|
-
**`Example`**
|
|
254
|
-
|
|
255
|
-
```ts
|
|
256
|
-
retryWrapper(someAsyncFunction, {
|
|
257
|
-
retries: 3,
|
|
258
|
-
onRetry: (_, error) => console.error(error)
|
|
259
|
-
});
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
#### Type parameters
|
|
263
|
-
|
|
264
|
-
| Name |
|
|
265
|
-
| :------ |
|
|
266
|
-
| `T` |
|
|
267
|
-
|
|
268
|
-
#### Parameters
|
|
269
|
-
|
|
270
|
-
| Name | Type | Description |
|
|
271
|
-
| :------ | :------ | :------ |
|
|
272
|
-
| `fn` | () => `Promise`<`T`\> | the function to be retried |
|
|
273
|
-
| `config` | [`RetryConfig`](interfaces/RetryConfig.md) | the configuration for retries |
|
|
274
|
-
|
|
275
|
-
#### Returns
|
|
276
|
-
|
|
277
|
-
`Promise`<`T`\>
|
|
278
|
-
|
|
279
|
-
#### Defined in
|
|
280
|
-
|
|
281
|
-
[retryWrapper/retryWrapper.ts:78](https://bitbucket.org/aligent/microservice-util-lib/src/c978f6c/src/retryWrapper/retryWrapper.ts#lines-78)
|
|
26
|
+
- [apiKeyAuthMiddleware](functions/apiKeyAuthMiddleware.md)
|
|
27
|
+
- [basicAuthMiddleware](functions/basicAuthMiddleware.md)
|
|
28
|
+
- [chunkBy](functions/chunkBy.md)
|
|
29
|
+
- [fetchSsmParams](functions/fetchSsmParams.md)
|
|
30
|
+
- [getAwsIdFromArn](functions/getAwsIdFromArn.md)
|
|
31
|
+
- [hasDefinedProperties](functions/hasDefinedProperties.md)
|
|
32
|
+
- [oAuth10aAuthMiddleware](functions/oAuth10aAuthMiddleware.md)
|
|
33
|
+
- [oAuth20AuthMiddleware](functions/oAuth20AuthMiddleware.md)
|
|
34
|
+
- [remap](functions/remap.md)
|
|
35
|
+
- [retryWrapper](functions/retryWrapper.md)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[**@aligent/microservice-util-lib**](../modules.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@aligent/microservice-util-lib](../modules.md) / ObjectMap
|
|
6
|
+
|
|
7
|
+
# Type Alias: ObjectMap
|
|
8
|
+
|
|
9
|
+
> **ObjectMap** = `ReadonlyArray`\<readonly \[`string`, `string`, (...`args`) => `any`?\]\>
|
|
10
|
+
|
|
11
|
+
Defined in: [remap/remap.ts:13](https://github.com/aligent/microservice-development-utilities/blob/e13483771966234032f5249dc36c2c31c71d7cf1/packages/microservice-util-lib/src/remap/remap.ts#L13)
|
|
12
|
+
|
|
13
|
+
A list of keys to keys, with an optional transformer function
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[**@aligent/microservice-util-lib**](../modules.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@aligent/microservice-util-lib](../modules.md) / Remap
|
|
6
|
+
|
|
7
|
+
# Type Alias: Remap\<MapArray, Original\>
|
|
8
|
+
|
|
9
|
+
> **Remap**\<`MapArray`, `Original`\> = `SimplifyIntersection`\<`ConstructTypeFromProperties`\<`MapArray`, `Original`\>\>
|
|
10
|
+
|
|
11
|
+
Defined in: [remap/remap.ts:145](https://github.com/aligent/microservice-development-utilities/blob/e13483771966234032f5249dc36c2c31c71d7cf1/packages/microservice-util-lib/src/remap/remap.ts#L145)
|
|
12
|
+
|
|
13
|
+
## Type Parameters
|
|
14
|
+
|
|
15
|
+
### MapArray
|
|
16
|
+
|
|
17
|
+
`MapArray` *extends* [`ObjectMap`](ObjectMap.md)
|
|
18
|
+
|
|
19
|
+
### Original
|
|
20
|
+
|
|
21
|
+
`Original` *extends* `object`
|
package/package.json
CHANGED
|
@@ -1,48 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aligent/microservice-util-lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A set of utility functions for Aligent Microservices",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"lint": "eslint src/*.ts src/**/*.ts",
|
|
9
|
-
"lint:fix": "eslint --fix src/*.ts src/**/*.ts",
|
|
10
|
-
"test": "npm run lint && npm run test:types && npm run test:jest",
|
|
11
|
-
"test:jest": "jest src/",
|
|
12
|
-
"test:types": "tsc --noEmit",
|
|
13
|
-
"docs": "typedoc --readme none --githubPages false --plugin typedoc-plugin-markdown --entryDocument modules.md --namedAnchors true --out docs src/index.ts"
|
|
14
|
-
},
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"typings": "./src/index.d.ts",
|
|
15
8
|
"repository": {
|
|
16
9
|
"type": "git",
|
|
17
|
-
"url": "
|
|
18
|
-
|
|
19
|
-
"author": "Aligent",
|
|
20
|
-
"license": "ISC",
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"@types/jest": "^29.2.4",
|
|
23
|
-
"@types/lodash": "^4.14.191",
|
|
24
|
-
"@types/node": "^18.11.17",
|
|
25
|
-
"@types/object-hash": "^3.0.2",
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
27
|
-
"@typescript-eslint/parser": "^5.46.1",
|
|
28
|
-
"aws-sdk-client-mock": "^2.1.1",
|
|
29
|
-
"aws-sdk-client-mock-jest": "^2.1.1",
|
|
30
|
-
"eslint": "^8.30.0",
|
|
31
|
-
"jest": "^29.3.1",
|
|
32
|
-
"ts-jest": "^29.0.3",
|
|
33
|
-
"typedoc": "^0.23.23",
|
|
34
|
-
"typedoc-plugin-markdown": "^3.14.0",
|
|
35
|
-
"typescript": "^4.9.4"
|
|
10
|
+
"url": "https://github.com/aligent/microservice-development-utilities.git",
|
|
11
|
+
"directory": "packages/microservice-util-lib"
|
|
36
12
|
},
|
|
37
13
|
"dependencies": {
|
|
38
|
-
"@aws-sdk/client-s3": "^3.
|
|
39
|
-
"@aws-sdk/client-ssm": "^3.
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
14
|
+
"@aws-sdk/client-s3": "^3.800.0",
|
|
15
|
+
"@aws-sdk/client-ssm": "^3.799.0",
|
|
16
|
+
"oauth-sign": "^0.9.0",
|
|
17
|
+
"object-hash": "^3.0.0",
|
|
18
|
+
"openapi-fetch": "^0.13.5"
|
|
43
19
|
},
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
20
|
+
"author": "Aligent",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"types": "./src/index.d.ts"
|
|
23
|
+
}
|
|
@@ -11,12 +11,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
*/
|
|
12
12
|
function chunkBy(source, chunkSize) {
|
|
13
13
|
if (chunkSize <= 0) {
|
|
14
|
-
throw new Error(
|
|
14
|
+
throw new Error(`Cannot create chunks of size ${chunkSize} (0 or less)`);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
return Array.from(new Array(numberOfChunks),
|
|
16
|
+
const numberOfChunks = Math.ceil(source.length / chunkSize);
|
|
17
|
+
return Array.from(new Array(numberOfChunks), (_, i) => {
|
|
18
18
|
return source.slice(i * chunkSize, (i + 1) * chunkSize);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
exports.default = chunkBy;
|
|
22
|
-
//# sourceMappingURL=chunkBy.js.map
|
package/{dist/fetchSsmParams/fetchSsmParams.d.ts → src/fetch-ssm-params/fetch-ssm-params.d.ts}
RENAMED
|
@@ -3,10 +3,10 @@ import { Parameter } from '@aws-sdk/client-ssm';
|
|
|
3
3
|
* Fetch one SSM parameter
|
|
4
4
|
* @param param key of the parameter to fetch
|
|
5
5
|
*/
|
|
6
|
-
declare function fetchSsmParams(param: string): Promise<Parameter>;
|
|
6
|
+
declare function fetchSsmParams(param: string): Promise<Parameter | undefined>;
|
|
7
7
|
/**
|
|
8
8
|
* Fetch a list of SSM parameters
|
|
9
9
|
* @param params list of parameter keys to fetch
|
|
10
10
|
*/
|
|
11
|
-
declare function fetchSsmParams(...params: string[]): Promise<Parameter
|
|
11
|
+
declare function fetchSsmParams(...params: string[]): Promise<Array<Parameter | undefined>>;
|
|
12
12
|
export default fetchSsmParams;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
4
|
+
const ssm = new client_ssm_1.SSMClient({});
|
|
5
|
+
/**
|
|
6
|
+
* Fetch SSM Parameters
|
|
7
|
+
* @param params the keys of the parameters to fetch
|
|
8
|
+
*/
|
|
9
|
+
async function fetchSsmParams(...params) {
|
|
10
|
+
if (params.length === 0) {
|
|
11
|
+
throw new Error('No SSM Params supplied');
|
|
12
|
+
}
|
|
13
|
+
if (params.length === 1) {
|
|
14
|
+
const result = await ssm.send(new client_ssm_1.GetParameterCommand({
|
|
15
|
+
Name: params[0],
|
|
16
|
+
WithDecryption: true,
|
|
17
|
+
}));
|
|
18
|
+
return result.Parameter;
|
|
19
|
+
}
|
|
20
|
+
const result = await ssm.send(new client_ssm_1.GetParametersCommand({
|
|
21
|
+
Names: params,
|
|
22
|
+
WithDecryption: true,
|
|
23
|
+
}));
|
|
24
|
+
return params.map(paramName => {
|
|
25
|
+
return result.Parameters?.find(param => param.Name === paramName);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.default = fetchSsmParams;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the AWS ID from its resource ARN
|
|
3
|
+
* @param resourceArn the ARN of the AWS resource
|
|
4
|
+
* @returns the ID (if present in the ARN) of the AWS resource/execution
|
|
5
|
+
* @throws when the provided ARN is empty
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* getAwsIdFromArn('arn:aws:states:ap-southeast-2:123123123:execution:prj-int-entity-ac-dc-dev-machine-name:this-is-the-id')
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
declare const getAwsIdFromArn: (resourceArn: string) => string;
|
|
12
|
+
export default getAwsIdFromArn;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Get the AWS ID from its resource ARN
|
|
5
|
+
* @param resourceArn the ARN of the AWS resource
|
|
6
|
+
* @returns the ID (if present in the ARN) of the AWS resource/execution
|
|
7
|
+
* @throws when the provided ARN is empty
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* getAwsIdFromArn('arn:aws:states:ap-southeast-2:123123123:execution:prj-int-entity-ac-dc-dev-machine-name:this-is-the-id')
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
const getAwsIdFromArn = (resourceArn) => {
|
|
14
|
+
if (resourceArn.length === 0) {
|
|
15
|
+
throw new Error('Received an empty resourceArn, unable to get an ID.');
|
|
16
|
+
}
|
|
17
|
+
const startIdx = resourceArn.lastIndexOf(':') + 1;
|
|
18
|
+
return resourceArn.substring(startIdx);
|
|
19
|
+
};
|
|
20
|
+
exports.default = getAwsIdFromArn;
|
|
@@ -19,13 +19,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
* }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
function hasDefinedProperties(obj) {
|
|
23
|
-
|
|
24
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
25
|
-
keys[_i - 1] = arguments[_i];
|
|
26
|
-
}
|
|
27
|
-
for (var _a = 0, keys_1 = keys; _a < keys_1.length; _a++) {
|
|
28
|
-
var key = keys_1[_a];
|
|
22
|
+
function hasDefinedProperties(obj, ...keys) {
|
|
23
|
+
for (const key of keys) {
|
|
29
24
|
if (obj[key] === undefined || obj[key] === null) {
|
|
30
25
|
return false;
|
|
31
26
|
}
|
|
@@ -33,4 +28,3 @@ function hasDefinedProperties(obj) {
|
|
|
33
28
|
return true;
|
|
34
29
|
}
|
|
35
30
|
exports.default = hasDefinedProperties;
|
|
36
|
-
//# sourceMappingURL=hasPropertiesDefined.js.map
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import chunkBy from './chunk-by/chunk-by';
|
|
2
|
+
import fetchSsmParams from './fetch-ssm-params/fetch-ssm-params';
|
|
3
|
+
import getAwsIdFromArn from './get-aws-id-from-arn/get-aws-id-from-arn';
|
|
4
|
+
import hasDefinedProperties from './has-properties-defined/has-properties-defined';
|
|
5
|
+
import { ApiKey, Basic, OAuth10a, OAuth20, apiKeyAuthMiddleware, basicAuthMiddleware, oAuth10aAuthMiddleware, oAuth20AuthMiddleware } from './openapi-fetch-middlewares/authentications';
|
|
6
|
+
import remap, { ObjectMap, Remap } from './remap/remap';
|
|
7
|
+
import retryWrapper, { RetryConfig } from './retry-wrapper/retry-wrapper';
|
|
8
|
+
import S3Dao from './s3/s3';
|
|
9
|
+
export type { ApiKey, Basic, OAuth10a, OAuth20, ObjectMap, Remap, RetryConfig, S3Dao };
|
|
10
|
+
export { apiKeyAuthMiddleware, basicAuthMiddleware, chunkBy, fetchSsmParams, getAwsIdFromArn, hasDefinedProperties, oAuth10aAuthMiddleware, oAuth20AuthMiddleware, remap, retryWrapper, };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.retryWrapper = exports.remap = exports.oAuth20AuthMiddleware = exports.oAuth10aAuthMiddleware = exports.hasDefinedProperties = exports.getAwsIdFromArn = exports.fetchSsmParams = exports.chunkBy = exports.basicAuthMiddleware = exports.apiKeyAuthMiddleware = void 0;
|
|
7
|
+
/* v8 ignore start */
|
|
8
|
+
const chunk_by_1 = __importDefault(require("./chunk-by/chunk-by"));
|
|
9
|
+
exports.chunkBy = chunk_by_1.default;
|
|
10
|
+
const fetch_ssm_params_1 = __importDefault(require("./fetch-ssm-params/fetch-ssm-params"));
|
|
11
|
+
exports.fetchSsmParams = fetch_ssm_params_1.default;
|
|
12
|
+
const get_aws_id_from_arn_1 = __importDefault(require("./get-aws-id-from-arn/get-aws-id-from-arn"));
|
|
13
|
+
exports.getAwsIdFromArn = get_aws_id_from_arn_1.default;
|
|
14
|
+
const has_properties_defined_1 = __importDefault(require("./has-properties-defined/has-properties-defined"));
|
|
15
|
+
exports.hasDefinedProperties = has_properties_defined_1.default;
|
|
16
|
+
const authentications_1 = require("./openapi-fetch-middlewares/authentications");
|
|
17
|
+
Object.defineProperty(exports, "apiKeyAuthMiddleware", { enumerable: true, get: function () { return authentications_1.apiKeyAuthMiddleware; } });
|
|
18
|
+
Object.defineProperty(exports, "basicAuthMiddleware", { enumerable: true, get: function () { return authentications_1.basicAuthMiddleware; } });
|
|
19
|
+
Object.defineProperty(exports, "oAuth10aAuthMiddleware", { enumerable: true, get: function () { return authentications_1.oAuth10aAuthMiddleware; } });
|
|
20
|
+
Object.defineProperty(exports, "oAuth20AuthMiddleware", { enumerable: true, get: function () { return authentications_1.oAuth20AuthMiddleware; } });
|
|
21
|
+
const remap_1 = __importDefault(require("./remap/remap"));
|
|
22
|
+
exports.remap = remap_1.default;
|
|
23
|
+
const retry_wrapper_1 = __importDefault(require("./retry-wrapper/retry-wrapper"));
|
|
24
|
+
exports.retryWrapper = retry_wrapper_1.default;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Middleware } from 'openapi-fetch';
|
|
2
|
+
import type { ApiKey, Basic, OAuth10a, OAuth20 } from './types/authentications';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an openapi-fetch middleware for API key authentication.
|
|
5
|
+
* This middleware sets the API key in the specified header for each request.
|
|
6
|
+
*
|
|
7
|
+
* @param {ApiKey} config - The configuration for API key authentication.
|
|
8
|
+
* @returns {Middleware} The middleware for API key authentication.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const middleware = apiKeyAuthMiddleware({
|
|
12
|
+
* header: 'x-api-key',
|
|
13
|
+
* value: async () => 'your-api-key',
|
|
14
|
+
* });
|
|
15
|
+
*/
|
|
16
|
+
declare function apiKeyAuthMiddleware(config: ApiKey): Middleware;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an openapi-fetch middleware for Basic authentication.
|
|
19
|
+
* This middleware sets the `Authorization` header with the Basic authentication credentials
|
|
20
|
+
* (username and password) for each request.
|
|
21
|
+
*
|
|
22
|
+
* @param {Basic} config - The configuration for Basic authentication.
|
|
23
|
+
* @returns {Middleware} The middleware for Basic authentication.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const middleware = basicAuthMiddleware({
|
|
27
|
+
* credentials: async () => ({ username: 'user', password: 'pass' }),
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
declare function basicAuthMiddleware(config: Basic): Middleware;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an openapi-fetch middleware for OAuth 1.0a authentication.
|
|
33
|
+
* This middleware generates OAuth 1.0a parameters and sets the `Authorization` header
|
|
34
|
+
* for each request.
|
|
35
|
+
*
|
|
36
|
+
* @param {OAuth10a} config - The configuration for OAuth 1.0a authentication.
|
|
37
|
+
* @returns {Middleware} The middleware for OAuth 1.0a authentication.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const middleware = oAuth10aAuthMiddleware({
|
|
41
|
+
* algorithm: 'HMAC-SHA256',
|
|
42
|
+
* credentials: async () => ({
|
|
43
|
+
* consumerKey: 'key',
|
|
44
|
+
* consumerSecret: 'secret',
|
|
45
|
+
* token: 'token',
|
|
46
|
+
* tokenSecret: 'tokenSecret',
|
|
47
|
+
* }),
|
|
48
|
+
* });
|
|
49
|
+
*/
|
|
50
|
+
declare function oAuth10aAuthMiddleware(config: OAuth10a): Middleware;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an openapi-fetch middleware for OAuth 2.0 authentication.
|
|
53
|
+
* This middleware sets the `Authorization` header with the OAuth 2.0 token for each request.
|
|
54
|
+
*
|
|
55
|
+
* @param {OAuth20} options - The configuration for OAuth 2.0 authentication.
|
|
56
|
+
* @returns {Middleware} The middleware for OAuth 2.0 authentication.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const middleware = oAuth20AuthMiddleware({
|
|
60
|
+
* token: async () => 'your-access-token',
|
|
61
|
+
* tokenType: 'Bearer',
|
|
62
|
+
* });
|
|
63
|
+
*/
|
|
64
|
+
declare function oAuth20AuthMiddleware(options: OAuth20): Middleware;
|
|
65
|
+
export type { ApiKey, Basic, OAuth10a, OAuth20 };
|
|
66
|
+
export { apiKeyAuthMiddleware, basicAuthMiddleware, oAuth10aAuthMiddleware, oAuth20AuthMiddleware };
|