File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed
packages/util-user-agent-node/src Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -54,4 +54,14 @@ describe("defaultUserAgent", () => {
54
54
const userAgent = await defaultUserAgent ( { serviceId : "s3" , clientVersion : "0.1.0" } ) ( ) ;
55
55
expect ( userAgent ) . toContainEqual ( [ `app/${ appId } ` ] ) ;
56
56
} ) ;
57
+
58
+ it ( "should memoize app id" , async ( ) => {
59
+ mockAppIdLoader . mockClear ( ) ;
60
+ const appId = "appId12345" ;
61
+ mockAppIdLoader . mockResolvedValue ( appId ) ;
62
+ const userAgnetProvider = defaultUserAgent ( { serviceId : "s3" , clientVersion : "0.1.0" } ) ;
63
+ await userAgnetProvider ( ) ;
64
+ await userAgnetProvider ( ) ;
65
+ expect ( mockAppIdLoader ) . toBeCalledTimes ( 1 ) ;
66
+ } ) ;
57
67
} ) ;
Original file line number Diff line number Diff line change @@ -14,10 +14,7 @@ interface DefaultUserAgentOptions {
14
14
/**
15
15
* Collect metrics from runtime to put into user agent.
16
16
*/
17
- export const defaultUserAgent = ( {
18
- serviceId,
19
- clientVersion,
20
- } : DefaultUserAgentOptions ) : Provider < UserAgent > => async ( ) => {
17
+ export const defaultUserAgent = ( { serviceId, clientVersion } : DefaultUserAgentOptions ) : Provider < UserAgent > => {
21
18
const sections : UserAgent = [
22
19
// sdk-metadata
23
20
[ "aws-sdk-js" , clientVersion ] ,
@@ -40,14 +37,17 @@ export const defaultUserAgent = ({
40
37
sections . push ( [ `exec-env/${ env . AWS_EXECUTION_ENV } ` ] ) ;
41
38
}
42
39
43
- const appId = await loadConfig < string | undefined > ( {
40
+ const appIdPromise = loadConfig < string | undefined > ( {
44
41
environmentVariableSelector : ( env ) => env [ UA_APP_ID_ENV_NAME ] ,
45
42
configFileSelector : ( profile ) => profile [ UA_APP_ID_INI_NAME ] ,
46
43
default : undefined ,
47
44
} ) ( ) ;
48
- if ( appId ) {
49
- sections . push ( [ `app/${ appId } ` ] ) ;
50
- }
51
45
52
- return sections ;
46
+ return async ( ) => {
47
+ const appId = await appIdPromise ;
48
+ if ( appId ) {
49
+ sections . push ( [ `app/${ appId } ` ] ) ;
50
+ }
51
+ return sections ;
52
+ } ;
53
53
} ;
You can’t perform that action at this time.
0 commit comments