@aligent/microservice-util-lib 1.0.0 → 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.
Files changed (84) hide show
  1. package/README.md +2 -2
  2. package/docs/classes/S3Dao.md +102 -107
  3. package/docs/functions/apiKeyAuthMiddleware.md +37 -0
  4. package/docs/functions/basicAuthMiddleware.md +37 -0
  5. package/docs/functions/chunkBy.md +43 -0
  6. package/docs/functions/fetchSsmParams.md +61 -0
  7. package/docs/functions/getAwsIdFromArn.md +37 -0
  8. package/docs/functions/hasDefinedProperties.md +57 -0
  9. package/docs/functions/oAuth10aAuthMiddleware.md +43 -0
  10. package/docs/functions/oAuth20AuthMiddleware.md +37 -0
  11. package/docs/functions/remap.md +71 -0
  12. package/docs/functions/retryWrapper.md +46 -0
  13. package/docs/interfaces/ApiKey.md +44 -0
  14. package/docs/interfaces/Basic.md +32 -0
  15. package/docs/interfaces/OAuth10a.md +93 -0
  16. package/docs/interfaces/OAuth20.md +44 -0
  17. package/docs/interfaces/RetryConfig.md +53 -42
  18. package/docs/modules.md +21 -302
  19. package/docs/type-aliases/ObjectMap.md +13 -0
  20. package/docs/type-aliases/Remap.md +21 -0
  21. package/package.json +15 -40
  22. package/{dist/chunkBy/chunkBy.js → src/chunk-by/chunk-by.js} +3 -4
  23. package/{dist/fetchSsmParams/fetchSsmParams.d.ts → src/fetch-ssm-params/fetch-ssm-params.d.ts} +2 -2
  24. package/src/fetch-ssm-params/fetch-ssm-params.js +28 -0
  25. package/{dist/getAwsIdFromArn/getAwsIdFromArn.js → src/get-aws-id-from-arn/get-aws-id-from-arn.js} +2 -3
  26. package/{dist/hasPropertiesDefined/hasPropertiesDefined.js → src/has-properties-defined/has-properties-defined.js} +2 -8
  27. package/src/index.d.ts +11 -0
  28. package/src/index.js +26 -0
  29. package/src/openapi-fetch-middlewares/authentications.d.ts +66 -0
  30. package/src/openapi-fetch-middlewares/authentications.js +96 -0
  31. package/src/openapi-fetch-middlewares/oauth10a/oauth10a.d.ts +12 -0
  32. package/src/openapi-fetch-middlewares/oauth10a/oauth10a.js +209 -0
  33. package/src/openapi-fetch-middlewares/retry.d.ts +54 -0
  34. package/src/openapi-fetch-middlewares/retry.js +218 -0
  35. package/src/openapi-fetch-middlewares/types/authentications.d.ts +71 -0
  36. package/src/openapi-fetch-middlewares/types/authentications.js +2 -0
  37. package/src/openapi-fetch-middlewares/types/retry.d.ts +93 -0
  38. package/src/openapi-fetch-middlewares/types/retry.js +2 -0
  39. package/src/openapi-fetch-middlewares/utils/is-network-error.d.ts +5 -0
  40. package/src/openapi-fetch-middlewares/utils/is-network-error.js +40 -0
  41. package/{dist → src}/remap/remap.d.ts +6 -6
  42. package/src/remap/remap.js +97 -0
  43. package/{dist/retryWrapper/retryWrapper.d.ts → src/retry-wrapper/retry-wrapper.d.ts} +1 -1
  44. package/src/retry-wrapper/retry-wrapper.js +56 -0
  45. package/{dist → src}/s3/s3.d.ts +2 -2
  46. package/src/s3/s3.js +86 -0
  47. package/dist/chunkBy/chunkBy.js.map +0 -1
  48. package/dist/chunkBy/chunkBy.test.d.ts +0 -1
  49. package/dist/chunkBy/chunkBy.test.js +0 -17
  50. package/dist/chunkBy/chunkBy.test.js.map +0 -1
  51. package/dist/fetchSsmParams/fetchSsmParams.js +0 -80
  52. package/dist/fetchSsmParams/fetchSsmParams.js.map +0 -1
  53. package/dist/fetchSsmParams/fetchSsmParams.test.d.ts +0 -1
  54. package/dist/fetchSsmParams/fetchSsmParams.test.js +0 -110
  55. package/dist/fetchSsmParams/fetchSsmParams.test.js.map +0 -1
  56. package/dist/getAwsIdFromArn/getAwsIdFromArn.js.map +0 -1
  57. package/dist/getAwsIdFromArn/getAwsIdFromArn.test.d.ts +0 -1
  58. package/dist/getAwsIdFromArn/getAwsIdFromArn.test.js +0 -20
  59. package/dist/getAwsIdFromArn/getAwsIdFromArn.test.js.map +0 -1
  60. package/dist/hasPropertiesDefined/hasPropertiesDefined.js.map +0 -1
  61. package/dist/hasPropertiesDefined/hasPropertiesDefined.test.d.ts +0 -1
  62. package/dist/hasPropertiesDefined/hasPropertiesDefined.test.js +0 -37
  63. package/dist/hasPropertiesDefined/hasPropertiesDefined.test.js.map +0 -1
  64. package/dist/index.d.ts +0 -8
  65. package/dist/index.js +0 -21
  66. package/dist/index.js.map +0 -1
  67. package/dist/remap/remap.js +0 -50
  68. package/dist/remap/remap.js.map +0 -1
  69. package/dist/remap/remap.test.d.ts +0 -1
  70. package/dist/remap/remap.test.js +0 -65
  71. package/dist/remap/remap.test.js.map +0 -1
  72. package/dist/retryWrapper/retryWrapper.js +0 -121
  73. package/dist/retryWrapper/retryWrapper.js.map +0 -1
  74. package/dist/retryWrapper/retryWrapper.test.d.ts +0 -1
  75. package/dist/retryWrapper/retryWrapper.test.js +0 -234
  76. package/dist/retryWrapper/retryWrapper.test.js.map +0 -1
  77. package/dist/s3/s3.js +0 -190
  78. package/dist/s3/s3.js.map +0 -1
  79. package/dist/s3/s3.test.d.ts +0 -1
  80. package/dist/s3/s3.test.js +0 -126
  81. package/dist/s3/s3.test.js.map +0 -1
  82. /package/{dist/chunkBy/chunkBy.d.ts → src/chunk-by/chunk-by.d.ts} +0 -0
  83. /package/{dist/getAwsIdFromArn/getAwsIdFromArn.d.ts → src/get-aws-id-from-arn/get-aws-id-from-arn.d.ts} +0 -0
  84. /package/{dist/hasPropertiesDefined/hasPropertiesDefined.d.ts → src/has-properties-defined/has-properties-defined.d.ts} +0 -0
package/docs/modules.md CHANGED
@@ -1,316 +1,35 @@
1
- @aligent/microservice-util-lib
1
+ **@aligent/microservice-util-lib**
2
2
 
3
- # @aligent/microservice-util-lib
3
+ ***
4
4
 
5
- ## Table of contents
5
+ # @aligent/microservice-util-lib
6
6
 
7
- ### Classes
7
+ ## Classes
8
8
 
9
9
  - [S3Dao](classes/S3Dao.md)
10
10
 
11
- ### Interfaces
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
- - [getAwsIdFromArn](modules.md#getawsidfromarn)
25
- - [hasDefinedProperties](modules.md#hasdefinedproperties)
26
- - [remap](modules.md#remap-1)
27
- - [retryWrapper](modules.md#retrywrapper)
28
-
29
19
  ## Type Aliases
30
20
 
31
- ### <a id="objectmap" name="objectmap"></a> ObjectMap
32
-
33
- Ƭ **ObjectMap**: readonly readonly [`string`, `string`, Function?][]
34
-
35
- A list of keys to keys, with an optional transformer function
36
-
37
- #### Defined in
38
-
39
- [remap/remap.ts:15](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/src/remap/remap.ts#lines-15)
40
-
41
- ___
42
-
43
- ### <a id="remap" name="remap"></a> Remap
44
-
45
- Ƭ **Remap**<`MapArray`, `Original`\>: `SimplifyIntersection`<`ConstructTypeFromProperties`<`MapArray`, `Original`\>\>
46
-
47
- #### Type parameters
48
-
49
- | Name | Type |
50
- | :------ | :------ |
51
- | `MapArray` | extends [`ObjectMap`](modules.md#objectmap) |
52
- | `Original` | extends `Object` |
53
-
54
- #### Defined in
55
-
56
- [remap/remap.ts:159](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/src/remap/remap.ts#lines-159)
21
+ - [ObjectMap](type-aliases/ObjectMap.md)
22
+ - [Remap](type-aliases/Remap.md)
57
23
 
58
24
  ## Functions
59
25
 
60
- ### <a id="chunkby" name="chunkby"></a> chunkBy
61
-
62
- **chunkBy**<`ArrayItem`\>(`source`, `chunkSize`): `ArrayItem`[][]
63
-
64
- Split an array into chunks of a certain size
65
-
66
- **`Example`**
67
-
68
- ```ts
69
- chunkBy([1, 2, 3, 4, 5, 6, 7], 2) // [[1, 2], [3, 4], [5, 6], [7]]
70
- ```
71
-
72
- #### Type parameters
73
-
74
- | Name |
75
- | :------ |
76
- | `ArrayItem` |
77
-
78
- #### Parameters
79
-
80
- | Name | Type | Description |
81
- | :------ | :------ | :------ |
82
- | `source` | `ArrayItem`[] | the array to split up |
83
- | `chunkSize` | `number` | the size of each chunk. (The final chunk will be whatever is remaining) |
84
-
85
- #### Returns
86
-
87
- `ArrayItem`[][]
88
-
89
- #### Defined in
90
-
91
- [chunkBy/chunkBy.ts:10](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/src/chunkBy/chunkBy.ts#lines-10)
92
-
93
- ___
94
-
95
- ### <a id="fetchssmparams" name="fetchssmparams"></a> fetchSsmParams
96
-
97
- ▸ **fetchSsmParams**(`param`): `Promise`<`Parameter`\>
98
-
99
- Fetch one SSM parameter
100
-
101
- #### Parameters
102
-
103
- | Name | Type | Description |
104
- | :------ | :------ | :------ |
105
- | `param` | `string` | key of the parameter to fetch |
106
-
107
- #### Returns
108
-
109
- `Promise`<`Parameter`\>
110
-
111
- #### Defined in
112
-
113
- [fetchSsmParams/fetchSsmParams.ts:14](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/src/fetchSsmParams/fetchSsmParams.ts#lines-14)
114
-
115
- ▸ **fetchSsmParams**(`...params`): `Promise`<`Parameter`[]\>
116
-
117
- Fetch a list of SSM parameters
118
-
119
- #### Parameters
120
-
121
- | Name | Type | Description |
122
- | :------ | :------ | :------ |
123
- | `...params` | `string`[] | list of parameter keys to fetch |
124
-
125
- #### Returns
126
-
127
- `Promise`<`Parameter`[]\>
128
-
129
- #### Defined in
130
-
131
- [fetchSsmParams/fetchSsmParams.ts:21](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/src/fetchSsmParams/fetchSsmParams.ts#lines-21)
132
-
133
- ___
134
-
135
- ### <a id="getawsidfromarn" name="getawsidfromarn"></a> getAwsIdFromArn
136
-
137
- ▸ **getAwsIdFromArn**(`resourceArn`): `string`
138
-
139
- Get the AWS ID from its resource ARN
140
-
141
- **`Throws`**
142
-
143
- when the provided ARN is empty
144
-
145
- **`Example`**
146
-
147
- ```ts
148
- getAwsIdFromArn('arn:aws:states:ap-southeast-2:123123123:execution:prj-int-entity-ac-dc-dev-machine-name:this-is-the-id')
149
- ```
150
-
151
- #### Parameters
152
-
153
- | Name | Type | Description |
154
- | :------ | :------ | :------ |
155
- | `resourceArn` | `string` | the ARN of the AWS resource |
156
-
157
- #### Returns
158
-
159
- `string`
160
-
161
- the ID (if present in the ARN) of the AWS resource/execution
162
-
163
- #### Defined in
164
-
165
- [getAwsIdFromArn/getAwsIdFromArn.ts:11](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/src/getAwsIdFromArn/getAwsIdFromArn.ts#lines-11)
166
-
167
- ___
168
-
169
- ### <a id="hasdefinedproperties" name="hasdefinedproperties"></a> hasDefinedProperties
170
-
171
- ▸ **hasDefinedProperties**<`T`, `K`\>(`obj`, `...keys`): obj is SimplifyIntersection<Required<Pick<T, K\>\> & Omit<T, K\>\>
172
-
173
- Ensure that the given properties are defined on the object.
174
-
175
- **`Example`**
176
-
177
- ```ts
178
- type Foo = { a?: number; b?: number };
179
- const foo: Foo = { a: 1, b: 2 };
180
- if (hasDefinedProperties(foo, 'a')) {
181
- console.log(foo);
182
- // ^? const bar: {
183
- // a: number;
184
- // b?: number;
185
- // }
186
- }
187
- ```
188
-
189
- #### Type parameters
190
-
191
- | Name | Type |
192
- | :------ | :------ |
193
- | `T` | extends `Object` |
194
- | `K` | extends `string` \| `number` \| `symbol` |
195
-
196
- #### Parameters
197
-
198
- | Name | Type | Description |
199
- | :------ | :------ | :------ |
200
- | `obj` | `object` \| `T` | The object to check. |
201
- | `...keys` | `K`[] | The keys to check. |
202
-
203
- #### Returns
204
-
205
- obj is SimplifyIntersection<Required<Pick<T, K\>\> & Omit<T, K\>\>
206
-
207
- `true` if the object has the given properties defined, `false` otherwise.
208
-
209
- #### Defined in
210
-
211
- [hasPropertiesDefined/hasPropertiesDefined.ts:22](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/src/hasPropertiesDefined/hasPropertiesDefined.ts#lines-22)
212
-
213
- ___
214
-
215
- ### <a id="remap-1" name="remap-1"></a> remap
216
-
217
- ▸ **remap**<`Original`, `MapArray`\>(`object`, `map`): [`Remap`](modules.md#remap)<`MapArray`, `Original`\>
218
-
219
- Map one object's values to another structure
220
-
221
- **`Example`**
222
-
223
- without a transformer function
224
- ```ts
225
- const map = [
226
- ['foo', 'baz'],
227
- ['bar', 'qux.0']
228
- ] as const;
229
- const obj = { foo: 'hi', bar: 7 }
230
- remap(obj, map); // { baz: 'hi', qux: [7] }
231
- ```
232
-
233
- **`Example`**
234
-
235
- with a transformer function
236
- ```ts
237
- const map = [
238
- ['foo', 'baz'],
239
- ['bar', 'qux.0', (x: number) => x + 1]
240
- ] as const;
241
- const obj = { foo: 'hi', bar: 7 }
242
- remap(obj, map); // { baz: 'hi', qux: [8] }
243
- ```
244
-
245
- **`Example`**
246
-
247
- with an empty initial key
248
- ```ts
249
- const map = [
250
- ['', 'baz', (x: { foo: number, bar: number }) => x.foo + x.bar]
251
- ]
252
- const obj = { foo: 3, bar: 7 }
253
- remap(obj, map); // { baz: 10 }
254
- ```
255
-
256
- #### Type parameters
257
-
258
- | Name | Type |
259
- | :------ | :------ |
260
- | `Original` | extends `Object` |
261
- | `MapArray` | extends readonly readonly [`string`, `string`, (...`args`: `any`[]) => `any`][] |
262
-
263
- #### Parameters
264
-
265
- | Name | Type | Description |
266
- | :------ | :------ | :------ |
267
- | `object` | `Original` | the object to map from |
268
- | `map` | `MapArray` | the keys for the mapping |
269
-
270
- #### Returns
271
-
272
- [`Remap`](modules.md#remap)<`MapArray`, `Original`\>
273
-
274
- the remapped object
275
-
276
- #### Defined in
277
-
278
- [remap/remap.ts:198](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/src/remap/remap.ts#lines-198)
279
-
280
- ___
281
-
282
- ### <a id="retrywrapper" name="retrywrapper"></a> retryWrapper
283
-
284
- ▸ **retryWrapper**<`T`\>(`fn`, `config`): `Promise`<`T`\>
285
-
286
- Retry an async function if it fails
287
-
288
- **`Example`**
289
-
290
- ```ts
291
- retryWrapper(someAsyncFunction, {
292
- retries: 3,
293
- onRetry: (_, error) => console.error(error)
294
- });
295
- ```
296
-
297
- #### Type parameters
298
-
299
- | Name |
300
- | :------ |
301
- | `T` |
302
-
303
- #### Parameters
304
-
305
- | Name | Type | Description |
306
- | :------ | :------ | :------ |
307
- | `fn` | () => `Promise`<`T`\> | the function to be retried |
308
- | `config` | [`RetryConfig`](interfaces/RetryConfig.md) | the configuration for retries |
309
-
310
- #### Returns
311
-
312
- `Promise`<`T`\>
313
-
314
- #### Defined in
315
-
316
- [retryWrapper/retryWrapper.ts:78](https://bitbucket.org/aligent/microservice-util-lib/src/5ba81bd/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": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "A set of utility functions for Aligent Microservices",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "build": "tsc && npm run docs",
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": "git+ssh://git@bitbucket.org/aligent/microservice-util-lib.git"
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.332.0",
39
- "@aws-sdk/client-ssm": "^3.332.0",
40
- "axios": "^1.2.1",
41
- "lodash": "^4.17.21",
42
- "object-hash": "^3.0.0"
14
+ "@aws-sdk/client-s3": "^3.922.0",
15
+ "@aws-sdk/client-ssm": "^3.922.0",
16
+ "oauth-sign": "^0.9.0",
17
+ "object-hash": "^3.0.0",
18
+ "openapi-fetch": "^0.15.0"
43
19
  },
44
- "files": [
45
- "dist",
46
- "docs"
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("Cannot create chunks of size ".concat(chunkSize, " (0 or less)"));
14
+ throw new Error(`Cannot create chunks of size ${chunkSize} (0 or less)`);
15
15
  }
16
- var numberOfChunks = Math.ceil(source.length / chunkSize);
17
- return Array.from(new Array(numberOfChunks), function (_, i) {
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
@@ -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;
@@ -10,12 +10,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  * getAwsIdFromArn('arn:aws:states:ap-southeast-2:123123123:execution:prj-int-entity-ac-dc-dev-machine-name:this-is-the-id')
11
11
  * ```
12
12
  */
13
- var getAwsIdFromArn = function (resourceArn) {
13
+ const getAwsIdFromArn = (resourceArn) => {
14
14
  if (resourceArn.length === 0) {
15
15
  throw new Error('Received an empty resourceArn, unable to get an ID.');
16
16
  }
17
- var startIdx = resourceArn.lastIndexOf(':') + 1;
17
+ const startIdx = resourceArn.lastIndexOf(':') + 1;
18
18
  return resourceArn.substring(startIdx);
19
19
  };
20
20
  exports.default = getAwsIdFromArn;
21
- //# sourceMappingURL=getAwsIdFromArn.js.map
@@ -19,13 +19,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  * }
20
20
  * ```
21
21
  */
22
- function hasDefinedProperties(obj) {
23
- var keys = [];
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,11 @@
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 { RetryConfig as RetryMiddlewareConfig, retryMiddleware } from './openapi-fetch-middlewares/retry';
7
+ import remap, { ObjectMap, Remap } from './remap/remap';
8
+ import retryWrapper, { RetryConfig } from './retry-wrapper/retry-wrapper';
9
+ import S3Dao from './s3/s3';
10
+ export type { ApiKey, Basic, OAuth10a, OAuth20, ObjectMap, Remap, RetryConfig, RetryMiddlewareConfig, S3Dao, };
11
+ export { apiKeyAuthMiddleware, basicAuthMiddleware, chunkBy, fetchSsmParams, getAwsIdFromArn, hasDefinedProperties, oAuth10aAuthMiddleware, oAuth20AuthMiddleware, remap, retryMiddleware, retryWrapper, };
package/src/index.js ADDED
@@ -0,0 +1,26 @@
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.retryMiddleware = 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 retry_1 = require("./openapi-fetch-middlewares/retry");
22
+ Object.defineProperty(exports, "retryMiddleware", { enumerable: true, get: function () { return retry_1.retryMiddleware; } });
23
+ const remap_1 = __importDefault(require("./remap/remap"));
24
+ exports.remap = remap_1.default;
25
+ const retry_wrapper_1 = __importDefault(require("./retry-wrapper/retry-wrapper"));
26
+ 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 };