@middy/appconfig 6.1.6 → 6.2.1

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 (3) hide show
  1. package/index.d.ts +49 -34
  2. package/index.js +114 -114
  3. package/package.json +65 -68
package/index.d.ts CHANGED
@@ -1,44 +1,59 @@
1
- import middy from '@middy/core'
2
- import { Options as MiddyOptions } from '@middy/util'
3
- import { Context as LambdaContext } from 'aws-lambda'
4
- import {
5
- AppConfigDataClient,
6
- AppConfigDataClientConfig,
7
- StartConfigurationSessionRequest
8
- } from '@aws-sdk/client-appconfigdata'
1
+ import type {
2
+ AppConfigDataClient,
3
+ AppConfigDataClientConfig,
4
+ StartConfigurationSessionRequest,
5
+ } from "@aws-sdk/client-appconfigdata";
6
+ import type middy from "@middy/core";
7
+ import type { Options as MiddyOptions } from "@middy/util";
8
+ import type { Context as LambdaContext } from "aws-lambda";
9
9
 
10
- export type ParamType<T> = StartConfigurationSessionRequest & { __returnType?: T }
11
- export declare function appConfigReq<T> (req: StartConfigurationSessionRequest): ParamType<T>
10
+ export type ParamType<T> = StartConfigurationSessionRequest & {
11
+ __returnType?: T;
12
+ };
13
+ export declare function appConfigReq<T>(
14
+ req: StartConfigurationSessionRequest,
15
+ ): ParamType<T>;
12
16
 
13
17
  export interface AppConfigOptions<AwsAppConfigClient = AppConfigDataClient>
14
- extends Omit<MiddyOptions<AwsAppConfigClient, AppConfigDataClientConfig>, 'fetchData'> {
15
- fetchData?: { [key: string]: StartConfigurationSessionRequest | ParamType<unknown> }
18
+ extends Omit<
19
+ MiddyOptions<AwsAppConfigClient, AppConfigDataClientConfig>,
20
+ "fetchData"
21
+ > {
22
+ fetchData?: {
23
+ [key: string]: StartConfigurationSessionRequest | ParamType<unknown>;
24
+ };
16
25
  }
17
26
 
18
27
  export type Context<TOptions extends AppConfigOptions | undefined> =
19
- TOptions extends { setToContext: true }
20
- ? TOptions extends { fetchData: infer TFetchData }
21
- ? LambdaContext & {
22
- [Key in keyof TFetchData]: TFetchData[Key] extends ParamType<infer T>
23
- ? T
24
- : unknown
25
- }
26
- : never
27
- : LambdaContext
28
+ TOptions extends { setToContext: true }
29
+ ? TOptions extends { fetchData: infer TFetchData }
30
+ ? LambdaContext & {
31
+ [Key in keyof TFetchData]: TFetchData[Key] extends ParamType<infer T>
32
+ ? T
33
+ : unknown;
34
+ }
35
+ : never
36
+ : LambdaContext;
28
37
 
29
38
  export type Internal<TOptions extends AppConfigOptions | undefined> =
30
- TOptions extends AppConfigOptions
31
- ? TOptions extends { fetchData: infer TFetchData }
32
- ? {
33
- [Key in keyof TFetchData]: TFetchData[Key] extends ParamType<infer T>
34
- ? T
35
- : unknown
36
- }
37
- : {}
38
- : {}
39
+ TOptions extends AppConfigOptions
40
+ ? TOptions extends { fetchData: infer TFetchData }
41
+ ? {
42
+ [Key in keyof TFetchData]: TFetchData[Key] extends ParamType<infer T>
43
+ ? T
44
+ : unknown;
45
+ }
46
+ : {}
47
+ : {};
39
48
 
40
- declare function appConfigMiddleware<TOptions extends AppConfigOptions> (
41
- options?: TOptions
42
- ): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>, Internal<TOptions>>
49
+ declare function appConfigMiddleware<TOptions extends AppConfigOptions>(
50
+ options?: TOptions,
51
+ ): middy.MiddlewareObj<
52
+ unknown,
53
+ any,
54
+ Error,
55
+ Context<TOptions>,
56
+ Internal<TOptions>
57
+ >;
43
58
 
44
- export default appConfigMiddleware
59
+ export default appConfigMiddleware;
package/index.js CHANGED
@@ -1,129 +1,129 @@
1
1
  import {
2
- canPrefetch,
3
- createPrefetchClient,
4
- createClient,
5
- getCache,
6
- getInternal,
7
- processCache,
8
- modifyCache,
9
- jsonSafeParse,
10
- catchInvalidSignatureException
11
- } from '@middy/util'
2
+ AppConfigDataClient,
3
+ GetLatestConfigurationCommand,
4
+ StartConfigurationSessionCommand,
5
+ } from "@aws-sdk/client-appconfigdata";
12
6
  import {
13
- StartConfigurationSessionCommand,
14
- GetLatestConfigurationCommand,
15
- AppConfigDataClient
16
- } from '@aws-sdk/client-appconfigdata'
7
+ canPrefetch,
8
+ catchInvalidSignatureException,
9
+ createClient,
10
+ createPrefetchClient,
11
+ getCache,
12
+ getInternal,
13
+ jsonSafeParse,
14
+ modifyCache,
15
+ processCache,
16
+ } from "@middy/util";
17
17
 
18
18
  const defaults = {
19
- AwsClient: AppConfigDataClient,
20
- awsClientOptions: {},
21
- awsClientAssumeRole: undefined,
22
- awsClientCapture: undefined,
23
- fetchData: {},
24
- disablePrefetch: false,
25
- cacheKey: 'appconfig',
26
- cacheKeyExpiry: {},
27
- cacheExpiry: -1,
28
- setToContext: false
29
- }
30
- const contentTypePattern = /^application\/(.+\+)?json($|;.+)/
19
+ AwsClient: AppConfigDataClient,
20
+ awsClientOptions: {},
21
+ awsClientAssumeRole: undefined,
22
+ awsClientCapture: undefined,
23
+ fetchData: {},
24
+ disablePrefetch: false,
25
+ cacheKey: "appconfig",
26
+ cacheKeyExpiry: {},
27
+ cacheExpiry: -1,
28
+ setToContext: false,
29
+ };
30
+ const contentTypePattern = /^application\/(.+\+)?json($|;.+)/;
31
31
  const appConfigMiddleware = (opts = {}) => {
32
- const options = {
33
- ...defaults,
34
- ...opts
35
- }
36
- const configurationTokenCache = {}
37
- const configurationCache = {}
32
+ const options = {
33
+ ...defaults,
34
+ ...opts,
35
+ };
36
+ const configurationTokenCache = {};
37
+ const configurationCache = {};
38
38
 
39
- function fetchLatestConfigurationRequest (configToken, internalKey) {
40
- const command = new GetLatestConfigurationCommand({
41
- ConfigurationToken: configToken
42
- })
43
- return client
44
- .send(command)
45
- .catch((e) => catchInvalidSignatureException(e, client, command))
46
- .then((configResp) => {
47
- configurationTokenCache[internalKey] =
48
- configResp.NextPollConfigurationToken
39
+ function fetchLatestConfigurationRequest(configToken, internalKey) {
40
+ const command = new GetLatestConfigurationCommand({
41
+ ConfigurationToken: configToken,
42
+ });
43
+ return client
44
+ .send(command)
45
+ .catch((e) => catchInvalidSignatureException(e, client, command))
46
+ .then((configResp) => {
47
+ configurationTokenCache[internalKey] =
48
+ configResp.NextPollConfigurationToken;
49
49
 
50
- if (configResp.Configuration.length === 0) {
51
- return configurationCache[internalKey]
52
- }
50
+ if (configResp.Configuration.length === 0) {
51
+ return configurationCache[internalKey];
52
+ }
53
53
 
54
- let value = String.fromCharCode.apply(null, configResp.Configuration)
55
- if (contentTypePattern.test(configResp.ContentType)) {
56
- value = jsonSafeParse(value)
57
- }
58
- configurationCache[internalKey] = value
59
- return value
60
- })
61
- .catch((e) => {
62
- const value = getCache(options.cacheKey).value ?? {}
63
- value[internalKey] = undefined
64
- modifyCache(options.cacheKey, value)
65
- throw e
66
- })
67
- }
54
+ let value = String.fromCharCode.apply(null, configResp.Configuration);
55
+ if (contentTypePattern.test(configResp.ContentType)) {
56
+ value = jsonSafeParse(value);
57
+ }
58
+ configurationCache[internalKey] = value;
59
+ return value;
60
+ })
61
+ .catch((e) => {
62
+ const value = getCache(options.cacheKey).value ?? {};
63
+ value[internalKey] = undefined;
64
+ modifyCache(options.cacheKey, value);
65
+ throw e;
66
+ });
67
+ }
68
68
 
69
- const fetchRequest = (request, cachedValues = {}) => {
70
- const values = {}
71
- for (const internalKey of Object.keys(options.fetchData)) {
72
- if (cachedValues[internalKey]) continue
73
- if (configurationTokenCache[internalKey] == null) {
74
- const command = new StartConfigurationSessionCommand(
75
- options.fetchData[internalKey]
76
- )
77
- values[internalKey] = client
78
- .send(command)
79
- .catch((e) => catchInvalidSignatureException(e, client, command))
80
- .then((configSessionResp) =>
81
- fetchLatestConfigurationRequest(
82
- configSessionResp.InitialConfigurationToken,
83
- internalKey
84
- )
85
- )
86
- .catch((e) => {
87
- const value = getCache(options.cacheKey).value ?? {}
88
- value[internalKey] = undefined
89
- modifyCache(options.cacheKey, value)
90
- throw e
91
- })
69
+ const fetchRequest = (request, cachedValues = {}) => {
70
+ const values = {};
71
+ for (const internalKey of Object.keys(options.fetchData)) {
72
+ if (cachedValues[internalKey]) continue;
73
+ if (configurationTokenCache[internalKey] == null) {
74
+ const command = new StartConfigurationSessionCommand(
75
+ options.fetchData[internalKey],
76
+ );
77
+ values[internalKey] = client
78
+ .send(command)
79
+ .catch((e) => catchInvalidSignatureException(e, client, command))
80
+ .then((configSessionResp) =>
81
+ fetchLatestConfigurationRequest(
82
+ configSessionResp.InitialConfigurationToken,
83
+ internalKey,
84
+ ),
85
+ )
86
+ .catch((e) => {
87
+ const value = getCache(options.cacheKey).value ?? {};
88
+ value[internalKey] = undefined;
89
+ modifyCache(options.cacheKey, value);
90
+ throw e;
91
+ });
92
92
 
93
- continue
94
- }
95
- values[internalKey] = fetchLatestConfigurationRequest(
96
- configurationTokenCache[internalKey],
97
- internalKey
98
- )
99
- }
100
- return values
101
- }
102
- let client
103
- if (canPrefetch(options)) {
104
- client = createPrefetchClient(options)
105
- processCache(options, fetchRequest)
106
- }
107
- const appConfigMiddlewareBefore = async (request) => {
108
- if (!client) {
109
- client = await createClient(options, request)
110
- }
111
- const { value } = processCache(options, fetchRequest, request)
112
- Object.assign(request.internal, value)
113
- if (options.setToContext) {
114
- const data = await getInternal(Object.keys(options.fetchData), request)
115
- Object.assign(request.context, data)
116
- }
117
- }
118
- return {
119
- before: appConfigMiddlewareBefore
120
- }
121
- }
122
- export default appConfigMiddleware
93
+ continue;
94
+ }
95
+ values[internalKey] = fetchLatestConfigurationRequest(
96
+ configurationTokenCache[internalKey],
97
+ internalKey,
98
+ );
99
+ }
100
+ return values;
101
+ };
102
+ let client;
103
+ if (canPrefetch(options)) {
104
+ client = createPrefetchClient(options);
105
+ processCache(options, fetchRequest);
106
+ }
107
+ const appConfigMiddlewareBefore = async (request) => {
108
+ if (!client) {
109
+ client = await createClient(options, request);
110
+ }
111
+ const { value } = processCache(options, fetchRequest, request);
112
+ Object.assign(request.internal, value);
113
+ if (options.setToContext) {
114
+ const data = await getInternal(Object.keys(options.fetchData), request);
115
+ Object.assign(request.context, data);
116
+ }
117
+ };
118
+ return {
119
+ before: appConfigMiddlewareBefore,
120
+ };
121
+ };
122
+ export default appConfigMiddleware;
123
123
 
124
124
  // used for TS type inference (see index.d.ts)
125
- export function appConfigReq (req) {
126
- return req
125
+ export function appConfigReq(req) {
126
+ return req;
127
127
  }
128
128
 
129
129
  // # sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,70 +1,67 @@
1
1
  {
2
- "name": "@middy/appconfig",
3
- "version": "6.1.6",
4
- "description": "AppConfig middleware for the middy framework",
5
- "type": "module",
6
- "engines": {
7
- "node": ">=20"
8
- },
9
- "engineStrict": true,
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "module": "./index.js",
14
- "exports": {
15
- ".": {
16
- "import": {
17
- "types": "./index.d.ts",
18
- "default": "./index.js"
19
- },
20
- "require": {
21
- "default": "./index.js"
22
- }
23
- }
24
- },
25
- "types": "index.d.ts",
26
- "files": [
27
- "index.js",
28
- "index.d.ts"
29
- ],
30
- "scripts": {
31
- "test": "npm run test:unit && npm run test:fuzz",
32
- "test:unit": "node --test __tests__/index.js",
33
- "test:fuzz": "node --test __tests__/fuzz.js",
34
- "test:benchmark": "node __benchmarks__/index.js"
35
- },
36
- "license": "MIT",
37
- "keywords": [
38
- "Lambda",
39
- "Middleware",
40
- "Serverless",
41
- "Framework",
42
- "AWS",
43
- "AWS Lambda",
44
- "Middy",
45
- "AppConfig"
46
- ],
47
- "author": {
48
- "name": "Middy contributors",
49
- "url": "https://github.com/middyjs/middy/graphs/contributors"
50
- },
51
- "repository": {
52
- "type": "git",
53
- "url": "git+https://github.com/middyjs/middy.git",
54
- "directory": "packages/appconfig"
55
- },
56
- "bugs": {
57
- "url": "https://github.com/middyjs/middy/issues"
58
- },
59
- "homepage": "https://middy.js.org",
60
- "funding": {
61
- "type": "github",
62
- "url": "https://github.com/sponsors/willfarrell"
63
- },
64
- "devDependencies": {
65
- "@aws-sdk/client-appconfigdata": "^3.0.0",
66
- "@types/aws-lambda": "^8.10.101",
67
- "aws-xray-sdk": "^3.3.3"
68
- },
69
- "gitHead": "4780887d818be31d9b6f1e2ced99c954d11a4a81"
2
+ "name": "@middy/appconfig",
3
+ "version": "6.2.1",
4
+ "description": "AppConfig middleware for the middy framework",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
9
+ "engineStrict": true,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "module": "./index.js",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./index.d.ts",
18
+ "default": "./index.js"
19
+ },
20
+ "require": {
21
+ "default": "./index.js"
22
+ }
23
+ }
24
+ },
25
+ "types": "index.d.ts",
26
+ "files": ["index.js", "index.d.ts"],
27
+ "scripts": {
28
+ "test": "npm run test:unit && npm run test:fuzz",
29
+ "test:unit": "node --test",
30
+ "test:fuzz": "node --test index.fuzz.js",
31
+ "test:perf": "node --test index.perf.js"
32
+ },
33
+ "license": "MIT",
34
+ "keywords": [
35
+ "Lambda",
36
+ "Middleware",
37
+ "Serverless",
38
+ "Framework",
39
+ "AWS",
40
+ "AWS Lambda",
41
+ "Middy",
42
+ "AppConfig"
43
+ ],
44
+ "author": {
45
+ "name": "Middy contributors",
46
+ "url": "https://github.com/middyjs/middy/graphs/contributors"
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/middyjs/middy.git",
51
+ "directory": "packages/appconfig"
52
+ },
53
+ "bugs": {
54
+ "url": "https://github.com/middyjs/middy/issues"
55
+ },
56
+ "homepage": "https://middy.js.org",
57
+ "funding": {
58
+ "type": "github",
59
+ "url": "https://github.com/sponsors/willfarrell"
60
+ },
61
+ "devDependencies": {
62
+ "@aws-sdk/client-appconfigdata": "^3.0.0",
63
+ "@types/aws-lambda": "^8.10.101",
64
+ "aws-xray-sdk": "^3.3.3"
65
+ },
66
+ "gitHead": "4780887d818be31d9b6f1e2ced99c954d11a4a81"
70
67
  }