@middy/appconfig 4.2.8 → 5.0.0-alpha.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/index.cjs +35 -14
- package/index.d.ts +7 -7
- package/index.js +35 -14
- package/package.json +6 -6
package/index.cjs
CHANGED
|
@@ -7,9 +7,9 @@ Object.defineProperty(module, "exports", {
|
|
|
7
7
|
get: ()=>_default
|
|
8
8
|
});
|
|
9
9
|
const _util = require("@middy/util");
|
|
10
|
-
const
|
|
10
|
+
const _clientAppconfigdata = require("@aws-sdk/client-appconfigdata");
|
|
11
11
|
const defaults = {
|
|
12
|
-
AwsClient:
|
|
12
|
+
AwsClient: _clientAppconfigdata.AppConfigDataClient,
|
|
13
13
|
awsClientOptions: {},
|
|
14
14
|
awsClientAssumeRole: undefined,
|
|
15
15
|
awsClientCapture: undefined,
|
|
@@ -25,22 +25,43 @@ const appConfigMiddleware = (opts = {})=>{
|
|
|
25
25
|
...defaults,
|
|
26
26
|
...opts
|
|
27
27
|
};
|
|
28
|
+
const configurationTokenCache = {};
|
|
29
|
+
const configurationCache = {};
|
|
30
|
+
function fetchLatestConfiguration(configToken, internalKey) {
|
|
31
|
+
return client.send(new _clientAppconfigdata.GetLatestConfigurationCommand({
|
|
32
|
+
ConfigurationToken: configToken
|
|
33
|
+
})).then((configResp)=>{
|
|
34
|
+
configurationTokenCache[internalKey] = configResp.NextPollConfigurationToken;
|
|
35
|
+
if (configResp.Configuration.length === 0) {
|
|
36
|
+
return configurationCache[internalKey];
|
|
37
|
+
}
|
|
38
|
+
let value = String.fromCharCode.apply(null, configResp.Configuration);
|
|
39
|
+
if (contentTypePattern.test(configResp.ContentType)) {
|
|
40
|
+
value = (0, _util.jsonSafeParse)(value);
|
|
41
|
+
}
|
|
42
|
+
configurationCache[internalKey] = value;
|
|
43
|
+
return value;
|
|
44
|
+
}).catch((e)=>{
|
|
45
|
+
const value = (0, _util.getCache)(options.cacheKey).value ?? {};
|
|
46
|
+
value[internalKey] = undefined;
|
|
47
|
+
(0, _util.modifyCache)(options.cacheKey, value);
|
|
48
|
+
throw e;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
28
51
|
const fetch = (request, cachedValues = {})=>{
|
|
29
52
|
const values = {};
|
|
30
53
|
for (const internalKey of Object.keys(options.fetchData)){
|
|
31
54
|
if (cachedValues[internalKey]) continue;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
value =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
throw e;
|
|
43
|
-
});
|
|
55
|
+
if (configurationTokenCache[internalKey] == null) {
|
|
56
|
+
values[internalKey] = client.send(new _clientAppconfigdata.StartConfigurationSessionCommand(options.fetchData[internalKey])).then((configSessionResp)=>fetchLatestConfiguration(configSessionResp.InitialConfigurationToken, internalKey)).catch((e)=>{
|
|
57
|
+
const value = (0, _util.getCache)(options.cacheKey).value ?? {};
|
|
58
|
+
value[internalKey] = undefined;
|
|
59
|
+
(0, _util.modifyCache)(options.cacheKey, value);
|
|
60
|
+
throw e;
|
|
61
|
+
});
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
values[internalKey] = fetchLatestConfiguration(configurationTokenCache[internalKey], internalKey);
|
|
44
65
|
}
|
|
45
66
|
return values;
|
|
46
67
|
};
|
package/index.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import middy from '@middy/core'
|
|
|
2
2
|
import { Options as MiddyOptions } from '@middy/util'
|
|
3
3
|
import { Context as LambdaContext } from 'aws-lambda'
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '@aws-sdk/client-
|
|
5
|
+
AppConfigDataClient,
|
|
6
|
+
AppConfigDataClientConfig,
|
|
7
|
+
StartConfigurationSessionRequest
|
|
8
|
+
} from '@aws-sdk/client-appconfigdata'
|
|
9
9
|
|
|
10
|
-
export type Options<AwsAppConfigClient =
|
|
11
|
-
= Omit<MiddyOptions<AwsAppConfigClient,
|
|
10
|
+
export type Options<AwsAppConfigClient = AppConfigDataClient>
|
|
11
|
+
= Omit<MiddyOptions<AwsAppConfigClient, AppConfigDataClientConfig>, 'fetchData'>
|
|
12
12
|
& {
|
|
13
13
|
fetchData?: {
|
|
14
|
-
[configurationRequestKey: string]:
|
|
14
|
+
[configurationRequestKey: string]: StartConfigurationSessionRequest
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { canPrefetch, createPrefetchClient, createClient, getCache, getInternal, processCache, modifyCache, jsonSafeParse } from '@middy/util';
|
|
2
|
-
import {
|
|
2
|
+
import { StartConfigurationSessionCommand, GetLatestConfigurationCommand, AppConfigDataClient } from '@aws-sdk/client-appconfigdata';
|
|
3
3
|
const defaults = {
|
|
4
|
-
AwsClient:
|
|
4
|
+
AwsClient: AppConfigDataClient,
|
|
5
5
|
awsClientOptions: {},
|
|
6
6
|
awsClientAssumeRole: undefined,
|
|
7
7
|
awsClientCapture: undefined,
|
|
@@ -17,22 +17,43 @@ const appConfigMiddleware = (opts = {})=>{
|
|
|
17
17
|
...defaults,
|
|
18
18
|
...opts
|
|
19
19
|
};
|
|
20
|
+
const configurationTokenCache = {};
|
|
21
|
+
const configurationCache = {};
|
|
22
|
+
function fetchLatestConfiguration(configToken, internalKey) {
|
|
23
|
+
return client.send(new GetLatestConfigurationCommand({
|
|
24
|
+
ConfigurationToken: configToken
|
|
25
|
+
})).then((configResp)=>{
|
|
26
|
+
configurationTokenCache[internalKey] = configResp.NextPollConfigurationToken;
|
|
27
|
+
if (configResp.Configuration.length === 0) {
|
|
28
|
+
return configurationCache[internalKey];
|
|
29
|
+
}
|
|
30
|
+
let value = String.fromCharCode.apply(null, configResp.Configuration);
|
|
31
|
+
if (contentTypePattern.test(configResp.ContentType)) {
|
|
32
|
+
value = jsonSafeParse(value);
|
|
33
|
+
}
|
|
34
|
+
configurationCache[internalKey] = value;
|
|
35
|
+
return value;
|
|
36
|
+
}).catch((e)=>{
|
|
37
|
+
const value = getCache(options.cacheKey).value ?? {};
|
|
38
|
+
value[internalKey] = undefined;
|
|
39
|
+
modifyCache(options.cacheKey, value);
|
|
40
|
+
throw e;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
20
43
|
const fetch = (request, cachedValues = {})=>{
|
|
21
44
|
const values = {};
|
|
22
45
|
for (const internalKey of Object.keys(options.fetchData)){
|
|
23
46
|
if (cachedValues[internalKey]) continue;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
value =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
throw e;
|
|
35
|
-
});
|
|
47
|
+
if (configurationTokenCache[internalKey] == null) {
|
|
48
|
+
values[internalKey] = client.send(new StartConfigurationSessionCommand(options.fetchData[internalKey])).then((configSessionResp)=>fetchLatestConfiguration(configSessionResp.InitialConfigurationToken, internalKey)).catch((e)=>{
|
|
49
|
+
const value = getCache(options.cacheKey).value ?? {};
|
|
50
|
+
value[internalKey] = undefined;
|
|
51
|
+
modifyCache(options.cacheKey, value);
|
|
52
|
+
throw e;
|
|
53
|
+
});
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
values[internalKey] = fetchLatestConfiguration(configurationTokenCache[internalKey], internalKey);
|
|
36
57
|
}
|
|
37
58
|
return values;
|
|
38
59
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/appconfig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha.0",
|
|
4
4
|
"description": "AppConfig middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=18"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"url": "https://github.com/sponsors/willfarrell"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@middy/util": "
|
|
67
|
+
"@middy/util": "5.0.0-alpha.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@aws-sdk/client-
|
|
71
|
-
"@middy/core": "
|
|
70
|
+
"@aws-sdk/client-appconfigdata": "^3.0.0",
|
|
71
|
+
"@middy/core": "5.0.0-alpha.0",
|
|
72
72
|
"@types/aws-lambda": "^8.10.101",
|
|
73
73
|
"aws-xray-sdk": "^3.3.3"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "08c35e3dba9efdad0b86666ce206ce302cc65d07"
|
|
76
76
|
}
|