@@ -7,17 +7,17 @@ import { GetParameterError, TransformParameterError } from './Exceptions';
7
7
import type { BaseProviderInterface , GetMultipleOptionsInterface , GetOptionsInterface , TransformOptions } from './types' ;
8
8
import type { SSMGetOptionsInterface , SSMGetMultipleOptionsInterface } from './types/SSMProvider' ;
9
9
10
- // These providers will be dynamically initialized on first use of the helper functions
11
- const DEFAULT_PROVIDERS : { [ key : string ] : BaseProvider } = { } ;
10
+ // These providers are dinamycally intialized on first use of the helper functions
11
+ const DEFAULT_PROVIDERS : Record < string , BaseProvider > = { } ;
12
12
13
13
abstract class BaseProvider implements BaseProviderInterface {
14
14
protected store : Map < string , ExpirableValue > ;
15
15
16
- public constructor ( ) {
16
+ public constructor ( ) {
17
17
this . store = new Map ( ) ;
18
18
}
19
19
20
- public addToCache ( key : string , value : string | Record < string , unknown > , maxAge : number ) : void {
20
+ public addToCache ( key : string , value : string | Uint8Array | Record < string , unknown > , maxAge : number ) : void {
21
21
if ( maxAge <= 0 ) return ;
22
22
23
23
this . store . set ( key , new ExpirableValue ( value , maxAge ) ) ;
@@ -26,7 +26,7 @@ abstract class BaseProvider implements BaseProviderInterface {
26
26
public clearCache ( ) : void {
27
27
this . store . clear ( ) ;
28
28
}
29
-
29
+
30
30
/**
31
31
* Retrieve a parameter value or return the cached value
32
32
*
@@ -42,7 +42,7 @@ abstract class BaseProvider implements BaseProviderInterface {
42
42
* @param {GetOptionsInterface|SSMGetOptionsInterface } options - Options to configure maximum age, trasformation, AWS SDK options, or force fetch
43
43
*/
44
44
public async get ( name : string , options ?: SSMGetOptionsInterface ) : Promise < undefined | string | Record < string , unknown > > ;
45
- public async get ( name : string , options ?: GetOptionsInterface ) : Promise < undefined | string | Record < string , unknown > > {
45
+ public async get ( name : string , options ?: GetOptionsInterface ) : Promise < undefined | string | Uint8Array | Record < string , unknown > > {
46
46
const configs = new GetOptions ( options ) ;
47
47
const key = [ name , configs . transform ] . toString ( ) ;
48
48
@@ -82,7 +82,7 @@ abstract class BaseProvider implements BaseProviderInterface {
82
82
return this . store . get ( key ) ! . value as Record < string , unknown > ;
83
83
}
84
84
85
- let values : Record < string , unknown > = { } ;
85
+ let values = { } ;
86
86
try {
87
87
values = await this . _getMultiple ( path , options ) ;
88
88
} catch ( error ) {
@@ -119,44 +119,51 @@ abstract class BaseProvider implements BaseProviderInterface {
119
119
* Retrieve parameter value from the underlying parameter store
120
120
*
121
121
* @param {string } name - Parameter name
122
- * @param {unknown } sdkOptions - Options to pass to the underlying AWS SDK
122
+ * @param {unknown } options - Options to pass to the underlying implemented method
123
123
*/
124
- protected abstract _get ( name : string , sdkOptions ?: unknown ) : Promise < string | undefined > ;
124
+ protected abstract _get ( name : string , options ?: unknown ) : Promise < string | Uint8Array | undefined > ;
125
125
126
- protected abstract _getMultiple ( path : string , sdkOptions ?: unknown ) : Promise < Record < string , string | undefined > > ;
126
+ /**
127
+ * Retrieve multiple parameter values from the underlying parameter store
128
+ *
129
+ * @param {string } path - Parameter name
130
+ * @param {unknown } options - Options to pass to the underlying implementated method
131
+ */
132
+ protected abstract _getMultiple ( path : string , options ?: unknown ) : Promise < Record < string , string | undefined > > ;
127
133
128
134
}
129
135
130
- // TODO: revisit `value` type once we are clearer on the types returned by the various SDKs
131
- const transformValue = ( value : unknown , transform : TransformOptions , throwOnTransformError : boolean , key : string = '' ) : string | Record < string , unknown > | undefined => {
136
+ const transformValue = ( value : string | Uint8Array | undefined , transform : TransformOptions , throwOnTransformError : boolean , key : string = '' ) : string | Record < string , unknown > | undefined => {
132
137
try {
133
138
const normalizedTransform = transform . toLowerCase ( ) ;
134
139
if (
135
140
( normalizedTransform === TRANSFORM_METHOD_JSON ||
136
- ( normalizedTransform === 'auto' && key . toLowerCase ( ) . endsWith ( `.${ TRANSFORM_METHOD_JSON } ` ) ) ) &&
141
+ ( normalizedTransform === 'auto' && key . toLowerCase ( ) . endsWith ( `.${ TRANSFORM_METHOD_JSON } ` ) ) ) &&
137
142
typeof value === 'string'
138
143
) {
139
144
return JSON . parse ( value ) as Record < string , unknown > ;
140
145
} else if (
141
146
( normalizedTransform === TRANSFORM_METHOD_BINARY ||
142
- ( normalizedTransform === 'auto' && key . toLowerCase ( ) . endsWith ( `.${ TRANSFORM_METHOD_BINARY } ` ) ) ) &&
143
- typeof value === 'string'
147
+ ( normalizedTransform === 'auto' && key . toLowerCase ( ) . endsWith ( `.${ TRANSFORM_METHOD_BINARY } ` ) ) )
144
148
) {
145
- return new TextDecoder ( 'utf-8' ) . decode ( fromBase64 ( value ) ) ;
149
+ if ( typeof value === 'string' ) {
150
+ return new TextDecoder ( 'utf-8' ) . decode ( fromBase64 ( value ) ) ;
151
+ } else {
152
+ return new TextDecoder ( 'utf-8' ) . decode ( value ) ;
153
+ }
146
154
} else {
147
- // TODO: revisit this type once we are clearer on types returned by SDKs
148
155
return value as string ;
149
156
}
150
157
} catch ( error ) {
151
158
if ( throwOnTransformError )
152
159
throw new TransformParameterError ( transform , ( error as Error ) . message ) ;
153
-
160
+
154
161
return ;
155
162
}
156
163
} ;
157
164
158
- const transformValues = ( value : Record < string , unknown > , transform : TransformOptions , throwOnTransformError : boolean ) : Record < string , unknown > => {
159
- const transformedValues : Record < string , unknown > = { } ;
165
+ const transformValues = ( value : Record < string , string | undefined > , transform : TransformOptions , throwOnTransformError : boolean ) : Record < string , string | Record < string , unknown > | undefined > => {
166
+ const transformedValues : Record < string , string | Record < string , unknown > | undefined > = { } ;
160
167
for ( const [ entryKey , entryValue ] of Object . entries ( value ) ) {
161
168
try {
162
169
transformedValues [ entryKey ] = transformValue ( entryValue , transform , throwOnTransformError , entryKey ) ;
0 commit comments