@middy/util 7.0.0-alpha.1 → 7.0.0-alpha.3

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/README.md +25 -32
  2. package/index.js +43 -0
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -2,38 +2,31 @@
2
2
  <h1>Middy Utilities</h1>
3
3
  <img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.svg"/>
4
4
  <p><strong>Util component of the middy middleware, the stylish Node.js middleware engine for AWS Lambda</strong></p>
5
- <p>
6
- <a href="https://www.npmjs.com/package/@middy/util?activeTab=versions">
7
- <img src="https://badge.fury.io/js/%40middy%2Futil.svg" alt="npm version" style="max-width:100%;">
8
- </a>
9
- <a href="https://packagephobia.com/result?p=@middy/util">
10
- <img src="https://packagephobia.com/badge?p=@middy/util" alt="npm install size" style="max-width:100%;">
11
- </a>
12
- <a href="https://github.com/middyjs/middy/actions/workflows/tests.yml">
13
- <img src="https://github.com/middyjs/middy/actions/workflows/tests.yml/badge.svg?branch=main&event=push" alt="GitHub Actions CI status badge" style="max-width:100%;">
14
- </a>
15
- <br/>
16
- <a href="https://standardjs.com/">
17
- <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
18
- </a>
19
- <a href="https://snyk.io/test/github/middyjs/middy">
20
- <img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
21
- </a>
22
- <a href="https://github.com/middyjs/middy/actions/workflows/sast.yml">
23
- <img src="https://github.com/middyjs/middy/actions/workflows/sast.yml/badge.svg
24
- ?branch=main&event=push" alt="CodeQL" style="max-width:100%;">
25
- </a>
26
- <a href="https://bestpractices.coreinfrastructure.org/projects/5280">
27
- <img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
28
- </a>
29
- <br/>
30
- <a href="https://gitter.im/middyjs/Lobby">
31
- <img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
32
- </a>
33
- <a href="https://stackoverflow.com/questions/tagged/middy?sort=Newest&uqlId=35052">
34
- <img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
35
- </a>
36
- </p>
5
+ <p>
6
+ <a href="https://github.com/middyjs/middy/actions/workflows/test-unit.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-unit.yml/badge.svg" alt="GitHub Actions unit test status"></a>
7
+ <a href="https://github.com/middyjs/middy/actions/workflows/test-dast.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-dast.yml/badge.svg" alt="GitHub Actions dast test status"></a>
8
+ <a href="https://github.com/middyjs/middy/actions/workflows/test-perf.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-pref.yml/badge.svg" alt="GitHub Actions perf test status"></a>
9
+ <a href="https://github.com/middyjs/middy/actions/workflows/test-sast.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-sast.yml/badge.svg" alt="GitHub Actions SAST test status"></a>
10
+ <a href="https://github.com/middyjs/middy/actions/workflows/test-lint.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-lint.yml/badge.svg" alt="GitHub Actions lint test status"></a>
11
+ <br/>
12
+ <a href="https://www.npmjs.com/package/@middy/util"><img alt="npm version" src="https://img.shields.io/npm/v/@middy/util.svg"></a>
13
+ <a href="https://packagephobia.com/result?p=@middy/util"><img src="https://packagephobia.com/badge?p=@middy/util" alt="npm install size"></a>
14
+ <a href="https://www.npmjs.com/package/@middy/util">
15
+ <img alt="npm weekly downloads" src="https://img.shields.io/npm/dw/@middy/util.svg"></a>
16
+ <a href="https://www.npmjs.com/package/@middy/util#provenance">
17
+ <img alt="npm provenance" src="https://img.shields.io/badge/provenance-Yes-brightgreen"></a>
18
+ <br/>
19
+ <a href="https://scorecard.dev/viewer/?uri=github.com/middyjs/middy"><img src="https://api.scorecard.dev/projects/github.com/middyjs/middy/badge" alt="Open Source Security Foundation (OpenSSF) Scorecard"></a>
20
+ <a href="https://slsa.dev"><img src="https://slsa.dev/images/gh-badge-level3.svg" alt="SLSA 3"></a>
21
+ <a href="https://github.com/middyjs/middy/blob/main/docs/CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg"></a>
22
+ <a href="https://biomejs.dev"><img alt="Checked with Biome" src="https://img.shields.io/badge/Checked_with-Biome-60a5fa?style=flat&logo=biome"></a>
23
+ <a href="https://conventionalcommits.org"><img alt="Conventional Commits" src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white"></a>
24
+ <a href="https://github.com/middyjs/middy/blob/main/package.json#L32">
25
+ <img alt="code coverage" src="https://img.shields.io/badge/code%20coverage-95%25-brightgreen"></a>
26
+ <br/>
27
+ <a href="https://gitter.im/middyjs/Lobby"><img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;"></a>
28
+ <a href="https://stackoverflow.com/questions/tagged/middy?sort=Newest&uqlId=35052"><img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;"></a>
29
+ </p>
37
30
  <p>You can read the documentation at: <a href="https://middy.js.org/docs/intro/utilities">https://middy.js.org/docs/intro/utilities</a></p>
38
31
  </div>
39
32
 
package/index.js CHANGED
@@ -174,6 +174,49 @@ export const clearCache = (inputKeys = null) => {
174
174
  }
175
175
  };
176
176
 
177
+ // context
178
+ // https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html
179
+ export const lambdaContextKeys = [
180
+ "functionName",
181
+ "functionVersion",
182
+ "invokedFunctionArn",
183
+ "memoryLimitInMB",
184
+ "awsRequestId",
185
+ "logGroupName",
186
+ "logStreamName",
187
+ "identity",
188
+ "clientContext",
189
+ "callbackWaitsForEmptyEventLoop",
190
+ ];
191
+
192
+ export const executionContextKeys = [
193
+ //'requestId',
194
+ "tenantId",
195
+ ];
196
+
197
+ export const isExecutionModeDurable = (context) => {
198
+ // using `context instanceof DurableContextImpl` would be better
199
+ // but would require an extra dependency
200
+ if (context.constructor.name === "DurableContextImpl") {
201
+ return true;
202
+ }
203
+ return false;
204
+ };
205
+
206
+ export const executionContext = (key, context) => {
207
+ if (isExecutionModeDurable(context)) {
208
+ return request.context.executionContext[key];
209
+ }
210
+ return request.context[key];
211
+ };
212
+
213
+ export const lambdaContext = (key, context) => {
214
+ if (isExecutionModeDurable(context)) {
215
+ return request.context.lambdaContext[key];
216
+ }
217
+ return request.context[key];
218
+ };
219
+
177
220
  export const jsonSafeParse = (text, reviver) => {
178
221
  if (typeof text !== "string") return text;
179
222
  const firstChar = text[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/util",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.3",
4
4
  "description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "@aws-sdk/client-ssm": "^3.0.0",
62
- "@middy/core": "7.0.0-alpha.1",
62
+ "@middy/core": "7.0.0-alpha.3",
63
63
  "@types/aws-lambda": "^8.10.76",
64
64
  "@types/node": "^22.0.0",
65
65
  "aws-xray-sdk": "^3.3.3"