diff --git a/404.html b/404.html index 17aaad9c9..9f05d6699 100644 --- a/404.html +++ b/404.html @@ -4,13 +4,13 @@ Page Not Found | Middy.js - - + +
Skip to main content

404

Sorry, we could not find what you were looking for!

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

Go to the homeRead the docs

- - + + \ No newline at end of file diff --git a/assets/js/01c9695c.eac1e659.js b/assets/js/01c9695c.abfd7136.js similarity index 99% rename from assets/js/01c9695c.eac1e659.js rename to assets/js/01c9695c.abfd7136.js index 2d5c26703..a14192fd6 100644 --- a/assets/js/01c9695c.eac1e659.js +++ b/assets/js/01c9695c.abfd7136.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3295],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>b});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function l(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var s=n.createContext({}),u=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},d=function(e){var t=u(e.components);return n.createElement(s.Provider,{value:t},e.children)},p="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),p=u(r),m=a,b=p["".concat(s,".").concat(m)]||p[m]||c[m]||o;return r?n.createElement(b,l(l({ref:t},d),{},{components:r})):n.createElement(b,l({ref:t},d))}));function b(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,l=new Array(o);l[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[p]="string"==typeof e?e:a,l[1]=i;for(var u=2;u{r.d(t,{Z:()=>l});var n=r(7294),a=r(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:r,className:l}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(o.tabItem,l),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7462),a=r(7294),o=r(6010),l=r(2466),i=r(6550),s=r(1980),u=r(7392),d=r(12);function p(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function c(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??p(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:r}=e;const n=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(o),(0,a.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(n.location.search);t.set(o,e),n.replace({...n.location,search:t.toString()})}),[o,n])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,o=c(e),[l,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[s,u]=b({queryString:r,groupId:n}),[p,h]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,o]=(0,d.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&o.set(e)}),[r,o])]}({groupId:n}),f=(()=>{const e=s??p;return m({value:e,tabValues:o})?e:null})();(0,a.useLayoutEffect)((()=>{f&&i(f)}),[f]);return{selectedValue:l,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),h(e)}),[u,h,o]),tabValues:o}}var f=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:i,selectValue:s,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:p}=(0,l.o5)(),c=e=>{const t=e.currentTarget,r=d.indexOf(t),n=u[r].value;n!==i&&(p(t),s(n))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:l}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:c},l,{className:(0,o.Z)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":i===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:n}=e;const o=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function k(e){const t=h(e);return a.createElement("div",{className:(0,o.Z)("tabs-container",y.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(g,(0,n.Z)({},e,t)))}function w(e){const t=(0,f.Z)();return a.createElement(k,(0,n.Z)({key:String(t)},e))}},4284:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>b,frontMatter:()=>i,metadata:()=>u,toc:()=>p});var n=r(7462),a=(r(7294),r(3905)),o=r(4866),l=r(5162);const i={title:"http-json-body-parser"},s=void 0,u={unversionedId:"middlewares/http-json-body-parser",id:"middlewares/http-json-body-parser",title:"http-json-body-parser",description:"This middleware automatically parses HTTP requests with a JSON body and converts the body into an",source:"@site/docs/middlewares/http-json-body-parser.md",sourceDirName:"middlewares",slug:"/middlewares/http-json-body-parser",permalink:"/docs/middlewares/http-json-body-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-json-body-parser.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-json-body-parser"},sidebar:"tutorialSidebar",previous:{title:"http-header-normalizer",permalink:"/docs/middlewares/http-header-normalizer"},next:{title:"http-multipart-body-parser",permalink:"/docs/middlewares/http-multipart-body-parser"}},d={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:p},m="wrapper";function b(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware automatically parses HTTP requests with a JSON body and converts the body into an\nobject. Also handles gracefully broken JSON as ",(0,a.kt)("em",{parentName:"p"},"Unsupported Media Type")," (415 errors)\nif used in combination with ",(0,a.kt)("inlineCode",{parentName:"p"},"httpErrorHandler"),"."),(0,a.kt)("p",null,"It can also be used in combination with validator as a prior step to normalize the\nevent body input as an object so that the content can be validated."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-json-body-parser\n"))),(0,a.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-json-body-parser\n"))),(0,a.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-json-body-parser\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reviver")," (",(0,a.kt)("inlineCode",{parentName:"li"},"function"),") (optional): A ",(0,a.kt)("a",{parentName:"li",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters"},"reviver")," parameter may be passed which will be used ",(0,a.kt)("inlineCode",{parentName:"li"},"JSON.parse"),"ing the body."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disableContentTypeError")," (",(0,a.kt)("inlineCode",{parentName:"li"},"boolean"),") (optional): Skip throwing 415 when ",(0,a.kt)("inlineCode",{parentName:"li"},"Content-Type")," is invalid. Default: ",(0,a.kt)("inlineCode",{parentName:"li"},"true"),", will default to ",(0,a.kt)("inlineCode",{parentName:"li"},"false")," in next major version.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpJsonBodyParser from '@middy/http-json-body-parser'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler.use(httpHeaderNormalizer()).use(httpJsonBodyParser())\n\n// invokes the handler\nconst event = {\n headers: {\n 'Content-Type': 'application/json'\n // It is important that the request has the proper content type.\n },\n body: JSON.stringify({ foo: 'bar' })\n}\nhandler(event, {}, (_, body) => {\n t.is(body, { foo: 'bar' })\n})\n")))}b.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3295],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>b});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function l(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var s=n.createContext({}),u=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},d=function(e){var t=u(e.components);return n.createElement(s.Provider,{value:t},e.children)},p="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),p=u(r),m=a,b=p["".concat(s,".").concat(m)]||p[m]||c[m]||o;return r?n.createElement(b,l(l({ref:t},d),{},{components:r})):n.createElement(b,l({ref:t},d))}));function b(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,l=new Array(o);l[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[p]="string"==typeof e?e:a,l[1]=i;for(var u=2;u{r.d(t,{Z:()=>l});var n=r(7294),a=r(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:r,className:l}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(o.tabItem,l),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7462),a=r(7294),o=r(6010),l=r(2466),i=r(6550),s=r(1980),u=r(7392),d=r(12);function p(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function c(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??p(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:r}=e;const n=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(o),(0,a.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(n.location.search);t.set(o,e),n.replace({...n.location,search:t.toString()})}),[o,n])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,o=c(e),[l,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[s,u]=b({queryString:r,groupId:n}),[p,h]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,o]=(0,d.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&o.set(e)}),[r,o])]}({groupId:n}),f=(()=>{const e=s??p;return m({value:e,tabValues:o})?e:null})();(0,a.useLayoutEffect)((()=>{f&&i(f)}),[f]);return{selectedValue:l,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),h(e)}),[u,h,o]),tabValues:o}}var f=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:i,selectValue:s,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:p}=(0,l.o5)(),c=e=>{const t=e.currentTarget,r=d.indexOf(t),n=u[r].value;n!==i&&(p(t),s(n))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:l}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:c},l,{className:(0,o.Z)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":i===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:n}=e;const o=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function k(e){const t=h(e);return a.createElement("div",{className:(0,o.Z)("tabs-container",y.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(g,(0,n.Z)({},e,t)))}function w(e){const t=(0,f.Z)();return a.createElement(k,(0,n.Z)({key:String(t)},e))}},4284:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>b,frontMatter:()=>i,metadata:()=>u,toc:()=>p});var n=r(7462),a=(r(7294),r(3905)),o=r(4866),l=r(5162);const i={title:"http-json-body-parser"},s=void 0,u={unversionedId:"middlewares/http-json-body-parser",id:"middlewares/http-json-body-parser",title:"http-json-body-parser",description:"This middleware automatically parses HTTP requests with a JSON body and converts the body into an",source:"@site/docs/middlewares/http-json-body-parser.md",sourceDirName:"middlewares",slug:"/middlewares/http-json-body-parser",permalink:"/docs/middlewares/http-json-body-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-json-body-parser.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-json-body-parser"},sidebar:"tutorialSidebar",previous:{title:"http-header-normalizer",permalink:"/docs/middlewares/http-header-normalizer"},next:{title:"http-multipart-body-parser",permalink:"/docs/middlewares/http-multipart-body-parser"}},d={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:p},m="wrapper";function b(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware automatically parses HTTP requests with a JSON body and converts the body into an\nobject. Also handles gracefully broken JSON as ",(0,a.kt)("em",{parentName:"p"},"Unsupported Media Type")," (415 errors)\nif used in combination with ",(0,a.kt)("inlineCode",{parentName:"p"},"httpErrorHandler"),"."),(0,a.kt)("p",null,"It can also be used in combination with validator as a prior step to normalize the\nevent body input as an object so that the content can be validated."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-json-body-parser\n"))),(0,a.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-json-body-parser\n"))),(0,a.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-json-body-parser\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reviver")," (",(0,a.kt)("inlineCode",{parentName:"li"},"function"),") (optional): A ",(0,a.kt)("a",{parentName:"li",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters"},"reviver")," parameter may be passed which will be used ",(0,a.kt)("inlineCode",{parentName:"li"},"JSON.parse"),"ing the body."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disableContentTypeError")," (",(0,a.kt)("inlineCode",{parentName:"li"},"boolean"),") (optional): Skip throwing 415 when ",(0,a.kt)("inlineCode",{parentName:"li"},"Content-Type")," is invalid. Default: ",(0,a.kt)("inlineCode",{parentName:"li"},"true"),", will default to ",(0,a.kt)("inlineCode",{parentName:"li"},"false")," in next major version.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpJsonBodyParser from '@middy/http-json-body-parser'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler.use(httpHeaderNormalizer()).use(httpJsonBodyParser())\n\n// invokes the handler\nconst event = {\n headers: {\n 'Content-Type': 'application/json'\n // It is important that the request has the proper content type.\n },\n body: JSON.stringify({ foo: 'bar' })\n}\nhandler(event, {}, (_, body) => {\n t.is(body, { foo: 'bar' })\n})\n")))}b.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/028754be.41cf5258.js b/assets/js/028754be.87bbc6ba.js similarity index 98% rename from assets/js/028754be.41cf5258.js rename to assets/js/028754be.87bbc6ba.js index e2a6a951f..7a690c267 100644 --- a/assets/js/028754be.41cf5258.js +++ b/assets/js/028754be.87bbc6ba.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6238],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var l=n.createContext({}),c=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=c(e.components);return n.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=c(r),m=a,f=u["".concat(l,".").concat(m)]||u[m]||d[m]||o;return r?n.createElement(f,i(i({ref:t},p),{},{components:r})):n.createElement(f,i({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[u]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var n=r(7462),a=(r(7294),r(3905));const o={title:"SQS"},i=void 0,s={unversionedId:"events/sqs",id:"events/sqs",title:"SQS",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/sqs.md",sourceDirName:"events",slug:"/events/sqs",permalink:"/docs/events/sqs",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/sqs.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"SQS"},sidebar:"tutorialSidebar",previous:{title:"SNS",permalink:"/docs/events/sns"},next:{title:"VPC Lattice",permalink:"/docs/events/vpc-lattice"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},u="wrapper";function d(e){let{components:t,...r}=e;return(0,a.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html"},"Using AWS Lambda with Amazon SQS"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\nimport sqsPartialBatchFailure from '@middy/sqs-partial-batch-failure'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .use(sqsPartialBatchFailure())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6238],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var l=n.createContext({}),c=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=c(e.components);return n.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=c(r),m=a,f=u["".concat(l,".").concat(m)]||u[m]||d[m]||o;return r?n.createElement(f,i(i({ref:t},p),{},{components:r})):n.createElement(f,i({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[u]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var n=r(7462),a=(r(7294),r(3905));const o={title:"SQS"},i=void 0,s={unversionedId:"events/sqs",id:"events/sqs",title:"SQS",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/sqs.md",sourceDirName:"events",slug:"/events/sqs",permalink:"/docs/events/sqs",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/sqs.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"SQS"},sidebar:"tutorialSidebar",previous:{title:"SNS",permalink:"/docs/events/sns"},next:{title:"VPC Lattice",permalink:"/docs/events/vpc-lattice"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},u="wrapper";function d(e){let{components:t,...r}=e;return(0,a.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html"},"Using AWS Lambda with Amazon SQS"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\nimport sqsPartialBatchFailure from '@middy/sqs-partial-batch-failure'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .use(sqsPartialBatchFailure())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/0480b142.739e4424.js b/assets/js/0480b142.347f72ff.js similarity index 96% rename from assets/js/0480b142.739e4424.js rename to assets/js/0480b142.347f72ff.js index a4a6d13cb..24d34bf58 100644 --- a/assets/js/0480b142.739e4424.js +++ b/assets/js/0480b142.347f72ff.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[836],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),l=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},d=function(e){var t=l(e.components);return n.createElement(c.Provider,{value:t},e.children)},s="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,c=e.parentName,d=p(e,["components","mdxType","originalType","parentName"]),s=l(r),m=o,f=s["".concat(c,".").concat(m)]||s[m]||u[m]||i;return r?n.createElement(f,a(a({ref:t},d),{},{components:r})):n.createElement(f,a({ref:t},d))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=m;var p={};for(var c in t)hasOwnProperty.call(t,c)&&(p[c]=t[c]);p.originalType=e,p[s]="string"==typeof e?e:o,a[1]=p;for(var l=2;l{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>p,toc:()=>l});var n=r(7462),o=(r(7294),r(3905));const i={title:"FAQ",sidebar_position:10},a=void 0,p={unversionedId:"faq",id:"faq",title:"FAQ",description:"My lambda keep timing out without responding, what do I do?",source:"@site/docs/faq.md",sourceDirName:".",slug:"/faq",permalink:"/docs/faq",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/faq.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:10,frontMatter:{title:"FAQ",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"Profiling",permalink:"/docs/best-practices/profiling"}},c={},l=[{value:"My lambda keep timing out without responding, what do I do?",id:"my-lambda-keep-timing-out-without-responding-what-do-i-do",level:3}],d={toc:l},s="wrapper";function u(e){let{components:t,...r}=e;return(0,o.kt)(s,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h3",{id:"my-lambda-keep-timing-out-without-responding-what-do-i-do"},"My lambda keep timing out without responding, what do I do?"),(0,o.kt)("p",null,"Likely your event loop is not empty. This happens when you have a database connect still open for example. Checkout ",(0,o.kt)("inlineCode",{parentName:"p"},"@middy/do-not-wait-for-empty-event-loop"),"."))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[836],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),l=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},d=function(e){var t=l(e.components);return n.createElement(c.Provider,{value:t},e.children)},s="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,c=e.parentName,d=p(e,["components","mdxType","originalType","parentName"]),s=l(r),m=o,f=s["".concat(c,".").concat(m)]||s[m]||u[m]||i;return r?n.createElement(f,a(a({ref:t},d),{},{components:r})):n.createElement(f,a({ref:t},d))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=m;var p={};for(var c in t)hasOwnProperty.call(t,c)&&(p[c]=t[c]);p.originalType=e,p[s]="string"==typeof e?e:o,a[1]=p;for(var l=2;l{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>p,toc:()=>l});var n=r(7462),o=(r(7294),r(3905));const i={title:"FAQ",sidebar_position:10},a=void 0,p={unversionedId:"faq",id:"faq",title:"FAQ",description:"My lambda keep timing out without responding, what do I do?",source:"@site/docs/faq.md",sourceDirName:".",slug:"/faq",permalink:"/docs/faq",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/faq.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:10,frontMatter:{title:"FAQ",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"Profiling",permalink:"/docs/best-practices/profiling"}},c={},l=[{value:"My lambda keep timing out without responding, what do I do?",id:"my-lambda-keep-timing-out-without-responding-what-do-i-do",level:3}],d={toc:l},s="wrapper";function u(e){let{components:t,...r}=e;return(0,o.kt)(s,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h3",{id:"my-lambda-keep-timing-out-without-responding-what-do-i-do"},"My lambda keep timing out without responding, what do I do?"),(0,o.kt)("p",null,"Likely your event loop is not empty. This happens when you have a database connect still open for example. Checkout ",(0,o.kt)("inlineCode",{parentName:"p"},"@middy/do-not-wait-for-empty-event-loop"),"."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/08eadb91.13bced74.js b/assets/js/08eadb91.fc13e5e5.js similarity index 97% rename from assets/js/08eadb91.13bced74.js rename to assets/js/08eadb91.fc13e5e5.js index 356b0ff67..b9768563d 100644 --- a/assets/js/08eadb91.13bced74.js +++ b/assets/js/08eadb91.fc13e5e5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1428],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),d=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=d(e.components);return r.createElement(s.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,i=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),p=d(n),m=a,f=p["".concat(s,".").concat(m)]||p[m]||u[m]||i;return n?r.createElement(f,o(o({ref:t},c),{},{components:n})):r.createElement(f,o({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=n.length,o=new Array(i);o[0]=m;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:a,o[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>u,frontMatter:()=>i,metadata:()=>l,toc:()=>d});var r=n(7462),a=(n(7294),n(3905));const i={title:"Custom Middlewares",position:1},o=void 0,l={unversionedId:"writing-middlewares/intro",id:"writing-middlewares/intro",title:"Custom Middlewares",description:"A middleware is an object that should contain at least 1 of 3 possible keys:",source:"@site/docs/writing-middlewares/01-intro.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/intro",permalink:"/docs/writing-middlewares/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:1,frontMatter:{title:"Custom Middlewares",position:1},sidebar:"tutorialSidebar",previous:{title:"Writing Middlewares",permalink:"/docs/category/writing-middlewares"},next:{title:"Configurable Middlewares",permalink:"/docs/writing-middlewares/configurable-middlewares"}},s={},d=[],c={toc:d},p="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"A middleware is an object that should contain at least 1 of 3 possible keys:"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"before"),": a function that is executed in the before phase"),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"after"),": a function that is executed in the after phase"),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"onError"),": a function that is executed in case of errors")),(0,a.kt)("p",null,(0,a.kt)("inlineCode",{parentName:"p"},"before"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"after")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"onError")," functions need to have the following signature:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"const defaults = {\n // ...\n}\n\nconst nameMiddleware = (opts = {}) => {\n const options = { ...defaults, ...opts }\n\n const nameMiddlewareBefore = async (request) => {\n // ...\n }\n \n const nameMiddlewareAfter = async (request) => {\n // ...\n }\n \n const nameMiddlewareOnError = async (request) => {\n // ...\n }\n \n return {\n before: nameMiddlewareBefore,\n after: nameMiddlewareAfter,\n onError: nameMiddlewareOnError\n }\n}\n\nexport default nameMiddleware\n")),(0,a.kt)("p",null,"Where:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"request"),": is a reference to the current context and allows access to (and modification of)\nthe current ",(0,a.kt)("inlineCode",{parentName:"li"},"event")," (request), the ",(0,a.kt)("inlineCode",{parentName:"li"},"response")," (in the ",(0,a.kt)("em",{parentName:"li"},"after")," phase), and ",(0,a.kt)("inlineCode",{parentName:"li"},"error"),"\n(in case of an error).")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1428],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),d=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=d(e.components);return r.createElement(s.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,i=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),p=d(n),m=a,f=p["".concat(s,".").concat(m)]||p[m]||u[m]||i;return n?r.createElement(f,o(o({ref:t},c),{},{components:n})):r.createElement(f,o({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=n.length,o=new Array(i);o[0]=m;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:a,o[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>u,frontMatter:()=>i,metadata:()=>l,toc:()=>d});var r=n(7462),a=(n(7294),n(3905));const i={title:"Custom Middlewares",position:1},o=void 0,l={unversionedId:"writing-middlewares/intro",id:"writing-middlewares/intro",title:"Custom Middlewares",description:"A middleware is an object that should contain at least 1 of 3 possible keys:",source:"@site/docs/writing-middlewares/01-intro.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/intro",permalink:"/docs/writing-middlewares/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:1,frontMatter:{title:"Custom Middlewares",position:1},sidebar:"tutorialSidebar",previous:{title:"Writing Middlewares",permalink:"/docs/category/writing-middlewares"},next:{title:"Configurable Middlewares",permalink:"/docs/writing-middlewares/configurable-middlewares"}},s={},d=[],c={toc:d},p="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"A middleware is an object that should contain at least 1 of 3 possible keys:"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"before"),": a function that is executed in the before phase"),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"after"),": a function that is executed in the after phase"),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"onError"),": a function that is executed in case of errors")),(0,a.kt)("p",null,(0,a.kt)("inlineCode",{parentName:"p"},"before"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"after")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"onError")," functions need to have the following signature:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"const defaults = {\n // ...\n}\n\nconst nameMiddleware = (opts = {}) => {\n const options = { ...defaults, ...opts }\n\n const nameMiddlewareBefore = async (request) => {\n // ...\n }\n \n const nameMiddlewareAfter = async (request) => {\n // ...\n }\n \n const nameMiddlewareOnError = async (request) => {\n // ...\n }\n \n return {\n before: nameMiddlewareBefore,\n after: nameMiddlewareAfter,\n onError: nameMiddlewareOnError\n }\n}\n\nexport default nameMiddleware\n")),(0,a.kt)("p",null,"Where:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"request"),": is a reference to the current context and allows access to (and modification of)\nthe current ",(0,a.kt)("inlineCode",{parentName:"li"},"event")," (request), the ",(0,a.kt)("inlineCode",{parentName:"li"},"response")," (in the ",(0,a.kt)("em",{parentName:"li"},"after")," phase), and ",(0,a.kt)("inlineCode",{parentName:"li"},"error"),"\n(in case of an error).")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/08f83687.70f4bfb6.js b/assets/js/08f83687.ffb6b2db.js similarity index 98% rename from assets/js/08f83687.70f4bfb6.js rename to assets/js/08f83687.ffb6b2db.js index 2bab665a5..f97d9df3e 100644 --- a/assets/js/08f83687.70f4bfb6.js +++ b/assets/js/08f83687.ffb6b2db.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5409],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},m=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,m=c(e,["components","mdxType","originalType","parentName"]),p=s(n),u=o,f=p["".concat(l,".").concat(u)]||p[u]||d[u]||a;return n?r.createElement(f,i(i({ref:t},m),{},{components:n})):r.createElement(f,i({ref:t},m))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=u;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[p]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"Code Commit"},i=void 0,c={unversionedId:"events/code-commit",id:"events/code-commit",title:"Code Commit",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/code-commit.md",sourceDirName:"events",slug:"/events/code-commit",permalink:"/docs/events/code-commit",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/code-commit.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Code Commit"},sidebar:"tutorialSidebar",previous:{title:"Cloud Watch Logs",permalink:"/docs/events/cloud-watch-logs"},next:{title:"CodePipeline",permalink:"/docs/events/code-pipeline"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],m={toc:s},p="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(p,(0,r.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-codecommit.html"},"Using AWS Lambda with AWS CodeCommit"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5409],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},m=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,m=c(e,["components","mdxType","originalType","parentName"]),p=s(n),u=o,f=p["".concat(l,".").concat(u)]||p[u]||d[u]||a;return n?r.createElement(f,i(i({ref:t},m),{},{components:n})):r.createElement(f,i({ref:t},m))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=u;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[p]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"Code Commit"},i=void 0,c={unversionedId:"events/code-commit",id:"events/code-commit",title:"Code Commit",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/code-commit.md",sourceDirName:"events",slug:"/events/code-commit",permalink:"/docs/events/code-commit",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/code-commit.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Code Commit"},sidebar:"tutorialSidebar",previous:{title:"Cloud Watch Logs",permalink:"/docs/events/cloud-watch-logs"},next:{title:"CodePipeline",permalink:"/docs/events/code-pipeline"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],m={toc:s},p="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(p,(0,r.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-codecommit.html"},"Using AWS Lambda with AWS CodeCommit"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/0976e874.b44937b8.js b/assets/js/0976e874.8a583726.js similarity index 98% rename from assets/js/0976e874.b44937b8.js rename to assets/js/0976e874.8a583726.js index e9acdbb1c..fd214043d 100644 --- a/assets/js/0976e874.b44937b8.js +++ b/assets/js/0976e874.8a583726.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4267],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>g});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function l(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var u=a.createContext({}),s=function(e){var t=a.useContext(u),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},c=function(e){var t=s(e.components);return a.createElement(u.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,u=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),d=s(r),m=n,g=d["".concat(u,".").concat(m)]||d[m]||p[m]||o;return r?a.createElement(g,l(l({ref:t},c),{},{components:r})):a.createElement(g,l({ref:t},c))}));function g(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,l=new Array(o);l[0]=m;var i={};for(var u in t)hasOwnProperty.call(t,u)&&(i[u]=t[u]);i.originalType=e,i[d]="string"==typeof e?e:n,l[1]=i;for(var s=2;s{r.d(t,{Z:()=>l});var a=r(7294),n=r(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:r,className:l}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(o.tabItem,l),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var a=r(7462),n=r(7294),o=r(6010),l=r(2466),i=r(6550),u=r(1980),s=r(7392),c=r(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??d(r);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:r}=e;const a=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,u._X)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(a.location.search);t.set(o,e),a.replace({...a.location,search:t.toString()})}),[o,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,o=p(e),[l,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:o}))),[u,s]=g({queryString:r,groupId:a}),[d,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,c.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&o.set(e)}),[r,o])]}({groupId:a}),b=(()=>{const e=u??d;return m({value:e,tabValues:o})?e:null})();(0,n.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),s(e),f(e)}),[s,f,o]),tabValues:o}}var b=r(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:r,selectedValue:i,selectValue:u,tabValues:s}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),p=e=>{const t=e.currentTarget,r=c.indexOf(t),a=s[r].value;a!==i&&(d(t),u(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=c.indexOf(e.currentTarget)+1;t=c[r]??c[0];break}case"ArrowLeft":{const r=c.indexOf(e.currentTarget)-1;t=c[r]??c[c.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":r},t)},s.map((e=>{let{value:t,label:r,attributes:l}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},l,{className:(0,o.Z)("tabs__item",h.tabItem,l?.className,{"tabs__item--active":i===t})}),r??t)})))}function v(e){let{lazy:t,children:r,selectedValue:a}=e;const o=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function w(e){const t=f(e);return n.createElement("div",{className:(0,o.Z)("tabs-container",h.tabList)},n.createElement(y,(0,a.Z)({},e,t)),n.createElement(v,(0,a.Z)({},e,t)))}function k(e){const t=(0,b.Z)();return n.createElement(w,(0,a.Z)({key:String(t)},e))}},6252:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>g,frontMatter:()=>i,metadata:()=>s,toc:()=>d});var a=r(7462),n=(r(7294),r(3905)),o=r(4866),l=r(5162);const i={title:"error-logger"},u=void 0,s={unversionedId:"middlewares/error-logger",id:"middlewares/error-logger",title:"error-logger",description:"Logs the error and propagates it to the next middleware.",source:"@site/docs/middlewares/error-logger.md",sourceDirName:"middlewares",slug:"/middlewares/error-logger",permalink:"/docs/middlewares/error-logger",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/error-logger.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"error-logger"},sidebar:"tutorialSidebar",previous:{title:"dynamodb",permalink:"/docs/middlewares/dynamodb"},next:{title:"event-normalizer",permalink:"/docs/middlewares/event-normalizer"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:d},m="wrapper";function g(e){let{components:t,...r}=e;return(0,n.kt)(m,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Logs the error and propagates it to the next middleware."),(0,n.kt)("p",null,"By default AWS Lambda does not print errors in the CloudWatch logs. If you want to make sure that you don't miss error logs, you would have to catch any error and pass it through ",(0,n.kt)("inlineCode",{parentName:"p"},"console.error")," yourself."),(0,n.kt)("p",null,"This middleware will take care to intercept any error and log it for you. The middleware is not going to interfere with other error handlers because it will propagate the error to the next error handler middleware without handling it. You just have to make sure to attach this middleware before any other error handling middleware."),(0,n.kt)("p",null,"By default, the logging operate by using the ",(0,n.kt)("inlineCode",{parentName:"p"},"console.error")," function. You can pass as a parameter a custom logger with additional logic if you need. It can be useful if you want to process the log by doing a http call or anything else."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/error-logger\n"))),(0,n.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/error-logger\n"))),(0,n.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/error-logger\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"logger")," property: a function (default ",(0,n.kt)("inlineCode",{parentName:"li"},"console.error"),") that is used to define the logging logic. It receives the Error object as first and only parameter.")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLogger from '@middy/error-logger'\n\nconst handler = middy((event, context) => {\n // your handler logic\n})\n\nhandler\n .use(errorLogger())\n")))}g.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4267],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>g});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function l(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var u=a.createContext({}),s=function(e){var t=a.useContext(u),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},c=function(e){var t=s(e.components);return a.createElement(u.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,u=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),d=s(r),m=n,g=d["".concat(u,".").concat(m)]||d[m]||p[m]||o;return r?a.createElement(g,l(l({ref:t},c),{},{components:r})):a.createElement(g,l({ref:t},c))}));function g(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,l=new Array(o);l[0]=m;var i={};for(var u in t)hasOwnProperty.call(t,u)&&(i[u]=t[u]);i.originalType=e,i[d]="string"==typeof e?e:n,l[1]=i;for(var s=2;s{r.d(t,{Z:()=>l});var a=r(7294),n=r(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:r,className:l}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(o.tabItem,l),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var a=r(7462),n=r(7294),o=r(6010),l=r(2466),i=r(6550),u=r(1980),s=r(7392),c=r(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??d(r);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:r}=e;const a=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,u._X)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(a.location.search);t.set(o,e),a.replace({...a.location,search:t.toString()})}),[o,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,o=p(e),[l,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:o}))),[u,s]=g({queryString:r,groupId:a}),[d,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,c.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&o.set(e)}),[r,o])]}({groupId:a}),b=(()=>{const e=u??d;return m({value:e,tabValues:o})?e:null})();(0,n.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),s(e),f(e)}),[s,f,o]),tabValues:o}}var b=r(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:r,selectedValue:i,selectValue:u,tabValues:s}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),p=e=>{const t=e.currentTarget,r=c.indexOf(t),a=s[r].value;a!==i&&(d(t),u(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=c.indexOf(e.currentTarget)+1;t=c[r]??c[0];break}case"ArrowLeft":{const r=c.indexOf(e.currentTarget)-1;t=c[r]??c[c.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":r},t)},s.map((e=>{let{value:t,label:r,attributes:l}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},l,{className:(0,o.Z)("tabs__item",h.tabItem,l?.className,{"tabs__item--active":i===t})}),r??t)})))}function v(e){let{lazy:t,children:r,selectedValue:a}=e;const o=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function w(e){const t=f(e);return n.createElement("div",{className:(0,o.Z)("tabs-container",h.tabList)},n.createElement(y,(0,a.Z)({},e,t)),n.createElement(v,(0,a.Z)({},e,t)))}function k(e){const t=(0,b.Z)();return n.createElement(w,(0,a.Z)({key:String(t)},e))}},6252:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>g,frontMatter:()=>i,metadata:()=>s,toc:()=>d});var a=r(7462),n=(r(7294),r(3905)),o=r(4866),l=r(5162);const i={title:"error-logger"},u=void 0,s={unversionedId:"middlewares/error-logger",id:"middlewares/error-logger",title:"error-logger",description:"Logs the error and propagates it to the next middleware.",source:"@site/docs/middlewares/error-logger.md",sourceDirName:"middlewares",slug:"/middlewares/error-logger",permalink:"/docs/middlewares/error-logger",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/error-logger.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"error-logger"},sidebar:"tutorialSidebar",previous:{title:"dynamodb",permalink:"/docs/middlewares/dynamodb"},next:{title:"event-normalizer",permalink:"/docs/middlewares/event-normalizer"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:d},m="wrapper";function g(e){let{components:t,...r}=e;return(0,n.kt)(m,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Logs the error and propagates it to the next middleware."),(0,n.kt)("p",null,"By default AWS Lambda does not print errors in the CloudWatch logs. If you want to make sure that you don't miss error logs, you would have to catch any error and pass it through ",(0,n.kt)("inlineCode",{parentName:"p"},"console.error")," yourself."),(0,n.kt)("p",null,"This middleware will take care to intercept any error and log it for you. The middleware is not going to interfere with other error handlers because it will propagate the error to the next error handler middleware without handling it. You just have to make sure to attach this middleware before any other error handling middleware."),(0,n.kt)("p",null,"By default, the logging operate by using the ",(0,n.kt)("inlineCode",{parentName:"p"},"console.error")," function. You can pass as a parameter a custom logger with additional logic if you need. It can be useful if you want to process the log by doing a http call or anything else."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/error-logger\n"))),(0,n.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/error-logger\n"))),(0,n.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/error-logger\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"logger")," property: a function (default ",(0,n.kt)("inlineCode",{parentName:"li"},"console.error"),") that is used to define the logging logic. It receives the Error object as first and only parameter.")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLogger from '@middy/error-logger'\n\nconst handler = middy((event, context) => {\n // your handler logic\n})\n\nhandler\n .use(errorLogger())\n")))}g.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/0ce61a91.21b29b6f.js b/assets/js/0ce61a91.3c1ee684.js similarity index 99% rename from assets/js/0ce61a91.21b29b6f.js rename to assets/js/0ce61a91.3c1ee684.js index c26de6239..5aef5d380 100644 --- a/assets/js/0ce61a91.21b29b6f.js +++ b/assets/js/0ce61a91.3c1ee684.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6540],{3905:(e,n,t)=>{t.d(n,{Zo:()=>c,kt:()=>b});var s=t(7294);function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);n&&(s=s.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,s)}return t}function l(e){for(var n=1;n=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(s=0;s=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var o=s.createContext({}),d=function(e){var n=s.useContext(o),t=n;return e&&(t="function"==typeof e?e(n):l(l({},n),e)),t},c=function(e){var n=d(e.components);return s.createElement(o.Provider,{value:n},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var n=e.children;return s.createElement(s.Fragment,{},n)}},m=s.forwardRef((function(e,n){var t=e.components,r=e.mdxType,a=e.originalType,o=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),p=d(t),m=r,b=p["".concat(o,".").concat(m)]||p[m]||u[m]||a;return t?s.createElement(b,l(l({ref:n},c),{},{components:t})):s.createElement(b,l({ref:n},c))}));function b(e,n){var t=arguments,r=n&&n.mdxType;if("string"==typeof e||r){var a=t.length,l=new Array(a);l[0]=m;var i={};for(var o in n)hasOwnProperty.call(n,o)&&(i[o]=n[o]);i.originalType=e,i[p]="string"==typeof e?e:r,l[1]=i;for(var d=2;d{t.r(n),t.d(n,{assets:()=>o,contentTitle:()=>l,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>d});var s=t(7462),r=(t(7294),t(3905));const a={title:"Bundling Lambda packages",sidebar_position:5},l=void 0,i={unversionedId:"best-practices/bundling",id:"best-practices/bundling",title:"Bundling Lambda packages",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/best-practices/05-bundling.md",sourceDirName:"best-practices",slug:"/best-practices/bundling",permalink:"/docs/best-practices/bundling",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/05-bundling.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:5,frontMatter:{title:"Bundling Lambda packages",sidebar_position:5},sidebar:"tutorialSidebar",previous:{title:"Internal Context",permalink:"/docs/best-practices/internal-context"},next:{title:"Small node_modules",permalink:"/docs/best-practices/small-node-modules"}},o={},d=[{value:"Compilers",id:"compilers",level:2},{value:"typescript",id:"typescript",level:3},{value:"tsconfig.json",id:"tsconfigjson",level:4},{value:"Bundlers",id:"bundlers",level:2},{value:"esbuild",id:"esbuild",level:3},{value:"rollup",id:"rollup",level:3},{value:"rollup.config.mjs",id:"rollupconfigmjs",level:4},{value:"swc/pack",id:"swcpack",level:3},{value:"webpack",id:"webpack",level:3},{value:"webpack.config.mjs",id:"webpackconfigmjs",level:4},{value:"Transpilers",id:"transpilers",level:2},{value:"babel",id:"babel",level:3},{value:"babel.config.json",id:"babelconfigjson",level:4},{value:"esbuild",id:"esbuild-1",level:3},{value:"swc",id:"swc",level:3},{value:".swcrc",id:"swcrc",level:4}],c={toc:d},p="wrapper";function u(e){let{components:n,...t}=e;return(0,r.kt)(p,(0,s.Z)({},c,t,{components:n,mdxType:"MDXLayout"}),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,r.kt)("p",null,"Always bundle the ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/*")," with your project eventhough the Lambda runtime already includes it by default (Note: nodejs16.x does not have AWS SDK v3 included).\nThis gives you full control of when to update the SDK to prevent unexpected errors from a bad SDK version, allows you to ensure that you are running the latest version with the most up to date fixes and features, and has been shown to decrease cold start times."),(0,r.kt)("h2",{id:"compilers"},"Compilers"),(0,r.kt)("h3",{id:"typescript"},"typescript"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D typescript\nnode_modules/.bin/tsc\n")),(0,r.kt)("h4",{id:"tsconfigjson"},"tsconfig.json"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "compilerOptions": {\n "baseUrl": "./",\n "esModuleInterop": true,\n "preserveConstEnums": true,\n "strictNullChecks": true,\n "allowJs": false,\n "target": "es2021",\n "typeRoots": ["node_modules/@types"],\n "resolveJsonModule": true,\n "moduleResolution": "node"\n }\n}\n')),(0,r.kt)("h2",{id:"bundlers"},"Bundlers"),(0,r.kt)("h3",{id:"esbuild"},"esbuild"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D esbuild\n\n# --banner:js hack from https://github.com/evanw/esbuild/pull/2067\nnode_modules/.bin/esbuild index.js \\\n --platform=node --format=esm --target=node18 --bundle --minify \\\n --banner:js=\"import { createRequire } from 'module';const require = createRequire(import.meta.url);\" \\\n --legal-comments=external --sourcemap=external \\\n --allow-overwrite --outfile=index.mjs\n\n")),(0,r.kt)("h3",{id:"rollup"},"rollup"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs\nnode_modules/.bin/rollup --config\n")),(0,r.kt)("h4",{id:"rollupconfigmjs"},"rollup.config.mjs"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import { nodeResolve } from '@rollup/plugin-node-resolve'\nimport commonjs from '@rollup/plugin-commonjs'\n\nconst plugins = [nodeResolve({ preferBuiltins: true }), commonjs()]\n\nexport default (input) => ({\n input: 'index.js',\n output: {\n file: 'index.bundle.rollup.mjs',\n format: 'es' // cjs, es\n },\n plugins,\n external: [\n // AWS SDK\n '@aws-sdk/client-apigatewaymanagementapi', // @middy/ws-response\n '@aws-sdk/client-rds', // @middy/rds-signer\n '@aws-sdk/client-s3', // @middy/s3-object-response\n '@aws-sdk/client-secretsmanager', // @middy/sercrets-manager\n '@aws-sdk/client-servicediscovery', // @middy/service-discovery\n '@aws-sdk/client-ssm', // @middy/ssm\n '@aws-sdk/client-sts' // @middy/sts\n ]\n})\n")),(0,r.kt)("h3",{id:"swcpack"},"swc/pack"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D @swc/cli @swc/core\nnode_modules/.bin/spack\n")),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"Incomplete")),(0,r.kt)("h3",{id:"webpack"},"webpack"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D webpack-cli webpack\nnode_modules/.bin/webpack\n")),(0,r.kt)("h4",{id:"webpackconfigmjs"},"webpack.config.mjs"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\nexport default {\n mode: 'development',\n entry: './index.js',\n output: {\n filename: 'index.bundle.webpack.mjs',\n path: __dirname\n },\n experiments: {\n outputModule: true\n },\n externals: [\n // NodeJS modules\n 'events', // @middy/core\n 'https', // @middy/s3-object-response\n 'stream', // @middy/http-content-encoding @middy/s3-object-response\n 'util', // @middy/http-content-encoding\n 'zlib', // @middy/http-content-encoding\n // AWS SDK\n '@aws-sdk/client-apigatewaymanagementapi', // @middy/ws-response\n '@aws-sdk/client-rds', // @middy/rds-signer\n '@aws-sdk/client-s3', // @middy/s3-object-response\n '@aws-sdk/client-secretsmanager', // @middy/sercrets-manager\n '@aws-sdk/client-servicediscovery', // @middy/service-discovery\n '@aws-sdk/client-ssm', // @middy/ssm\n '@aws-sdk/client-sts' // @middy/sts\n ]\n}\n")),(0,r.kt)("h2",{id:"transpilers"},"Transpilers"),(0,r.kt)("h3",{id:"babel"},"babel"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D @babel/cli @babel/core @babel/preset-env\nnode_modules/.bin/babel index.js --out-file index.transpile.babel.cjs\n")),(0,r.kt)("h4",{id:"babelconfigjson"},"babel.config.json"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "presets": [\n [\n "@babel/preset-env",\n {\n "targets": {\n "node": "16"\n }\n }\n ]\n ]\n}\n')),(0,r.kt)("h3",{id:"esbuild-1"},"esbuild"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D esbuild\nnode_modules/.bin/esbuild --platform=node --target=node16 --format=cjs index.js --outfile=index.cjs\n")),(0,r.kt)("h3",{id:"swc"},"swc"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D @swc/cli @swc/core\nnode_modules/.bin/swc index.js --out-file index.transpile.swc.cjs\n")),(0,r.kt)("h4",{id:"swcrc"},".swcrc"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "jsc": {\n "parser": {\n "syntax": "ecmascript"\n },\n "target": "es2021"\n },\n "module": {\n "type": "commonjs"\n }\n}\n')))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6540],{3905:(e,n,t)=>{t.d(n,{Zo:()=>c,kt:()=>b});var s=t(7294);function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);n&&(s=s.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,s)}return t}function l(e){for(var n=1;n=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(s=0;s=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var o=s.createContext({}),d=function(e){var n=s.useContext(o),t=n;return e&&(t="function"==typeof e?e(n):l(l({},n),e)),t},c=function(e){var n=d(e.components);return s.createElement(o.Provider,{value:n},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var n=e.children;return s.createElement(s.Fragment,{},n)}},m=s.forwardRef((function(e,n){var t=e.components,r=e.mdxType,a=e.originalType,o=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),p=d(t),m=r,b=p["".concat(o,".").concat(m)]||p[m]||u[m]||a;return t?s.createElement(b,l(l({ref:n},c),{},{components:t})):s.createElement(b,l({ref:n},c))}));function b(e,n){var t=arguments,r=n&&n.mdxType;if("string"==typeof e||r){var a=t.length,l=new Array(a);l[0]=m;var i={};for(var o in n)hasOwnProperty.call(n,o)&&(i[o]=n[o]);i.originalType=e,i[p]="string"==typeof e?e:r,l[1]=i;for(var d=2;d{t.r(n),t.d(n,{assets:()=>o,contentTitle:()=>l,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>d});var s=t(7462),r=(t(7294),t(3905));const a={title:"Bundling Lambda packages",sidebar_position:5},l=void 0,i={unversionedId:"best-practices/bundling",id:"best-practices/bundling",title:"Bundling Lambda packages",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/best-practices/05-bundling.md",sourceDirName:"best-practices",slug:"/best-practices/bundling",permalink:"/docs/best-practices/bundling",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/05-bundling.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:5,frontMatter:{title:"Bundling Lambda packages",sidebar_position:5},sidebar:"tutorialSidebar",previous:{title:"Internal Context",permalink:"/docs/best-practices/internal-context"},next:{title:"Small node_modules",permalink:"/docs/best-practices/small-node-modules"}},o={},d=[{value:"Compilers",id:"compilers",level:2},{value:"typescript",id:"typescript",level:3},{value:"tsconfig.json",id:"tsconfigjson",level:4},{value:"Bundlers",id:"bundlers",level:2},{value:"esbuild",id:"esbuild",level:3},{value:"rollup",id:"rollup",level:3},{value:"rollup.config.mjs",id:"rollupconfigmjs",level:4},{value:"swc/pack",id:"swcpack",level:3},{value:"webpack",id:"webpack",level:3},{value:"webpack.config.mjs",id:"webpackconfigmjs",level:4},{value:"Transpilers",id:"transpilers",level:2},{value:"babel",id:"babel",level:3},{value:"babel.config.json",id:"babelconfigjson",level:4},{value:"esbuild",id:"esbuild-1",level:3},{value:"swc",id:"swc",level:3},{value:".swcrc",id:"swcrc",level:4}],c={toc:d},p="wrapper";function u(e){let{components:n,...t}=e;return(0,r.kt)(p,(0,s.Z)({},c,t,{components:n,mdxType:"MDXLayout"}),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,r.kt)("p",null,"Always bundle the ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/*")," with your project eventhough the Lambda runtime already includes it by default (Note: nodejs16.x does not have AWS SDK v3 included).\nThis gives you full control of when to update the SDK to prevent unexpected errors from a bad SDK version, allows you to ensure that you are running the latest version with the most up to date fixes and features, and has been shown to decrease cold start times."),(0,r.kt)("h2",{id:"compilers"},"Compilers"),(0,r.kt)("h3",{id:"typescript"},"typescript"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D typescript\nnode_modules/.bin/tsc\n")),(0,r.kt)("h4",{id:"tsconfigjson"},"tsconfig.json"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "compilerOptions": {\n "baseUrl": "./",\n "esModuleInterop": true,\n "preserveConstEnums": true,\n "strictNullChecks": true,\n "allowJs": false,\n "target": "es2021",\n "typeRoots": ["node_modules/@types"],\n "resolveJsonModule": true,\n "moduleResolution": "node"\n }\n}\n')),(0,r.kt)("h2",{id:"bundlers"},"Bundlers"),(0,r.kt)("h3",{id:"esbuild"},"esbuild"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D esbuild\n\n# --banner:js hack from https://github.com/evanw/esbuild/pull/2067\nnode_modules/.bin/esbuild index.js \\\n --platform=node --format=esm --target=node18 --bundle --minify \\\n --banner:js=\"import { createRequire } from 'module';const require = createRequire(import.meta.url);\" \\\n --legal-comments=external --sourcemap=external \\\n --allow-overwrite --outfile=index.mjs\n\n")),(0,r.kt)("h3",{id:"rollup"},"rollup"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs\nnode_modules/.bin/rollup --config\n")),(0,r.kt)("h4",{id:"rollupconfigmjs"},"rollup.config.mjs"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import { nodeResolve } from '@rollup/plugin-node-resolve'\nimport commonjs from '@rollup/plugin-commonjs'\n\nconst plugins = [nodeResolve({ preferBuiltins: true }), commonjs()]\n\nexport default (input) => ({\n input: 'index.js',\n output: {\n file: 'index.bundle.rollup.mjs',\n format: 'es' // cjs, es\n },\n plugins,\n external: [\n // AWS SDK\n '@aws-sdk/client-apigatewaymanagementapi', // @middy/ws-response\n '@aws-sdk/client-rds', // @middy/rds-signer\n '@aws-sdk/client-s3', // @middy/s3-object-response\n '@aws-sdk/client-secretsmanager', // @middy/sercrets-manager\n '@aws-sdk/client-servicediscovery', // @middy/service-discovery\n '@aws-sdk/client-ssm', // @middy/ssm\n '@aws-sdk/client-sts' // @middy/sts\n ]\n})\n")),(0,r.kt)("h3",{id:"swcpack"},"swc/pack"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D @swc/cli @swc/core\nnode_modules/.bin/spack\n")),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"Incomplete")),(0,r.kt)("h3",{id:"webpack"},"webpack"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D webpack-cli webpack\nnode_modules/.bin/webpack\n")),(0,r.kt)("h4",{id:"webpackconfigmjs"},"webpack.config.mjs"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\nexport default {\n mode: 'development',\n entry: './index.js',\n output: {\n filename: 'index.bundle.webpack.mjs',\n path: __dirname\n },\n experiments: {\n outputModule: true\n },\n externals: [\n // NodeJS modules\n 'events', // @middy/core\n 'https', // @middy/s3-object-response\n 'stream', // @middy/http-content-encoding @middy/s3-object-response\n 'util', // @middy/http-content-encoding\n 'zlib', // @middy/http-content-encoding\n // AWS SDK\n '@aws-sdk/client-apigatewaymanagementapi', // @middy/ws-response\n '@aws-sdk/client-rds', // @middy/rds-signer\n '@aws-sdk/client-s3', // @middy/s3-object-response\n '@aws-sdk/client-secretsmanager', // @middy/sercrets-manager\n '@aws-sdk/client-servicediscovery', // @middy/service-discovery\n '@aws-sdk/client-ssm', // @middy/ssm\n '@aws-sdk/client-sts' // @middy/sts\n ]\n}\n")),(0,r.kt)("h2",{id:"transpilers"},"Transpilers"),(0,r.kt)("h3",{id:"babel"},"babel"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D @babel/cli @babel/core @babel/preset-env\nnode_modules/.bin/babel index.js --out-file index.transpile.babel.cjs\n")),(0,r.kt)("h4",{id:"babelconfigjson"},"babel.config.json"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "presets": [\n [\n "@babel/preset-env",\n {\n "targets": {\n "node": "16"\n }\n }\n ]\n ]\n}\n')),(0,r.kt)("h3",{id:"esbuild-1"},"esbuild"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D esbuild\nnode_modules/.bin/esbuild --platform=node --target=node16 --format=cjs index.js --outfile=index.cjs\n")),(0,r.kt)("h3",{id:"swc"},"swc"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm i -D @swc/cli @swc/core\nnode_modules/.bin/swc index.js --out-file index.transpile.swc.cjs\n")),(0,r.kt)("h4",{id:"swcrc"},".swcrc"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "jsc": {\n "parser": {\n "syntax": "ecmascript"\n },\n "target": "es2021"\n },\n "module": {\n "type": "commonjs"\n }\n}\n')))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/0d245e6a.85677f2a.js b/assets/js/0d245e6a.54868ccb.js similarity index 97% rename from assets/js/0d245e6a.85677f2a.js rename to assets/js/0d245e6a.54868ccb.js index 60fb18422..2ebef1da1 100644 --- a/assets/js/0d245e6a.85677f2a.js +++ b/assets/js/0d245e6a.54868ccb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8481],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,a=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(n),u=i,f=d["".concat(l,".").concat(u)]||d[u]||m[u]||a;return n?r.createElement(f,o(o({ref:t},p),{},{components:n})):r.createElement(f,o({ref:t},p))}));function f(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=n.length,o=new Array(a);o[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:i,o[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>s,toc:()=>c});var r=n(7462),i=(n(7294),n(3905));const a={title:"Kinesis Firehose"},o=void 0,s={unversionedId:"events/kinesis-firehose",id:"events/kinesis-firehose",title:"Kinesis Firehose",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/kinesis-firehose.md",sourceDirName:"events",slug:"/events/kinesis-firehose",permalink:"/docs/events/kinesis-firehose",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kinesis-firehose.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Kinesis Firehose"},sidebar:"tutorialSidebar",previous:{title:"Kafka, Self-Managed",permalink:"/docs/events/kafka-self-managed"},next:{title:"Kinesis Streams",permalink:"/docs/events/kinesis-streams"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},d="wrapper";function m(e){let{components:t,...n}=e;return(0,i.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,i.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-kinesisfirehose.html"},"Using AWS Lambda with Amazon Kinesis Data Firehose"))),(0,i.kt)("h2",{id:"example"},"Example"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8481],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,a=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(n),u=i,f=d["".concat(l,".").concat(u)]||d[u]||m[u]||a;return n?r.createElement(f,o(o({ref:t},p),{},{components:n})):r.createElement(f,o({ref:t},p))}));function f(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=n.length,o=new Array(a);o[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:i,o[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>s,toc:()=>c});var r=n(7462),i=(n(7294),n(3905));const a={title:"Kinesis Firehose"},o=void 0,s={unversionedId:"events/kinesis-firehose",id:"events/kinesis-firehose",title:"Kinesis Firehose",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/kinesis-firehose.md",sourceDirName:"events",slug:"/events/kinesis-firehose",permalink:"/docs/events/kinesis-firehose",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kinesis-firehose.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Kinesis Firehose"},sidebar:"tutorialSidebar",previous:{title:"Kafka, Self-Managed",permalink:"/docs/events/kafka-self-managed"},next:{title:"Kinesis Streams",permalink:"/docs/events/kinesis-streams"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},d="wrapper";function m(e){let{components:t,...n}=e;return(0,i.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,i.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-kinesisfirehose.html"},"Using AWS Lambda with Amazon Kinesis Data Firehose"))),(0,i.kt)("h2",{id:"example"},"Example"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/0e90e864.a723fb4c.js b/assets/js/0e90e864.c3cd9246.js similarity index 99% rename from assets/js/0e90e864.a723fb4c.js rename to assets/js/0e90e864.c3cd9246.js index e6172de30..bfab15fe6 100644 --- a/assets/js/0e90e864.a723fb4c.js +++ b/assets/js/0e90e864.c3cd9246.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1469],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>f});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function i(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var o=n.createContext({}),c=function(e){var t=n.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):i(i({},t),e)),a},u=function(e){var t=c(e.components);return n.createElement(o.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},p=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),d=c(a),p=r,f=d["".concat(o,".").concat(p)]||d[p]||m[p]||l;return a?n.createElement(f,i(i({ref:t},u),{},{components:a})):n.createElement(f,i({ref:t},u))}));function f(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=a.length,i=new Array(l);i[0]=p;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[d]="string"==typeof e?e:r,i[1]=s;for(var c=2;c{a.d(t,{Z:()=>i});var n=a(7294),r=a(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:a,className:i}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var n=a(7462),r=a(7294),l=a(6010),i=a(2466),s=a(6550),o=a(1980),c=a(7392),u=a(12);function d(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function m(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??d(a);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function p(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const n=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function h(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,l=m(e),[i,s]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[o,c]=f({queryString:a,groupId:n}),[d,h]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,u.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),b=(()=>{const e=o??d;return p({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{b&&s(b)}),[b]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),c(e),h(e)}),[c,h,l]),tabValues:l}}var b=a(2389);const k={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:a,selectedValue:s,selectValue:o,tabValues:c}=e;const u=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),m=e=>{const t=e.currentTarget,a=u.indexOf(t),n=c[a].value;n!==s&&(d(t),o(n))},p=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const a=u.indexOf(e.currentTarget)+1;t=u[a]??u[0];break}case"ArrowLeft":{const a=u.indexOf(e.currentTarget)-1;t=u[a]??u[u.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},c.map((e=>{let{value:t,label:a,attributes:i}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>u.push(e),onKeyDown:p,onClick:m},i,{className:(0,l.Z)("tabs__item",k.tabItem,i?.className,{"tabs__item--active":s===t})}),a??t)})))}function y(e){let{lazy:t,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function v(e){const t=h(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",k.tabList)},r.createElement(g,(0,n.Z)({},e,t)),r.createElement(y,(0,n.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return r.createElement(v,(0,n.Z)({key:String(t)},e))}},5891:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>f,frontMatter:()=>s,metadata:()=>c,toc:()=>d});var n=a(7462),r=(a(7294),a(3905)),l=a(4866),i=a(5162);const s={title:"secrets-manager"},o=void 0,c={unversionedId:"middlewares/secrets-manager",id:"middlewares/secrets-manager",title:"secrets-manager",description:"This middleware fetches secrets from AWS Secrets Manager.",source:"@site/docs/middlewares/secrets-manager.md",sourceDirName:"middlewares",slug:"/middlewares/secrets-manager",permalink:"/docs/middlewares/secrets-manager",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/secrets-manager.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"secrets-manager"},sidebar:"tutorialSidebar",previous:{title:"s3",permalink:"/docs/middlewares/s3"},next:{title:"service-discovery",permalink:"/docs/middlewares/service-discovery"}},u={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],m={toc:d},p="wrapper";function f(e){let{components:t,...a}=e;return(0,r.kt)(p,(0,n.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This middleware fetches secrets from ",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html"},"AWS Secrets Manager"),"."),(0,r.kt)("p",null,"Secrets to fetch can be defined by by name. See AWS docs ",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/tutorials_basic.html"},"here"),"."),(0,r.kt)("p",null,"Secrets are assigned to the function handler's ",(0,r.kt)("inlineCode",{parentName:"p"},"context")," object."),(0,r.kt)("p",null,"The Middleware makes a single ",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html"},"API request")," for each secret as Secrets Manager does not support batch get."),(0,r.kt)("p",null,"For each secret, you also provide the name under which its value should be added to ",(0,r.kt)("inlineCode",{parentName:"p"},"context"),"."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/secrets-manager\nnpm install --save-dev @aws-sdk/client-secrets-manager\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/secrets-manager\nyarn add --dev @aws-sdk/client-secrets-manager\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/secrets-manager\npnpm add --save-dev @aws-sdk/client-secrets-manager\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"SecretsManagerClient"),"): SecretsManagerClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-secrets-manager"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to SecretsManagerClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (optional): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (optional): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameter ",(0,r.kt)("inlineCode",{parentName:"li"},"SecretId"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchRotationDate")," (boolean|object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Boolean to apply to all or mapping of internal key name to boolean. This indicates what secrets should fetch and cached based on ",(0,r.kt)("inlineCode",{parentName:"li"},"NextRotationDate"),"/",(0,r.kt)("inlineCode",{parentName:"li"},"LastRotationDate"),"/",(0,r.kt)("inlineCode",{parentName:"li"},"LastChangedDate"),". ",(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," of ",(0,r.kt)("inlineCode",{parentName:"li"},"-1")," will use ",(0,r.kt)("inlineCode",{parentName:"li"},"NextRotationDate"),", while any other value will be added to the ",(0,r.kt)("inlineCode",{parentName:"li"},"LastRotationDate")," or ",(0,r.kt)("inlineCode",{parentName:"li"},"LastChangedDate"),", whichever is more recent. If secrets have different rotation schedules, use multiple instances of this middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"secrets-manager"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store secrets to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"secretsmanager:GetSecretValue"),". If using ",(0,r.kt)("inlineCode",{parentName:"li"},"fetchRotationDate")," add ",(0,r.kt)("inlineCode",{parentName:"li"},"secretsmanager:DescribeSecret")," in as well.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport secretsManager from '@middy/secrets-manager'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler.use(\n secretsManager({\n fetchData: {\n apiToken: 'dev/api_token'\n },\n awsClientOptions: {\n region: 'us-east-1'\n },\n setToContext: true\n })\n)\n\n// Before running the function handler, the middleware will fetch from Secrets Manager\nhandler(event, context, (_, response) => {\n // assuming the dev/api_token has two keys, 'Username' and 'Password'\n t.is(context.apiToken.Username, 'username')\n t.is(context.apiToken.Password, 'password')\n})\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-secrets-manager")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1469],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>f});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function i(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var o=n.createContext({}),c=function(e){var t=n.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):i(i({},t),e)),a},u=function(e){var t=c(e.components);return n.createElement(o.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},p=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),d=c(a),p=r,f=d["".concat(o,".").concat(p)]||d[p]||m[p]||l;return a?n.createElement(f,i(i({ref:t},u),{},{components:a})):n.createElement(f,i({ref:t},u))}));function f(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=a.length,i=new Array(l);i[0]=p;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[d]="string"==typeof e?e:r,i[1]=s;for(var c=2;c{a.d(t,{Z:()=>i});var n=a(7294),r=a(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:a,className:i}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var n=a(7462),r=a(7294),l=a(6010),i=a(2466),s=a(6550),o=a(1980),c=a(7392),u=a(12);function d(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function m(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??d(a);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function p(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const n=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function h(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,l=m(e),[i,s]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[o,c]=f({queryString:a,groupId:n}),[d,h]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,u.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),b=(()=>{const e=o??d;return p({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{b&&s(b)}),[b]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),c(e),h(e)}),[c,h,l]),tabValues:l}}var b=a(2389);const k={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:a,selectedValue:s,selectValue:o,tabValues:c}=e;const u=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),m=e=>{const t=e.currentTarget,a=u.indexOf(t),n=c[a].value;n!==s&&(d(t),o(n))},p=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const a=u.indexOf(e.currentTarget)+1;t=u[a]??u[0];break}case"ArrowLeft":{const a=u.indexOf(e.currentTarget)-1;t=u[a]??u[u.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},c.map((e=>{let{value:t,label:a,attributes:i}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>u.push(e),onKeyDown:p,onClick:m},i,{className:(0,l.Z)("tabs__item",k.tabItem,i?.className,{"tabs__item--active":s===t})}),a??t)})))}function y(e){let{lazy:t,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function v(e){const t=h(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",k.tabList)},r.createElement(g,(0,n.Z)({},e,t)),r.createElement(y,(0,n.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return r.createElement(v,(0,n.Z)({key:String(t)},e))}},5891:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>f,frontMatter:()=>s,metadata:()=>c,toc:()=>d});var n=a(7462),r=(a(7294),a(3905)),l=a(4866),i=a(5162);const s={title:"secrets-manager"},o=void 0,c={unversionedId:"middlewares/secrets-manager",id:"middlewares/secrets-manager",title:"secrets-manager",description:"This middleware fetches secrets from AWS Secrets Manager.",source:"@site/docs/middlewares/secrets-manager.md",sourceDirName:"middlewares",slug:"/middlewares/secrets-manager",permalink:"/docs/middlewares/secrets-manager",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/secrets-manager.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"secrets-manager"},sidebar:"tutorialSidebar",previous:{title:"s3",permalink:"/docs/middlewares/s3"},next:{title:"service-discovery",permalink:"/docs/middlewares/service-discovery"}},u={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],m={toc:d},p="wrapper";function f(e){let{components:t,...a}=e;return(0,r.kt)(p,(0,n.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This middleware fetches secrets from ",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html"},"AWS Secrets Manager"),"."),(0,r.kt)("p",null,"Secrets to fetch can be defined by by name. See AWS docs ",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/tutorials_basic.html"},"here"),"."),(0,r.kt)("p",null,"Secrets are assigned to the function handler's ",(0,r.kt)("inlineCode",{parentName:"p"},"context")," object."),(0,r.kt)("p",null,"The Middleware makes a single ",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html"},"API request")," for each secret as Secrets Manager does not support batch get."),(0,r.kt)("p",null,"For each secret, you also provide the name under which its value should be added to ",(0,r.kt)("inlineCode",{parentName:"p"},"context"),"."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/secrets-manager\nnpm install --save-dev @aws-sdk/client-secrets-manager\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/secrets-manager\nyarn add --dev @aws-sdk/client-secrets-manager\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/secrets-manager\npnpm add --save-dev @aws-sdk/client-secrets-manager\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"SecretsManagerClient"),"): SecretsManagerClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-secrets-manager"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to SecretsManagerClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (optional): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (optional): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameter ",(0,r.kt)("inlineCode",{parentName:"li"},"SecretId"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchRotationDate")," (boolean|object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Boolean to apply to all or mapping of internal key name to boolean. This indicates what secrets should fetch and cached based on ",(0,r.kt)("inlineCode",{parentName:"li"},"NextRotationDate"),"/",(0,r.kt)("inlineCode",{parentName:"li"},"LastRotationDate"),"/",(0,r.kt)("inlineCode",{parentName:"li"},"LastChangedDate"),". ",(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," of ",(0,r.kt)("inlineCode",{parentName:"li"},"-1")," will use ",(0,r.kt)("inlineCode",{parentName:"li"},"NextRotationDate"),", while any other value will be added to the ",(0,r.kt)("inlineCode",{parentName:"li"},"LastRotationDate")," or ",(0,r.kt)("inlineCode",{parentName:"li"},"LastChangedDate"),", whichever is more recent. If secrets have different rotation schedules, use multiple instances of this middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"secrets-manager"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store secrets to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"secretsmanager:GetSecretValue"),". If using ",(0,r.kt)("inlineCode",{parentName:"li"},"fetchRotationDate")," add ",(0,r.kt)("inlineCode",{parentName:"li"},"secretsmanager:DescribeSecret")," in as well.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport secretsManager from '@middy/secrets-manager'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler.use(\n secretsManager({\n fetchData: {\n apiToken: 'dev/api_token'\n },\n awsClientOptions: {\n region: 'us-east-1'\n },\n setToContext: true\n })\n)\n\n// Before running the function handler, the middleware will fetch from Secrets Manager\nhandler(event, context, (_, response) => {\n // assuming the dev/api_token has two keys, 'Username' and 'Password'\n t.is(context.apiToken.Username, 'username')\n t.is(context.apiToken.Password, 'password')\n})\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-secrets-manager")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/1124057e.5f08f71e.js b/assets/js/1124057e.6eab4f08.js similarity index 99% rename from assets/js/1124057e.5f08f71e.js rename to assets/js/1124057e.6eab4f08.js index 2c6d6453c..f88a45dbf 100644 --- a/assets/js/1124057e.5f08f71e.js +++ b/assets/js/1124057e.6eab4f08.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2308],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>b});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},u=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},p=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),c=d(n),p=r,b=c["".concat(s,".").concat(p)]||c[p]||m[p]||l;return n?a.createElement(b,o(o({ref:t},u),{},{components:n})):a.createElement(b,o({ref:t},u))}));function b(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,o=new Array(l);o[0]=p;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[c]="string"==typeof e?e:r,o[1]=i;for(var d=2;d{n.d(t,{Z:()=>o});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var a=n(7462),r=n(7294),l=n(6010),o=n(2466),i=n(6550),s=n(1980),d=n(7392),u=n(12);function c(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??c(n);return function(e){const t=(0,d.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const a=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=m(e),[o,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,d]=b({queryString:n,groupId:a}),[c,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),y=(()=>{const e=s??c;return p({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{y&&i(y)}),[y]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,l]),tabValues:l}}var y=n(2389);const k={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function h(e){let{className:t,block:n,selectedValue:i,selectValue:s,tabValues:d}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),m=e=>{const t=e.currentTarget,n=u.indexOf(t),a=d[n].value;a!==i&&(c(t),s(a))},p=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},d.map((e=>{let{value:t,label:n,attributes:o}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>u.push(e),onKeyDown:p,onClick:m},o,{className:(0,l.Z)("tabs__item",k.tabItem,o?.className,{"tabs__item--active":i===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function g(e){const t=f(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",k.tabList)},r.createElement(h,(0,a.Z)({},e,t)),r.createElement(v,(0,a.Z)({},e,t)))}function w(e){const t=(0,y.Z)();return r.createElement(g,(0,a.Z)({key:String(t)},e))}},4724:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>s,default:()=>b,frontMatter:()=>i,metadata:()=>d,toc:()=>c});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),o=n(5162);const i={title:"dynamodb"},s=void 0,d={unversionedId:"middlewares/dynamodb",id:"middlewares/dynamodb",title:"dynamodb",description:"Fetches DynamoDB stored configuration and parses out JSON.",source:"@site/docs/middlewares/dynamodb.md",sourceDirName:"middlewares",slug:"/middlewares/dynamodb",permalink:"/docs/middlewares/dynamodb",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/dynamodb.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"dynamodb"},sidebar:"tutorialSidebar",previous:{title:"do-not-wait-for-empty-event-loop",permalink:"/docs/middlewares/do-not-wait-for-empty-event-loop"},next:{title:"error-logger",permalink:"/docs/middlewares/error-logger"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],m={toc:c},p="wrapper";function b(e){let{components:t,...n}=e;return(0,r.kt)(p,(0,a.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Fetches DynamoDB stored configuration and parses out JSON."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/dynamodb\nnpm install --save-dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"))),(0,r.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/dynamodb\nyarn add --dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"))),(0,r.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/dynamodb\npnpm add --save-dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"DynamoDBClient"),"): DynamoDBClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-dynamodb"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to DynamoDBClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"dynamodb"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"dynamodb:BatchGetItemCommand"))),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport dynamodb from '@middy/dynamodb'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n dynamodb({\n fetchData: {\n config: {\n TableName: '...'\n Key: {\n pk: '0000'\n }\n }\n }\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-dynamodb")," to the exclude list."))}b.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2308],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>b});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},u=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},p=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),c=d(n),p=r,b=c["".concat(s,".").concat(p)]||c[p]||m[p]||l;return n?a.createElement(b,o(o({ref:t},u),{},{components:n})):a.createElement(b,o({ref:t},u))}));function b(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,o=new Array(l);o[0]=p;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[c]="string"==typeof e?e:r,o[1]=i;for(var d=2;d{n.d(t,{Z:()=>o});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var a=n(7462),r=n(7294),l=n(6010),o=n(2466),i=n(6550),s=n(1980),d=n(7392),u=n(12);function c(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??c(n);return function(e){const t=(0,d.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const a=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=m(e),[o,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,d]=b({queryString:n,groupId:a}),[c,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),y=(()=>{const e=s??c;return p({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{y&&i(y)}),[y]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,l]),tabValues:l}}var y=n(2389);const k={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function h(e){let{className:t,block:n,selectedValue:i,selectValue:s,tabValues:d}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),m=e=>{const t=e.currentTarget,n=u.indexOf(t),a=d[n].value;a!==i&&(c(t),s(a))},p=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},d.map((e=>{let{value:t,label:n,attributes:o}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>u.push(e),onKeyDown:p,onClick:m},o,{className:(0,l.Z)("tabs__item",k.tabItem,o?.className,{"tabs__item--active":i===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function g(e){const t=f(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",k.tabList)},r.createElement(h,(0,a.Z)({},e,t)),r.createElement(v,(0,a.Z)({},e,t)))}function w(e){const t=(0,y.Z)();return r.createElement(g,(0,a.Z)({key:String(t)},e))}},4724:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>s,default:()=>b,frontMatter:()=>i,metadata:()=>d,toc:()=>c});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),o=n(5162);const i={title:"dynamodb"},s=void 0,d={unversionedId:"middlewares/dynamodb",id:"middlewares/dynamodb",title:"dynamodb",description:"Fetches DynamoDB stored configuration and parses out JSON.",source:"@site/docs/middlewares/dynamodb.md",sourceDirName:"middlewares",slug:"/middlewares/dynamodb",permalink:"/docs/middlewares/dynamodb",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/dynamodb.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"dynamodb"},sidebar:"tutorialSidebar",previous:{title:"do-not-wait-for-empty-event-loop",permalink:"/docs/middlewares/do-not-wait-for-empty-event-loop"},next:{title:"error-logger",permalink:"/docs/middlewares/error-logger"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],m={toc:c},p="wrapper";function b(e){let{components:t,...n}=e;return(0,r.kt)(p,(0,a.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Fetches DynamoDB stored configuration and parses out JSON."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/dynamodb\nnpm install --save-dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"))),(0,r.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/dynamodb\nyarn add --dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"))),(0,r.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/dynamodb\npnpm add --save-dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"DynamoDBClient"),"): DynamoDBClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-dynamodb"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to DynamoDBClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"dynamodb"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"dynamodb:BatchGetItemCommand"))),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport dynamodb from '@middy/dynamodb'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n dynamodb({\n fetchData: {\n config: {\n TableName: '...'\n Key: {\n pk: '0000'\n }\n }\n }\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-dynamodb")," to the exclude list."))}b.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/171930c3.e6140d77.js b/assets/js/171930c3.44703c37.js similarity index 97% rename from assets/js/171930c3.e6140d77.js rename to assets/js/171930c3.44703c37.js index 2b5b56afe..561eda5ad 100644 --- a/assets/js/171930c3.e6140d77.js +++ b/assets/js/171930c3.44703c37.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2786],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const a={title:"AWS Relational Database Service (RDS)"},i=void 0,s={unversionedId:"integrations/RDS",id:"integrations/RDS",title:"AWS Relational Database Service (RDS)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/RDS.md",sourceDirName:"integrations",slug:"/integrations/RDS",permalink:"/docs/integrations/RDS",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/RDS.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"AWS Relational Database Service (RDS)"},sidebar:"tutorialSidebar",previous:{title:"Integrations",permalink:"/docs/integrations/intro"},next:{title:"Apollo Server",permalink:"/docs/integrations/apollo-server"}},c={},l=[],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("p",null,"First, you need to pass in a password. In order from most secure to least: ",(0,o.kt)("inlineCode",{parentName:"p"},"RDS.Signer"),", ",(0,o.kt)("inlineCode",{parentName:"p"},"SecretsManager"),", ",(0,o.kt)("inlineCode",{parentName:"p"},"SSM")," using SecureString.\n",(0,o.kt)("inlineCode",{parentName:"p"},"SSM")," can be considered equally secure to ",(0,o.kt)("inlineCode",{parentName:"p"},"SecretsManager")," if you have your own password rotation system."),(0,o.kt)("p",null,"Additionally, you will want to verify the RDS certificate and the domain of your connection. You can use this sudo code to get you started:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import tls from 'tls'\n\n// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html\nconst ca = `-----BEGIN CERTIFICATE----- ...` \n\nconnectionOptions = {\n ...,\n ssl: {\n rejectUnauthorized: true,\n ca,\n checkServerIdentity: (host, cert) => {\n const error = tls.checkServerIdentity(host, cert)\n if (\n error &&\n !cert.subject.CN.endsWith('.rds.amazonaws.com')\n ) {\n return error\n }\n }\n }\n}\n")),(0,o.kt)("p",null,"Corresponding ",(0,o.kt)("inlineCode",{parentName:"p"},"RDS.ParameterGroups")," values should be set to enforce TLS connections."))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2786],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const a={title:"AWS Relational Database Service (RDS)"},i=void 0,s={unversionedId:"integrations/RDS",id:"integrations/RDS",title:"AWS Relational Database Service (RDS)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/RDS.md",sourceDirName:"integrations",slug:"/integrations/RDS",permalink:"/docs/integrations/RDS",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/RDS.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"AWS Relational Database Service (RDS)"},sidebar:"tutorialSidebar",previous:{title:"Integrations",permalink:"/docs/integrations/intro"},next:{title:"Apollo Server",permalink:"/docs/integrations/apollo-server"}},c={},l=[],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("p",null,"First, you need to pass in a password. In order from most secure to least: ",(0,o.kt)("inlineCode",{parentName:"p"},"RDS.Signer"),", ",(0,o.kt)("inlineCode",{parentName:"p"},"SecretsManager"),", ",(0,o.kt)("inlineCode",{parentName:"p"},"SSM")," using SecureString.\n",(0,o.kt)("inlineCode",{parentName:"p"},"SSM")," can be considered equally secure to ",(0,o.kt)("inlineCode",{parentName:"p"},"SecretsManager")," if you have your own password rotation system."),(0,o.kt)("p",null,"Additionally, you will want to verify the RDS certificate and the domain of your connection. You can use this sudo code to get you started:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import tls from 'tls'\n\n// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html\nconst ca = `-----BEGIN CERTIFICATE----- ...` \n\nconnectionOptions = {\n ...,\n ssl: {\n rejectUnauthorized: true,\n ca,\n checkServerIdentity: (host, cert) => {\n const error = tls.checkServerIdentity(host, cert)\n if (\n error &&\n !cert.subject.CN.endsWith('.rds.amazonaws.com')\n ) {\n return error\n }\n }\n }\n}\n")),(0,o.kt)("p",null,"Corresponding ",(0,o.kt)("inlineCode",{parentName:"p"},"RDS.ParameterGroups")," values should be set to enforce TLS connections."))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/18dc5a76.c3badfef.js b/assets/js/18dc5a76.0ce3fddd.js similarity index 98% rename from assets/js/18dc5a76.c3badfef.js rename to assets/js/18dc5a76.0ce3fddd.js index a32a9447c..d7a206d10 100644 --- a/assets/js/18dc5a76.c3badfef.js +++ b/assets/js/18dc5a76.0ce3fddd.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7566],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),s=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},l=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,l=d(e,["components","mdxType","originalType","parentName"]),m=s(r),u=a,y=m["".concat(p,".").concat(u)]||m[u]||c[u]||o;return r?n.createElement(y,i(i({ref:t},l),{},{components:r})):n.createElement(y,i({ref:t},l))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var s=2;s{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>d,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"API Gateway (HTTP)"},i=void 0,d={unversionedId:"events/api-gateway-http",id:"events/api-gateway-http",title:"API Gateway (HTTP)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/api-gateway-http.md",sourceDirName:"events",slug:"/events/api-gateway-http",permalink:"/docs/events/api-gateway-http",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-http.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"API Gateway (HTTP)"},sidebar:"tutorialSidebar",previous:{title:"API Gateway Authorizer",permalink:"/docs/events/api-gateway-authorizer"},next:{title:"API Gateway (REST)",permalink:"/docs/events/api-gateway-rest"}},p={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],l={toc:s},m="wrapper";function c(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html"},"Using AWS Lambda with Amazon API Gateway")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html"},"Working with HTTP APIs"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer'\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n default: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .use(httpErrorHandlerMiddleware())\n .handler((event, context, { signal }) => {\n // ...\n })\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7566],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),s=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},l=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,l=d(e,["components","mdxType","originalType","parentName"]),m=s(r),u=a,y=m["".concat(p,".").concat(u)]||m[u]||c[u]||o;return r?n.createElement(y,i(i({ref:t},l),{},{components:r})):n.createElement(y,i({ref:t},l))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var s=2;s{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>d,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"API Gateway (HTTP)"},i=void 0,d={unversionedId:"events/api-gateway-http",id:"events/api-gateway-http",title:"API Gateway (HTTP)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/api-gateway-http.md",sourceDirName:"events",slug:"/events/api-gateway-http",permalink:"/docs/events/api-gateway-http",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-http.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"API Gateway (HTTP)"},sidebar:"tutorialSidebar",previous:{title:"API Gateway Authorizer",permalink:"/docs/events/api-gateway-authorizer"},next:{title:"API Gateway (REST)",permalink:"/docs/events/api-gateway-rest"}},p={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],l={toc:s},m="wrapper";function c(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html"},"Using AWS Lambda with Amazon API Gateway")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html"},"Working with HTTP APIs"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer'\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n default: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .use(httpErrorHandlerMiddleware())\n .handler((event, context, { signal }) => {\n // ...\n })\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/19606b2d.9d19e9cd.js b/assets/js/19606b2d.93d9e091.js similarity index 99% rename from assets/js/19606b2d.9d19e9cd.js rename to assets/js/19606b2d.93d9e091.js index 1d1071459..7114f3c4b 100644 --- a/assets/js/19606b2d.9d19e9cd.js +++ b/assets/js/19606b2d.93d9e091.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1544],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>c});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function i(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var d=n.createContext({}),u=function(e){var t=n.useContext(d),a=t;return e&&(a="function"==typeof e?e(t):i(i({},t),e)),a},m=function(e){var t=u(e.components);return n.createElement(d.Provider,{value:t},e.children)},p="mdxType",s={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},N=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,l=e.originalType,d=e.parentName,m=o(e,["components","mdxType","originalType","parentName"]),p=u(a),N=r,c=p["".concat(d,".").concat(N)]||p[N]||s[N]||l;return a?n.createElement(c,i(i({ref:t},m),{},{components:a})):n.createElement(c,i({ref:t},m))}));function c(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=a.length,i=new Array(l);i[0]=N;var o={};for(var d in t)hasOwnProperty.call(t,d)&&(o[d]=t[d]);o.originalType=e,o[p]="string"==typeof e?e:r,i[1]=o;for(var u=2;u{a.d(t,{Z:()=>i});var n=a(7294),r=a(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:a,className:i}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>h});var n=a(7462),r=a(7294),l=a(6010),i=a(2466),o=a(6550),d=a(1980),u=a(7392),m=a(12);function p(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function s(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??p(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function N(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function c(e){let{queryString:t=!1,groupId:a}=e;const n=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,d._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function k(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,l=s(e),[i,o]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!N({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[d,u]=c({queryString:a,groupId:n}),[p,k]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,m.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),g=(()=>{const e=d??p;return N({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!N({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),k(e)}),[u,k,l]),tabValues:l}}var g=a(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:a,selectedValue:o,selectValue:d,tabValues:u}=e;const m=[],{blockElementScrollPositionUntilNextRender:p}=(0,i.o5)(),s=e=>{const t=e.currentTarget,a=m.indexOf(t),n=u[a].value;n!==o&&(p(t),d(n))},N=e=>{let t=null;switch(e.key){case"Enter":s(e);break;case"ArrowRight":{const a=m.indexOf(e.currentTarget)+1;t=m[a]??m[0];break}case"ArrowLeft":{const a=m.indexOf(e.currentTarget)-1;t=m[a]??m[m.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:i}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>m.push(e),onKeyDown:N,onClick:s},i,{className:(0,l.Z)("tabs__item",b.tabItem,i?.className,{"tabs__item--active":o===t})}),a??t)})))}function f(e){let{lazy:t,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function v(e){const t=k(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",b.tabList)},r.createElement(y,(0,n.Z)({},e,t)),r.createElement(f,(0,n.Z)({},e,t)))}function h(e){const t=(0,g.Z)();return r.createElement(v,(0,n.Z)({key:String(t)},e))}},236:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>m,contentTitle:()=>d,default:()=>c,frontMatter:()=>o,metadata:()=>u,toc:()=>p});var n=a(7462),r=(a(7294),a(3905)),l=a(4866),i=a(5162);const o={title:"event-normalizer"},d=void 0,u={unversionedId:"middlewares/event-normalizer",id:"middlewares/event-normalizer",title:"event-normalizer",description:"Middleware for iterating through an AWS event records, parsing and normalizing nested events.",source:"@site/docs/middlewares/event-normalizer.md",sourceDirName:"middlewares",slug:"/middlewares/event-normalizer",permalink:"/docs/middlewares/event-normalizer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/event-normalizer.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"event-normalizer"},sidebar:"tutorialSidebar",previous:{title:"error-logger",permalink:"/docs/middlewares/error-logger"},next:{title:"http-content-encoding",permalink:"/docs/middlewares/http-content-encoding"}},m={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],s={toc:p},N="wrapper";function c(e){let{components:t,...a}=e;return(0,r.kt)(N,(0,n.Z)({},s,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Middleware for iterating through an AWS event records, parsing and normalizing nested events."),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"AWS Events Transformations:"),"\n",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html"},"https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html")),(0,r.kt)("table",null,(0,r.kt)("thead",{parentName:"table"},(0,r.kt)("tr",{parentName:"thead"},(0,r.kt)("th",{parentName:"tr",align:null},"Event Source"),(0,r.kt)("th",{parentName:"tr",align:null},"Included"),(0,r.kt)("th",{parentName:"tr",align:null},"Comments"))),(0,r.kt)("tbody",{parentName:"table"},(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Alexa"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"API Gateway (HTTP)"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware prefixed with ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/http-"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"API Gateway (REST)"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware prefixed with ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/http-"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"API Gateway (WS)"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/ws-json-body-parser"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Application LB"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware prefixed with ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/http-"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CloudFormation"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CloudFront"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CloudTrail"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CloudWatch Logs"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"data"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CodeCommit"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CodePipeline"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"UserParameters"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Cognito"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Config"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"invokingEvent")," and ",(0,r.kt)("inlineCode",{parentName:"td"},"ruleParameters"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Connect"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"DocumentDB"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"DynamoDB"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Unmarshall ",(0,r.kt)("inlineCode",{parentName:"td"},"Keys"),", ",(0,r.kt)("inlineCode",{parentName:"td"},"OldImage"),", and ",(0,r.kt)("inlineCode",{parentName:"td"},"NewImage"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"EC2"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"EventBridge"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"IoT"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"IoT Event"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Kafka"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"value"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Kafka (MSK)"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"value"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Kinesis Firehose"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"data"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Kinesis Stream"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"data"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Lex"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"MQ"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"data"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"RDS"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"S3"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"URI decode ",(0,r.kt)("inlineCode",{parentName:"td"},"key"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"S3 Batch"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"URI decode ",(0,r.kt)("inlineCode",{parentName:"td"},"s3Key"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"S3 Object Lambda"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/s3-object-response"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Secrets Manager"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"SES"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"SNS"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"Message"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"SQS"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"body"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"VPC Lattice"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware prefixed with ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/http-"))))),(0,r.kt)("p",null,"*"," Handled in another dedicated middleware(s)"),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"Test Events"),"\nSome events send test events after set, you will need to handle these."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-js"},"// S3 Test Event\n{\n Service: 'Amazon S3',\n Event: 's3:TestEvent',\n Time: '2020-01-01T00:00:00.000Z',\n Bucket: 'bucket-name',\n RequestId: '***********',\n HostId: '***/***/***='\n}\n")),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/event-normalizer\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/event-normalizer\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/event-normalizer\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"wrapNumbers")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Whether to return numbers as a string instead of converting them to native JavaScript numbers. This allows for the safe round-trip transport of numbers of arbitrary size. For DynamoDB Events only.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizer from '@middy/event-normalizer'\n\nconst lambdaHandler = (event, context) => {\n const { Records } = event\n for (const record of Records) {\n // ...\n }\n}\n\nconst handler = middy(lambdaHandler).use(eventNormalizer())\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1544],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>c});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function i(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var d=n.createContext({}),u=function(e){var t=n.useContext(d),a=t;return e&&(a="function"==typeof e?e(t):i(i({},t),e)),a},m=function(e){var t=u(e.components);return n.createElement(d.Provider,{value:t},e.children)},p="mdxType",s={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},N=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,l=e.originalType,d=e.parentName,m=o(e,["components","mdxType","originalType","parentName"]),p=u(a),N=r,c=p["".concat(d,".").concat(N)]||p[N]||s[N]||l;return a?n.createElement(c,i(i({ref:t},m),{},{components:a})):n.createElement(c,i({ref:t},m))}));function c(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=a.length,i=new Array(l);i[0]=N;var o={};for(var d in t)hasOwnProperty.call(t,d)&&(o[d]=t[d]);o.originalType=e,o[p]="string"==typeof e?e:r,i[1]=o;for(var u=2;u{a.d(t,{Z:()=>i});var n=a(7294),r=a(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:a,className:i}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>h});var n=a(7462),r=a(7294),l=a(6010),i=a(2466),o=a(6550),d=a(1980),u=a(7392),m=a(12);function p(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function s(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??p(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function N(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function c(e){let{queryString:t=!1,groupId:a}=e;const n=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,d._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function k(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,l=s(e),[i,o]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!N({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[d,u]=c({queryString:a,groupId:n}),[p,k]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,m.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),g=(()=>{const e=d??p;return N({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!N({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),k(e)}),[u,k,l]),tabValues:l}}var g=a(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:a,selectedValue:o,selectValue:d,tabValues:u}=e;const m=[],{blockElementScrollPositionUntilNextRender:p}=(0,i.o5)(),s=e=>{const t=e.currentTarget,a=m.indexOf(t),n=u[a].value;n!==o&&(p(t),d(n))},N=e=>{let t=null;switch(e.key){case"Enter":s(e);break;case"ArrowRight":{const a=m.indexOf(e.currentTarget)+1;t=m[a]??m[0];break}case"ArrowLeft":{const a=m.indexOf(e.currentTarget)-1;t=m[a]??m[m.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:i}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>m.push(e),onKeyDown:N,onClick:s},i,{className:(0,l.Z)("tabs__item",b.tabItem,i?.className,{"tabs__item--active":o===t})}),a??t)})))}function f(e){let{lazy:t,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function v(e){const t=k(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",b.tabList)},r.createElement(y,(0,n.Z)({},e,t)),r.createElement(f,(0,n.Z)({},e,t)))}function h(e){const t=(0,g.Z)();return r.createElement(v,(0,n.Z)({key:String(t)},e))}},236:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>m,contentTitle:()=>d,default:()=>c,frontMatter:()=>o,metadata:()=>u,toc:()=>p});var n=a(7462),r=(a(7294),a(3905)),l=a(4866),i=a(5162);const o={title:"event-normalizer"},d=void 0,u={unversionedId:"middlewares/event-normalizer",id:"middlewares/event-normalizer",title:"event-normalizer",description:"Middleware for iterating through an AWS event records, parsing and normalizing nested events.",source:"@site/docs/middlewares/event-normalizer.md",sourceDirName:"middlewares",slug:"/middlewares/event-normalizer",permalink:"/docs/middlewares/event-normalizer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/event-normalizer.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"event-normalizer"},sidebar:"tutorialSidebar",previous:{title:"error-logger",permalink:"/docs/middlewares/error-logger"},next:{title:"http-content-encoding",permalink:"/docs/middlewares/http-content-encoding"}},m={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],s={toc:p},N="wrapper";function c(e){let{components:t,...a}=e;return(0,r.kt)(N,(0,n.Z)({},s,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Middleware for iterating through an AWS event records, parsing and normalizing nested events."),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"AWS Events Transformations:"),"\n",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html"},"https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html")),(0,r.kt)("table",null,(0,r.kt)("thead",{parentName:"table"},(0,r.kt)("tr",{parentName:"thead"},(0,r.kt)("th",{parentName:"tr",align:null},"Event Source"),(0,r.kt)("th",{parentName:"tr",align:null},"Included"),(0,r.kt)("th",{parentName:"tr",align:null},"Comments"))),(0,r.kt)("tbody",{parentName:"table"},(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Alexa"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"API Gateway (HTTP)"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware prefixed with ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/http-"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"API Gateway (REST)"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware prefixed with ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/http-"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"API Gateway (WS)"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/ws-json-body-parser"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Application LB"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware prefixed with ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/http-"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CloudFormation"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CloudFront"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CloudTrail"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CloudWatch Logs"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"data"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CodeCommit"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"CodePipeline"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"UserParameters"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Cognito"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Config"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"invokingEvent")," and ",(0,r.kt)("inlineCode",{parentName:"td"},"ruleParameters"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Connect"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"DocumentDB"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"DynamoDB"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Unmarshall ",(0,r.kt)("inlineCode",{parentName:"td"},"Keys"),", ",(0,r.kt)("inlineCode",{parentName:"td"},"OldImage"),", and ",(0,r.kt)("inlineCode",{parentName:"td"},"NewImage"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"EC2"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"EventBridge"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"IoT"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"IoT Event"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Kafka"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"value"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Kafka (MSK)"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"value"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Kinesis Firehose"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"data"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Kinesis Stream"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"data"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Lex"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"MQ"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"Base64 decode and JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"data"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"RDS"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"S3"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"URI decode ",(0,r.kt)("inlineCode",{parentName:"td"},"key"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"S3 Batch"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"URI decode ",(0,r.kt)("inlineCode",{parentName:"td"},"s3Key"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"S3 Object Lambda"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/s3-object-response"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Secrets Manager"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"SES"),(0,r.kt)("td",{parentName:"tr",align:null},"No"),(0,r.kt)("td",{parentName:"tr",align:null},"Normalization not required")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"SNS"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"Message"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"SQS"),(0,r.kt)("td",{parentName:"tr",align:null},"Yes"),(0,r.kt)("td",{parentName:"tr",align:null},"JSON parse ",(0,r.kt)("inlineCode",{parentName:"td"},"body"))),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"VPC Lattice"),(0,r.kt)("td",{parentName:"tr",align:null},"No ","*"),(0,r.kt)("td",{parentName:"tr",align:null},"See middleware prefixed with ",(0,r.kt)("inlineCode",{parentName:"td"},"@middy/http-"))))),(0,r.kt)("p",null,"*"," Handled in another dedicated middleware(s)"),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"Test Events"),"\nSome events send test events after set, you will need to handle these."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-js"},"// S3 Test Event\n{\n Service: 'Amazon S3',\n Event: 's3:TestEvent',\n Time: '2020-01-01T00:00:00.000Z',\n Bucket: 'bucket-name',\n RequestId: '***********',\n HostId: '***/***/***='\n}\n")),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/event-normalizer\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/event-normalizer\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/event-normalizer\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"wrapNumbers")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Whether to return numbers as a string instead of converting them to native JavaScript numbers. This allows for the safe round-trip transport of numbers of arbitrary size. For DynamoDB Events only.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizer from '@middy/event-normalizer'\n\nconst lambdaHandler = (event, context) => {\n const { Records } = event\n for (const record of Records) {\n // ...\n }\n}\n\nconst handler = middy(lambdaHandler).use(eventNormalizer())\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/1c88510b.40415123.js b/assets/js/1c88510b.9ce37300.js similarity index 99% rename from assets/js/1c88510b.40415123.js rename to assets/js/1c88510b.9ce37300.js index ec03f870e..f4a2ae518 100644 --- a/assets/js/1c88510b.40415123.js +++ b/assets/js/1c88510b.9ce37300.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7858],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>b});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var i=r.createContext({}),u=function(e){var t=r.useContext(i),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=u(e.components);return r.createElement(i.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),d=u(n),m=a,b=d["".concat(i,".").concat(m)]||d[m]||p[m]||l;return n?r.createElement(b,o(o({ref:t},c),{},{components:n})):r.createElement(b,o({ref:t},c))}));function b(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,o=new Array(l);o[0]=m;var s={};for(var i in t)hasOwnProperty.call(t,i)&&(s[i]=t[i]);s.originalType=e,s[d]="string"==typeof e?e:a,o[1]=s;for(var u=2;u{n.d(t,{Z:()=>o});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7462),a=n(7294),l=n(6010),o=n(2466),s=n(6550),i=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const r=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=p(e),[o,s]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[i,u]=b({queryString:n,groupId:r}),[d,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),y=(()=>{const e=i??d;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{y&&s(y)}),[y]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),u(e),f(e)}),[u,f,l]),tabValues:l}}var y=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),r=u[n].value;r!==s&&(d(t),i(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:o}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",h.tabItem,o?.className,{"tabs__item--active":s===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function g(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},a.createElement(k,(0,r.Z)({},e,t)),a.createElement(v,(0,r.Z)({},e,t)))}function w(e){const t=(0,y.Z)();return a.createElement(g,(0,r.Z)({key:String(t)},e))}},1113:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>b,frontMatter:()=>s,metadata:()=>u,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),o=n(5162);const s={title:"s3-object-response"},i=void 0,u={unversionedId:"middlewares/s3-object-response",id:"middlewares/s3-object-response",title:"s3-object-response",description:"This middleware is a Proof of Concept and requires real world testing before use, not recommended for production",source:"@site/docs/middlewares/s3-object-response.md",sourceDirName:"middlewares",slug:"/middlewares/s3-object-response",permalink:"/docs/middlewares/s3-object-response",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/s3-object-response.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"s3-object-response"},sidebar:"tutorialSidebar",previous:{title:"rds-signer",permalink:"/docs/middlewares/rds-signer"},next:{title:"s3",permalink:"/docs/middlewares/s3"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Stream",id:"stream",level:3},{value:"Promise",id:"promise",level:3},{value:"Bundling",id:"bundling",level:2}],p={toc:d},m="wrapper";function b(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,(0,a.kt)("strong",{parentName:"p"}," This middleware is a Proof of Concept and requires real world testing before use, not recommended for production ")),(0,a.kt)("p",null,"Fetches S3 object as a stream and writes back to s3 object response."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/s3-object-response\nnpm install --save-dev @aws-sdk/client-s3\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/s3-object-response\nyarn add --dev @aws-sdk/client-s3\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/s3-object-response\npnpm add --save-dev @aws-sdk/client-s3\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"bodyType")," (string) (required): How to pass in the s3 object through the handler. Can be ",(0,a.kt)("inlineCode",{parentName:"li"},"stream")," or ",(0,a.kt)("inlineCode",{parentName:"li"},"promise"),"."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"S3Client"),"): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-s3"),"."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to S3Client class constructor."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (optional): Enable XRay by passing ",(0,a.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,a.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"httpsCapture")," (function) (optional): Enable XRay by passing ",(0,a.kt)("inlineCode",{parentName:"li"},"captureHTTPsGlobal")," from ",(0,a.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,a.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch.")),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"The response from the handler must match the allowed parameters for ",(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#writeGetObjectResponse-property"},(0,a.kt)("inlineCode",{parentName:"a"},"S3.writeGetObjectResponse")),", excluding ",(0,a.kt)("inlineCode",{parentName:"li"},"RequestRoute")," and ",(0,a.kt)("inlineCode",{parentName:"li"},"RequestToken"),"."),(0,a.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,a.kt)("inlineCode",{parentName:"li"},"s3-object-lambda:WriteGetObjectResponse"))),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("h3",{id:"stream"},"Stream"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import zlib from 'zlib'\nimport middy from '@middy/core'\nimport s3ObjectResponse from '@middy/s3-object-response'\n\nconst handler = middy((event, context) => {\n const readStream = context.s3Object\n const transformStream = zlib.createBrotliCompress()\n return {\n Body: readStream.pipe(transformStream)\n }\n})\n\nhandler.use(\n s3ObjectResponse({\n bodyType: 'stream'\n })\n)\n")),(0,a.kt)("h3",{id:"promise"},"Promise"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import zlib from 'zlib'\nimport middy from '@middy/core'\nimport s3ObjectResponse from '@middy/s3-object-response'\n\nconst handler = middy(async (event, context) => {\n let body = await context.s3Object\n // change body\n return {\n Body: JSON.stringify(body)\n }\n})\n\nhandler.use(\n s3ObjectResponse({\n bodyType: 'promise'\n })\n)\n")),(0,a.kt)("h2",{id:"bundling"},"Bundling"),(0,a.kt)("p",null,"To exclude ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-s3")," to the exclude list."))}b.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7858],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>b});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var i=r.createContext({}),u=function(e){var t=r.useContext(i),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=u(e.components);return r.createElement(i.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),d=u(n),m=a,b=d["".concat(i,".").concat(m)]||d[m]||p[m]||l;return n?r.createElement(b,o(o({ref:t},c),{},{components:n})):r.createElement(b,o({ref:t},c))}));function b(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,o=new Array(l);o[0]=m;var s={};for(var i in t)hasOwnProperty.call(t,i)&&(s[i]=t[i]);s.originalType=e,s[d]="string"==typeof e?e:a,o[1]=s;for(var u=2;u{n.d(t,{Z:()=>o});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7462),a=n(7294),l=n(6010),o=n(2466),s=n(6550),i=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const r=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=p(e),[o,s]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[i,u]=b({queryString:n,groupId:r}),[d,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),y=(()=>{const e=i??d;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{y&&s(y)}),[y]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),u(e),f(e)}),[u,f,l]),tabValues:l}}var y=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),r=u[n].value;r!==s&&(d(t),i(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:o}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",h.tabItem,o?.className,{"tabs__item--active":s===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function g(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},a.createElement(k,(0,r.Z)({},e,t)),a.createElement(v,(0,r.Z)({},e,t)))}function w(e){const t=(0,y.Z)();return a.createElement(g,(0,r.Z)({key:String(t)},e))}},1113:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>b,frontMatter:()=>s,metadata:()=>u,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),o=n(5162);const s={title:"s3-object-response"},i=void 0,u={unversionedId:"middlewares/s3-object-response",id:"middlewares/s3-object-response",title:"s3-object-response",description:"This middleware is a Proof of Concept and requires real world testing before use, not recommended for production",source:"@site/docs/middlewares/s3-object-response.md",sourceDirName:"middlewares",slug:"/middlewares/s3-object-response",permalink:"/docs/middlewares/s3-object-response",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/s3-object-response.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"s3-object-response"},sidebar:"tutorialSidebar",previous:{title:"rds-signer",permalink:"/docs/middlewares/rds-signer"},next:{title:"s3",permalink:"/docs/middlewares/s3"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Stream",id:"stream",level:3},{value:"Promise",id:"promise",level:3},{value:"Bundling",id:"bundling",level:2}],p={toc:d},m="wrapper";function b(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,(0,a.kt)("strong",{parentName:"p"}," This middleware is a Proof of Concept and requires real world testing before use, not recommended for production ")),(0,a.kt)("p",null,"Fetches S3 object as a stream and writes back to s3 object response."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/s3-object-response\nnpm install --save-dev @aws-sdk/client-s3\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/s3-object-response\nyarn add --dev @aws-sdk/client-s3\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/s3-object-response\npnpm add --save-dev @aws-sdk/client-s3\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"bodyType")," (string) (required): How to pass in the s3 object through the handler. Can be ",(0,a.kt)("inlineCode",{parentName:"li"},"stream")," or ",(0,a.kt)("inlineCode",{parentName:"li"},"promise"),"."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"S3Client"),"): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-s3"),"."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to S3Client class constructor."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (optional): Enable XRay by passing ",(0,a.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,a.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"httpsCapture")," (function) (optional): Enable XRay by passing ",(0,a.kt)("inlineCode",{parentName:"li"},"captureHTTPsGlobal")," from ",(0,a.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,a.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch.")),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"The response from the handler must match the allowed parameters for ",(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#writeGetObjectResponse-property"},(0,a.kt)("inlineCode",{parentName:"a"},"S3.writeGetObjectResponse")),", excluding ",(0,a.kt)("inlineCode",{parentName:"li"},"RequestRoute")," and ",(0,a.kt)("inlineCode",{parentName:"li"},"RequestToken"),"."),(0,a.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,a.kt)("inlineCode",{parentName:"li"},"s3-object-lambda:WriteGetObjectResponse"))),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("h3",{id:"stream"},"Stream"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import zlib from 'zlib'\nimport middy from '@middy/core'\nimport s3ObjectResponse from '@middy/s3-object-response'\n\nconst handler = middy((event, context) => {\n const readStream = context.s3Object\n const transformStream = zlib.createBrotliCompress()\n return {\n Body: readStream.pipe(transformStream)\n }\n})\n\nhandler.use(\n s3ObjectResponse({\n bodyType: 'stream'\n })\n)\n")),(0,a.kt)("h3",{id:"promise"},"Promise"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import zlib from 'zlib'\nimport middy from '@middy/core'\nimport s3ObjectResponse from '@middy/s3-object-response'\n\nconst handler = middy(async (event, context) => {\n let body = await context.s3Object\n // change body\n return {\n Body: JSON.stringify(body)\n }\n})\n\nhandler.use(\n s3ObjectResponse({\n bodyType: 'promise'\n })\n)\n")),(0,a.kt)("h2",{id:"bundling"},"Bundling"),(0,a.kt)("p",null,"To exclude ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-s3")," to the exclude list."))}b.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/1e42f3f3.8755555c.js b/assets/js/1e42f3f3.9c68957b.js similarity index 98% rename from assets/js/1e42f3f3.8755555c.js rename to assets/js/1e42f3f3.9c68957b.js index 6cd5a6d73..863cf2106 100644 --- a/assets/js/1e42f3f3.8755555c.js +++ b/assets/js/1e42f3f3.9c68957b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8102],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var l=n.createContext({}),d=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):s(s({},t),e)),r},p=function(e){var t=d(e.components);return n.createElement(l.Provider,{value:t},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),c=d(r),m=a,y=c["".concat(l,".").concat(m)]||c[m]||u[m]||o;return r?n.createElement(y,s(s({ref:t},p),{},{components:r})):n.createElement(y,s({ref:t},p))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,s=new Array(o);s[0]=m;var i={};for(var l in t)hasOwnProperty.call(t,l)&&(i[l]=t[l]);i.originalType=e,i[c]="string"==typeof e?e:a,s[1]=i;for(var d=2;d{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>s,default:()=>u,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var n=r(7462),a=(r(7294),r(3905));const o={title:"ws-json-body-parser"},s=void 0,i={unversionedId:"middlewares/ws-json-body-parser",id:"middlewares/ws-json-body-parser",title:"ws-json-body-parser",description:"This middleware automatically parses WebSocket requests with a JSON body and converts the body into an",source:"@site/docs/middlewares/ws-json-body-parser.md",sourceDirName:"middlewares",slug:"/middlewares/ws-json-body-parser",permalink:"/docs/middlewares/ws-json-body-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ws-json-body-parser.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"ws-json-body-parser"},sidebar:"tutorialSidebar",previous:{title:"warmup",permalink:"/docs/middlewares/warmup"},next:{title:"ws-response",permalink:"/docs/middlewares/ws-response"}},l={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:d},c="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(c,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware automatically parses WebSocket requests with a JSON body and converts the body into an\nobject."),(0,a.kt)("p",null,"It can also be used in combination with validator as a prior step to normalize the\nevent body input as an object so that the content can be validated."),(0,a.kt)("p",null,"If the body has been parsed as JSON, you can access the original body through the ",(0,a.kt)("inlineCode",{parentName:"p"},"request.event.rawBody"),"."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/ws-json-body-parser\n")),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reviver")," (function) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"undefined"),"): A ",(0,a.kt)("a",{parentName:"li",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters"},"reviver")," parameter may be passed which will be used ",(0,a.kt)("inlineCode",{parentName:"li"},"JSON.parse"),"ing the body.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsJsonBodyParserMiddleware from '@middy/ws-json-body-parser'\nimport wsResponseMiddleware from '@middy/ws-response'\n\nexport const handler = middy()\n .use(wsJsonBodyParserMiddleware())\n .use(wsResponseMiddleware())\n .handler((event) => {\n return event.body.message\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8102],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var l=n.createContext({}),d=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):s(s({},t),e)),r},p=function(e){var t=d(e.components);return n.createElement(l.Provider,{value:t},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),c=d(r),m=a,y=c["".concat(l,".").concat(m)]||c[m]||u[m]||o;return r?n.createElement(y,s(s({ref:t},p),{},{components:r})):n.createElement(y,s({ref:t},p))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,s=new Array(o);s[0]=m;var i={};for(var l in t)hasOwnProperty.call(t,l)&&(i[l]=t[l]);i.originalType=e,i[c]="string"==typeof e?e:a,s[1]=i;for(var d=2;d{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>s,default:()=>u,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var n=r(7462),a=(r(7294),r(3905));const o={title:"ws-json-body-parser"},s=void 0,i={unversionedId:"middlewares/ws-json-body-parser",id:"middlewares/ws-json-body-parser",title:"ws-json-body-parser",description:"This middleware automatically parses WebSocket requests with a JSON body and converts the body into an",source:"@site/docs/middlewares/ws-json-body-parser.md",sourceDirName:"middlewares",slug:"/middlewares/ws-json-body-parser",permalink:"/docs/middlewares/ws-json-body-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ws-json-body-parser.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"ws-json-body-parser"},sidebar:"tutorialSidebar",previous:{title:"warmup",permalink:"/docs/middlewares/warmup"},next:{title:"ws-response",permalink:"/docs/middlewares/ws-response"}},l={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:d},c="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(c,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware automatically parses WebSocket requests with a JSON body and converts the body into an\nobject."),(0,a.kt)("p",null,"It can also be used in combination with validator as a prior step to normalize the\nevent body input as an object so that the content can be validated."),(0,a.kt)("p",null,"If the body has been parsed as JSON, you can access the original body through the ",(0,a.kt)("inlineCode",{parentName:"p"},"request.event.rawBody"),"."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/ws-json-body-parser\n")),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reviver")," (function) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"undefined"),"): A ",(0,a.kt)("a",{parentName:"li",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters"},"reviver")," parameter may be passed which will be used ",(0,a.kt)("inlineCode",{parentName:"li"},"JSON.parse"),"ing the body.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsJsonBodyParserMiddleware from '@middy/ws-json-body-parser'\nimport wsResponseMiddleware from '@middy/ws-response'\n\nexport const handler = middy()\n .use(wsJsonBodyParserMiddleware())\n .use(wsResponseMiddleware())\n .handler((event) => {\n return event.body.message\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/1ea8ecd6.92bd53b9.js b/assets/js/1ea8ecd6.5e94cf62.js similarity index 96% rename from assets/js/1ea8ecd6.92bd53b9.js rename to assets/js/1ea8ecd6.5e94cf62.js index ed1721334..8a2cadda1 100644 --- a/assets/js/1ea8ecd6.92bd53b9.js +++ b/assets/js/1ea8ecd6.5e94cf62.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5341],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const a={title:"Internet of things (IoT)"},i=void 0,s={unversionedId:"events/iot",id:"events/iot",title:"Internet of things (IoT)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/iot.md",sourceDirName:"events",slug:"/events/iot",permalink:"/docs/events/iot",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/iot.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Internet of things (IoT)"},sidebar:"tutorialSidebar",previous:{title:"IoT Events",permalink:"/docs/events/iot-events"},next:{title:"Kafka, Managed Streaming (MSK)",permalink:"/docs/events/kafka-managed-streaming"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-iot.html"},"Using AWS Lambda with AWS IoT"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5341],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const a={title:"Internet of things (IoT)"},i=void 0,s={unversionedId:"events/iot",id:"events/iot",title:"Internet of things (IoT)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/iot.md",sourceDirName:"events",slug:"/events/iot",permalink:"/docs/events/iot",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/iot.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Internet of things (IoT)"},sidebar:"tutorialSidebar",previous:{title:"IoT Events",permalink:"/docs/events/iot-events"},next:{title:"Kafka, Managed Streaming (MSK)",permalink:"/docs/events/kafka-managed-streaming"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-iot.html"},"Using AWS Lambda with AWS IoT"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/211396ae.39ff8015.js b/assets/js/211396ae.cc492d70.js similarity index 96% rename from assets/js/211396ae.39ff8015.js rename to assets/js/211396ae.cc492d70.js index a5bc3f619..f78385032 100644 --- a/assets/js/211396ae.39ff8015.js +++ b/assets/js/211396ae.cc492d70.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3616],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),s=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},d=function(e){var t=s(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),u=s(r),m=o,f=u["".concat(c,".").concat(m)]||u[m]||p[m]||a;return r?n.createElement(f,i(i({ref:t},d),{},{components:r})):n.createElement(f,i({ref:t},d))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[u]="string"==typeof e?e:o,i[1]=l;for(var s=2;s{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var n=r(7462),o=(r(7294),r(3905));const a={title:"Cloud Watch Logs"},i=void 0,l={unversionedId:"events/cloud-watch-logs",id:"events/cloud-watch-logs",title:"Cloud Watch Logs",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cloud-watch-logs.md",sourceDirName:"events",slug:"/events/cloud-watch-logs",permalink:"/docs/events/cloud-watch-logs",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-watch-logs.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Cloud Watch Logs"},sidebar:"tutorialSidebar",previous:{title:"CloudTrail",permalink:"/docs/events/cloud-trail"},next:{title:"Code Commit",permalink:"/docs/events/code-commit"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],d={toc:s},u="wrapper";function p(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchlogs.html"},"Using Lambda with CloudWatch Logs"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3616],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),s=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},d=function(e){var t=s(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),u=s(r),m=o,f=u["".concat(c,".").concat(m)]||u[m]||p[m]||a;return r?n.createElement(f,i(i({ref:t},d),{},{components:r})):n.createElement(f,i({ref:t},d))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[u]="string"==typeof e?e:o,i[1]=l;for(var s=2;s{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var n=r(7462),o=(r(7294),r(3905));const a={title:"Cloud Watch Logs"},i=void 0,l={unversionedId:"events/cloud-watch-logs",id:"events/cloud-watch-logs",title:"Cloud Watch Logs",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cloud-watch-logs.md",sourceDirName:"events",slug:"/events/cloud-watch-logs",permalink:"/docs/events/cloud-watch-logs",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-watch-logs.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Cloud Watch Logs"},sidebar:"tutorialSidebar",previous:{title:"CloudTrail",permalink:"/docs/events/cloud-trail"},next:{title:"Code Commit",permalink:"/docs/events/code-commit"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],d={toc:s},u="wrapper";function p(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchlogs.html"},"Using Lambda with CloudWatch Logs"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/24a252b9.591d80e1.js b/assets/js/24a252b9.8a1558d6.js similarity index 98% rename from assets/js/24a252b9.591d80e1.js rename to assets/js/24a252b9.8a1558d6.js index db7ef1948..f64a39e65 100644 --- a/assets/js/24a252b9.591d80e1.js +++ b/assets/js/24a252b9.8a1558d6.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1098],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>g});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var i=r.createContext({}),s=function(e){var t=r.useContext(i),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=s(e.components);return r.createElement(i.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,c=u(e,["components","mdxType","originalType","parentName"]),p=s(n),m=a,g=p["".concat(i,".").concat(m)]||p[m]||d[m]||l;return n?r.createElement(g,o(o({ref:t},c),{},{components:n})):r.createElement(g,o({ref:t},c))}));function g(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,o=new Array(l);o[0]=m;var u={};for(var i in t)hasOwnProperty.call(t,i)&&(u[i]=t[i]);u.originalType=e,u[p]="string"==typeof e?e:a,o[1]=u;for(var s=2;s{n.d(t,{Z:()=>o});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7462),a=n(7294),l=n(6010),o=n(2466),u=n(6550),i=n(1980),s=n(7392),c=n(12);function p(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function d(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??p(n);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:n}=e;const r=(0,u.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=d(e),[o,u]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[i,s]=g({queryString:n,groupId:r}),[p,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),b=(()=>{const e=i??p;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&u(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);u(e),s(e),f(e)}),[s,f,l]),tabValues:l}}var b=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:u,selectValue:i,tabValues:s}=e;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,o.o5)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),r=s[n].value;r!==u&&(p(t),i(r))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},s.map((e=>{let{value:t,label:n,attributes:o}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:u===t?0:-1,"aria-selected":u===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:d},o,{className:(0,l.Z)("tabs__item",h.tabItem,o?.className,{"tabs__item--active":u===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function k(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},a.createElement(y,(0,r.Z)({},e,t)),a.createElement(v,(0,r.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return a.createElement(k,(0,r.Z)({key:String(t)},e))}},5796:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>g,frontMatter:()=>u,metadata:()=>s,toc:()=>p});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),o=n(5162);const u={title:"input-output-logger"},i=void 0,s={unversionedId:"middlewares/input-output-logger",id:"middlewares/input-output-logger",title:"input-output-logger",description:"Logs the incoming request (input) and the response (output).",source:"@site/docs/middlewares/input-output-logger.md",sourceDirName:"middlewares",slug:"/middlewares/input-output-logger",permalink:"/docs/middlewares/input-output-logger",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/input-output-logger.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"input-output-logger"},sidebar:"tutorialSidebar",previous:{title:"http-urlencode-path-parser",permalink:"/docs/middlewares/http-urlencode-path-parser"},next:{title:"rds-signer",permalink:"/docs/middlewares/rds-signer"}},c={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:p},m="wrapper";function g(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Logs the incoming request (input) and the response (output)."),(0,a.kt)("p",null,"By default, the logging operate by using the ",(0,a.kt)("inlineCode",{parentName:"p"},"console.log")," function. You can pass as a parameter a custom logger with additional logic if you need. It can be useful if you want to process the log by doing a http call or anything else."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/input-output-logger\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/input-output-logger\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/input-output-logger\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"logger")," function (default ",(0,a.kt)("inlineCode",{parentName:"li"},"console.log"),"): logging function that accepts an object"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsContext")," boolean (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): Include ",(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html"},"AWS Lambda context object")," to the logger"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"omitPaths")," string[] (default ",(0,a.kt)("inlineCode",{parentName:"li"},"[]"),"): property accepts an array of paths that will be used to remove particular fields import the logged objects. This could serve as a simple way to redact sensitive data from logs (default []). Examples: ",(0,a.kt)("inlineCode",{parentName:"li"},"name"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"user.name"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"users.[].name")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"mask")," string: String to replace omitted values with. Example: ",(0,a.kt)("inlineCode",{parentName:"li"},"***omitted***")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"replacer")," function: stringify ",(0,a.kt)("inlineCode",{parentName:"li"},"replacer")," function")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport inputOutputLogger from '@middy/input-output-logger'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n return response\n})\n\nhandler.use(inputOutputLogger())\n")),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport inputOutputLogger from '@middy/input-output-logger'\nimport pino from 'pino'\n\nconst logger = pino()\n\nconst handler = middy((event, context) => {\n // ...\n return response\n})\n\nhandler.use(\n inputOutputLogger({\n logger: (request) => {\n const child = logger.child(request.context)\n child.info(request.event ?? request.response)\n },\n awsContext: true\n })\n)\n")))}g.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1098],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>g});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var i=r.createContext({}),s=function(e){var t=r.useContext(i),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=s(e.components);return r.createElement(i.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,c=u(e,["components","mdxType","originalType","parentName"]),p=s(n),m=a,g=p["".concat(i,".").concat(m)]||p[m]||d[m]||l;return n?r.createElement(g,o(o({ref:t},c),{},{components:n})):r.createElement(g,o({ref:t},c))}));function g(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,o=new Array(l);o[0]=m;var u={};for(var i in t)hasOwnProperty.call(t,i)&&(u[i]=t[i]);u.originalType=e,u[p]="string"==typeof e?e:a,o[1]=u;for(var s=2;s{n.d(t,{Z:()=>o});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7462),a=n(7294),l=n(6010),o=n(2466),u=n(6550),i=n(1980),s=n(7392),c=n(12);function p(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function d(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??p(n);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:n}=e;const r=(0,u.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=d(e),[o,u]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[i,s]=g({queryString:n,groupId:r}),[p,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),b=(()=>{const e=i??p;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&u(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);u(e),s(e),f(e)}),[s,f,l]),tabValues:l}}var b=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:u,selectValue:i,tabValues:s}=e;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,o.o5)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),r=s[n].value;r!==u&&(p(t),i(r))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},s.map((e=>{let{value:t,label:n,attributes:o}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:u===t?0:-1,"aria-selected":u===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:d},o,{className:(0,l.Z)("tabs__item",h.tabItem,o?.className,{"tabs__item--active":u===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function k(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},a.createElement(y,(0,r.Z)({},e,t)),a.createElement(v,(0,r.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return a.createElement(k,(0,r.Z)({key:String(t)},e))}},5796:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>g,frontMatter:()=>u,metadata:()=>s,toc:()=>p});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),o=n(5162);const u={title:"input-output-logger"},i=void 0,s={unversionedId:"middlewares/input-output-logger",id:"middlewares/input-output-logger",title:"input-output-logger",description:"Logs the incoming request (input) and the response (output).",source:"@site/docs/middlewares/input-output-logger.md",sourceDirName:"middlewares",slug:"/middlewares/input-output-logger",permalink:"/docs/middlewares/input-output-logger",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/input-output-logger.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"input-output-logger"},sidebar:"tutorialSidebar",previous:{title:"http-urlencode-path-parser",permalink:"/docs/middlewares/http-urlencode-path-parser"},next:{title:"rds-signer",permalink:"/docs/middlewares/rds-signer"}},c={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:p},m="wrapper";function g(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Logs the incoming request (input) and the response (output)."),(0,a.kt)("p",null,"By default, the logging operate by using the ",(0,a.kt)("inlineCode",{parentName:"p"},"console.log")," function. You can pass as a parameter a custom logger with additional logic if you need. It can be useful if you want to process the log by doing a http call or anything else."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/input-output-logger\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/input-output-logger\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/input-output-logger\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"logger")," function (default ",(0,a.kt)("inlineCode",{parentName:"li"},"console.log"),"): logging function that accepts an object"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsContext")," boolean (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): Include ",(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html"},"AWS Lambda context object")," to the logger"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"omitPaths")," string[] (default ",(0,a.kt)("inlineCode",{parentName:"li"},"[]"),"): property accepts an array of paths that will be used to remove particular fields import the logged objects. This could serve as a simple way to redact sensitive data from logs (default []). Examples: ",(0,a.kt)("inlineCode",{parentName:"li"},"name"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"user.name"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"users.[].name")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"mask")," string: String to replace omitted values with. Example: ",(0,a.kt)("inlineCode",{parentName:"li"},"***omitted***")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"replacer")," function: stringify ",(0,a.kt)("inlineCode",{parentName:"li"},"replacer")," function")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport inputOutputLogger from '@middy/input-output-logger'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n return response\n})\n\nhandler.use(inputOutputLogger())\n")),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport inputOutputLogger from '@middy/input-output-logger'\nimport pino from 'pino'\n\nconst logger = pino()\n\nconst handler = middy((event, context) => {\n // ...\n return response\n})\n\nhandler.use(\n inputOutputLogger({\n logger: (request) => {\n const child = logger.child(request.context)\n child.info(request.event ?? request.response)\n },\n awsContext: true\n })\n)\n")))}g.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/28b74e92.93397682.js b/assets/js/28b74e92.8469dc40.js similarity index 96% rename from assets/js/28b74e92.93397682.js rename to assets/js/28b74e92.8469dc40.js index e2fdb55bc..a4deb2152 100644 --- a/assets/js/28b74e92.93397682.js +++ b/assets/js/28b74e92.8469dc40.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3839],{3905:(e,t,r)=>{r.d(t,{Zo:()=>u,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),s=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},u=function(e){var t=s(e.components);return n.createElement(c.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),d=s(r),m=o,f=d["".concat(c,".").concat(m)]||d[m]||p[m]||a;return r?n.createElement(f,i(i({ref:t},u),{},{components:r})):n.createElement(f,i({ref:t},u))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[d]="string"==typeof e?e:o,i[1]=l;for(var s=2;s{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var n=r(7462),o=(r(7294),r(3905));const a={title:"CloudTrail"},i=void 0,l={unversionedId:"events/cloud-trail",id:"events/cloud-trail",title:"CloudTrail",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cloud-trail.md",sourceDirName:"events",slug:"/events/cloud-trail",permalink:"/docs/events/cloud-trail",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-trail.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"CloudTrail"},sidebar:"tutorialSidebar",previous:{title:"CloudFront Lambda@Edge",permalink:"/docs/events/cloud-front"},next:{title:"Cloud Watch Logs",permalink:"/docs/events/cloud-watch-logs"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],u={toc:s},d="wrapper";function p(e){let{components:t,...r}=e;return(0,o.kt)(d,(0,n.Z)({},u,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-cloudtrail.html"},"Using AWS Lambda with AWS CloudTrail"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3839],{3905:(e,t,r)=>{r.d(t,{Zo:()=>u,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),s=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},u=function(e){var t=s(e.components);return n.createElement(c.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),d=s(r),m=o,f=d["".concat(c,".").concat(m)]||d[m]||p[m]||a;return r?n.createElement(f,i(i({ref:t},u),{},{components:r})):n.createElement(f,i({ref:t},u))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[d]="string"==typeof e?e:o,i[1]=l;for(var s=2;s{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var n=r(7462),o=(r(7294),r(3905));const a={title:"CloudTrail"},i=void 0,l={unversionedId:"events/cloud-trail",id:"events/cloud-trail",title:"CloudTrail",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cloud-trail.md",sourceDirName:"events",slug:"/events/cloud-trail",permalink:"/docs/events/cloud-trail",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-trail.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"CloudTrail"},sidebar:"tutorialSidebar",previous:{title:"CloudFront Lambda@Edge",permalink:"/docs/events/cloud-front"},next:{title:"Cloud Watch Logs",permalink:"/docs/events/cloud-watch-logs"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],u={toc:s},d="wrapper";function p(e){let{components:t,...r}=e;return(0,o.kt)(d,(0,n.Z)({},u,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-cloudtrail.html"},"Using AWS Lambda with AWS CloudTrail"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/2b234cfe.c14de910.js b/assets/js/2b234cfe.1d819a63.js similarity index 96% rename from assets/js/2b234cfe.c14de910.js rename to assets/js/2b234cfe.1d819a63.js index f8ce491db..802ce3d88 100644 --- a/assets/js/2b234cfe.c14de910.js +++ b/assets/js/2b234cfe.1d819a63.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9158],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var c=n.createContext({}),l=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=l(e.components);return n.createElement(c.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},d=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=l(r),d=a,f=m["".concat(c,".").concat(d)]||m[d]||u[d]||o;return r?n.createElement(f,i(i({ref:t},p),{},{components:r})):n.createElement(f,i({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=d;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[m]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var n=r(7462),a=(r(7294),r(3905));const o={title:"Secrets Manager"},i=void 0,s={unversionedId:"events/secrets-manager",id:"events/secrets-manager",title:"Secrets Manager",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/secrets-manager.md",sourceDirName:"events",slug:"/events/secrets-manager",permalink:"/docs/events/secrets-manager",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/secrets-manager.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Secrets Manager"},sidebar:"tutorialSidebar",previous:{title:"S3",permalink:"/docs/events/s3"},next:{title:"SES",permalink:"/docs/events/ses"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},m="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-secrets-manager.html"},"Using AWS Lambda with Secrets Manager"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9158],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var c=n.createContext({}),l=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=l(e.components);return n.createElement(c.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},d=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=l(r),d=a,f=m["".concat(c,".").concat(d)]||m[d]||u[d]||o;return r?n.createElement(f,i(i({ref:t},p),{},{components:r})):n.createElement(f,i({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=d;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[m]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var n=r(7462),a=(r(7294),r(3905));const o={title:"Secrets Manager"},i=void 0,s={unversionedId:"events/secrets-manager",id:"events/secrets-manager",title:"Secrets Manager",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/secrets-manager.md",sourceDirName:"events",slug:"/events/secrets-manager",permalink:"/docs/events/secrets-manager",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/secrets-manager.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Secrets Manager"},sidebar:"tutorialSidebar",previous:{title:"S3",permalink:"/docs/events/s3"},next:{title:"SES",permalink:"/docs/events/ses"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},m="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-secrets-manager.html"},"Using AWS Lambda with Secrets Manager"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/2e6cdb22.a46d037d.js b/assets/js/2e6cdb22.58a90d4e.js similarity index 99% rename from assets/js/2e6cdb22.a46d037d.js rename to assets/js/2e6cdb22.58a90d4e.js index a13f68fa1..cf138c5aa 100644 --- a/assets/js/2e6cdb22.a46d037d.js +++ b/assets/js/2e6cdb22.58a90d4e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5774],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var o=a.createContext({}),u=function(e){var t=a.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=u(e.components);return a.createElement(o.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),c=u(n),m=r,f=c["".concat(o,".").concat(m)]||c[m]||p[m]||l;return n?a.createElement(f,i(i({ref:t},d),{},{components:n})):a.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=m;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[c]="string"==typeof e?e:r,i[1]=s;for(var u=2;u{n.d(t,{Z:()=>i});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>h});var a=n(7462),r=n(7294),l=n(6010),i=n(2466),s=n(6550),o=n(1980),u=n(7392),d=n(12);function c(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??c(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=p(e),[i,s]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:n,groupId:a}),[c,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),y=(()=>{const e=o??c;return m({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{y&&s(y)}),[y]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var y=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function w(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=d.indexOf(t),a=u[n].value;a!==s&&(c(t),o(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=d.indexOf(e.currentTarget)+1;t=d[n]??d[0];break}case"ArrowLeft":{const n=d.indexOf(e.currentTarget)-1;t=d[n]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:i}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",g.tabItem,i?.className,{"tabs__item--active":s===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function k(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",g.tabList)},r.createElement(w,(0,a.Z)({},e,t)),r.createElement(v,(0,a.Z)({},e,t)))}function h(e){const t=(0,y.Z)();return r.createElement(k,(0,a.Z)({key:String(t)},e))}},4087:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>f,frontMatter:()=>s,metadata:()=>u,toc:()=>c});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),i=n(5162);const s={title:"ws-response"},o=void 0,u={unversionedId:"middlewares/ws-response",id:"middlewares/ws-response",title:"ws-response",description:"Post message to WebSocket connection.",source:"@site/docs/middlewares/ws-response.md",sourceDirName:"middlewares",slug:"/middlewares/ws-response",permalink:"/docs/middlewares/ws-response",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ws-response.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"ws-response"},sidebar:"tutorialSidebar",previous:{title:"ws-json-body-parser",permalink:"/docs/middlewares/ws-json-body-parser"},next:{title:"Writing Middlewares",permalink:"/docs/category/writing-middlewares"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"API Gateway",id:"api-gateway",level:3},{value:"General",id:"general",level:3},{value:"Bundling",id:"bundling",level:2}],p={toc:c},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Post message to WebSocket connection."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/ws-response\nnpm install --save-dev @aws-sdk/client-apigatewaymanagementapi\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/ws-response\nyarn add --dev @aws-sdk/client-apigatewaymanagementapi\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/ws-response\npnpm add --save-dev @aws-sdk/client-apigatewaymanagementapi\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"ApiGatewayManagementApiClient"),"): ApiGatewayManagementApi class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-apigatewaymanagementapi"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to ApiGatewayManagementApiClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch.")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"execute-api:ManageConnections")),(0,r.kt)("li",{parentName:"ul"},"If ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions.endpoint")," is not set it will be set using ",(0,r.kt)("inlineCode",{parentName:"li"},"event.requestContext.{domainName,stage}")),(0,r.kt)("li",{parentName:"ul"},"If response does not contain ",(0,r.kt)("inlineCode",{parentName:"li"},"ConnectId"),", it will be set from ",(0,r.kt)("inlineCode",{parentName:"li"},"event.requestContext.connectionId"))),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("h3",{id:"api-gateway"},"API Gateway"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsResponse from '@middy/ws-response'\n\nexport const handler = middy((event, context) => {\n return 'message'\n})\n\nhandler.use(wsResponse())\n")),(0,r.kt)("h3",{id:"general"},"General"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsResponse from '@middy/ws-response'\n\nexport const handler = middy((event, context) => {\n return {\n ConnectionId: '...',\n Data: 'message'\n }\n})\n\nhandler.use(\n wsResponse({\n awsClientOptions: {\n endpoint: '...'\n }\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-apigatewaymanagementapi")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5774],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var o=a.createContext({}),u=function(e){var t=a.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=u(e.components);return a.createElement(o.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),c=u(n),m=r,f=c["".concat(o,".").concat(m)]||c[m]||p[m]||l;return n?a.createElement(f,i(i({ref:t},d),{},{components:n})):a.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=m;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[c]="string"==typeof e?e:r,i[1]=s;for(var u=2;u{n.d(t,{Z:()=>i});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>h});var a=n(7462),r=n(7294),l=n(6010),i=n(2466),s=n(6550),o=n(1980),u=n(7392),d=n(12);function c(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??c(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=p(e),[i,s]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:n,groupId:a}),[c,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),y=(()=>{const e=o??c;return m({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{y&&s(y)}),[y]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var y=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function w(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=d.indexOf(t),a=u[n].value;a!==s&&(c(t),o(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=d.indexOf(e.currentTarget)+1;t=d[n]??d[0];break}case"ArrowLeft":{const n=d.indexOf(e.currentTarget)-1;t=d[n]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:i}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",g.tabItem,i?.className,{"tabs__item--active":s===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function k(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",g.tabList)},r.createElement(w,(0,a.Z)({},e,t)),r.createElement(v,(0,a.Z)({},e,t)))}function h(e){const t=(0,y.Z)();return r.createElement(k,(0,a.Z)({key:String(t)},e))}},4087:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>f,frontMatter:()=>s,metadata:()=>u,toc:()=>c});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),i=n(5162);const s={title:"ws-response"},o=void 0,u={unversionedId:"middlewares/ws-response",id:"middlewares/ws-response",title:"ws-response",description:"Post message to WebSocket connection.",source:"@site/docs/middlewares/ws-response.md",sourceDirName:"middlewares",slug:"/middlewares/ws-response",permalink:"/docs/middlewares/ws-response",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ws-response.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"ws-response"},sidebar:"tutorialSidebar",previous:{title:"ws-json-body-parser",permalink:"/docs/middlewares/ws-json-body-parser"},next:{title:"Writing Middlewares",permalink:"/docs/category/writing-middlewares"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"API Gateway",id:"api-gateway",level:3},{value:"General",id:"general",level:3},{value:"Bundling",id:"bundling",level:2}],p={toc:c},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Post message to WebSocket connection."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/ws-response\nnpm install --save-dev @aws-sdk/client-apigatewaymanagementapi\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/ws-response\nyarn add --dev @aws-sdk/client-apigatewaymanagementapi\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/ws-response\npnpm add --save-dev @aws-sdk/client-apigatewaymanagementapi\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"ApiGatewayManagementApiClient"),"): ApiGatewayManagementApi class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-apigatewaymanagementapi"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to ApiGatewayManagementApiClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch.")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"execute-api:ManageConnections")),(0,r.kt)("li",{parentName:"ul"},"If ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions.endpoint")," is not set it will be set using ",(0,r.kt)("inlineCode",{parentName:"li"},"event.requestContext.{domainName,stage}")),(0,r.kt)("li",{parentName:"ul"},"If response does not contain ",(0,r.kt)("inlineCode",{parentName:"li"},"ConnectId"),", it will be set from ",(0,r.kt)("inlineCode",{parentName:"li"},"event.requestContext.connectionId"))),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("h3",{id:"api-gateway"},"API Gateway"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsResponse from '@middy/ws-response'\n\nexport const handler = middy((event, context) => {\n return 'message'\n})\n\nhandler.use(wsResponse())\n")),(0,r.kt)("h3",{id:"general"},"General"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsResponse from '@middy/ws-response'\n\nexport const handler = middy((event, context) => {\n return {\n ConnectionId: '...',\n Data: 'message'\n }\n})\n\nhandler.use(\n wsResponse({\n awsClientOptions: {\n endpoint: '...'\n }\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-apigatewaymanagementapi")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/2f4f2e7a.19b5b6c2.js b/assets/js/2f4f2e7a.eb24b03f.js similarity index 98% rename from assets/js/2f4f2e7a.19b5b6c2.js rename to assets/js/2f4f2e7a.eb24b03f.js index 52b45eaa8..4933ccf13 100644 --- a/assets/js/2f4f2e7a.19b5b6c2.js +++ b/assets/js/2f4f2e7a.eb24b03f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5222],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),u=s(n),m=a,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[u]="string"==typeof e?e:a,i[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>l,toc:()=>s});var r=n(7462),a=(n(7294),n(3905));const o={title:"Alexa"},i=void 0,l={unversionedId:"events/alexa",id:"events/alexa",title:"Alexa",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/alexa.md",sourceDirName:"events",slug:"/events/alexa",permalink:"/docs/events/alexa",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/alexa.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Alexa"},sidebar:"tutorialSidebar",previous:{title:"All AWS Events",permalink:"/docs/events/intro"},next:{title:"API Gateway Authorizer",permalink:"/docs/events/api-gateway-authorizer"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},u="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-alexa.html"},"Using AWS Lambda with Alexa"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5222],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),u=s(n),m=a,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[u]="string"==typeof e?e:a,i[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>l,toc:()=>s});var r=n(7462),a=(n(7294),n(3905));const o={title:"Alexa"},i=void 0,l={unversionedId:"events/alexa",id:"events/alexa",title:"Alexa",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/alexa.md",sourceDirName:"events",slug:"/events/alexa",permalink:"/docs/events/alexa",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/alexa.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Alexa"},sidebar:"tutorialSidebar",previous:{title:"All AWS Events",permalink:"/docs/events/intro"},next:{title:"API Gateway Authorizer",permalink:"/docs/events/api-gateway-authorizer"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},u="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-alexa.html"},"Using AWS Lambda with Alexa"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/340d0816.ed96af5e.js b/assets/js/340d0816.7d591ed9.js similarity index 96% rename from assets/js/340d0816.ed96af5e.js rename to assets/js/340d0816.7d591ed9.js index e58cf9603..6d19df142 100644 --- a/assets/js/340d0816.ed96af5e.js +++ b/assets/js/340d0816.7d591ed9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8729],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},m="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),m=s(n),u=a,f=m["".concat(c,".").concat(u)]||m[u]||d[u]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[m]="string"==typeof e?e:a,i[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>l,toc:()=>s});var r=n(7462),a=(n(7294),n(3905));const o={title:"MQ"},i=void 0,l={unversionedId:"events/mq",id:"events/mq",title:"MQ",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/mq.md",sourceDirName:"events",slug:"/events/mq",permalink:"/docs/events/mq",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/mq.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"MQ"},sidebar:"tutorialSidebar",previous:{title:"Lex",permalink:"/docs/events/lex"},next:{title:"RDS",permalink:"/docs/events/rds"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},m="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-mq.html"},"Using Lambda with Amazon MQ"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8729],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},m="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),m=s(n),u=a,f=m["".concat(c,".").concat(u)]||m[u]||d[u]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[m]="string"==typeof e?e:a,i[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>l,toc:()=>s});var r=n(7462),a=(n(7294),n(3905));const o={title:"MQ"},i=void 0,l={unversionedId:"events/mq",id:"events/mq",title:"MQ",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/mq.md",sourceDirName:"events",slug:"/events/mq",permalink:"/docs/events/mq",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/mq.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"MQ"},sidebar:"tutorialSidebar",previous:{title:"Lex",permalink:"/docs/events/lex"},next:{title:"RDS",permalink:"/docs/events/rds"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},m="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-mq.html"},"Using Lambda with Amazon MQ"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/34ad80cb.1d22f28b.js b/assets/js/34ad80cb.fcec2b91.js similarity index 98% rename from assets/js/34ad80cb.1d22f28b.js rename to assets/js/34ad80cb.fcec2b91.js index a7845091a..e15fc1b01 100644 --- a/assets/js/34ad80cb.1d22f28b.js +++ b/assets/js/34ad80cb.fcec2b91.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4662],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),d=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},s=function(e){var t=d(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),u=d(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||p[m]||a;return n?r.createElement(f,i(i({ref:t},s),{},{components:n})):r.createElement(f,i({ref:t},s))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[u]="string"==typeof e?e:o,i[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>d});var r=n(7462),o=(n(7294),n(3905));const a={title:"CloudFront Lambda@Edge"},i=void 0,l={unversionedId:"events/cloud-front",id:"events/cloud-front",title:"CloudFront Lambda@Edge",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cloud-front.md",sourceDirName:"events",slug:"/events/cloud-front",permalink:"/docs/events/cloud-front",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-front.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"CloudFront Lambda@Edge"},sidebar:"tutorialSidebar",previous:{title:"CloudFormation",permalink:"/docs/events/cloud-formation"},next:{title:"CloudTrail",permalink:"/docs/events/cloud-trail"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:d},u="wrapper";function p(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html"},"Using AWS Lambda with CloudFront Lambda@Edge"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n //.use(cfHeaderNormalizer()) // Let use know if this would have value\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4662],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),d=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},s=function(e){var t=d(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),u=d(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||p[m]||a;return n?r.createElement(f,i(i({ref:t},s),{},{components:n})):r.createElement(f,i({ref:t},s))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[u]="string"==typeof e?e:o,i[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>d});var r=n(7462),o=(n(7294),n(3905));const a={title:"CloudFront Lambda@Edge"},i=void 0,l={unversionedId:"events/cloud-front",id:"events/cloud-front",title:"CloudFront Lambda@Edge",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cloud-front.md",sourceDirName:"events",slug:"/events/cloud-front",permalink:"/docs/events/cloud-front",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-front.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"CloudFront Lambda@Edge"},sidebar:"tutorialSidebar",previous:{title:"CloudFormation",permalink:"/docs/events/cloud-formation"},next:{title:"CloudTrail",permalink:"/docs/events/cloud-trail"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:d},u="wrapper";function p(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html"},"Using AWS Lambda with CloudFront Lambda@Edge"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n //.use(cfHeaderNormalizer()) // Let use know if this would have value\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/34ebece8.345fb63f.js b/assets/js/34ebece8.b42d31d5.js similarity index 96% rename from assets/js/34ebece8.345fb63f.js rename to assets/js/34ebece8.b42d31d5.js index c84d9f44a..e2143f880 100644 --- a/assets/js/34ebece8.345fb63f.js +++ b/assets/js/34ebece8.b42d31d5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5853],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var c=n.createContext({}),s=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=s(e.components);return n.createElement(c.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},d=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),m=s(r),d=a,f=m["".concat(c,".").concat(d)]||m[d]||u[d]||o;return r?n.createElement(f,i(i({ref:t},p),{},{components:r})):n.createElement(f,i({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=d;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[m]="string"==typeof e?e:a,i[1]=l;for(var s=2;s{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>l,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"WorkMail"},i=void 0,l={unversionedId:"events/workmail",id:"events/workmail",title:"WorkMail",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/workmail.md",sourceDirName:"events",slug:"/events/workmail",permalink:"/docs/events/workmail",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/workmail.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"WorkMail"},sidebar:"tutorialSidebar",previous:{title:"VPC Lattice",permalink:"/docs/events/vpc-lattice"},next:{title:"Integrations",permalink:"/docs/category/integrations"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},m="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/workmail/latest/adminguide/lambda.html"},"Configuring AWS Lambda for Amazon WorkMail"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5853],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var c=n.createContext({}),s=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=s(e.components);return n.createElement(c.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},d=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),m=s(r),d=a,f=m["".concat(c,".").concat(d)]||m[d]||u[d]||o;return r?n.createElement(f,i(i({ref:t},p),{},{components:r})):n.createElement(f,i({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=d;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[m]="string"==typeof e?e:a,i[1]=l;for(var s=2;s{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>l,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"WorkMail"},i=void 0,l={unversionedId:"events/workmail",id:"events/workmail",title:"WorkMail",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/workmail.md",sourceDirName:"events",slug:"/events/workmail",permalink:"/docs/events/workmail",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/workmail.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"WorkMail"},sidebar:"tutorialSidebar",previous:{title:"VPC Lattice",permalink:"/docs/events/vpc-lattice"},next:{title:"Integrations",permalink:"/docs/category/integrations"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},m="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/workmail/latest/adminguide/lambda.html"},"Configuring AWS Lambda for Amazon WorkMail"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/3673b941.2cf10567.js b/assets/js/3673b941.04dbea8d.js similarity index 98% rename from assets/js/3673b941.2cf10567.js rename to assets/js/3673b941.04dbea8d.js index d8c603b17..f37c5f67d 100644 --- a/assets/js/3673b941.2cf10567.js +++ b/assets/js/3673b941.04dbea8d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2344],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var o=r.createContext({}),u=function(e){var t=r.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):s(s({},t),e)),n},d=function(e){var t=u(e.components);return r.createElement(o.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,o=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),c=u(n),m=a,f=c["".concat(o,".").concat(m)]||c[m]||p[m]||l;return n?r.createElement(f,s(s({ref:t},d),{},{components:n})):r.createElement(f,s({ref:t},d))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,s=new Array(l);s[0]=m;var i={};for(var o in t)hasOwnProperty.call(t,o)&&(i[o]=t[o]);i.originalType=e,i[c]="string"==typeof e?e:a,s[1]=i;for(var u=2;u{n.d(t,{Z:()=>s});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:n,className:s}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,s),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7462),a=n(7294),l=n(6010),s=n(2466),i=n(6550),o=n(1980),u=n(7392),d=n(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??c(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=p(e),[s,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:n,groupId:r}),[c,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,d.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),g=(()=>{const e=o??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{g&&i(g)}),[g]);return{selectedValue:s,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var g=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:i,selectValue:o,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),p=e=>{const t=e.currentTarget,n=d.indexOf(t),r=u[n].value;r!==i&&(c(t),o(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=d.indexOf(e.currentTarget)+1;t=d[n]??d[0];break}case"ArrowLeft":{const n=d.indexOf(e.currentTarget)-1;t=d[n]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:s}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},s,{className:(0,l.Z)("tabs__item",h.tabItem,s?.className,{"tabs__item--active":i===t})}),n??t)})))}function k(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function v(e){const t=b(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},a.createElement(y,(0,r.Z)({},e,t)),a.createElement(k,(0,r.Z)({},e,t)))}function w(e){const t=(0,g.Z)();return a.createElement(v,(0,r.Z)({key:String(t)},e))}},3230:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),s=n(5162);const i={title:"rds-signer"},o=void 0,u={unversionedId:"middlewares/rds-signer",id:"middlewares/rds-signer",title:"rds-signer",description:"Fetches RDS credentials to be used when connecting to RDS with IAM roles.",source:"@site/docs/middlewares/rds-signer.md",sourceDirName:"middlewares",slug:"/middlewares/rds-signer",permalink:"/docs/middlewares/rds-signer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/rds-signer.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"rds-signer"},sidebar:"tutorialSidebar",previous:{title:"input-output-logger",permalink:"/docs/middlewares/input-output-logger"},next:{title:"s3-object-response",permalink:"/docs/middlewares/s3-object-response"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:c},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Fetches RDS credentials to be used when connecting to RDS with IAM roles."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/rds-signer\nnpm install --save-dev @aws-sdk/rds-signer\n"))),(0,a.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/rds-signer\nyarn add --dev @aws-sdk/rds-signer\n"))),(0,a.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/rds-signer\npnpm add --save-dev @aws-sdk/rds-signer\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"Signer"),"): Signer class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.kt)("inlineCode",{parentName:"li"},"@aws-sdk/rds-signer"),"."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to Signer class constructor."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,a.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"rds-signer"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,a.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,a.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,a.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): Store role tokens to ",(0,a.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,a.kt)("inlineCode",{parentName:"li"},"rds-db:connect")," with a resource like ",(0,a.kt)("inlineCode",{parentName:"li"},"arn:aws:rds-db:#{AWS::Region}:#{AWS::AccountId}:dbuser:${database_resource}/${iam_role}"))),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport rdsSigner from '@middy/rds-signer'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n rdsSigner({\n fetchData: {\n rdsToken: {\n region: 'ca-central-1',\n hostname: '***.rds.amazonaws.com',\n username: 'iam_role',\n database: 'postgres',\n port: 5432\n }\n }\n })\n)\n")),(0,a.kt)("h2",{id:"bundling"},"Bundling"),(0,a.kt)("p",null,"To exclude ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk/rds-signer")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2344],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var o=r.createContext({}),u=function(e){var t=r.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):s(s({},t),e)),n},d=function(e){var t=u(e.components);return r.createElement(o.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,o=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),c=u(n),m=a,f=c["".concat(o,".").concat(m)]||c[m]||p[m]||l;return n?r.createElement(f,s(s({ref:t},d),{},{components:n})):r.createElement(f,s({ref:t},d))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,s=new Array(l);s[0]=m;var i={};for(var o in t)hasOwnProperty.call(t,o)&&(i[o]=t[o]);i.originalType=e,i[c]="string"==typeof e?e:a,s[1]=i;for(var u=2;u{n.d(t,{Z:()=>s});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:n,className:s}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,s),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7462),a=n(7294),l=n(6010),s=n(2466),i=n(6550),o=n(1980),u=n(7392),d=n(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??c(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=p(e),[s,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:n,groupId:r}),[c,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,d.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),g=(()=>{const e=o??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{g&&i(g)}),[g]);return{selectedValue:s,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var g=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:i,selectValue:o,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),p=e=>{const t=e.currentTarget,n=d.indexOf(t),r=u[n].value;r!==i&&(c(t),o(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=d.indexOf(e.currentTarget)+1;t=d[n]??d[0];break}case"ArrowLeft":{const n=d.indexOf(e.currentTarget)-1;t=d[n]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:s}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},s,{className:(0,l.Z)("tabs__item",h.tabItem,s?.className,{"tabs__item--active":i===t})}),n??t)})))}function k(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function v(e){const t=b(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},a.createElement(y,(0,r.Z)({},e,t)),a.createElement(k,(0,r.Z)({},e,t)))}function w(e){const t=(0,g.Z)();return a.createElement(v,(0,r.Z)({key:String(t)},e))}},3230:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),s=n(5162);const i={title:"rds-signer"},o=void 0,u={unversionedId:"middlewares/rds-signer",id:"middlewares/rds-signer",title:"rds-signer",description:"Fetches RDS credentials to be used when connecting to RDS with IAM roles.",source:"@site/docs/middlewares/rds-signer.md",sourceDirName:"middlewares",slug:"/middlewares/rds-signer",permalink:"/docs/middlewares/rds-signer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/rds-signer.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"rds-signer"},sidebar:"tutorialSidebar",previous:{title:"input-output-logger",permalink:"/docs/middlewares/input-output-logger"},next:{title:"s3-object-response",permalink:"/docs/middlewares/s3-object-response"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:c},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Fetches RDS credentials to be used when connecting to RDS with IAM roles."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/rds-signer\nnpm install --save-dev @aws-sdk/rds-signer\n"))),(0,a.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/rds-signer\nyarn add --dev @aws-sdk/rds-signer\n"))),(0,a.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/rds-signer\npnpm add --save-dev @aws-sdk/rds-signer\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"Signer"),"): Signer class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.kt)("inlineCode",{parentName:"li"},"@aws-sdk/rds-signer"),"."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to Signer class constructor."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,a.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"rds-signer"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,a.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,a.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,a.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): Store role tokens to ",(0,a.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,a.kt)("inlineCode",{parentName:"li"},"rds-db:connect")," with a resource like ",(0,a.kt)("inlineCode",{parentName:"li"},"arn:aws:rds-db:#{AWS::Region}:#{AWS::AccountId}:dbuser:${database_resource}/${iam_role}"))),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport rdsSigner from '@middy/rds-signer'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n rdsSigner({\n fetchData: {\n rdsToken: {\n region: 'ca-central-1',\n hostname: '***.rds.amazonaws.com',\n username: 'iam_role',\n database: 'postgres',\n port: 5432\n }\n }\n })\n)\n")),(0,a.kt)("h2",{id:"bundling"},"Bundling"),(0,a.kt)("p",null,"To exclude ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk/rds-signer")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/3a74057e.4b574e2e.js b/assets/js/3a74057e.12726071.js similarity index 96% rename from assets/js/3a74057e.4b574e2e.js rename to assets/js/3a74057e.12726071.js index 1f59a5e24..6a6a86e52 100644 --- a/assets/js/3a74057e.4b574e2e.js +++ b/assets/js/3a74057e.12726071.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[517],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),p=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=p(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,c=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(r),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||i;return r?n.createElement(f,a(a({ref:t},l),{},{components:r})):n.createElement(f,a({ref:t},l))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,a[1]=s;for(var p=2;p{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var n=r(7462),o=(r(7294),r(3905));const i={title:"Pino"},a=void 0,s={unversionedId:"integrations/pino",id:"integrations/pino",title:"Pino",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/pino.md",sourceDirName:"integrations",slug:"/integrations/pino",permalink:"/docs/integrations/pino",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/pino.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Pino"},sidebar:"tutorialSidebar",previous:{title:"Powertools for AWS Lambda",permalink:"/docs/integrations/lambda-powertools"},next:{title:"Serverless Framework",permalink:"/docs/integrations/serverless-framework"}},c={},p=[],l={toc:p},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[517],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),p=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=p(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,c=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(r),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||i;return r?n.createElement(f,a(a({ref:t},l),{},{components:r})):n.createElement(f,a({ref:t},l))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,a[1]=s;for(var p=2;p{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var n=r(7462),o=(r(7294),r(3905));const i={title:"Pino"},a=void 0,s={unversionedId:"integrations/pino",id:"integrations/pino",title:"Pino",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/pino.md",sourceDirName:"integrations",slug:"/integrations/pino",permalink:"/docs/integrations/pino",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/pino.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Pino"},sidebar:"tutorialSidebar",previous:{title:"Powertools for AWS Lambda",permalink:"/docs/integrations/lambda-powertools"},next:{title:"Serverless Framework",permalink:"/docs/integrations/serverless-framework"}},c={},p=[],l={toc:p},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/3db93d31.5c6db2b2.js b/assets/js/3db93d31.4c00d67b.js similarity index 99% rename from assets/js/3db93d31.5c6db2b2.js rename to assets/js/3db93d31.4c00d67b.js index 5b4ff0532..369263d54 100644 --- a/assets/js/3db93d31.5c6db2b2.js +++ b/assets/js/3db93d31.4c00d67b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3631],{3905:(e,t,a)=>{a.d(t,{Zo:()=>p,kt:()=>b});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function l(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var s=r.createContext({}),u=function(e){var t=r.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},p=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,o=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),d=u(a),m=n,b=d["".concat(s,".").concat(m)]||d[m]||c[m]||o;return a?r.createElement(b,l(l({ref:t},p),{},{components:a})):r.createElement(b,l({ref:t},p))}));function b(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=a.length,l=new Array(o);l[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[d]="string"==typeof e?e:n,l[1]=i;for(var u=2;u{a.d(t,{Z:()=>l});var r=a(7294),n=a(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:a,className:l}=e;return r.createElement("div",{role:"tabpanel",className:(0,n.Z)(o.tabItem,l),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var r=a(7462),n=a(7294),o=a(6010),l=a(2466),i=a(6550),s=a(1980),u=a(7392),p=a(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:r,default:n}}=e;return{value:t,label:a,attributes:r,default:n}}))}function c(e){const{values:t,children:a}=e;return(0,n.useMemo)((()=>{const e=t??d(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function m(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:a}=e;const r=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,s._X)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function h(e){const{defaultValue:t,queryString:a=!1,groupId:r}=e,o=c(e),[l,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=a.find((e=>e.default))??a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[s,u]=b({queryString:a,groupId:r}),[d,h]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,p.Nk)(a);return[r,(0,n.useCallback)((e=>{a&&o.set(e)}),[a,o])]}({groupId:r}),f=(()=>{const e=s??d;return m({value:e,tabValues:o})?e:null})();(0,n.useLayoutEffect)((()=>{f&&i(f)}),[f]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),h(e)}),[u,h,o]),tabValues:o}}var f=a(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:a,selectedValue:i,selectValue:s,tabValues:u}=e;const p=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),c=e=>{const t=e.currentTarget,a=p.indexOf(t),r=u[a].value;r!==i&&(d(t),s(r))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=p.indexOf(e.currentTarget)+1;t=p[a]??p[0];break}case"ArrowLeft":{const a=p.indexOf(e.currentTarget)-1;t=p[a]??p[p.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:l}=e;return n.createElement("li",(0,r.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:c},l,{className:(0,o.Z)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":i===t})}),a??t)})))}function k(e){let{lazy:t,children:a,selectedValue:r}=e;const o=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function g(e){const t=h(e);return n.createElement("div",{className:(0,o.Z)("tabs-container",y.tabList)},n.createElement(v,(0,r.Z)({},e,t)),n.createElement(k,(0,r.Z)({},e,t)))}function w(e){const t=(0,f.Z)();return n.createElement(g,(0,r.Z)({key:String(t)},e))}},7427:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>p,contentTitle:()=>s,default:()=>b,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=a(7462),n=(a(7294),a(3905)),o=a(4866),l=a(5162);const i={title:"http-multipart-body-parser"},s=void 0,u={unversionedId:"middlewares/http-multipart-body-parser",id:"middlewares/http-multipart-body-parser",title:"http-multipart-body-parser",description:"Automatically parses HTTP requests with content type multipart/form-data and converts the body into an",source:"@site/docs/middlewares/http-multipart-body-parser.md",sourceDirName:"middlewares",slug:"/middlewares/http-multipart-body-parser",permalink:"/docs/middlewares/http-multipart-body-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-multipart-body-parser.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-multipart-body-parser"},sidebar:"tutorialSidebar",previous:{title:"http-json-body-parser",permalink:"/docs/middlewares/http-json-body-parser"},next:{title:"http-partial-response",permalink:"/docs/middlewares/http-partial-response"}},p={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:d},m="wrapper";function b(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},c,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Automatically parses HTTP requests with content type ",(0,n.kt)("inlineCode",{parentName:"p"},"multipart/form-data")," and converts the body into an\nobject. Also handles gracefully broken JSON as ",(0,n.kt)("em",{parentName:"p"},"Unsupported Media Type")," (415 errors)\nif used in combination with ",(0,n.kt)("inlineCode",{parentName:"p"},"httpErrorHandler"),"."),(0,n.kt)("p",null,"It can also be used in combination with validator so that the content can be validated."),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Note"),": by default this is going to parse only events that contain the header ",(0,n.kt)("inlineCode",{parentName:"p"},"Content-Type")," (or ",(0,n.kt)("inlineCode",{parentName:"p"},"content-type"),") set to ",(0,n.kt)("inlineCode",{parentName:"p"},"multipart/form-data"),". If you want to support different casing for the header name (e.g. ",(0,n.kt)("inlineCode",{parentName:"p"},"Content-type"),") then you should use the ",(0,n.kt)("a",{parentName:"p",href:"#httpheadernormalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"httpHeaderNormalizer"))," middleware before this middleware."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-multipart-body-parser\n"))),(0,n.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-multipart-body-parser\n"))),(0,n.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-multipart-body-parser\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"busboy")," (",(0,n.kt)("inlineCode",{parentName:"li"},"object"),") (optional): defaults to ",(0,n.kt)("inlineCode",{parentName:"li"},"{}")," and it can be used to pass extraparameters to the internal ",(0,n.kt)("inlineCode",{parentName:"li"},"busboy")," instance at creation time. Checkout ",(0,n.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/busboy#busboy-methods"},"the official documentation")," for more information on the supported options."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"charset")," (string) (default ",(0,n.kt)("inlineCode",{parentName:"li"},"utf8"),"): it can be used to change default charset."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"disableContentTypeError")," (",(0,n.kt)("inlineCode",{parentName:"li"},"boolean"),") (optional): Skip throwing 415 when ",(0,n.kt)("inlineCode",{parentName:"li"},"Content-Type")," is invalid. Default: ",(0,n.kt)("inlineCode",{parentName:"li"},"true"),", will default to ",(0,n.kt)("inlineCode",{parentName:"li"},"false")," in next major version.")),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Note"),": this middleware will buffer all the data as it is processed internally by ",(0,n.kt)("inlineCode",{parentName:"p"},"busboy"),", so, if you are using this approach to parse significantly big volumes of data, keep in mind that all the data will be allocated in memory. This is somewhat inevitable with Lambdas (as the data is already encoded into the JSON in memory as Base64), but it's good to keep this in mind and evaluate the impact on you application.",(0,n.kt)("br",{parentName:"p"}),"\n","If you really have to deal with big files, then you might also want to consider to allowing your users to ",(0,n.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html"},"directly upload files to S3")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpMultipartBodyParser from '@middy/http-multipart-body-parser'\nconst handler = middy((event, context) => {\n return {}\n})\nhandler.use(httpHeaderNormalizer()).use(httpMultipartBodyParser())\n\n// invokes the handler\nconst event = {\n headers: {\n 'Content-Type':\n 'multipart/form-data; boundary=----WebKitFormBoundaryppsQEwf2BVJeCe0M'\n },\n body: 'LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5cHBzUUV3ZjJCVkplQ2UwTQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmb28iDQoNCmJhcg0KLS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5cHBzUUV3ZjJCVkplQ2UwTS0t',\n isBase64Encoded: true\n}\nhandler(event, {}, (_, body) => {\n t.is(body, { foo: 'bar' })\n})\n")))}b.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3631],{3905:(e,t,a)=>{a.d(t,{Zo:()=>p,kt:()=>b});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function l(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var s=r.createContext({}),u=function(e){var t=r.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},p=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,o=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),d=u(a),m=n,b=d["".concat(s,".").concat(m)]||d[m]||c[m]||o;return a?r.createElement(b,l(l({ref:t},p),{},{components:a})):r.createElement(b,l({ref:t},p))}));function b(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=a.length,l=new Array(o);l[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[d]="string"==typeof e?e:n,l[1]=i;for(var u=2;u{a.d(t,{Z:()=>l});var r=a(7294),n=a(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:a,className:l}=e;return r.createElement("div",{role:"tabpanel",className:(0,n.Z)(o.tabItem,l),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var r=a(7462),n=a(7294),o=a(6010),l=a(2466),i=a(6550),s=a(1980),u=a(7392),p=a(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:r,default:n}}=e;return{value:t,label:a,attributes:r,default:n}}))}function c(e){const{values:t,children:a}=e;return(0,n.useMemo)((()=>{const e=t??d(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function m(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:a}=e;const r=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,s._X)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function h(e){const{defaultValue:t,queryString:a=!1,groupId:r}=e,o=c(e),[l,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=a.find((e=>e.default))??a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[s,u]=b({queryString:a,groupId:r}),[d,h]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,p.Nk)(a);return[r,(0,n.useCallback)((e=>{a&&o.set(e)}),[a,o])]}({groupId:r}),f=(()=>{const e=s??d;return m({value:e,tabValues:o})?e:null})();(0,n.useLayoutEffect)((()=>{f&&i(f)}),[f]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),h(e)}),[u,h,o]),tabValues:o}}var f=a(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:a,selectedValue:i,selectValue:s,tabValues:u}=e;const p=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),c=e=>{const t=e.currentTarget,a=p.indexOf(t),r=u[a].value;r!==i&&(d(t),s(r))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=p.indexOf(e.currentTarget)+1;t=p[a]??p[0];break}case"ArrowLeft":{const a=p.indexOf(e.currentTarget)-1;t=p[a]??p[p.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:l}=e;return n.createElement("li",(0,r.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:c},l,{className:(0,o.Z)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":i===t})}),a??t)})))}function k(e){let{lazy:t,children:a,selectedValue:r}=e;const o=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function g(e){const t=h(e);return n.createElement("div",{className:(0,o.Z)("tabs-container",y.tabList)},n.createElement(v,(0,r.Z)({},e,t)),n.createElement(k,(0,r.Z)({},e,t)))}function w(e){const t=(0,f.Z)();return n.createElement(g,(0,r.Z)({key:String(t)},e))}},7427:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>p,contentTitle:()=>s,default:()=>b,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=a(7462),n=(a(7294),a(3905)),o=a(4866),l=a(5162);const i={title:"http-multipart-body-parser"},s=void 0,u={unversionedId:"middlewares/http-multipart-body-parser",id:"middlewares/http-multipart-body-parser",title:"http-multipart-body-parser",description:"Automatically parses HTTP requests with content type multipart/form-data and converts the body into an",source:"@site/docs/middlewares/http-multipart-body-parser.md",sourceDirName:"middlewares",slug:"/middlewares/http-multipart-body-parser",permalink:"/docs/middlewares/http-multipart-body-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-multipart-body-parser.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-multipart-body-parser"},sidebar:"tutorialSidebar",previous:{title:"http-json-body-parser",permalink:"/docs/middlewares/http-json-body-parser"},next:{title:"http-partial-response",permalink:"/docs/middlewares/http-partial-response"}},p={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:d},m="wrapper";function b(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},c,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Automatically parses HTTP requests with content type ",(0,n.kt)("inlineCode",{parentName:"p"},"multipart/form-data")," and converts the body into an\nobject. Also handles gracefully broken JSON as ",(0,n.kt)("em",{parentName:"p"},"Unsupported Media Type")," (415 errors)\nif used in combination with ",(0,n.kt)("inlineCode",{parentName:"p"},"httpErrorHandler"),"."),(0,n.kt)("p",null,"It can also be used in combination with validator so that the content can be validated."),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Note"),": by default this is going to parse only events that contain the header ",(0,n.kt)("inlineCode",{parentName:"p"},"Content-Type")," (or ",(0,n.kt)("inlineCode",{parentName:"p"},"content-type"),") set to ",(0,n.kt)("inlineCode",{parentName:"p"},"multipart/form-data"),". If you want to support different casing for the header name (e.g. ",(0,n.kt)("inlineCode",{parentName:"p"},"Content-type"),") then you should use the ",(0,n.kt)("a",{parentName:"p",href:"#httpheadernormalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"httpHeaderNormalizer"))," middleware before this middleware."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-multipart-body-parser\n"))),(0,n.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-multipart-body-parser\n"))),(0,n.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-multipart-body-parser\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"busboy")," (",(0,n.kt)("inlineCode",{parentName:"li"},"object"),") (optional): defaults to ",(0,n.kt)("inlineCode",{parentName:"li"},"{}")," and it can be used to pass extraparameters to the internal ",(0,n.kt)("inlineCode",{parentName:"li"},"busboy")," instance at creation time. Checkout ",(0,n.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/busboy#busboy-methods"},"the official documentation")," for more information on the supported options."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"charset")," (string) (default ",(0,n.kt)("inlineCode",{parentName:"li"},"utf8"),"): it can be used to change default charset."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"disableContentTypeError")," (",(0,n.kt)("inlineCode",{parentName:"li"},"boolean"),") (optional): Skip throwing 415 when ",(0,n.kt)("inlineCode",{parentName:"li"},"Content-Type")," is invalid. Default: ",(0,n.kt)("inlineCode",{parentName:"li"},"true"),", will default to ",(0,n.kt)("inlineCode",{parentName:"li"},"false")," in next major version.")),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Note"),": this middleware will buffer all the data as it is processed internally by ",(0,n.kt)("inlineCode",{parentName:"p"},"busboy"),", so, if you are using this approach to parse significantly big volumes of data, keep in mind that all the data will be allocated in memory. This is somewhat inevitable with Lambdas (as the data is already encoded into the JSON in memory as Base64), but it's good to keep this in mind and evaluate the impact on you application.",(0,n.kt)("br",{parentName:"p"}),"\n","If you really have to deal with big files, then you might also want to consider to allowing your users to ",(0,n.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html"},"directly upload files to S3")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpMultipartBodyParser from '@middy/http-multipart-body-parser'\nconst handler = middy((event, context) => {\n return {}\n})\nhandler.use(httpHeaderNormalizer()).use(httpMultipartBodyParser())\n\n// invokes the handler\nconst event = {\n headers: {\n 'Content-Type':\n 'multipart/form-data; boundary=----WebKitFormBoundaryppsQEwf2BVJeCe0M'\n },\n body: 'LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5cHBzUUV3ZjJCVkplQ2UwTQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmb28iDQoNCmJhcg0KLS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5cHBzUUV3ZjJCVkplQ2UwTS0t',\n isBase64Encoded: true\n}\nhandler(event, {}, (_, body) => {\n t.is(body, { foo: 'bar' })\n})\n")))}b.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/3f569cdf.1f4bb74d.js b/assets/js/3f569cdf.585f4a5c.js similarity index 98% rename from assets/js/3f569cdf.1f4bb74d.js rename to assets/js/3f569cdf.585f4a5c.js index 7a87429b4..0c76a53d0 100644 --- a/assets/js/3f569cdf.1f4bb74d.js +++ b/assets/js/3f569cdf.585f4a5c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3775],{3905:(e,t,a)=>{a.d(t,{Zo:()=>c,kt:()=>f});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var i=r.createContext({}),s=function(e){var t=r.useContext(i),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},c=function(e){var t=s(e.components);return r.createElement(i.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,l=e.originalType,i=e.parentName,c=u(e,["components","mdxType","originalType","parentName"]),p=s(a),m=n,f=p["".concat(i,".").concat(m)]||p[m]||d[m]||l;return a?r.createElement(f,o(o({ref:t},c),{},{components:a})):r.createElement(f,o({ref:t},c))}));function f(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=a.length,o=new Array(l);o[0]=m;var u={};for(var i in t)hasOwnProperty.call(t,i)&&(u[i]=t[i]);u.originalType=e,u[p]="string"==typeof e?e:n,o[1]=u;for(var s=2;s{a.d(t,{Z:()=>o});var r=a(7294),n=a(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:a,className:o}=e;return r.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,o),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>k});var r=a(7462),n=a(7294),l=a(6010),o=a(2466),u=a(6550),i=a(1980),s=a(7392),c=a(12);function p(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:r,default:n}}=e;return{value:t,label:a,attributes:r,default:n}}))}function d(e){const{values:t,children:a}=e;return(0,n.useMemo)((()=>{const e=t??p(a);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function m(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const r=(0,u.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,i._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function b(e){const{defaultValue:t,queryString:a=!1,groupId:r}=e,l=d(e),[o,u]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=a.find((e=>e.default))??a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[i,s]=f({queryString:a,groupId:r}),[p,b]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(a);return[r,(0,n.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:r}),h=(()=>{const e=i??p;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{h&&u(h)}),[h]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);u(e),s(e),b(e)}),[s,b,l]),tabValues:l}}var h=a(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:a,selectedValue:u,selectValue:i,tabValues:s}=e;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,o.o5)(),d=e=>{const t=e.currentTarget,a=c.indexOf(t),r=s[a].value;r!==u&&(p(t),i(r))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const a=c.indexOf(e.currentTarget)+1;t=c[a]??c[0];break}case"ArrowLeft":{const a=c.indexOf(e.currentTarget)-1;t=c[a]??c[c.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},s.map((e=>{let{value:t,label:a,attributes:o}=e;return n.createElement("li",(0,r.Z)({role:"tab",tabIndex:u===t?0:-1,"aria-selected":u===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:d},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":u===t})}),a??t)})))}function w(e){let{lazy:t,children:a,selectedValue:r}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function g(e){const t=b(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,r.Z)({},e,t)),n.createElement(w,(0,r.Z)({},e,t)))}function k(e){const t=(0,h.Z)();return n.createElement(g,(0,r.Z)({key:String(t)},e))}},504:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>f,frontMatter:()=>u,metadata:()=>s,toc:()=>p});var r=a(7462),n=(a(7294),a(3905)),l=a(4866),o=a(5162);const u={title:"warmup"},i=void 0,s={unversionedId:"middlewares/warmup",id:"middlewares/warmup",title:"warmup",description:"Warmup middleware that helps to reduce the cold-start issue. Compatible by default with serverless-plugin-warmup, but it can be configured to suit your implementation.",source:"@site/docs/middlewares/warmup.md",sourceDirName:"middlewares",slug:"/middlewares/warmup",permalink:"/docs/middlewares/warmup",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/warmup.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"warmup"},sidebar:"tutorialSidebar",previous:{title:"validator",permalink:"/docs/middlewares/validator"},next:{title:"ws-json-body-parser",permalink:"/docs/middlewares/ws-json-body-parser"}},c={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:p},m="wrapper";function f(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},d,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Warmup middleware that helps to reduce the ",(0,n.kt)("a",{parentName:"p",href:"https://serverless.com/blog/keep-your-lambdas-warm/"},"cold-start issue"),". Compatible by default with ",(0,n.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/serverless-plugin-warmup"},(0,n.kt)("inlineCode",{parentName:"a"},"serverless-plugin-warmup")),", but it can be configured to suit your implementation."),(0,n.kt)("p",null,"This middleware allows you to specify a schedule to keep Lambdas that always need to be very responsive warmed-up. It does this by regularly invoking the Lambda, but will terminate early to avoid the actual handler logic from being run."),(0,n.kt)("p",null,"If you use ",(0,n.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/serverless-plugin-warmup"},(0,n.kt)("inlineCode",{parentName:"a"},"serverless-plugin-warmup")),' the scheduling part is done by the plugin and you just have to attach the middleware to your "middyfied" handler. If you don\'t want to use the plugin you have to create the schedule yourself and define the ',(0,n.kt)("inlineCode",{parentName:"p"},"isWarmingUp")," function to define whether the current event is a warmup event or an actual business logic execution."),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Important:")," AWS recently announced Lambda ",(0,n.kt)("a",{parentName:"p",href:"https://aws.amazon.com/about-aws/whats-new/2019/12/aws-lambda-announces-provisioned-concurrency/"},"Provisioned Concurrency"),". If you have this enabled, you do not need this middleware."),(0,n.kt)("p",null,"To update your code to use Provisioned Concurrency see:"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://aws.amazon.com/blogs/compute/new-for-aws-lambda-predictable-start-up-times-with-provisioned-concurrency/"},"AWS Console")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://serverless.com/blog/aws-lambda-provisioned-concurrency/"},"Serverless")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://www.terraform.io/docs/providers/aws/r/lambda_provisioned_concurrency_config.html"},"Terraform"))),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/warmup\n"))),(0,n.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/warmup\n"))),(0,n.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/warmup\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"isWarmingUp"),": a function that accepts the ",(0,n.kt)("inlineCode",{parentName:"li"},"event")," object as a parameter\nand returns ",(0,n.kt)("inlineCode",{parentName:"li"},"true")," if the current event is a warmup event and ",(0,n.kt)("inlineCode",{parentName:"li"},"false")," if it's a regular execution. The default function will check if the ",(0,n.kt)("inlineCode",{parentName:"li"},"event")," object has a ",(0,n.kt)("inlineCode",{parentName:"li"},"source")," property set to ",(0,n.kt)("inlineCode",{parentName:"li"},"serverless-plugin-warmup"),".")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"const middy = require('@middy/core')\nconst warmup = require('@middy/warmup')\n\nconst isWarmingUp = (event) => event.isWarmingUp === true\n\nconst originalHandler = (event, context, cb) => {\n /* ... */\n}\n\nconst handler = middy(originalHandler)\n .use(warmup({ isWarmingUp }))\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3775],{3905:(e,t,a)=>{a.d(t,{Zo:()=>c,kt:()=>f});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var i=r.createContext({}),s=function(e){var t=r.useContext(i),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},c=function(e){var t=s(e.components);return r.createElement(i.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,l=e.originalType,i=e.parentName,c=u(e,["components","mdxType","originalType","parentName"]),p=s(a),m=n,f=p["".concat(i,".").concat(m)]||p[m]||d[m]||l;return a?r.createElement(f,o(o({ref:t},c),{},{components:a})):r.createElement(f,o({ref:t},c))}));function f(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=a.length,o=new Array(l);o[0]=m;var u={};for(var i in t)hasOwnProperty.call(t,i)&&(u[i]=t[i]);u.originalType=e,u[p]="string"==typeof e?e:n,o[1]=u;for(var s=2;s{a.d(t,{Z:()=>o});var r=a(7294),n=a(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:a,className:o}=e;return r.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,o),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>k});var r=a(7462),n=a(7294),l=a(6010),o=a(2466),u=a(6550),i=a(1980),s=a(7392),c=a(12);function p(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:r,default:n}}=e;return{value:t,label:a,attributes:r,default:n}}))}function d(e){const{values:t,children:a}=e;return(0,n.useMemo)((()=>{const e=t??p(a);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function m(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const r=(0,u.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,i._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function b(e){const{defaultValue:t,queryString:a=!1,groupId:r}=e,l=d(e),[o,u]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=a.find((e=>e.default))??a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[i,s]=f({queryString:a,groupId:r}),[p,b]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(a);return[r,(0,n.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:r}),h=(()=>{const e=i??p;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{h&&u(h)}),[h]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);u(e),s(e),b(e)}),[s,b,l]),tabValues:l}}var h=a(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:a,selectedValue:u,selectValue:i,tabValues:s}=e;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,o.o5)(),d=e=>{const t=e.currentTarget,a=c.indexOf(t),r=s[a].value;r!==u&&(p(t),i(r))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const a=c.indexOf(e.currentTarget)+1;t=c[a]??c[0];break}case"ArrowLeft":{const a=c.indexOf(e.currentTarget)-1;t=c[a]??c[c.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},s.map((e=>{let{value:t,label:a,attributes:o}=e;return n.createElement("li",(0,r.Z)({role:"tab",tabIndex:u===t?0:-1,"aria-selected":u===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:d},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":u===t})}),a??t)})))}function w(e){let{lazy:t,children:a,selectedValue:r}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function g(e){const t=b(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,r.Z)({},e,t)),n.createElement(w,(0,r.Z)({},e,t)))}function k(e){const t=(0,h.Z)();return n.createElement(g,(0,r.Z)({key:String(t)},e))}},504:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>f,frontMatter:()=>u,metadata:()=>s,toc:()=>p});var r=a(7462),n=(a(7294),a(3905)),l=a(4866),o=a(5162);const u={title:"warmup"},i=void 0,s={unversionedId:"middlewares/warmup",id:"middlewares/warmup",title:"warmup",description:"Warmup middleware that helps to reduce the cold-start issue. Compatible by default with serverless-plugin-warmup, but it can be configured to suit your implementation.",source:"@site/docs/middlewares/warmup.md",sourceDirName:"middlewares",slug:"/middlewares/warmup",permalink:"/docs/middlewares/warmup",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/warmup.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"warmup"},sidebar:"tutorialSidebar",previous:{title:"validator",permalink:"/docs/middlewares/validator"},next:{title:"ws-json-body-parser",permalink:"/docs/middlewares/ws-json-body-parser"}},c={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:p},m="wrapper";function f(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},d,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Warmup middleware that helps to reduce the ",(0,n.kt)("a",{parentName:"p",href:"https://serverless.com/blog/keep-your-lambdas-warm/"},"cold-start issue"),". Compatible by default with ",(0,n.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/serverless-plugin-warmup"},(0,n.kt)("inlineCode",{parentName:"a"},"serverless-plugin-warmup")),", but it can be configured to suit your implementation."),(0,n.kt)("p",null,"This middleware allows you to specify a schedule to keep Lambdas that always need to be very responsive warmed-up. It does this by regularly invoking the Lambda, but will terminate early to avoid the actual handler logic from being run."),(0,n.kt)("p",null,"If you use ",(0,n.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/serverless-plugin-warmup"},(0,n.kt)("inlineCode",{parentName:"a"},"serverless-plugin-warmup")),' the scheduling part is done by the plugin and you just have to attach the middleware to your "middyfied" handler. If you don\'t want to use the plugin you have to create the schedule yourself and define the ',(0,n.kt)("inlineCode",{parentName:"p"},"isWarmingUp")," function to define whether the current event is a warmup event or an actual business logic execution."),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Important:")," AWS recently announced Lambda ",(0,n.kt)("a",{parentName:"p",href:"https://aws.amazon.com/about-aws/whats-new/2019/12/aws-lambda-announces-provisioned-concurrency/"},"Provisioned Concurrency"),". If you have this enabled, you do not need this middleware."),(0,n.kt)("p",null,"To update your code to use Provisioned Concurrency see:"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://aws.amazon.com/blogs/compute/new-for-aws-lambda-predictable-start-up-times-with-provisioned-concurrency/"},"AWS Console")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://serverless.com/blog/aws-lambda-provisioned-concurrency/"},"Serverless")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://www.terraform.io/docs/providers/aws/r/lambda_provisioned_concurrency_config.html"},"Terraform"))),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/warmup\n"))),(0,n.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/warmup\n"))),(0,n.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/warmup\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"isWarmingUp"),": a function that accepts the ",(0,n.kt)("inlineCode",{parentName:"li"},"event")," object as a parameter\nand returns ",(0,n.kt)("inlineCode",{parentName:"li"},"true")," if the current event is a warmup event and ",(0,n.kt)("inlineCode",{parentName:"li"},"false")," if it's a regular execution. The default function will check if the ",(0,n.kt)("inlineCode",{parentName:"li"},"event")," object has a ",(0,n.kt)("inlineCode",{parentName:"li"},"source")," property set to ",(0,n.kt)("inlineCode",{parentName:"li"},"serverless-plugin-warmup"),".")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"const middy = require('@middy/core')\nconst warmup = require('@middy/warmup')\n\nconst isWarmingUp = (event) => event.isWarmingUp === true\n\nconst originalHandler = (event, context, cb) => {\n /* ... */\n}\n\nconst handler = middy(originalHandler)\n .use(warmup({ isWarmingUp }))\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/4149078a.5b774359.js b/assets/js/4149078a.d749d3ce.js similarity index 99% rename from assets/js/4149078a.5b774359.js rename to assets/js/4149078a.d749d3ce.js index 53a93ad52..37857ad16 100644 --- a/assets/js/4149078a.5b774359.js +++ b/assets/js/4149078a.d749d3ce.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4183],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>c});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),d=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},h=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),u=d(r),h=n,c=u["".concat(s,".").concat(h)]||u[h]||m[h]||l;return r?a.createElement(c,o(o({ref:t},p),{},{components:r})):a.createElement(c,o({ref:t},p))}));function c(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,o=new Array(l);o[0]=h;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[u]="string"==typeof e?e:n,o[1]=i;for(var d=2;d{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>m,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var a=r(7462),n=(r(7294),r(3905));const l={title:"Upgrade 2.x -> 3.x",sidebar_position:100},o=void 0,i={unversionedId:"upgrade/2-3",id:"upgrade/2-3",title:"Upgrade 2.x -> 3.x",description:"Version 3.x of Middy no longer supports Node.js versions 12.x. You are highly encouraged to move to Node.js 16.x.",source:"@site/docs/upgrade/2-3.md",sourceDirName:"upgrade",slug:"/upgrade/2-3",permalink:"/docs/upgrade/2-3",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/2-3.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:100,frontMatter:{title:"Upgrade 2.x -> 3.x",sidebar_position:100},sidebar:"tutorialSidebar",previous:{title:"Upgrade 3.x -> 4.x",permalink:"/docs/upgrade/3-4"},next:{title:"Upgrade 1.x -> 2.x",permalink:"/docs/upgrade/1-2"}},s={},d=[{value:"Notable changes",id:"notable-changes",level:2},{value:"Core",id:"core",level:2},{value:"Util",id:"util",level:2},{value:"Middleware",id:"middleware",level:2},{value:"cloudwatch-metrics",id:"cloudwatch-metrics",level:3},{value:"do-not-wait-for-empty-event-loop",id:"do-not-wait-for-empty-event-loop",level:3},{value:"error-logger",id:"error-logger",level:3},{value:"event-normalizer",id:"event-normalizer",level:3},{value:"http-content-encoding",id:"http-content-encoding",level:3},{value:"http-content-negotiation",id:"http-content-negotiation",level:3},{value:"http-cors",id:"http-cors",level:3},{value:"http-error-handler",id:"http-error-handler",level:3},{value:"http-event-normalizer",id:"http-event-normalizer",level:3},{value:"http-header-normalizer",id:"http-header-normalizer",level:3},{value:"http-json-body-parser",id:"http-json-body-parser",level:3},{value:"http-multipart-body-parser",id:"http-multipart-body-parser",level:3},{value:"http-partial-response",id:"http-partial-response",level:3},{value:"http-response-serializer",id:"http-response-serializer",level:3},{value:"http-router",id:"http-router",level:3},{value:"http-security-headers",id:"http-security-headers",level:3},{value:"http-urlencode-body-parser",id:"http-urlencode-body-parser",level:3},{value:"http-urlencode-path-parser",id:"http-urlencode-path-parser",level:3},{value:"input-output-logger",id:"input-output-logger",level:3},{value:"rds-signer",id:"rds-signer",level:3},{value:"s3-key-normalizer",id:"s3-key-normalizer",level:3},{value:"s3-object-response",id:"s3-object-response",level:3},{value:"secrets-manager",id:"secrets-manager",level:3},{value:"service-discovery",id:"service-discovery",level:3},{value:"sqs-json-body-parser",id:"sqs-json-body-parser",level:3},{value:"sqs-partial-batch-failure",id:"sqs-partial-batch-failure",level:3},{value:"ssm",id:"ssm",level:3},{value:"sts",id:"sts",level:3},{value:"validator",id:"validator",level:3},{value:"warmup",id:"warmup",level:3},{value:"ws-json-body-parser",id:"ws-json-body-parser",level:3},{value:"ws-response",id:"ws-response",level:3},{value:"ws-router",id:"ws-router",level:3},{value:"Notes",id:"notes",level:2}],p={toc:d},u="wrapper";function m(e){let{components:t,...r}=e;return(0,n.kt)(u,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Version 3.x of Middy no longer supports Node.js versions 12.x. You are highly encouraged to move to Node.js 16.x.\nWith the Node.js version change all packages are now ECMAScript Modules along side CommonJS Modules."),(0,n.kt)("h2",{id:"notable-changes"},"Notable changes"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"New WebSocket middlewares"),(0,n.kt)("li",{parentName:"ul"},"HTTP & WebSocket Routers!"),(0,n.kt)("li",{parentName:"ul"},"Better error handling"),(0,n.kt)("li",{parentName:"ul"},"Timeout error handling"),(0,n.kt)("li",{parentName:"ul"},"Errors now use ",(0,n.kt)("inlineCode",{parentName:"li"},"{ cause }")," for better context")),(0,n.kt)("h2",{id:"core"},"Core"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"onError")," middleware stack order reversed to match ",(0,n.kt)("inlineCode",{parentName:"li"},"after")," ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"),(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},"If you only use ",(0,n.kt)("inlineCode",{parentName:"li"},"@middy/*")," middlewares no change should be required"),(0,n.kt)("li",{parentName:"ul"},"This change has trickle down effects on middlewares with ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," (see below for details)"),(0,n.kt)("li",{parentName:"ul"},"If you're handling errors yourself here are some things to review:",(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},"Attach near the end so it is triggered first (likely already done)"),(0,n.kt)("li",{parentName:"ul"},"Remove ",(0,n.kt)("inlineCode",{parentName:"li"},"return response"),", this will short circuit the response and block later middleware from modifying the response"))))),(0,n.kt)("li",{parentName:"ul"},"lambdaHandler now passes ",(0,n.kt)("inlineCode",{parentName:"li"},"{signal}")," from ",(0,n.kt)("inlineCode",{parentName:"li"},"AbortController")," to allow for ending lambda early to handle timeout errors"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"plugin")," argument now supports:",(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"internal"),": Allow the use of ",(0,n.kt)("inlineCode",{parentName:"li"},"new Proxy()")," for smarter triggering in advanced use cases."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"timeoutEarlyInMillis"),": When before lambda timeout to trigger early exit. Default ",(0,n.kt)("inlineCode",{parentName:"li"},"5")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"timeoutEarlyResponse"),": Function to throw a custom error or return a pre-set value. Default ",(0,n.kt)("inlineCode",{parentName:"li"},"() => { throw new Error('Timeout') }")))),(0,n.kt)("li",{parentName:"ul"},"Added ",(0,n.kt)("inlineCode",{parentName:"li"},".handler()")," method to allow easier understanding of the execution cycle"),(0,n.kt)("li",{parentName:"ul"},"Deprecate ",(0,n.kt)("inlineCode",{parentName:"li"},"applyMiddleware()")," and ",(0,n.kt)("inlineCode",{parentName:"li"},"__middlewares")," ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h2",{id:"util"},"Util"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"getInternal")," error now includes ",(0,n.kt)("inlineCode",{parentName:"li"},"cause")," set to an array of Errors"),(0,n.kt)("li",{parentName:"ul"},"Catch when ",(0,n.kt)("inlineCode",{parentName:"li"},"X-Ray")," is applied outside of handler invocation scope"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"normalizeHttpResponse")," now takes ",(0,n.kt)("inlineCode",{parentName:"li"},"request")," and mutates response ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"getCache")," will return ",(0,n.kt)("inlineCode",{parentName:"li"},"{}")," instead of ",(0,n.kt)("inlineCode",{parentName:"li"},"undefined")," when not found ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h2",{id:"middleware"},"Middleware"),(0,n.kt)("h3",{id:"cloudwatch-metrics"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/cloudwatch-metrics"},"cloudwatch-metrics")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"do-not-wait-for-empty-event-loop"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/do-not-wait-for-empty-event-loop"},"do-not-wait-for-empty-event-loop")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"error-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/error-logger"},"error-logger")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/event-normalizer"},"event-normalizer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Add support for all missing AWS events"),(0,n.kt)("li",{parentName:"ul"},"Refactored for performance improvements")),(0,n.kt)("h3",{id:"http-content-encoding"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-encoding"},"http-content-encoding")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Applies ",(0,n.kt)("inlineCode",{parentName:"li"},"brotli"),", ",(0,n.kt)("inlineCode",{parentName:"li"},"gzip"),", ands ",(0,n.kt)("inlineCode",{parentName:"li"},"deflate")," compression to response body")),(0,n.kt)("h3",{id:"http-content-negotiation"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-negotiation"},"http-content-negotiation")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Add in ",(0,n.kt)("inlineCode",{parentName:"li"},"defaultToFirstLanguage")," to allow fallback to a safe language to use")),(0,n.kt)("h3",{id:"http-cors"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-cors"},"http-cors")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"onError")," will not modify response unless error has been handled"),(0,n.kt)("li",{parentName:"ul"},"Small refactor for performance improvements")),(0,n.kt)("h3",{id:"http-error-handler"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-error-handler"},"http-error-handler")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"No longer returns the response to short circuit the middleware stack to allow for easier use now that ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," is called in reverse order.")),(0,n.kt)("h3",{id:"http-event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-event-normalizer"},"http-event-normalizer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Option ",(0,n.kt)("inlineCode",{parentName:"li"},"payloadFormatVersion")," no longer needed"),(0,n.kt)("li",{parentName:"ul"},"Will now throw error if not an http event ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"http-header-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-header-normalizer"},"http-header-normalizer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Modified so that all headers are set to lowercase when ",(0,n.kt)("inlineCode",{parentName:"li"},"canonical:false")," ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"http-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-json-body-parser"},"http-json-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-multipart-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-multipart-body-parser"},"http-multipart-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Change default charset from ",(0,n.kt)("inlineCode",{parentName:"li"},"binary"),"/",(0,n.kt)("inlineCode",{parentName:"li"},"latin1")," to ",(0,n.kt)("inlineCode",{parentName:"li"},"utf-8"),". ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"http-partial-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-partial-response"},"http-partial-response")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-response-serializer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-response-serializer"},"http-response-serializer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Renamed ",(0,n.kt)("inlineCode",{parentName:"li"},"default")," option to ",(0,n.kt)("inlineCode",{parentName:"li"},"defaultContentType")," to improve maintainability ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"onError")," will not modify response unless error has been handled")),(0,n.kt)("h3",{id:"http-router"},(0,n.kt)("a",{parentName:"h3",href:"/docs/routers/http-router"},"http-router")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Allow re-routing of events to different handlers")),(0,n.kt)("h3",{id:"http-security-headers"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-security-headers"},"http-security-headers")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"onError")," will not modify response unless error has been handled"),(0,n.kt)("li",{parentName:"ul"},"Complete rewrite of options and inclusion of new HTML only headers ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"http-urlencode-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-body-parser"},"http-urlencode-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-urlencode-path-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-path-parser"},"http-urlencode-path-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"input-output-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/input-output-logger"},"input-output-logger")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Add in new option to mask instead of omit a path.")),(0,n.kt)("h3",{id:"rds-signer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/rds-signer"},"rds-signer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated ",(0,n.kt)("inlineCode",{parentName:"li"},"setToEnv")," option due to possible security misuse ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"s3-key-normalizer"},"s3-key-normalizer"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated in favour of ",(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/event-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"event-normalizer")),", v2.x compatible with v3")),(0,n.kt)("h3",{id:"s3-object-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/s3-object-response"},"s3-object-response")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"secrets-manager"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/secrets-manager"},"secrets-manager")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated ",(0,n.kt)("inlineCode",{parentName:"li"},"setToEnv")," option due to possible security misuse ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"service-discovery"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/service-discovery"},"service-discovery")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Allow easy access to discoveryInstances")),(0,n.kt)("h3",{id:"sqs-json-body-parser"},"sqs-json-body-parser"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated in favour of ",(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/event-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"event-normalizer")),", v2.x compatible with v3")),(0,n.kt)("h3",{id:"sqs-partial-batch-failure"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sqs-partial-batch-failure"},"sqs-partial-batch-failure")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Complete rewrite to take advantage of ",(0,n.kt)("a",{parentName:"li",href:"https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/"},"https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/"),", will no longer throw an error if any message fails ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"ssm"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ssm"},"ssm")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated ",(0,n.kt)("inlineCode",{parentName:"li"},"setToEnv")," option ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"sts"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sts"},"sts")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"validator"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/validator"},"validator")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Change where errors are stored, from ",(0,n.kt)("inlineCode",{parentName:"li"},"request.error.details")," to ",(0,n.kt)("inlineCode",{parentName:"li"},"request.error.cause")," ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]")),(0,n.kt)("li",{parentName:"ul"},"Add new options ",(0,n.kt)("inlineCode",{parentName:"li"},"eventSchema"),", ",(0,n.kt)("inlineCode",{parentName:"li"},"contextSchema"),", ",(0,n.kt)("inlineCode",{parentName:"li"},"responseSchema"),". ",(0,n.kt)("inlineCode",{parentName:"li"},"inputSchema")," and ",(0,n.kt)("inlineCode",{parentName:"li"},"outputSchema")," become aliases.")),(0,n.kt)("h3",{id:"warmup"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/warmup"},"warmup")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"ws-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ws-json-body-parser"},"ws-json-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Parse body from WebSocket event")),(0,n.kt)("h3",{id:"ws-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ws-response"},"ws-response")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Post responses to WebSocket API Gateway")),(0,n.kt)("h3",{id:"ws-router"},(0,n.kt)("a",{parentName:"h3",href:"/docs/routers/ws-router"},"ws-router")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Allow re-routing of events to different handlers")),(0,n.kt)("h2",{id:"notes"},"Notes"),(0,n.kt)("p",null,"If you still need ",(0,n.kt)("inlineCode",{parentName:"p"},"setToEnv")," you can do something like so:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"middy(lambdaHandler)\n .use(/*...*/)\n .before(async (request) => {\n const values = await getInternal(['NODE_ENV'], request)\n process.env.NODE_ENV = values.NODE_ENV\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4183],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>c});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),d=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},h=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),u=d(r),h=n,c=u["".concat(s,".").concat(h)]||u[h]||m[h]||l;return r?a.createElement(c,o(o({ref:t},p),{},{components:r})):a.createElement(c,o({ref:t},p))}));function c(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,o=new Array(l);o[0]=h;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[u]="string"==typeof e?e:n,o[1]=i;for(var d=2;d{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>m,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var a=r(7462),n=(r(7294),r(3905));const l={title:"Upgrade 2.x -> 3.x",sidebar_position:100},o=void 0,i={unversionedId:"upgrade/2-3",id:"upgrade/2-3",title:"Upgrade 2.x -> 3.x",description:"Version 3.x of Middy no longer supports Node.js versions 12.x. You are highly encouraged to move to Node.js 16.x.",source:"@site/docs/upgrade/2-3.md",sourceDirName:"upgrade",slug:"/upgrade/2-3",permalink:"/docs/upgrade/2-3",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/2-3.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:100,frontMatter:{title:"Upgrade 2.x -> 3.x",sidebar_position:100},sidebar:"tutorialSidebar",previous:{title:"Upgrade 3.x -> 4.x",permalink:"/docs/upgrade/3-4"},next:{title:"Upgrade 1.x -> 2.x",permalink:"/docs/upgrade/1-2"}},s={},d=[{value:"Notable changes",id:"notable-changes",level:2},{value:"Core",id:"core",level:2},{value:"Util",id:"util",level:2},{value:"Middleware",id:"middleware",level:2},{value:"cloudwatch-metrics",id:"cloudwatch-metrics",level:3},{value:"do-not-wait-for-empty-event-loop",id:"do-not-wait-for-empty-event-loop",level:3},{value:"error-logger",id:"error-logger",level:3},{value:"event-normalizer",id:"event-normalizer",level:3},{value:"http-content-encoding",id:"http-content-encoding",level:3},{value:"http-content-negotiation",id:"http-content-negotiation",level:3},{value:"http-cors",id:"http-cors",level:3},{value:"http-error-handler",id:"http-error-handler",level:3},{value:"http-event-normalizer",id:"http-event-normalizer",level:3},{value:"http-header-normalizer",id:"http-header-normalizer",level:3},{value:"http-json-body-parser",id:"http-json-body-parser",level:3},{value:"http-multipart-body-parser",id:"http-multipart-body-parser",level:3},{value:"http-partial-response",id:"http-partial-response",level:3},{value:"http-response-serializer",id:"http-response-serializer",level:3},{value:"http-router",id:"http-router",level:3},{value:"http-security-headers",id:"http-security-headers",level:3},{value:"http-urlencode-body-parser",id:"http-urlencode-body-parser",level:3},{value:"http-urlencode-path-parser",id:"http-urlencode-path-parser",level:3},{value:"input-output-logger",id:"input-output-logger",level:3},{value:"rds-signer",id:"rds-signer",level:3},{value:"s3-key-normalizer",id:"s3-key-normalizer",level:3},{value:"s3-object-response",id:"s3-object-response",level:3},{value:"secrets-manager",id:"secrets-manager",level:3},{value:"service-discovery",id:"service-discovery",level:3},{value:"sqs-json-body-parser",id:"sqs-json-body-parser",level:3},{value:"sqs-partial-batch-failure",id:"sqs-partial-batch-failure",level:3},{value:"ssm",id:"ssm",level:3},{value:"sts",id:"sts",level:3},{value:"validator",id:"validator",level:3},{value:"warmup",id:"warmup",level:3},{value:"ws-json-body-parser",id:"ws-json-body-parser",level:3},{value:"ws-response",id:"ws-response",level:3},{value:"ws-router",id:"ws-router",level:3},{value:"Notes",id:"notes",level:2}],p={toc:d},u="wrapper";function m(e){let{components:t,...r}=e;return(0,n.kt)(u,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Version 3.x of Middy no longer supports Node.js versions 12.x. You are highly encouraged to move to Node.js 16.x.\nWith the Node.js version change all packages are now ECMAScript Modules along side CommonJS Modules."),(0,n.kt)("h2",{id:"notable-changes"},"Notable changes"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"New WebSocket middlewares"),(0,n.kt)("li",{parentName:"ul"},"HTTP & WebSocket Routers!"),(0,n.kt)("li",{parentName:"ul"},"Better error handling"),(0,n.kt)("li",{parentName:"ul"},"Timeout error handling"),(0,n.kt)("li",{parentName:"ul"},"Errors now use ",(0,n.kt)("inlineCode",{parentName:"li"},"{ cause }")," for better context")),(0,n.kt)("h2",{id:"core"},"Core"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"onError")," middleware stack order reversed to match ",(0,n.kt)("inlineCode",{parentName:"li"},"after")," ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"),(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},"If you only use ",(0,n.kt)("inlineCode",{parentName:"li"},"@middy/*")," middlewares no change should be required"),(0,n.kt)("li",{parentName:"ul"},"This change has trickle down effects on middlewares with ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," (see below for details)"),(0,n.kt)("li",{parentName:"ul"},"If you're handling errors yourself here are some things to review:",(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},"Attach near the end so it is triggered first (likely already done)"),(0,n.kt)("li",{parentName:"ul"},"Remove ",(0,n.kt)("inlineCode",{parentName:"li"},"return response"),", this will short circuit the response and block later middleware from modifying the response"))))),(0,n.kt)("li",{parentName:"ul"},"lambdaHandler now passes ",(0,n.kt)("inlineCode",{parentName:"li"},"{signal}")," from ",(0,n.kt)("inlineCode",{parentName:"li"},"AbortController")," to allow for ending lambda early to handle timeout errors"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"plugin")," argument now supports:",(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"internal"),": Allow the use of ",(0,n.kt)("inlineCode",{parentName:"li"},"new Proxy()")," for smarter triggering in advanced use cases."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"timeoutEarlyInMillis"),": When before lambda timeout to trigger early exit. Default ",(0,n.kt)("inlineCode",{parentName:"li"},"5")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"timeoutEarlyResponse"),": Function to throw a custom error or return a pre-set value. Default ",(0,n.kt)("inlineCode",{parentName:"li"},"() => { throw new Error('Timeout') }")))),(0,n.kt)("li",{parentName:"ul"},"Added ",(0,n.kt)("inlineCode",{parentName:"li"},".handler()")," method to allow easier understanding of the execution cycle"),(0,n.kt)("li",{parentName:"ul"},"Deprecate ",(0,n.kt)("inlineCode",{parentName:"li"},"applyMiddleware()")," and ",(0,n.kt)("inlineCode",{parentName:"li"},"__middlewares")," ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h2",{id:"util"},"Util"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"getInternal")," error now includes ",(0,n.kt)("inlineCode",{parentName:"li"},"cause")," set to an array of Errors"),(0,n.kt)("li",{parentName:"ul"},"Catch when ",(0,n.kt)("inlineCode",{parentName:"li"},"X-Ray")," is applied outside of handler invocation scope"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"normalizeHttpResponse")," now takes ",(0,n.kt)("inlineCode",{parentName:"li"},"request")," and mutates response ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"getCache")," will return ",(0,n.kt)("inlineCode",{parentName:"li"},"{}")," instead of ",(0,n.kt)("inlineCode",{parentName:"li"},"undefined")," when not found ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h2",{id:"middleware"},"Middleware"),(0,n.kt)("h3",{id:"cloudwatch-metrics"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/cloudwatch-metrics"},"cloudwatch-metrics")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"do-not-wait-for-empty-event-loop"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/do-not-wait-for-empty-event-loop"},"do-not-wait-for-empty-event-loop")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"error-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/error-logger"},"error-logger")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/event-normalizer"},"event-normalizer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Add support for all missing AWS events"),(0,n.kt)("li",{parentName:"ul"},"Refactored for performance improvements")),(0,n.kt)("h3",{id:"http-content-encoding"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-encoding"},"http-content-encoding")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Applies ",(0,n.kt)("inlineCode",{parentName:"li"},"brotli"),", ",(0,n.kt)("inlineCode",{parentName:"li"},"gzip"),", ands ",(0,n.kt)("inlineCode",{parentName:"li"},"deflate")," compression to response body")),(0,n.kt)("h3",{id:"http-content-negotiation"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-negotiation"},"http-content-negotiation")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Add in ",(0,n.kt)("inlineCode",{parentName:"li"},"defaultToFirstLanguage")," to allow fallback to a safe language to use")),(0,n.kt)("h3",{id:"http-cors"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-cors"},"http-cors")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"onError")," will not modify response unless error has been handled"),(0,n.kt)("li",{parentName:"ul"},"Small refactor for performance improvements")),(0,n.kt)("h3",{id:"http-error-handler"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-error-handler"},"http-error-handler")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"No longer returns the response to short circuit the middleware stack to allow for easier use now that ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," is called in reverse order.")),(0,n.kt)("h3",{id:"http-event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-event-normalizer"},"http-event-normalizer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Option ",(0,n.kt)("inlineCode",{parentName:"li"},"payloadFormatVersion")," no longer needed"),(0,n.kt)("li",{parentName:"ul"},"Will now throw error if not an http event ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"http-header-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-header-normalizer"},"http-header-normalizer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Modified so that all headers are set to lowercase when ",(0,n.kt)("inlineCode",{parentName:"li"},"canonical:false")," ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"http-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-json-body-parser"},"http-json-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-multipart-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-multipart-body-parser"},"http-multipart-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Change default charset from ",(0,n.kt)("inlineCode",{parentName:"li"},"binary"),"/",(0,n.kt)("inlineCode",{parentName:"li"},"latin1")," to ",(0,n.kt)("inlineCode",{parentName:"li"},"utf-8"),". ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"http-partial-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-partial-response"},"http-partial-response")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-response-serializer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-response-serializer"},"http-response-serializer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Renamed ",(0,n.kt)("inlineCode",{parentName:"li"},"default")," option to ",(0,n.kt)("inlineCode",{parentName:"li"},"defaultContentType")," to improve maintainability ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"onError")," will not modify response unless error has been handled")),(0,n.kt)("h3",{id:"http-router"},(0,n.kt)("a",{parentName:"h3",href:"/docs/routers/http-router"},"http-router")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Allow re-routing of events to different handlers")),(0,n.kt)("h3",{id:"http-security-headers"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-security-headers"},"http-security-headers")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"onError")," will not modify response unless error has been handled"),(0,n.kt)("li",{parentName:"ul"},"Complete rewrite of options and inclusion of new HTML only headers ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"http-urlencode-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-body-parser"},"http-urlencode-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-urlencode-path-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-path-parser"},"http-urlencode-path-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"input-output-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/input-output-logger"},"input-output-logger")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Add in new option to mask instead of omit a path.")),(0,n.kt)("h3",{id:"rds-signer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/rds-signer"},"rds-signer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated ",(0,n.kt)("inlineCode",{parentName:"li"},"setToEnv")," option due to possible security misuse ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"s3-key-normalizer"},"s3-key-normalizer"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated in favour of ",(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/event-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"event-normalizer")),", v2.x compatible with v3")),(0,n.kt)("h3",{id:"s3-object-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/s3-object-response"},"s3-object-response")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"secrets-manager"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/secrets-manager"},"secrets-manager")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated ",(0,n.kt)("inlineCode",{parentName:"li"},"setToEnv")," option due to possible security misuse ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"service-discovery"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/service-discovery"},"service-discovery")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Allow easy access to discoveryInstances")),(0,n.kt)("h3",{id:"sqs-json-body-parser"},"sqs-json-body-parser"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated in favour of ",(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/event-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"event-normalizer")),", v2.x compatible with v3")),(0,n.kt)("h3",{id:"sqs-partial-batch-failure"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sqs-partial-batch-failure"},"sqs-partial-batch-failure")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Complete rewrite to take advantage of ",(0,n.kt)("a",{parentName:"li",href:"https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/"},"https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/"),", will no longer throw an error if any message fails ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"ssm"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ssm"},"ssm")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecated ",(0,n.kt)("inlineCode",{parentName:"li"},"setToEnv")," option ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]"))),(0,n.kt)("h3",{id:"sts"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sts"},"sts")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"validator"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/validator"},"validator")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Change where errors are stored, from ",(0,n.kt)("inlineCode",{parentName:"li"},"request.error.details")," to ",(0,n.kt)("inlineCode",{parentName:"li"},"request.error.cause")," ",(0,n.kt)("strong",{parentName:"li"},"[Breaking Change]")),(0,n.kt)("li",{parentName:"ul"},"Add new options ",(0,n.kt)("inlineCode",{parentName:"li"},"eventSchema"),", ",(0,n.kt)("inlineCode",{parentName:"li"},"contextSchema"),", ",(0,n.kt)("inlineCode",{parentName:"li"},"responseSchema"),". ",(0,n.kt)("inlineCode",{parentName:"li"},"inputSchema")," and ",(0,n.kt)("inlineCode",{parentName:"li"},"outputSchema")," become aliases.")),(0,n.kt)("h3",{id:"warmup"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/warmup"},"warmup")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"ws-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ws-json-body-parser"},"ws-json-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Parse body from WebSocket event")),(0,n.kt)("h3",{id:"ws-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ws-response"},"ws-response")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Post responses to WebSocket API Gateway")),(0,n.kt)("h3",{id:"ws-router"},(0,n.kt)("a",{parentName:"h3",href:"/docs/routers/ws-router"},"ws-router")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"[New]"," Allow re-routing of events to different handlers")),(0,n.kt)("h2",{id:"notes"},"Notes"),(0,n.kt)("p",null,"If you still need ",(0,n.kt)("inlineCode",{parentName:"p"},"setToEnv")," you can do something like so:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"middy(lambdaHandler)\n .use(/*...*/)\n .before(async (request) => {\n const values = await getInternal(['NODE_ENV'], request)\n process.env.NODE_ENV = values.NODE_ENV\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/41b3f383.5b61facc.js b/assets/js/41b3f383.3340716d.js similarity index 99% rename from assets/js/41b3f383.5b61facc.js rename to assets/js/41b3f383.3340716d.js index 695051914..18a15b9bc 100644 --- a/assets/js/41b3f383.5b61facc.js +++ b/assets/js/41b3f383.3340716d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[479],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>v});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var o=r.createContext({}),c=function(e){var t=r.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},u=function(e){var t=c(e.components);return r.createElement(o.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,o=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),d=c(n),m=a,v=d["".concat(o,".").concat(m)]||d[m]||p[m]||l;return n?r.createElement(v,i(i({ref:t},u),{},{components:n})):r.createElement(v,i({ref:t},u))}));function v(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,i=new Array(l);i[0]=m;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.d(t,{Z:()=>i});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var r=n(7462),a=n(7294),l=n(6010),i=n(2466),s=n(6550),o=n(1980),c=n(7392),u=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function v(e){let{queryString:t=!1,groupId:n}=e;const r=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=p(e),[i,s]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[o,c]=v({queryString:n,groupId:r}),[d,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,u.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),b=(()=>{const e=o??d;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&s(b)}),[b]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),c(e),f(e)}),[c,f,l]),tabValues:l}}var b=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function h(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:c}=e;const u=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=u.indexOf(t),r=c[n].value;r!==s&&(d(t),o(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},c.map((e=>{let{value:t,label:n,attributes:i}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>u.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",y.tabItem,i?.className,{"tabs__item--active":s===t})}),n??t)})))}function k(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function g(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(h,(0,r.Z)({},e,t)),a.createElement(k,(0,r.Z)({},e,t)))}function N(e){const t=(0,b.Z)();return a.createElement(g,(0,r.Z)({key:String(t)},e))}},6241:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>v,frontMatter:()=>s,metadata:()=>c,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),i=n(5162);const s={title:"service-discovery"},o=void 0,c={unversionedId:"middlewares/service-discovery",id:"middlewares/service-discovery",title:"service-discovery",description:"Fetches Service Discovery instances to be used when connecting to other AWS services.",source:"@site/docs/middlewares/service-discovery.md",sourceDirName:"middlewares",slug:"/middlewares/service-discovery",permalink:"/docs/middlewares/service-discovery",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/service-discovery.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"service-discovery"},sidebar:"tutorialSidebar",previous:{title:"secrets-manager",permalink:"/docs/middlewares/secrets-manager"},next:{title:"sqs-partial-batch-failure",permalink:"/docs/middlewares/sqs-partial-batch-failure"}},u={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:d},m="wrapper";function v(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Fetches Service Discovery instances to be used when connecting to other AWS services."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/service-discovery\nnpm install --save-dev @aws-sdk/client-servicediscovery\n"))),(0,a.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/service-discovery\nyarn add --dev @aws-sdk/client-servicediscovery\n"))),(0,a.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/service-discovery\npnpm add --save-dev @aws-sdk/client-servicediscovery\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"ServiceDiscoveryClient"),"): ServiceDiscoveryClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-servicediscovery"),"."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to ServiceDiscoveryClient class constructor."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,a.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,a.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,a.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,a.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"sts"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,a.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,a.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,a.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,a.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,a.kt)("inlineCode",{parentName:"li"},"servicediscovery:DiscoverInstances"))),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport serviceDiscovery from '@middy/service-discovery'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n serviceDiscovery({\n fetchData: {\n instances: {\n NamespaceName: '...',\n ServiceName: '...'\n }\n }\n })\n)\n")),(0,a.kt)("h2",{id:"bundling"},"Bundling"),(0,a.kt)("p",null,"To exclude ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-servicediscovery")," to the exclude list."))}v.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[479],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>v});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var o=r.createContext({}),c=function(e){var t=r.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},u=function(e){var t=c(e.components);return r.createElement(o.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,o=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),d=c(n),m=a,v=d["".concat(o,".").concat(m)]||d[m]||p[m]||l;return n?r.createElement(v,i(i({ref:t},u),{},{components:n})):r.createElement(v,i({ref:t},u))}));function v(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,i=new Array(l);i[0]=m;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.d(t,{Z:()=>i});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var r=n(7462),a=n(7294),l=n(6010),i=n(2466),s=n(6550),o=n(1980),c=n(7392),u=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function v(e){let{queryString:t=!1,groupId:n}=e;const r=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=p(e),[i,s]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[o,c]=v({queryString:n,groupId:r}),[d,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,u.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),b=(()=>{const e=o??d;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&s(b)}),[b]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),c(e),f(e)}),[c,f,l]),tabValues:l}}var b=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function h(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:c}=e;const u=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=u.indexOf(t),r=c[n].value;r!==s&&(d(t),o(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},c.map((e=>{let{value:t,label:n,attributes:i}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>u.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",y.tabItem,i?.className,{"tabs__item--active":s===t})}),n??t)})))}function k(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function g(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(h,(0,r.Z)({},e,t)),a.createElement(k,(0,r.Z)({},e,t)))}function N(e){const t=(0,b.Z)();return a.createElement(g,(0,r.Z)({key:String(t)},e))}},6241:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>v,frontMatter:()=>s,metadata:()=>c,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),i=n(5162);const s={title:"service-discovery"},o=void 0,c={unversionedId:"middlewares/service-discovery",id:"middlewares/service-discovery",title:"service-discovery",description:"Fetches Service Discovery instances to be used when connecting to other AWS services.",source:"@site/docs/middlewares/service-discovery.md",sourceDirName:"middlewares",slug:"/middlewares/service-discovery",permalink:"/docs/middlewares/service-discovery",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/service-discovery.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"service-discovery"},sidebar:"tutorialSidebar",previous:{title:"secrets-manager",permalink:"/docs/middlewares/secrets-manager"},next:{title:"sqs-partial-batch-failure",permalink:"/docs/middlewares/sqs-partial-batch-failure"}},u={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:d},m="wrapper";function v(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Fetches Service Discovery instances to be used when connecting to other AWS services."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/service-discovery\nnpm install --save-dev @aws-sdk/client-servicediscovery\n"))),(0,a.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/service-discovery\nyarn add --dev @aws-sdk/client-servicediscovery\n"))),(0,a.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/service-discovery\npnpm add --save-dev @aws-sdk/client-servicediscovery\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"ServiceDiscoveryClient"),"): ServiceDiscoveryClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-servicediscovery"),"."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to ServiceDiscoveryClient class constructor."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,a.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,a.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,a.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,a.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"sts"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,a.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,a.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,a.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,a.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,a.kt)("inlineCode",{parentName:"li"},"servicediscovery:DiscoverInstances"))),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport serviceDiscovery from '@middy/service-discovery'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n serviceDiscovery({\n fetchData: {\n instances: {\n NamespaceName: '...',\n ServiceName: '...'\n }\n }\n })\n)\n")),(0,a.kt)("h2",{id:"bundling"},"Bundling"),(0,a.kt)("p",null,"To exclude ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,a.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-servicediscovery")," to the exclude list."))}v.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/436b299f.f6828c80.js b/assets/js/436b299f.9ac23bc8.js similarity index 98% rename from assets/js/436b299f.f6828c80.js rename to assets/js/436b299f.9ac23bc8.js index c3ceddb95..5f5748ddc 100644 --- a/assets/js/436b299f.f6828c80.js +++ b/assets/js/436b299f.9ac23bc8.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5077],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var i=n.createContext({}),u=function(e){var t=n.useContext(i),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},d=function(e){var t=u(e.components);return n.createElement(i.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),c=u(r),m=a,h=c["".concat(i,".").concat(m)]||c[m]||p[m]||l;return r?n.createElement(h,o(o({ref:t},d),{},{components:r})):n.createElement(h,o({ref:t},d))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=m;var s={};for(var i in t)hasOwnProperty.call(t,i)&&(s[i]=t[i]);s.originalType=e,s[c]="string"==typeof e?e:a,o[1]=s;for(var u=2;u{r.d(t,{Z:()=>o});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7462),a=r(7294),l=r(6010),o=r(2466),s=r(6550),i=r(1980),u=r(7392),d=r(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function p(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:r}=e;const n=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,i._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=p(e),[o,s]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[i,u]=h({queryString:r,groupId:n}),[c,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),b=(()=>{const e=i??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&s(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),u(e),f(e)}),[u,f,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:r,selectedValue:s,selectValue:i,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),p=e=>{const t=e.currentTarget,r=d.indexOf(t),n=u[r].value;n!==s&&(c(t),i(n))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:o}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":s===t})}),r??t)})))}function v(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function k(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(g,(0,n.Z)({},e,t)),a.createElement(v,(0,n.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return a.createElement(k,(0,n.Z)({key:String(t)},e))}},3687:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>h,frontMatter:()=>s,metadata:()=>u,toc:()=>c});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),o=r(5162);const s={title:"http-error-handler"},i=void 0,u={unversionedId:"middlewares/http-error-handler",id:"middlewares/http-error-handler",title:"http-error-handler",description:"Automatically handles uncaught errors that contain the properties statusCode (number) and message (string) and creates a proper HTTP response",source:"@site/docs/middlewares/http-error-handler.md",sourceDirName:"middlewares",slug:"/middlewares/http-error-handler",permalink:"/docs/middlewares/http-error-handler",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-error-handler.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-error-handler"},sidebar:"tutorialSidebar",previous:{title:"http-cors",permalink:"/docs/middlewares/http-cors"},next:{title:"http-event-normalizer",permalink:"/docs/middlewares/http-event-normalizer"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:c},m="wrapper";function h(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Automatically handles uncaught errors that contain the properties ",(0,a.kt)("inlineCode",{parentName:"p"},"statusCode")," (number) and ",(0,a.kt)("inlineCode",{parentName:"p"},"message")," (string) and creates a proper HTTP response\nfor them (using the message and the status code provided by the error object). Additionally, support for the property ",(0,a.kt)("inlineCode",{parentName:"p"},"expose")," is included with a default value of ",(0,a.kt)("inlineCode",{parentName:"p"},"statusCode < 500"),".\nWe recommend generating these HTTP errors with the npm module ",(0,a.kt)("a",{parentName:"p",href:"https://npm.im/http-errors"},(0,a.kt)("inlineCode",{parentName:"a"},"http-errors")),". When manually catching and setting errors with ",(0,a.kt)("inlineCode",{parentName:"p"},"statusCode >= 500")," setting ",(0,a.kt)("inlineCode",{parentName:"p"},"{expose: true}"),"\nis needed for them to be handled."),(0,a.kt)("p",null,"This middleware should be set as the last error handler attached, first to execute."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-error-handler\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-error-handler\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-error-handler\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"logger")," (defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"console.error"),") - a logging function that is invoked with the current error as an argument. You can pass ",(0,a.kt)("inlineCode",{parentName:"li"},"false")," if you don't want the logging to happen."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"fallbackMessage")," (default to null) - When non-http errors (those without `",(0,a.kt)("inlineCode",{parentName:"li"},"statusCode"),") occur you can catch them by setting a fallback message to be used. These will be returned with a 500 status code.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpErrorHandler from '@middy/http-error-handler'\n\nconst handler = middy((event, context) => {\n throw new createError.UnprocessableEntity()\n})\n\nhandler\n .use(httpErrorHandler())\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.deepEqual(response,{\n statusCode: 422,\n body: 'Unprocessable Entity'\n })\n})\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5077],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var i=n.createContext({}),u=function(e){var t=n.useContext(i),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},d=function(e){var t=u(e.components);return n.createElement(i.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),c=u(r),m=a,h=c["".concat(i,".").concat(m)]||c[m]||p[m]||l;return r?n.createElement(h,o(o({ref:t},d),{},{components:r})):n.createElement(h,o({ref:t},d))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=m;var s={};for(var i in t)hasOwnProperty.call(t,i)&&(s[i]=t[i]);s.originalType=e,s[c]="string"==typeof e?e:a,o[1]=s;for(var u=2;u{r.d(t,{Z:()=>o});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7462),a=r(7294),l=r(6010),o=r(2466),s=r(6550),i=r(1980),u=r(7392),d=r(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function p(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:r}=e;const n=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,i._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=p(e),[o,s]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[i,u]=h({queryString:r,groupId:n}),[c,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),b=(()=>{const e=i??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&s(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),u(e),f(e)}),[u,f,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:r,selectedValue:s,selectValue:i,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),p=e=>{const t=e.currentTarget,r=d.indexOf(t),n=u[r].value;n!==s&&(c(t),i(n))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:o}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":s===t})}),r??t)})))}function v(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function k(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(g,(0,n.Z)({},e,t)),a.createElement(v,(0,n.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return a.createElement(k,(0,n.Z)({key:String(t)},e))}},3687:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>h,frontMatter:()=>s,metadata:()=>u,toc:()=>c});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),o=r(5162);const s={title:"http-error-handler"},i=void 0,u={unversionedId:"middlewares/http-error-handler",id:"middlewares/http-error-handler",title:"http-error-handler",description:"Automatically handles uncaught errors that contain the properties statusCode (number) and message (string) and creates a proper HTTP response",source:"@site/docs/middlewares/http-error-handler.md",sourceDirName:"middlewares",slug:"/middlewares/http-error-handler",permalink:"/docs/middlewares/http-error-handler",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-error-handler.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-error-handler"},sidebar:"tutorialSidebar",previous:{title:"http-cors",permalink:"/docs/middlewares/http-cors"},next:{title:"http-event-normalizer",permalink:"/docs/middlewares/http-event-normalizer"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:c},m="wrapper";function h(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Automatically handles uncaught errors that contain the properties ",(0,a.kt)("inlineCode",{parentName:"p"},"statusCode")," (number) and ",(0,a.kt)("inlineCode",{parentName:"p"},"message")," (string) and creates a proper HTTP response\nfor them (using the message and the status code provided by the error object). Additionally, support for the property ",(0,a.kt)("inlineCode",{parentName:"p"},"expose")," is included with a default value of ",(0,a.kt)("inlineCode",{parentName:"p"},"statusCode < 500"),".\nWe recommend generating these HTTP errors with the npm module ",(0,a.kt)("a",{parentName:"p",href:"https://npm.im/http-errors"},(0,a.kt)("inlineCode",{parentName:"a"},"http-errors")),". When manually catching and setting errors with ",(0,a.kt)("inlineCode",{parentName:"p"},"statusCode >= 500")," setting ",(0,a.kt)("inlineCode",{parentName:"p"},"{expose: true}"),"\nis needed for them to be handled."),(0,a.kt)("p",null,"This middleware should be set as the last error handler attached, first to execute."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-error-handler\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-error-handler\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-error-handler\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"logger")," (defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"console.error"),") - a logging function that is invoked with the current error as an argument. You can pass ",(0,a.kt)("inlineCode",{parentName:"li"},"false")," if you don't want the logging to happen."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"fallbackMessage")," (default to null) - When non-http errors (those without `",(0,a.kt)("inlineCode",{parentName:"li"},"statusCode"),") occur you can catch them by setting a fallback message to be used. These will be returned with a 500 status code.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpErrorHandler from '@middy/http-error-handler'\n\nconst handler = middy((event, context) => {\n throw new createError.UnprocessableEntity()\n})\n\nhandler\n .use(httpErrorHandler())\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.deepEqual(response,{\n statusCode: 422,\n body: 'Unprocessable Entity'\n })\n})\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/447662a1.2744980f.js b/assets/js/447662a1.f37846bb.js similarity index 97% rename from assets/js/447662a1.2744980f.js rename to assets/js/447662a1.f37846bb.js index 0c7fb7ea7..3552b0225 100644 --- a/assets/js/447662a1.2744980f.js +++ b/assets/js/447662a1.f37846bb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1768],{3905:(e,r,t)=>{t.d(r,{Zo:()=>c,kt:()=>f});var n=t(7294);function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function a(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var l=n.createContext({}),s=function(e){var r=n.useContext(l),t=r;return e&&(t="function"==typeof e?e(r):i(i({},r),e)),t},c=function(e){var r=s(e.components);return n.createElement(l.Provider,{value:r},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var r=e.children;return n.createElement(n.Fragment,{},r)}},m=n.forwardRef((function(e,r){var t=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,c=d(e,["components","mdxType","originalType","parentName"]),u=s(t),m=o,f=u["".concat(l,".").concat(m)]||u[m]||p[m]||a;return t?n.createElement(f,i(i({ref:r},c),{},{components:t})):n.createElement(f,i({ref:r},c))}));function f(e,r){var t=arguments,o=r&&r.mdxType;if("string"==typeof e||o){var a=t.length,i=new Array(a);i[0]=m;var d={};for(var l in r)hasOwnProperty.call(r,l)&&(d[l]=r[l]);d.originalType=e,d[u]="string"==typeof e?e:o,i[1]=d;for(var s=2;s{t.r(r),t.d(r,{assets:()=>l,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>d,toc:()=>s});var n=t(7462),o=(t(7294),t(3905));const a={title:"Configurable Middlewares",position:2},i=void 0,d={unversionedId:"writing-middlewares/configurable-middlewares",id:"writing-middlewares/configurable-middlewares",title:"Configurable Middlewares",description:"In order to make middlewares configurable, they are generally exported as a function that accepts",source:"@site/docs/writing-middlewares/02-configurable-middlewares.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/configurable-middlewares",permalink:"/docs/writing-middlewares/configurable-middlewares",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/02-configurable-middlewares.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:2,frontMatter:{title:"Configurable Middlewares",position:2},sidebar:"tutorialSidebar",previous:{title:"Custom Middlewares",permalink:"/docs/writing-middlewares/intro"},next:{title:"Inline Middlewares",permalink:"/docs/writing-middlewares/inline-middlewares"}},l={},s=[],c={toc:s},u="wrapper";function p(e){let{components:r,...t}=e;return(0,o.kt)(u,(0,n.Z)({},c,t,{components:r,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"In order to make middlewares configurable, they are generally exported as a function that accepts\na configuration object. This function should then return the middleware object with ",(0,o.kt)("inlineCode",{parentName:"p"},"before"),",\n",(0,o.kt)("inlineCode",{parentName:"p"},"after"),", and ",(0,o.kt)("inlineCode",{parentName:"p"},"onError")," as keys."),(0,o.kt)("p",null,"E.g."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"// customMiddleware.js\n\nconst defaults = {}\n\nconst customMiddleware = (opts) => {\n const options = { ...defaults, ...opts }\n\n const customMiddlewareBefore = async (request) => {\n const { event, context } = request\n // ...\n }\n\n const customMiddlewareAfter = async (request) => {\n const { response } = request\n // ...\n request.response = response\n }\n\n const customMiddlewareOnError = async (request) => {\n if (request.response === undefined) return\n await customMiddlewareAfter(request)\n }\n\n return {\n before: customMiddlewareBefore,\n after: customMiddlewareAfter,\n onError: customMiddlewareOnError\n }\n}\n\nexport default customMiddleware\n")),(0,o.kt)("p",null,"With this convention in mind, using a middleware will always look like the following example:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport customMiddleware from 'customMiddleware.js'\n\nconst lambdaHandler = async (event, context) => {\n // do stuff\n return {}\n}\n\nexport const handler = middy(lambdaHandler)\n .use(customMiddleware({\n option1: 'foo',\n option2: 'bar'\n }))\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1768],{3905:(e,r,t)=>{t.d(r,{Zo:()=>c,kt:()=>f});var n=t(7294);function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function a(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var l=n.createContext({}),s=function(e){var r=n.useContext(l),t=r;return e&&(t="function"==typeof e?e(r):i(i({},r),e)),t},c=function(e){var r=s(e.components);return n.createElement(l.Provider,{value:r},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var r=e.children;return n.createElement(n.Fragment,{},r)}},m=n.forwardRef((function(e,r){var t=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,c=d(e,["components","mdxType","originalType","parentName"]),u=s(t),m=o,f=u["".concat(l,".").concat(m)]||u[m]||p[m]||a;return t?n.createElement(f,i(i({ref:r},c),{},{components:t})):n.createElement(f,i({ref:r},c))}));function f(e,r){var t=arguments,o=r&&r.mdxType;if("string"==typeof e||o){var a=t.length,i=new Array(a);i[0]=m;var d={};for(var l in r)hasOwnProperty.call(r,l)&&(d[l]=r[l]);d.originalType=e,d[u]="string"==typeof e?e:o,i[1]=d;for(var s=2;s{t.r(r),t.d(r,{assets:()=>l,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>d,toc:()=>s});var n=t(7462),o=(t(7294),t(3905));const a={title:"Configurable Middlewares",position:2},i=void 0,d={unversionedId:"writing-middlewares/configurable-middlewares",id:"writing-middlewares/configurable-middlewares",title:"Configurable Middlewares",description:"In order to make middlewares configurable, they are generally exported as a function that accepts",source:"@site/docs/writing-middlewares/02-configurable-middlewares.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/configurable-middlewares",permalink:"/docs/writing-middlewares/configurable-middlewares",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/02-configurable-middlewares.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:2,frontMatter:{title:"Configurable Middlewares",position:2},sidebar:"tutorialSidebar",previous:{title:"Custom Middlewares",permalink:"/docs/writing-middlewares/intro"},next:{title:"Inline Middlewares",permalink:"/docs/writing-middlewares/inline-middlewares"}},l={},s=[],c={toc:s},u="wrapper";function p(e){let{components:r,...t}=e;return(0,o.kt)(u,(0,n.Z)({},c,t,{components:r,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"In order to make middlewares configurable, they are generally exported as a function that accepts\na configuration object. This function should then return the middleware object with ",(0,o.kt)("inlineCode",{parentName:"p"},"before"),",\n",(0,o.kt)("inlineCode",{parentName:"p"},"after"),", and ",(0,o.kt)("inlineCode",{parentName:"p"},"onError")," as keys."),(0,o.kt)("p",null,"E.g."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"// customMiddleware.js\n\nconst defaults = {}\n\nconst customMiddleware = (opts) => {\n const options = { ...defaults, ...opts }\n\n const customMiddlewareBefore = async (request) => {\n const { event, context } = request\n // ...\n }\n\n const customMiddlewareAfter = async (request) => {\n const { response } = request\n // ...\n request.response = response\n }\n\n const customMiddlewareOnError = async (request) => {\n if (request.response === undefined) return\n await customMiddlewareAfter(request)\n }\n\n return {\n before: customMiddlewareBefore,\n after: customMiddlewareAfter,\n onError: customMiddlewareOnError\n }\n}\n\nexport default customMiddleware\n")),(0,o.kt)("p",null,"With this convention in mind, using a middleware will always look like the following example:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport customMiddleware from 'customMiddleware.js'\n\nconst lambdaHandler = async (event, context) => {\n // do stuff\n return {}\n}\n\nexport const handler = middy(lambdaHandler)\n .use(customMiddleware({\n option1: 'foo',\n option2: 'bar'\n }))\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/4924cac4.c721cce9.js b/assets/js/4924cac4.cb64840c.js similarity index 99% rename from assets/js/4924cac4.c721cce9.js rename to assets/js/4924cac4.cb64840c.js index 0dd1dabe0..8939f4ebf 100644 --- a/assets/js/4924cac4.c721cce9.js +++ b/assets/js/4924cac4.cb64840c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5270],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),u=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,s=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),d=u(n),m=a,f=d["".concat(s,".").concat(m)]||d[m]||p[m]||l;return n?r.createElement(f,o(o({ref:t},c),{},{components:n})):r.createElement(f,o({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,o=new Array(l);o[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[d]="string"==typeof e?e:a,o[1]=i;for(var u=2;u{n.d(t,{Z:()=>o});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var r=n(7462),a=n(7294),l=n(6010),o=n(2466),i=n(6550),s=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=p(e),[o,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[s,u]=f({queryString:n,groupId:r}),[d,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),b=(()=>{const e=s??d;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),h(e)}),[u,h,l]),tabValues:l}}var b=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:n,selectedValue:i,selectValue:s,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),r=u[n].value;r!==i&&(d(t),s(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:o}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",g.tabItem,o?.className,{"tabs__item--active":i===t})}),n??t)})))}function y(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function v(e){const t=h(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",g.tabList)},a.createElement(k,(0,r.Z)({},e,t)),a.createElement(y,(0,r.Z)({},e,t)))}function N(e){const t=(0,b.Z)();return a.createElement(v,(0,r.Z)({key:String(t)},e))}},8760:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),o=n(5162);const i={title:"http-cors"},s=void 0,u={unversionedId:"middlewares/http-cors",id:"middlewares/http-cors",title:"http-cors",description:"This middleware sets HTTP CORS headers (Access-Control-Allow-Origin, Access-Control-Allow-Headers, Access-Control-Allow-Credentials), necessary for making cross-origin requests, to the response object.",source:"@site/docs/middlewares/http-cors.md",sourceDirName:"middlewares",slug:"/middlewares/http-cors",permalink:"/docs/middlewares/http-cors",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-cors.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-cors"},sidebar:"tutorialSidebar",previous:{title:"http-content-negotiation",permalink:"/docs/middlewares/http-content-negotiation"},next:{title:"http-error-handler",permalink:"/docs/middlewares/http-error-handler"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware sets HTTP CORS headers (",(0,a.kt)("inlineCode",{parentName:"p"},"Access-Control-Allow-Origin"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"Access-Control-Allow-Headers"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"Access-Control-Allow-Credentials"),"), necessary for making cross-origin requests, to the response object."),(0,a.kt)("p",null,"Sets headers in ",(0,a.kt)("inlineCode",{parentName:"p"},"after")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"onError")," phases."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-cors\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-cors\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-cors\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"credentials")," (bool) (optional): if true, sets ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Allow-Credentials")," (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disableBeforePreflightResponse")," (bool) (optional): if false, replies automatically to cors preflight requests. Set to true if handling the response in a custom way (default ",(0,a.kt)("inlineCode",{parentName:"li"},"true"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"headers")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Allow-Headers")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"methods")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Allow-Methods")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"getOrigin")," (function(incomingOrigin:string, options)) (optional): take full control of the generating the returned origin. Defaults to using the origin or origins option."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"origin"),' (string) (optional): origin to put in the header (default: "',(0,a.kt)("inlineCode",{parentName:"li"},"*"),'")'),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"origins")," (array) (optional): An array of allowed origins. The incoming origin is matched against the list and is returned if present."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"exposeHeaders")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Expose-Headers")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"maxAge")," (string) (optional): value to put in Access-Control-Max-Age header (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"null"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"requestHeaders")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Request-Headers")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"requestMethods")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Request-Methods")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheControl")," (string) (optional): value to put in Cache-Control header on pre-flight (OPTIONS) requests (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"null"),")")),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpErrorHandler from '@middy/http-error-handler'\nimport cors from '@middy/http-cors'\n\nconst handler = middy((event, context) => {\n throw new createError.UnprocessableEntity()\n})\nhandler.use(httpErrorHandler()).use(cors())\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.is(response.headers['Access-Control-Allow-Origin'], '*')\n t.deepEqual(response, {\n statusCode: 422,\n body: 'Unprocessable Entity'\n })\n})\n")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport cors from '@middy/http-cors'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler.use(cors())\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.is(response.headers['Access-Control-Allow-Origin'], '*')\n})\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5270],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),u=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,s=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),d=u(n),m=a,f=d["".concat(s,".").concat(m)]||d[m]||p[m]||l;return n?r.createElement(f,o(o({ref:t},c),{},{components:n})):r.createElement(f,o({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,o=new Array(l);o[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[d]="string"==typeof e?e:a,o[1]=i;for(var u=2;u{n.d(t,{Z:()=>o});var r=n(7294),a=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var r=n(7462),a=n(7294),l=n(6010),o=n(2466),i=n(6550),s=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,l=p(e),[o,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[s,u]=f({queryString:n,groupId:r}),[d,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:r}),b=(()=>{const e=s??d;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),h(e)}),[u,h,l]),tabValues:l}}var b=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:n,selectedValue:i,selectValue:s,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),r=u[n].value;r!==i&&(d(t),s(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:o}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",g.tabItem,o?.className,{"tabs__item--active":i===t})}),n??t)})))}function y(e){let{lazy:t,children:n,selectedValue:r}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function v(e){const t=h(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",g.tabList)},a.createElement(k,(0,r.Z)({},e,t)),a.createElement(y,(0,r.Z)({},e,t)))}function N(e){const t=(0,b.Z)();return a.createElement(v,(0,r.Z)({key:String(t)},e))}},8760:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),l=n(4866),o=n(5162);const i={title:"http-cors"},s=void 0,u={unversionedId:"middlewares/http-cors",id:"middlewares/http-cors",title:"http-cors",description:"This middleware sets HTTP CORS headers (Access-Control-Allow-Origin, Access-Control-Allow-Headers, Access-Control-Allow-Credentials), necessary for making cross-origin requests, to the response object.",source:"@site/docs/middlewares/http-cors.md",sourceDirName:"middlewares",slug:"/middlewares/http-cors",permalink:"/docs/middlewares/http-cors",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-cors.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-cors"},sidebar:"tutorialSidebar",previous:{title:"http-content-negotiation",permalink:"/docs/middlewares/http-content-negotiation"},next:{title:"http-error-handler",permalink:"/docs/middlewares/http-error-handler"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware sets HTTP CORS headers (",(0,a.kt)("inlineCode",{parentName:"p"},"Access-Control-Allow-Origin"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"Access-Control-Allow-Headers"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"Access-Control-Allow-Credentials"),"), necessary for making cross-origin requests, to the response object."),(0,a.kt)("p",null,"Sets headers in ",(0,a.kt)("inlineCode",{parentName:"p"},"after")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"onError")," phases."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-cors\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-cors\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-cors\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"credentials")," (bool) (optional): if true, sets ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Allow-Credentials")," (default ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disableBeforePreflightResponse")," (bool) (optional): if false, replies automatically to cors preflight requests. Set to true if handling the response in a custom way (default ",(0,a.kt)("inlineCode",{parentName:"li"},"true"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"headers")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Allow-Headers")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"methods")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Allow-Methods")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"getOrigin")," (function(incomingOrigin:string, options)) (optional): take full control of the generating the returned origin. Defaults to using the origin or origins option."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"origin"),' (string) (optional): origin to put in the header (default: "',(0,a.kt)("inlineCode",{parentName:"li"},"*"),'")'),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"origins")," (array) (optional): An array of allowed origins. The incoming origin is matched against the list and is returned if present."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"exposeHeaders")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Expose-Headers")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"maxAge")," (string) (optional): value to put in Access-Control-Max-Age header (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"null"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"requestHeaders")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Request-Headers")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"requestMethods")," (string) (optional): value to put in ",(0,a.kt)("inlineCode",{parentName:"li"},"Access-Control-Request-Methods")," (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"cacheControl")," (string) (optional): value to put in Cache-Control header on pre-flight (OPTIONS) requests (default: ",(0,a.kt)("inlineCode",{parentName:"li"},"null"),")")),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpErrorHandler from '@middy/http-error-handler'\nimport cors from '@middy/http-cors'\n\nconst handler = middy((event, context) => {\n throw new createError.UnprocessableEntity()\n})\nhandler.use(httpErrorHandler()).use(cors())\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.is(response.headers['Access-Control-Allow-Origin'], '*')\n t.deepEqual(response, {\n statusCode: 422,\n body: 'Unprocessable Entity'\n })\n})\n")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport cors from '@middy/http-cors'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler.use(cors())\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.is(response.headers['Access-Control-Allow-Origin'], '*')\n})\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/49fe1afb.c29ff92f.js b/assets/js/49fe1afb.02fb3141.js similarity index 97% rename from assets/js/49fe1afb.c29ff92f.js rename to assets/js/49fe1afb.02fb3141.js index 00634b7ab..9c4fbaaf6 100644 --- a/assets/js/49fe1afb.c29ff92f.js +++ b/assets/js/49fe1afb.02fb3141.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9076],{3905:(e,t,r)=>{r.d(t,{Zo:()=>s,kt:()=>u});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var p=n.createContext({}),d=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},s=function(e){var t=d(e.components);return n.createElement(p.Provider,{value:t},e.children)},l="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},y=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,a=e.originalType,p=e.parentName,s=c(e,["components","mdxType","originalType","parentName"]),l=d(r),y=i,u=l["".concat(p,".").concat(y)]||l[y]||m[y]||a;return r?n.createElement(u,o(o({ref:t},s),{},{components:r})):n.createElement(u,o({ref:t},s))}));function u(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=r.length,o=new Array(a);o[0]=y;var c={};for(var p in t)hasOwnProperty.call(t,p)&&(c[p]=t[p]);c.originalType=e,c[l]="string"==typeof e?e:i,o[1]=c;for(var d=2;d{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>c,toc:()=>d});var n=r(7462),i=(r(7294),r(3905));const a={title:"With TypeScript",position:7},o=void 0,c={unversionedId:"writing-middlewares/with-typescript",id:"writing-middlewares/with-typescript",title:"With TypeScript",description:"here's an example of how you can write a custom middleware for a Lambda receiving events from API Gateway:",source:"@site/docs/writing-middlewares/07-with-typescript.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/with-typescript",permalink:"/docs/writing-middlewares/with-typescript",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/07-with-typescript.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:7,frontMatter:{title:"With TypeScript",position:7},sidebar:"tutorialSidebar",previous:{title:"More Examples",permalink:"/docs/writing-middlewares/more-examples"},next:{title:"Routers",permalink:"/docs/category/routers"}},p={},d=[],s={toc:d},l="wrapper";function m(e){let{components:t,...r}=e;return(0,i.kt)(l,(0,n.Z)({},s,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"here's an example of how you can write a custom middleware for a Lambda receiving events from API Gateway:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-typescript"},"import middy from '@middy/core'\nimport { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'\n\nconst middleware = (): middy.MiddlewareObj => {\n const before: middy.MiddlewareFn = async (\n request\n ): Promise => {\n // Your middleware logic\n }\n\n const after: middy.MiddlewareFn = async (\n request\n ): Promise => {\n // Your middleware logic\n }\n\n return {\n before,\n after\n }\n}\n\nexport default middleware\n")),(0,i.kt)("p",null,(0,i.kt)("strong",{parentName:"p"},"Note"),": The Middy core team does not use TypeScript often and we can't certainly claim that we are TypeScript experts. We tried our best to come up\nwith type definitions that should give TypeScript users a good experience. There is certainly room for improvement, so we would be more than happy to receive contributions \ud83d\ude0a"),(0,i.kt)("p",null,"See ",(0,i.kt)("inlineCode",{parentName:"p"},"devDependencies")," for each middleware for list of dependencies that may be required with transpiling TypeScript."))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9076],{3905:(e,t,r)=>{r.d(t,{Zo:()=>s,kt:()=>u});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var p=n.createContext({}),d=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},s=function(e){var t=d(e.components);return n.createElement(p.Provider,{value:t},e.children)},l="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},y=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,a=e.originalType,p=e.parentName,s=c(e,["components","mdxType","originalType","parentName"]),l=d(r),y=i,u=l["".concat(p,".").concat(y)]||l[y]||m[y]||a;return r?n.createElement(u,o(o({ref:t},s),{},{components:r})):n.createElement(u,o({ref:t},s))}));function u(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=r.length,o=new Array(a);o[0]=y;var c={};for(var p in t)hasOwnProperty.call(t,p)&&(c[p]=t[p]);c.originalType=e,c[l]="string"==typeof e?e:i,o[1]=c;for(var d=2;d{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>c,toc:()=>d});var n=r(7462),i=(r(7294),r(3905));const a={title:"With TypeScript",position:7},o=void 0,c={unversionedId:"writing-middlewares/with-typescript",id:"writing-middlewares/with-typescript",title:"With TypeScript",description:"here's an example of how you can write a custom middleware for a Lambda receiving events from API Gateway:",source:"@site/docs/writing-middlewares/07-with-typescript.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/with-typescript",permalink:"/docs/writing-middlewares/with-typescript",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/07-with-typescript.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:7,frontMatter:{title:"With TypeScript",position:7},sidebar:"tutorialSidebar",previous:{title:"More Examples",permalink:"/docs/writing-middlewares/more-examples"},next:{title:"Routers",permalink:"/docs/category/routers"}},p={},d=[],s={toc:d},l="wrapper";function m(e){let{components:t,...r}=e;return(0,i.kt)(l,(0,n.Z)({},s,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"here's an example of how you can write a custom middleware for a Lambda receiving events from API Gateway:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-typescript"},"import middy from '@middy/core'\nimport { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'\n\nconst middleware = (): middy.MiddlewareObj => {\n const before: middy.MiddlewareFn = async (\n request\n ): Promise => {\n // Your middleware logic\n }\n\n const after: middy.MiddlewareFn = async (\n request\n ): Promise => {\n // Your middleware logic\n }\n\n return {\n before,\n after\n }\n}\n\nexport default middleware\n")),(0,i.kt)("p",null,(0,i.kt)("strong",{parentName:"p"},"Note"),": The Middy core team does not use TypeScript often and we can't certainly claim that we are TypeScript experts. We tried our best to come up\nwith type definitions that should give TypeScript users a good experience. There is certainly room for improvement, so we would be more than happy to receive contributions \ud83d\ude0a"),(0,i.kt)("p",null,"See ",(0,i.kt)("inlineCode",{parentName:"p"},"devDependencies")," for each middleware for list of dependencies that may be required with transpiling TypeScript."))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/4f3a9363.7b67e565.js b/assets/js/4f3a9363.dc15cbce.js similarity index 96% rename from assets/js/4f3a9363.7b67e565.js rename to assets/js/4f3a9363.dc15cbce.js index 1e80491af..5e3808c16 100644 --- a/assets/js/4f3a9363.7b67e565.js +++ b/assets/js/4f3a9363.dc15cbce.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8852],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,d=c(e,["components","mdxType","originalType","parentName"]),p=s(n),m=o,f=p["".concat(l,".").concat(m)]||p[m]||u[m]||a;return n?r.createElement(f,i(i({ref:t},d),{},{components:n})):r.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[p]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"DocumentDB"},i=void 0,c={unversionedId:"events/documentdb",id:"events/documentdb",title:"DocumentDB",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/documentdb.md",sourceDirName:"events",slug:"/events/documentdb",permalink:"/docs/events/documentdb",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/documentdb.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"DocumentDB"},sidebar:"tutorialSidebar",previous:{title:"Connect",permalink:"/docs/events/connect"},next:{title:"DynamoDB",permalink:"/docs/events/dynamodb"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],d={toc:s},p="wrapper";function u(e){let{components:t,...n}=e;return(0,o.kt)(p,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html"},"Using AWS Lambda with Amazon DocumentDB"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8852],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,d=c(e,["components","mdxType","originalType","parentName"]),p=s(n),m=o,f=p["".concat(l,".").concat(m)]||p[m]||u[m]||a;return n?r.createElement(f,i(i({ref:t},d),{},{components:n})):r.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[p]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"DocumentDB"},i=void 0,c={unversionedId:"events/documentdb",id:"events/documentdb",title:"DocumentDB",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/documentdb.md",sourceDirName:"events",slug:"/events/documentdb",permalink:"/docs/events/documentdb",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/documentdb.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"DocumentDB"},sidebar:"tutorialSidebar",previous:{title:"Connect",permalink:"/docs/events/connect"},next:{title:"DynamoDB",permalink:"/docs/events/dynamodb"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],d={toc:s},p="wrapper";function u(e){let{components:t,...n}=e;return(0,o.kt)(p,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html"},"Using AWS Lambda with Amazon DocumentDB"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/5018e04c.1c11b203.js b/assets/js/5018e04c.ebb34ede.js similarity index 96% rename from assets/js/5018e04c.1c11b203.js rename to assets/js/5018e04c.ebb34ede.js index f5a73056a..30f5332e0 100644 --- a/assets/js/5018e04c.1c11b203.js +++ b/assets/js/5018e04c.ebb34ede.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9862],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>m});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var c=n.createContext({}),s=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=s(e.components);return n.createElement(c.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},y=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,o=e.originalType,c=e.parentName,l=p(e,["components","mdxType","originalType","parentName"]),d=s(r),y=i,m=d["".concat(c,".").concat(y)]||d[y]||u[y]||o;return r?n.createElement(m,a(a({ref:t},l),{},{components:r})):n.createElement(m,a({ref:t},l))}));function m(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=r.length,a=new Array(o);a[0]=y;var p={};for(var c in t)hasOwnProperty.call(t,c)&&(p[c]=t[c]);p.originalType=e,p[d]="string"==typeof e?e:i,a[1]=p;for(var s=2;s{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>u,frontMatter:()=>o,metadata:()=>p,toc:()=>s});var n=r(7462),i=(r(7294),r(3905));const o={title:"Use with TypeScript",position:6},a=void 0,p={unversionedId:"intro/typescript",id:"intro/typescript",title:"Use with TypeScript",description:"Middy can be used with TypeScript with typings built in in every official package.",source:"@site/docs/intro/06-typescript.md",sourceDirName:"intro",slug:"/intro/typescript",permalink:"/docs/intro/typescript",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-typescript.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:6,frontMatter:{title:"Use with TypeScript",position:6},sidebar:"tutorialSidebar",previous:{title:"Testing",permalink:"/docs/intro/testing"},next:{title:"Hooks",permalink:"/docs/intro/hooks"}},c={},s=[],l={toc:s},d="wrapper";function u(e){let{components:t,...r}=e;return(0,i.kt)(d,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Middy can be used with TypeScript with typings built in in every official package."),(0,i.kt)("p",null,"Here's an example of how you might be using Middy with TypeScript for a Lambda receiving events from API Gateway:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-typescript"},"import middy from '@middy/core'\nimport { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'\n\nasync function lambdaHandler (event: APIGatewayProxyEvent): Promise {\n // the returned response will be checked against the type `APIGatewayProxyResult`\n return {\n statusCode: 200,\n body: `Hello from ${event.path}`\n }\n}\n\nlet handler = middy(lambdaHandler)\n .use(someMiddleware)\n .use(someOtherMiddleware)\n\nexport default handler\n")),(0,i.kt)("p",null,"You can also ",(0,i.kt)("a",{parentName:"p",href:"/docs/writing-middlewares/intro"},"write custom middlewares with TypeScript"),"."))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9862],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>m});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var c=n.createContext({}),s=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=s(e.components);return n.createElement(c.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},y=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,o=e.originalType,c=e.parentName,l=p(e,["components","mdxType","originalType","parentName"]),d=s(r),y=i,m=d["".concat(c,".").concat(y)]||d[y]||u[y]||o;return r?n.createElement(m,a(a({ref:t},l),{},{components:r})):n.createElement(m,a({ref:t},l))}));function m(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=r.length,a=new Array(o);a[0]=y;var p={};for(var c in t)hasOwnProperty.call(t,c)&&(p[c]=t[c]);p.originalType=e,p[d]="string"==typeof e?e:i,a[1]=p;for(var s=2;s{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>u,frontMatter:()=>o,metadata:()=>p,toc:()=>s});var n=r(7462),i=(r(7294),r(3905));const o={title:"Use with TypeScript",position:6},a=void 0,p={unversionedId:"intro/typescript",id:"intro/typescript",title:"Use with TypeScript",description:"Middy can be used with TypeScript with typings built in in every official package.",source:"@site/docs/intro/06-typescript.md",sourceDirName:"intro",slug:"/intro/typescript",permalink:"/docs/intro/typescript",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-typescript.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:6,frontMatter:{title:"Use with TypeScript",position:6},sidebar:"tutorialSidebar",previous:{title:"Testing",permalink:"/docs/intro/testing"},next:{title:"Hooks",permalink:"/docs/intro/hooks"}},c={},s=[],l={toc:s},d="wrapper";function u(e){let{components:t,...r}=e;return(0,i.kt)(d,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Middy can be used with TypeScript with typings built in in every official package."),(0,i.kt)("p",null,"Here's an example of how you might be using Middy with TypeScript for a Lambda receiving events from API Gateway:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-typescript"},"import middy from '@middy/core'\nimport { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'\n\nasync function lambdaHandler (event: APIGatewayProxyEvent): Promise {\n // the returned response will be checked against the type `APIGatewayProxyResult`\n return {\n statusCode: 200,\n body: `Hello from ${event.path}`\n }\n}\n\nlet handler = middy(lambdaHandler)\n .use(someMiddleware)\n .use(someOtherMiddleware)\n\nexport default handler\n")),(0,i.kt)("p",null,"You can also ",(0,i.kt)("a",{parentName:"p",href:"/docs/writing-middlewares/intro"},"write custom middlewares with TypeScript"),"."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/52912c74.fdcf7151.js b/assets/js/52912c74.48869087.js similarity index 98% rename from assets/js/52912c74.fdcf7151.js rename to assets/js/52912c74.48869087.js index 454a75164..b73b290c3 100644 --- a/assets/js/52912c74.fdcf7151.js +++ b/assets/js/52912c74.48869087.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7452],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>v});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),d=s(n),m=o,v=d["".concat(l,".").concat(m)]||d[m]||u[m]||a;return n?r.createElement(v,i(i({ref:t},p),{},{components:n})):r.createElement(v,i({ref:t},p))}));function v(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[d]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"EventBridge"},i=void 0,c={unversionedId:"events/event-bridge",id:"events/event-bridge",title:"EventBridge",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/event-bridge.md",sourceDirName:"events",slug:"/events/event-bridge",permalink:"/docs/events/event-bridge",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/event-bridge.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"EventBridge"},sidebar:"tutorialSidebar",previous:{title:"EC2",permalink:"/docs/events/ec2"},next:{title:"Function URL",permalink:"/docs/events/function-url"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},d="wrapper";function u(e){let{components:t,...n}=e;return(0,o.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html"},"Using AWS Lambda with Amazon EventBridge (CloudWatch Events)"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7452],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>v});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),d=s(n),m=o,v=d["".concat(l,".").concat(m)]||d[m]||u[m]||a;return n?r.createElement(v,i(i({ref:t},p),{},{components:n})):r.createElement(v,i({ref:t},p))}));function v(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[d]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"EventBridge"},i=void 0,c={unversionedId:"events/event-bridge",id:"events/event-bridge",title:"EventBridge",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/event-bridge.md",sourceDirName:"events",slug:"/events/event-bridge",permalink:"/docs/events/event-bridge",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/event-bridge.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"EventBridge"},sidebar:"tutorialSidebar",previous:{title:"EC2",permalink:"/docs/events/ec2"},next:{title:"Function URL",permalink:"/docs/events/function-url"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},d="wrapper";function u(e){let{components:t,...n}=e;return(0,o.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html"},"Using AWS Lambda with Amazon EventBridge (CloudWatch Events)"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/53f1e98a.4dfd6eec.js b/assets/js/53f1e98a.c9cd4ba2.js similarity index 96% rename from assets/js/53f1e98a.4dfd6eec.js rename to assets/js/53f1e98a.c9cd4ba2.js index cbf8b0b38..3a81535cc 100644 --- a/assets/js/53f1e98a.4dfd6eec.js +++ b/assets/js/53f1e98a.c9cd4ba2.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2469],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=l(n),u=a,f=d["".concat(c,".").concat(u)]||d[u]||m[u]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"S3"},i=void 0,s={unversionedId:"events/s3",id:"events/s3",title:"S3",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/s3.md",sourceDirName:"events",slug:"/events/s3",permalink:"/docs/events/s3",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"S3"},sidebar:"tutorialSidebar",previous:{title:"S3 Object",permalink:"/docs/events/s3-object"},next:{title:"Secrets Manager",permalink:"/docs/events/secrets-manager"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},d="wrapper";function m(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html"},"Using AWS Lambda with Amazon S3"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware()) // S3 -> SNS -> SQS -> Lambda\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2469],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=l(n),u=a,f=d["".concat(c,".").concat(u)]||d[u]||m[u]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"S3"},i=void 0,s={unversionedId:"events/s3",id:"events/s3",title:"S3",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/s3.md",sourceDirName:"events",slug:"/events/s3",permalink:"/docs/events/s3",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"S3"},sidebar:"tutorialSidebar",previous:{title:"S3 Object",permalink:"/docs/events/s3-object"},next:{title:"Secrets Manager",permalink:"/docs/events/secrets-manager"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},d="wrapper";function m(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html"},"Using AWS Lambda with Amazon S3"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware()) // S3 -> SNS -> SQS -> Lambda\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/54ed1cf2.e259ecd6.js b/assets/js/54ed1cf2.074eb658.js similarity index 99% rename from assets/js/54ed1cf2.e259ecd6.js rename to assets/js/54ed1cf2.074eb658.js index c1a589985..2652aee40 100644 --- a/assets/js/54ed1cf2.e259ecd6.js +++ b/assets/js/54ed1cf2.074eb658.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6827],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var l=n.createContext({}),d=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},c=function(e){var t=d(e.components);return n.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),p=d(r),m=o,f=p["".concat(l,".").concat(m)]||p[m]||u[m]||a;return r?n.createElement(f,i(i({ref:t},c),{},{components:r})):n.createElement(f,i({ref:t},c))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:o,i[1]=s;for(var d=2;d{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>s,toc:()=>d});var n=r(7462),o=(r(7294),r(3905));const a={title:"Profiling",sidebar_position:7},i=void 0,s={unversionedId:"best-practices/profiling",id:"best-practices/profiling",title:"Profiling",description:"Inside of @middy/core we've added some hook before and after every middleware called, the handler and from start to end of it's execution.",source:"@site/docs/best-practices/07-profiling.md",sourceDirName:"best-practices",slug:"/best-practices/profiling",permalink:"/docs/best-practices/profiling",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/07-profiling.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:7,frontMatter:{title:"Profiling",sidebar_position:7},sidebar:"tutorialSidebar",previous:{title:"Small node_modules",permalink:"/docs/best-practices/small-node-modules"},next:{title:"FAQ",permalink:"/docs/faq"}},l={},d=[{value:"Time",id:"time",level:2},{value:"Memory",id:"memory",level:2}],c={toc:d},p="wrapper";function u(e){let{components:t,...r}=e;return(0,o.kt)(p,(0,n.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Inside of ",(0,o.kt)("inlineCode",{parentName:"p"},"@middy/core")," we've added some hook before and after every middleware called, the handler and from start to end of it's execution."),(0,o.kt)("h2",{id:"time"},"Time"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"\nconst defaults = {\n logger: console.log,\n enabled: true\n}\n\nconst timePlugin = (opts = {}) => {\n const { logger, enabled } = { ...defaults, ...opts }\n const store = {}\n\n const start = (id) => {\n store[id] = process.hrtime.bigint()\n }\n const stop = (id) => {\n if (!enabled) return\n logger(id, Number.parseInt((process.hrtime.bigint() - store[id]).toString()) / 1000000, 'ms')\n }\n\n // Only run during cold start\n const beforePrefetch = () => start('total')\n const requestStart = () => {\n if (!store.init) {\n store.init = store.total\n stop('init')\n } else {\n start('total')\n }\n }\n const beforeMiddleware = start\n const afterMiddleware = stop\n const beforeHandler = () => start('handler')\n const afterHandler = () => stop('handler')\n const requestEnd = () => stop('total')\n\n return {\n beforePrefetch,\n requestStart,\n beforeMiddleware,\n afterMiddleware,\n beforeHandler,\n afterHandler,\n requestEnd\n }\n}\n\nexport const handler = middy(timePlugin())\n .use(eventLogger())\n .use(errorLogger())\n .use(httpEventNormalizer())\n .use(httpHeaderNormalizer())\n .use(httpUrlencodePathParametersParser())\n .use(httpUrlencodeBodyParser())\n .use(httpJsonBodyParser())\n .use(httpCors())\n .use(httpSecurityHeaders())\n .use(validator({eventSchema}))\n .handler(()=>{})\n \nawait handler()\n")),(0,o.kt)("p",null,"This will log out something this:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"inputOutputLoggerMiddlewareBefore 0.156033 ms\nhttpEventNormalizerMiddlewareBefore 0.073921 ms\nhttpHeaderNormalizerMiddlewareBefore 0.095098 ms\nhttpUrlencodePathParserMiddlewareBefore 0.036255 ms\nhttpUrlencodeBodyParserMiddlewareBefore 0.038809 ms\nhttpJsonBodyParserMiddlewareBefore 0.048383 ms\nhttpContentNegotiationMiddlewareBefore 0.042311 ms\nvalidatorMiddlewareBefore 0.083366 ms\nhandler 0.094875 ms\nvalidatorMiddlewareAfter 0.083601 ms\nhttpSecurityHeadersMiddlewareAfter 0.19702 ms\nhttpCorsMiddlewareAfter 0.080532 ms\ninputOutputLoggerMiddlewareAfter 0.066886 ms\nlambda 66.141835 ms\n")),(0,o.kt)("p",null,"From this everything looks good. Sub 1ms for every middleware and the handler. But wait, that ",(0,o.kt)("inlineCode",{parentName:"p"},"total")," doesn't look right.\nYou're correct, ",(0,o.kt)("inlineCode",{parentName:"p"},"total")," includes the initial setup time (or cold start time) for all middlewares. In this case ",(0,o.kt)("inlineCode",{parentName:"p"},"validator")," is the culprit.\nThe Ajv constructor and compiler do a lot of magic when they first run to get ready for later schema validations.\nThis is why in the ",(0,o.kt)("inlineCode",{parentName:"p"},"validator")," middleware we now support passing in complied schema and expose the default compiler in\ncase you want to use it in a build step. We hope this feature will help to you in identify slow middlewares and improve your development experience."),(0,o.kt)("p",null,"There is also a ",(0,o.kt)("inlineCode",{parentName:"p"},"beforeRequest")," hook, but was left out of the example for dramatic effect."),(0,o.kt)("p",null,"Additionally, you'll notice that each middleware shows a descriptive name. This is printing out the function name passed into middy core.\nIf you've looked at the code for some the supported middlewares, you'll see these long descriptive variable names being set, then returned.\nThis is why."),(0,o.kt)("h2",{id:"memory"},"Memory"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import memwatch from '@airbnb/node-memwatch'\n\nconst defaults = {\n logger: console.log\n}\n\nconst memoryPlugin = (opts = {}) => {\n const { logger } = { ...defaults, ...opts }\n const store = {}\n\n const start = (id) => {\n store[id] = new memwatch.HeapDiff()\n }\n const stop = (id) => {\n logger(id, store[id].end())\n }\n\n const beforePrefetch = () => start('total')\n const requestStart = () => {\n store.init = store.total\n stop('init')\n }\n const beforeMiddleware = start\n const afterMiddleware = stop\n const beforeHandler = () => start('handler')\n const afterHandler = () => stop('handler')\n const requestEnd = () => stop('total')\n\n return {\n beforePrefetch,\n requestStart,\n beforeMiddleware,\n afterMiddleware,\n beforeHandler,\n afterHandler,\n requestEnd\n }\n}\n\nexport const handler = middy(memoryPlugin())\n .use(eventLogger())\n .use(errorLogger())\n .use(httpEventNormalizer())\n .use(httpHeaderNormalizer())\n .use(httpUrlencodePathParametersParser())\n .use(httpUrlencodeBodyParser())\n .use(httpJsonBodyParser())\n .use(httpCors())\n .use(httpSecurityHeaders())\n .use(validator({eventSchema}))\n .handler(()=>{})\n \nawait handler()\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6827],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var l=n.createContext({}),d=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},c=function(e){var t=d(e.components);return n.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),p=d(r),m=o,f=p["".concat(l,".").concat(m)]||p[m]||u[m]||a;return r?n.createElement(f,i(i({ref:t},c),{},{components:r})):n.createElement(f,i({ref:t},c))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:o,i[1]=s;for(var d=2;d{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>s,toc:()=>d});var n=r(7462),o=(r(7294),r(3905));const a={title:"Profiling",sidebar_position:7},i=void 0,s={unversionedId:"best-practices/profiling",id:"best-practices/profiling",title:"Profiling",description:"Inside of @middy/core we've added some hook before and after every middleware called, the handler and from start to end of it's execution.",source:"@site/docs/best-practices/07-profiling.md",sourceDirName:"best-practices",slug:"/best-practices/profiling",permalink:"/docs/best-practices/profiling",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/07-profiling.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:7,frontMatter:{title:"Profiling",sidebar_position:7},sidebar:"tutorialSidebar",previous:{title:"Small node_modules",permalink:"/docs/best-practices/small-node-modules"},next:{title:"FAQ",permalink:"/docs/faq"}},l={},d=[{value:"Time",id:"time",level:2},{value:"Memory",id:"memory",level:2}],c={toc:d},p="wrapper";function u(e){let{components:t,...r}=e;return(0,o.kt)(p,(0,n.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Inside of ",(0,o.kt)("inlineCode",{parentName:"p"},"@middy/core")," we've added some hook before and after every middleware called, the handler and from start to end of it's execution."),(0,o.kt)("h2",{id:"time"},"Time"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"\nconst defaults = {\n logger: console.log,\n enabled: true\n}\n\nconst timePlugin = (opts = {}) => {\n const { logger, enabled } = { ...defaults, ...opts }\n const store = {}\n\n const start = (id) => {\n store[id] = process.hrtime.bigint()\n }\n const stop = (id) => {\n if (!enabled) return\n logger(id, Number.parseInt((process.hrtime.bigint() - store[id]).toString()) / 1000000, 'ms')\n }\n\n // Only run during cold start\n const beforePrefetch = () => start('total')\n const requestStart = () => {\n if (!store.init) {\n store.init = store.total\n stop('init')\n } else {\n start('total')\n }\n }\n const beforeMiddleware = start\n const afterMiddleware = stop\n const beforeHandler = () => start('handler')\n const afterHandler = () => stop('handler')\n const requestEnd = () => stop('total')\n\n return {\n beforePrefetch,\n requestStart,\n beforeMiddleware,\n afterMiddleware,\n beforeHandler,\n afterHandler,\n requestEnd\n }\n}\n\nexport const handler = middy(timePlugin())\n .use(eventLogger())\n .use(errorLogger())\n .use(httpEventNormalizer())\n .use(httpHeaderNormalizer())\n .use(httpUrlencodePathParametersParser())\n .use(httpUrlencodeBodyParser())\n .use(httpJsonBodyParser())\n .use(httpCors())\n .use(httpSecurityHeaders())\n .use(validator({eventSchema}))\n .handler(()=>{})\n \nawait handler()\n")),(0,o.kt)("p",null,"This will log out something this:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"inputOutputLoggerMiddlewareBefore 0.156033 ms\nhttpEventNormalizerMiddlewareBefore 0.073921 ms\nhttpHeaderNormalizerMiddlewareBefore 0.095098 ms\nhttpUrlencodePathParserMiddlewareBefore 0.036255 ms\nhttpUrlencodeBodyParserMiddlewareBefore 0.038809 ms\nhttpJsonBodyParserMiddlewareBefore 0.048383 ms\nhttpContentNegotiationMiddlewareBefore 0.042311 ms\nvalidatorMiddlewareBefore 0.083366 ms\nhandler 0.094875 ms\nvalidatorMiddlewareAfter 0.083601 ms\nhttpSecurityHeadersMiddlewareAfter 0.19702 ms\nhttpCorsMiddlewareAfter 0.080532 ms\ninputOutputLoggerMiddlewareAfter 0.066886 ms\nlambda 66.141835 ms\n")),(0,o.kt)("p",null,"From this everything looks good. Sub 1ms for every middleware and the handler. But wait, that ",(0,o.kt)("inlineCode",{parentName:"p"},"total")," doesn't look right.\nYou're correct, ",(0,o.kt)("inlineCode",{parentName:"p"},"total")," includes the initial setup time (or cold start time) for all middlewares. In this case ",(0,o.kt)("inlineCode",{parentName:"p"},"validator")," is the culprit.\nThe Ajv constructor and compiler do a lot of magic when they first run to get ready for later schema validations.\nThis is why in the ",(0,o.kt)("inlineCode",{parentName:"p"},"validator")," middleware we now support passing in complied schema and expose the default compiler in\ncase you want to use it in a build step. We hope this feature will help to you in identify slow middlewares and improve your development experience."),(0,o.kt)("p",null,"There is also a ",(0,o.kt)("inlineCode",{parentName:"p"},"beforeRequest")," hook, but was left out of the example for dramatic effect."),(0,o.kt)("p",null,"Additionally, you'll notice that each middleware shows a descriptive name. This is printing out the function name passed into middy core.\nIf you've looked at the code for some the supported middlewares, you'll see these long descriptive variable names being set, then returned.\nThis is why."),(0,o.kt)("h2",{id:"memory"},"Memory"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import memwatch from '@airbnb/node-memwatch'\n\nconst defaults = {\n logger: console.log\n}\n\nconst memoryPlugin = (opts = {}) => {\n const { logger } = { ...defaults, ...opts }\n const store = {}\n\n const start = (id) => {\n store[id] = new memwatch.HeapDiff()\n }\n const stop = (id) => {\n logger(id, store[id].end())\n }\n\n const beforePrefetch = () => start('total')\n const requestStart = () => {\n store.init = store.total\n stop('init')\n }\n const beforeMiddleware = start\n const afterMiddleware = stop\n const beforeHandler = () => start('handler')\n const afterHandler = () => stop('handler')\n const requestEnd = () => stop('total')\n\n return {\n beforePrefetch,\n requestStart,\n beforeMiddleware,\n afterMiddleware,\n beforeHandler,\n afterHandler,\n requestEnd\n }\n}\n\nexport const handler = middy(memoryPlugin())\n .use(eventLogger())\n .use(errorLogger())\n .use(httpEventNormalizer())\n .use(httpHeaderNormalizer())\n .use(httpUrlencodePathParametersParser())\n .use(httpUrlencodeBodyParser())\n .use(httpJsonBodyParser())\n .use(httpCors())\n .use(httpSecurityHeaders())\n .use(validator({eventSchema}))\n .handler(()=>{})\n \nawait handler()\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/54fc444e.2d08c51a.js b/assets/js/54fc444e.4cfa423b.js similarity index 98% rename from assets/js/54fc444e.2d08c51a.js rename to assets/js/54fc444e.4cfa423b.js index 0fb5fb5bd..b7e7af791 100644 --- a/assets/js/54fc444e.2d08c51a.js +++ b/assets/js/54fc444e.4cfa423b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1790],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>m});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function c(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):c(c({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},f=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,i=e.originalType,s=e.parentName,p=a(e,["components","mdxType","originalType","parentName"]),u=l(n),f=o,m=u["".concat(s,".").concat(f)]||u[f]||d[f]||i;return n?r.createElement(m,c(c({ref:t},p),{},{components:n})):r.createElement(m,c({ref:t},p))}));function m(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=n.length,c=new Array(i);c[0]=f;var a={};for(var s in t)hasOwnProperty.call(t,s)&&(a[s]=t[s]);a.originalType=e,a[u]="string"==typeof e?e:o,c[1]=a;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>c,default:()=>d,frontMatter:()=>i,metadata:()=>a,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const i={title:"Connection reuse",sidebar_position:2},c=void 0,a={unversionedId:"best-practices/connection-reuse",id:"best-practices/connection-reuse",title:"Connection reuse",description:"Be sure to set the following environment variable when connecting to AWS services:",source:"@site/docs/best-practices/02-connection-reuse.md",sourceDirName:"best-practices",slug:"/best-practices/connection-reuse",permalink:"/docs/best-practices/connection-reuse",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/02-connection-reuse.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:2,frontMatter:{title:"Connection reuse",sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"Intro",permalink:"/docs/best-practices/intro"},next:{title:"Internal Context",permalink:"/docs/best-practices/internal-context"}},s={},l=[],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Be sure to set the following environment variable when connecting to AWS services:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-plain"},"AWS_NODEJS_CONNECTION_REUSE_ENABLED=1\n")),(0,o.kt)("p",null,"This allows you to reuse the first connection established across lambda invocations."),(0,o.kt)("p",null,"See ",(0,o.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html"},"Reusing Connections with Keep-Alive in Node.js")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1790],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>m});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function c(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):c(c({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},f=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,i=e.originalType,s=e.parentName,p=a(e,["components","mdxType","originalType","parentName"]),u=l(n),f=o,m=u["".concat(s,".").concat(f)]||u[f]||d[f]||i;return n?r.createElement(m,c(c({ref:t},p),{},{components:n})):r.createElement(m,c({ref:t},p))}));function m(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=n.length,c=new Array(i);c[0]=f;var a={};for(var s in t)hasOwnProperty.call(t,s)&&(a[s]=t[s]);a.originalType=e,a[u]="string"==typeof e?e:o,c[1]=a;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>c,default:()=>d,frontMatter:()=>i,metadata:()=>a,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const i={title:"Connection reuse",sidebar_position:2},c=void 0,a={unversionedId:"best-practices/connection-reuse",id:"best-practices/connection-reuse",title:"Connection reuse",description:"Be sure to set the following environment variable when connecting to AWS services:",source:"@site/docs/best-practices/02-connection-reuse.md",sourceDirName:"best-practices",slug:"/best-practices/connection-reuse",permalink:"/docs/best-practices/connection-reuse",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/02-connection-reuse.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:2,frontMatter:{title:"Connection reuse",sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"Intro",permalink:"/docs/best-practices/intro"},next:{title:"Internal Context",permalink:"/docs/best-practices/internal-context"}},s={},l=[],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Be sure to set the following environment variable when connecting to AWS services:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-plain"},"AWS_NODEJS_CONNECTION_REUSE_ENABLED=1\n")),(0,o.kt)("p",null,"This allows you to reuse the first connection established across lambda invocations."),(0,o.kt)("p",null,"See ",(0,o.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html"},"Reusing Connections with Keep-Alive in Node.js")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/56ed1c64.8b925cca.js b/assets/js/56ed1c64.ad8d1a01.js similarity index 99% rename from assets/js/56ed1c64.8b925cca.js rename to assets/js/56ed1c64.ad8d1a01.js index 457f0de1e..c46fd8c88 100644 --- a/assets/js/56ed1c64.8b925cca.js +++ b/assets/js/56ed1c64.ad8d1a01.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4097],{3905:(e,n,t)=>{t.d(n,{Zo:()=>c,kt:()=>f});var r=t(7294);function a(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function i(e){for(var n=1;n=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}var d=r.createContext({}),l=function(e){var n=r.useContext(d),t=n;return e&&(t="function"==typeof e?e(n):i(i({},n),e)),t},c=function(e){var n=l(e.components);return r.createElement(d.Provider,{value:n},e.children)},m="mdxType",p={inlineCode:"code",wrapper:function(e){var n=e.children;return r.createElement(r.Fragment,{},n)}},u=r.forwardRef((function(e,n){var t=e.components,a=e.mdxType,o=e.originalType,d=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),m=l(t),u=a,f=m["".concat(d,".").concat(u)]||m[u]||p[u]||o;return t?r.createElement(f,i(i({ref:n},c),{},{components:t})):r.createElement(f,i({ref:n},c))}));function f(e,n){var t=arguments,a=n&&n.mdxType;if("string"==typeof e||a){var o=t.length,i=new Array(o);i[0]=u;var s={};for(var d in n)hasOwnProperty.call(n,d)&&(s[d]=n[d]);s.originalType=e,s[m]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=t(7462),a=(t(7294),t(3905));const o={title:"All AWS Events",position:1},i=void 0,s={unversionedId:"events/intro",id:"events/intro",title:"All AWS Events",description:"Middy is built to help with all AWS Events that can connect with AWS Lambda.",source:"@site/docs/events/01-intro.md",sourceDirName:"events",slug:"/events/intro",permalink:"/docs/events/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:1,frontMatter:{title:"All AWS Events",position:1},sidebar:"tutorialSidebar",previous:{title:"AWS Event Examples",permalink:"/docs/category/aws-event-examples"},next:{title:"Alexa",permalink:"/docs/events/alexa"}},d={},l=[{value:"Middlewares that can benefit any Lambda",id:"middlewares-that-can-benefit-any-lambda",level:2},{value:"Need secrets? We have you covered there too",id:"need-secrets-we-have-you-covered-there-too",level:2},{value:"How about configs? We have you covered there as well",id:"how-about-configs-we-have-you-covered-there-as-well",level:2}],c={toc:l},m="wrapper";function p(e){let{components:n,...t}=e;return(0,a.kt)(m,(0,r.Z)({},c,t,{components:n,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Middy is built to help with all AWS Events that can connect with AWS Lambda."),(0,a.kt)("h2",{id:"middlewares-that-can-benefit-any-lambda"},"Middlewares that can benefit any Lambda"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport cloudWatchMetricsMiddleware from '@middy/cloudwatch-metrics'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nconst handler = middy()\n .use(warmupMiddleware())\n .use(cloudWatchMetricsMiddleware())\n .use(inputOutputLoggerMiddleware())\n .use(errorLoggerMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .handler(async (event, context, { signal }) => {\n // ...\n })\n")),(0,a.kt)("h2",{id:"need-secrets-we-have-you-covered-there-too"},"Need secrets? We have you covered there too"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport rdsSignerMiddleware from '@middy/rds-signer'\nimport secretsManagerMiddleware from '@middy/secrets-manager'\nimport ssmMiddleware from '@middy/ssm'\nimport stsMiddleware from '@middy/sts'\n\nexport const handler = middy()\n .use(\n rdsSignerMiddleware({\n fetchData: {\n rdsSigner: {\n region: process.env.AWS_REGION,\n hostname: process.env.RDS_HOSTNAME,\n username: 'iam_role',\n database: 'database',\n port: 5555\n }\n }\n })\n )\n .use(\n secretsManagerMiddleware({\n fetchData: {\n secretsManager: '/dev/service_name/key_name'\n }\n })\n )\n .use(\n ssmMiddleware({\n fetchData: {\n ssm: '/dev/service_name/key_name'\n }\n })\n )\n .use(\n stsMiddleware({\n fetchData: {\n sts: {\n RoleArn: '.../role'\n }\n }\n })\n )\n .before(async (request) => {\n request.context.secrets = await getInternal(true, request)\n })\n .handler(async (event, context, { signal }) => {\n // context.secrets = { rdsSigner, secretsManager, ssm, sts }\n })\n")),(0,a.kt)("h2",{id:"how-about-configs-we-have-you-covered-there-as-well"},"How about configs? We have you covered there as well"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport appConfigMiddleware from '@middy/appconfig'\nimport s3Middleware from '@middy/s3'\nimport dynamoDBMiddleware from '@middy/dynamodb'\nimport ssmMiddleware from '@middy/ssm'\n\nexport const handler = middy()\n .use(\n appConfigMiddleware({\n fetchData: {\n appConfig: {\n Application: '...',\n ClientId: '...',\n Configuration: '...',\n Environment: '...'\n }\n }\n })\n )\n .use(\n s3Middleware({\n fetchData: {\n s3: {\n Bucket: '...',\n Key: '...'\n }\n }\n })\n )\n .use(\n dynamoDBMiddleware({\n fetchData: {\n dynamodb: {\n TableName: '...',\n Key: { '...' }\n }\n }\n })\n )\n .use(\n ssmMiddleware({\n fetchData: {\n ssm: '/dev/service_name/key_name'\n }\n })\n )\n .before(async (request) => {\n request.context.configs = await getInternal(true, request)\n })\n .handler(async (event, context, { signal }) => {\n // context.configs = { appConfig, dynamodb, s3, ssm }\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4097],{3905:(e,n,t)=>{t.d(n,{Zo:()=>c,kt:()=>f});var r=t(7294);function a(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function i(e){for(var n=1;n=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}var d=r.createContext({}),l=function(e){var n=r.useContext(d),t=n;return e&&(t="function"==typeof e?e(n):i(i({},n),e)),t},c=function(e){var n=l(e.components);return r.createElement(d.Provider,{value:n},e.children)},m="mdxType",p={inlineCode:"code",wrapper:function(e){var n=e.children;return r.createElement(r.Fragment,{},n)}},u=r.forwardRef((function(e,n){var t=e.components,a=e.mdxType,o=e.originalType,d=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),m=l(t),u=a,f=m["".concat(d,".").concat(u)]||m[u]||p[u]||o;return t?r.createElement(f,i(i({ref:n},c),{},{components:t})):r.createElement(f,i({ref:n},c))}));function f(e,n){var t=arguments,a=n&&n.mdxType;if("string"==typeof e||a){var o=t.length,i=new Array(o);i[0]=u;var s={};for(var d in n)hasOwnProperty.call(n,d)&&(s[d]=n[d]);s.originalType=e,s[m]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=t(7462),a=(t(7294),t(3905));const o={title:"All AWS Events",position:1},i=void 0,s={unversionedId:"events/intro",id:"events/intro",title:"All AWS Events",description:"Middy is built to help with all AWS Events that can connect with AWS Lambda.",source:"@site/docs/events/01-intro.md",sourceDirName:"events",slug:"/events/intro",permalink:"/docs/events/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:1,frontMatter:{title:"All AWS Events",position:1},sidebar:"tutorialSidebar",previous:{title:"AWS Event Examples",permalink:"/docs/category/aws-event-examples"},next:{title:"Alexa",permalink:"/docs/events/alexa"}},d={},l=[{value:"Middlewares that can benefit any Lambda",id:"middlewares-that-can-benefit-any-lambda",level:2},{value:"Need secrets? We have you covered there too",id:"need-secrets-we-have-you-covered-there-too",level:2},{value:"How about configs? We have you covered there as well",id:"how-about-configs-we-have-you-covered-there-as-well",level:2}],c={toc:l},m="wrapper";function p(e){let{components:n,...t}=e;return(0,a.kt)(m,(0,r.Z)({},c,t,{components:n,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Middy is built to help with all AWS Events that can connect with AWS Lambda."),(0,a.kt)("h2",{id:"middlewares-that-can-benefit-any-lambda"},"Middlewares that can benefit any Lambda"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport cloudWatchMetricsMiddleware from '@middy/cloudwatch-metrics'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nconst handler = middy()\n .use(warmupMiddleware())\n .use(cloudWatchMetricsMiddleware())\n .use(inputOutputLoggerMiddleware())\n .use(errorLoggerMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .handler(async (event, context, { signal }) => {\n // ...\n })\n")),(0,a.kt)("h2",{id:"need-secrets-we-have-you-covered-there-too"},"Need secrets? We have you covered there too"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport rdsSignerMiddleware from '@middy/rds-signer'\nimport secretsManagerMiddleware from '@middy/secrets-manager'\nimport ssmMiddleware from '@middy/ssm'\nimport stsMiddleware from '@middy/sts'\n\nexport const handler = middy()\n .use(\n rdsSignerMiddleware({\n fetchData: {\n rdsSigner: {\n region: process.env.AWS_REGION,\n hostname: process.env.RDS_HOSTNAME,\n username: 'iam_role',\n database: 'database',\n port: 5555\n }\n }\n })\n )\n .use(\n secretsManagerMiddleware({\n fetchData: {\n secretsManager: '/dev/service_name/key_name'\n }\n })\n )\n .use(\n ssmMiddleware({\n fetchData: {\n ssm: '/dev/service_name/key_name'\n }\n })\n )\n .use(\n stsMiddleware({\n fetchData: {\n sts: {\n RoleArn: '.../role'\n }\n }\n })\n )\n .before(async (request) => {\n request.context.secrets = await getInternal(true, request)\n })\n .handler(async (event, context, { signal }) => {\n // context.secrets = { rdsSigner, secretsManager, ssm, sts }\n })\n")),(0,a.kt)("h2",{id:"how-about-configs-we-have-you-covered-there-as-well"},"How about configs? We have you covered there as well"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport appConfigMiddleware from '@middy/appconfig'\nimport s3Middleware from '@middy/s3'\nimport dynamoDBMiddleware from '@middy/dynamodb'\nimport ssmMiddleware from '@middy/ssm'\n\nexport const handler = middy()\n .use(\n appConfigMiddleware({\n fetchData: {\n appConfig: {\n Application: '...',\n ClientId: '...',\n Configuration: '...',\n Environment: '...'\n }\n }\n })\n )\n .use(\n s3Middleware({\n fetchData: {\n s3: {\n Bucket: '...',\n Key: '...'\n }\n }\n })\n )\n .use(\n dynamoDBMiddleware({\n fetchData: {\n dynamodb: {\n TableName: '...',\n Key: { '...' }\n }\n }\n })\n )\n .use(\n ssmMiddleware({\n fetchData: {\n ssm: '/dev/service_name/key_name'\n }\n })\n )\n .before(async (request) => {\n request.context.configs = await getInternal(true, request)\n })\n .handler(async (event, context, { signal }) => {\n // context.configs = { appConfig, dynamodb, s3, ssm }\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/58ba397f.e2b86f20.js b/assets/js/58ba397f.fe101f45.js similarity index 98% rename from assets/js/58ba397f.e2b86f20.js rename to assets/js/58ba397f.fe101f45.js index ae4935efe..6b5c05006 100644 --- a/assets/js/58ba397f.e2b86f20.js +++ b/assets/js/58ba397f.fe101f45.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1497],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var s=n.createContext({}),i=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},c=function(e){var t=i(e.components);return n.createElement(s.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,s=e.parentName,c=u(e,["components","mdxType","originalType","parentName"]),p=i(r),m=a,h=p["".concat(s,".").concat(m)]||p[m]||d[m]||l;return r?n.createElement(h,o(o({ref:t},c),{},{components:r})):n.createElement(h,o({ref:t},c))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=m;var u={};for(var s in t)hasOwnProperty.call(t,s)&&(u[s]=t[s]);u.originalType=e,u[p]="string"==typeof e?e:a,o[1]=u;for(var i=2;i{r.d(t,{Z:()=>o});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var n=r(7462),a=r(7294),l=r(6010),o=r(2466),u=r(6550),s=r(1980),i=r(7392),c=r(12);function p(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function d(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??p(r);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:r}=e;const n=(0,u.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=d(e),[o,u]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[s,i]=h({queryString:r,groupId:n}),[p,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,c.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),b=(()=>{const e=s??p;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&u(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);u(e),i(e),f(e)}),[i,f,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:u,selectValue:s,tabValues:i}=e;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,o.o5)(),d=e=>{const t=e.currentTarget,r=c.indexOf(t),n=i[r].value;n!==u&&(p(t),s(n))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=c.indexOf(e.currentTarget)+1;t=c[r]??c[0];break}case"ArrowLeft":{const r=c.indexOf(e.currentTarget)-1;t=c[r]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},i.map((e=>{let{value:t,label:r,attributes:o}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:u===t?0:-1,"aria-selected":u===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:d},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":u===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(g,(0,n.Z)({},e,t)))}function k(e){const t=(0,b.Z)();return a.createElement(w,(0,n.Z)({key:String(t)},e))}},3278:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>h,frontMatter:()=>u,metadata:()=>i,toc:()=>p});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),o=r(5162);const u={title:"http-urlencode-path-parser"},s=void 0,i={unversionedId:"middlewares/http-urlencode-path-parser",id:"middlewares/http-urlencode-path-parser",title:"http-urlencode-path-parser",description:"This middleware automatically parses HTTP requests with URL-encoded paths. This can happen when using path variables (ie //) for an endpoint and the UI encodeURIComponent the values before making the request.",source:"@site/docs/middlewares/http-urlencode-path-parser.md",sourceDirName:"middlewares",slug:"/middlewares/http-urlencode-path-parser",permalink:"/docs/middlewares/http-urlencode-path-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-urlencode-path-parser.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-urlencode-path-parser"},sidebar:"tutorialSidebar",previous:{title:"http-urlencode-body-parser",permalink:"/docs/middlewares/http-urlencode-body-parser"},next:{title:"input-output-logger",permalink:"/docs/middlewares/input-output-logger"}},c={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:p},m="wrapper";function h(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware automatically parses HTTP requests with URL-encoded paths. This can happen when using path variables (ie ",(0,a.kt)("inlineCode",{parentName:"p"},"/{name}/"),") for an endpoint and the UI ",(0,a.kt)("inlineCode",{parentName:"p"},"encodeURIComponent")," the values before making the request."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-urlencode-path-parser\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-urlencode-path-parser\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-urlencode-path-parser\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("p",null,"None"),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpUrlEncodePathParser from '@middy/http-urlencode-path-parser'\n\nconst handler = middy((event, context) => {\n return event.body // propagates the body as response\n})\n\nhandler.use(httpUrlEncodePathParser())\n\n// When Lambda runs the handler with a sample event...\nconst event = {\n\n pathParameters: {\n name: encodeURIComponent('M\xeeddy')\n }\n}\n\nhandler(event, {}, (_, body) => {\n t.deepEqual(body, {\n name: 'M\xeeddy'\n })\n})\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1497],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var s=n.createContext({}),i=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},c=function(e){var t=i(e.components);return n.createElement(s.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,s=e.parentName,c=u(e,["components","mdxType","originalType","parentName"]),p=i(r),m=a,h=p["".concat(s,".").concat(m)]||p[m]||d[m]||l;return r?n.createElement(h,o(o({ref:t},c),{},{components:r})):n.createElement(h,o({ref:t},c))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=m;var u={};for(var s in t)hasOwnProperty.call(t,s)&&(u[s]=t[s]);u.originalType=e,u[p]="string"==typeof e?e:a,o[1]=u;for(var i=2;i{r.d(t,{Z:()=>o});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var n=r(7462),a=r(7294),l=r(6010),o=r(2466),u=r(6550),s=r(1980),i=r(7392),c=r(12);function p(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function d(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??p(r);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:r}=e;const n=(0,u.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=d(e),[o,u]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[s,i]=h({queryString:r,groupId:n}),[p,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,c.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),b=(()=>{const e=s??p;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&u(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);u(e),i(e),f(e)}),[i,f,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:u,selectValue:s,tabValues:i}=e;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,o.o5)(),d=e=>{const t=e.currentTarget,r=c.indexOf(t),n=i[r].value;n!==u&&(p(t),s(n))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=c.indexOf(e.currentTarget)+1;t=c[r]??c[0];break}case"ArrowLeft":{const r=c.indexOf(e.currentTarget)-1;t=c[r]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},i.map((e=>{let{value:t,label:r,attributes:o}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:u===t?0:-1,"aria-selected":u===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:d},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":u===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(g,(0,n.Z)({},e,t)))}function k(e){const t=(0,b.Z)();return a.createElement(w,(0,n.Z)({key:String(t)},e))}},3278:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>h,frontMatter:()=>u,metadata:()=>i,toc:()=>p});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),o=r(5162);const u={title:"http-urlencode-path-parser"},s=void 0,i={unversionedId:"middlewares/http-urlencode-path-parser",id:"middlewares/http-urlencode-path-parser",title:"http-urlencode-path-parser",description:"This middleware automatically parses HTTP requests with URL-encoded paths. This can happen when using path variables (ie //) for an endpoint and the UI encodeURIComponent the values before making the request.",source:"@site/docs/middlewares/http-urlencode-path-parser.md",sourceDirName:"middlewares",slug:"/middlewares/http-urlencode-path-parser",permalink:"/docs/middlewares/http-urlencode-path-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-urlencode-path-parser.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-urlencode-path-parser"},sidebar:"tutorialSidebar",previous:{title:"http-urlencode-body-parser",permalink:"/docs/middlewares/http-urlencode-body-parser"},next:{title:"input-output-logger",permalink:"/docs/middlewares/input-output-logger"}},c={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:p},m="wrapper";function h(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware automatically parses HTTP requests with URL-encoded paths. This can happen when using path variables (ie ",(0,a.kt)("inlineCode",{parentName:"p"},"/{name}/"),") for an endpoint and the UI ",(0,a.kt)("inlineCode",{parentName:"p"},"encodeURIComponent")," the values before making the request."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-urlencode-path-parser\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-urlencode-path-parser\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-urlencode-path-parser\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("p",null,"None"),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpUrlEncodePathParser from '@middy/http-urlencode-path-parser'\n\nconst handler = middy((event, context) => {\n return event.body // propagates the body as response\n})\n\nhandler.use(httpUrlEncodePathParser())\n\n// When Lambda runs the handler with a sample event...\nconst event = {\n\n pathParameters: {\n name: encodeURIComponent('M\xeeddy')\n }\n}\n\nhandler(event, {}, (_, body) => {\n t.deepEqual(body, {\n name: 'M\xeeddy'\n })\n})\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/590578cb.8e9e9506.js b/assets/js/590578cb.f0092c82.js similarity index 97% rename from assets/js/590578cb.8e9e9506.js rename to assets/js/590578cb.f0092c82.js index f05b91cc6..4d0844ada 100644 --- a/assets/js/590578cb.8e9e9506.js +++ b/assets/js/590578cb.f0092c82.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3181],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var i=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=i.createContext({}),m=function(e){var t=i.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},c=function(e){var t=m(e.components);return i.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},u=i.forwardRef((function(e,t){var r=e.components,n=e.mdxType,a=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),d=m(r),u=n,f=d["".concat(s,".").concat(u)]||d[u]||p[u]||a;return r?i.createElement(f,o(o({ref:t},c),{},{components:r})):i.createElement(f,o({ref:t},c))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var a=r.length,o=new Array(a);o[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[d]="string"==typeof e?e:n,o[1]=l;for(var m=2;m{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>m});var i=r(7462),n=(r(7294),r(3905));const a={title:"History"},o=void 0,l={unversionedId:"intro/history",id:"intro/history",title:"History",description:"A brief history of Middy",source:"@site/docs/intro/08-history.md",sourceDirName:"intro",slug:"/intro/history",permalink:"/docs/intro/history",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-history.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:8,frontMatter:{title:"History"},sidebar:"tutorialSidebar",previous:{title:"Hooks",permalink:"/docs/intro/hooks"},next:{title:"Influence",permalink:"/docs/intro/influence"}},s={},m=[{value:"A brief history of Middy",id:"a-brief-history-of-middy",level:2}],c={toc:m},d="wrapper";function p(e){let{components:t,...r}=e;return(0,n.kt)(d,(0,i.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("h2",{id:"a-brief-history-of-middy"},"A brief history of Middy"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Middy was started in the early days of AWS Lambda (~2016) and it was initially only used to remove duplication in a big serverless project with tons of lambdas. Only in August 2017 Middy's source code was released on GitHub making it an open source project."),(0,n.kt)("li",{parentName:"ul"},"2017-08-03: First commit"),(0,n.kt)("li",{parentName:"ul"},"2017-09-04: v0.2.1 First release"),(0,n.kt)("li",{parentName:"ul"},"2020-04-25: ",(0,n.kt)("a",{parentName:"li",href:"https://loige.co/middy-1-is-here/"},"v1.0.0")," Released"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://loige.co/2020-a-year-in-review/#middy"},"2020 Review")," by ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/lmammino"},"@lmammino")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://github.com/middyjs/middy/issues/590"},"2020 Review")," by ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/willfarrell"},"@willfarrell")),(0,n.kt)("li",{parentName:"ul"},"2021: ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/middyjs/middy/issues/585"},"v2.0.0 Coming soon")),(0,n.kt)("li",{parentName:"ul"},"2021-04-01: v2.0.0 Released"),(0,n.kt)("li",{parentName:"ul"},"2021-02-02: ",(0,n.kt)("a",{parentName:"li",href:"https://loige.co/2021-a-year-in-review#middy"},"2021 Review")," from ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/lmammino"},"@lmammino")),(0,n.kt)("li",{parentName:"ul"},"2022-05-12: v3.0.0 Released"),(0,n.kt)("li",{parentName:"ul"},"2022-11-24: v4.0.0 Released")),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Fun Fact"),": The adding of the emoji-icon was the ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/commit/a0acf430bb72f6f6f604e38cfd8a571912b6b4d7"},"2nd commit")," to the project."))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3181],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var i=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=i.createContext({}),m=function(e){var t=i.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},c=function(e){var t=m(e.components);return i.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},u=i.forwardRef((function(e,t){var r=e.components,n=e.mdxType,a=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),d=m(r),u=n,f=d["".concat(s,".").concat(u)]||d[u]||p[u]||a;return r?i.createElement(f,o(o({ref:t},c),{},{components:r})):i.createElement(f,o({ref:t},c))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var a=r.length,o=new Array(a);o[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[d]="string"==typeof e?e:n,o[1]=l;for(var m=2;m{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>m});var i=r(7462),n=(r(7294),r(3905));const a={title:"History"},o=void 0,l={unversionedId:"intro/history",id:"intro/history",title:"History",description:"A brief history of Middy",source:"@site/docs/intro/08-history.md",sourceDirName:"intro",slug:"/intro/history",permalink:"/docs/intro/history",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-history.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:8,frontMatter:{title:"History"},sidebar:"tutorialSidebar",previous:{title:"Hooks",permalink:"/docs/intro/hooks"},next:{title:"Influence",permalink:"/docs/intro/influence"}},s={},m=[{value:"A brief history of Middy",id:"a-brief-history-of-middy",level:2}],c={toc:m},d="wrapper";function p(e){let{components:t,...r}=e;return(0,n.kt)(d,(0,i.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("h2",{id:"a-brief-history-of-middy"},"A brief history of Middy"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Middy was started in the early days of AWS Lambda (~2016) and it was initially only used to remove duplication in a big serverless project with tons of lambdas. Only in August 2017 Middy's source code was released on GitHub making it an open source project."),(0,n.kt)("li",{parentName:"ul"},"2017-08-03: First commit"),(0,n.kt)("li",{parentName:"ul"},"2017-09-04: v0.2.1 First release"),(0,n.kt)("li",{parentName:"ul"},"2020-04-25: ",(0,n.kt)("a",{parentName:"li",href:"https://loige.co/middy-1-is-here/"},"v1.0.0")," Released"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://loige.co/2020-a-year-in-review/#middy"},"2020 Review")," by ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/lmammino"},"@lmammino")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://github.com/middyjs/middy/issues/590"},"2020 Review")," by ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/willfarrell"},"@willfarrell")),(0,n.kt)("li",{parentName:"ul"},"2021: ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/middyjs/middy/issues/585"},"v2.0.0 Coming soon")),(0,n.kt)("li",{parentName:"ul"},"2021-04-01: v2.0.0 Released"),(0,n.kt)("li",{parentName:"ul"},"2021-02-02: ",(0,n.kt)("a",{parentName:"li",href:"https://loige.co/2021-a-year-in-review#middy"},"2021 Review")," from ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/lmammino"},"@lmammino")),(0,n.kt)("li",{parentName:"ul"},"2022-05-12: v3.0.0 Released"),(0,n.kt)("li",{parentName:"ul"},"2022-11-24: v4.0.0 Released")),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Fun Fact"),": The adding of the emoji-icon was the ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/commit/a0acf430bb72f6f6f604e38cfd8a571912b6b4d7"},"2nd commit")," to the project."))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/59ac4306.27b85bd1.js b/assets/js/59ac4306.94ca71d4.js similarity index 98% rename from assets/js/59ac4306.27b85bd1.js rename to assets/js/59ac4306.94ca71d4.js index 0270209c8..cae2e1636 100644 --- a/assets/js/59ac4306.27b85bd1.js +++ b/assets/js/59ac4306.94ca71d4.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3151],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>b});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var s=n.createContext({}),i=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},d=function(e){var t=i(e.components);return n.createElement(s.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,s=e.parentName,d=u(e,["components","mdxType","originalType","parentName"]),c=i(r),m=a,b=c["".concat(s,".").concat(m)]||c[m]||p[m]||l;return r?n.createElement(b,o(o({ref:t},d),{},{components:r})):n.createElement(b,o({ref:t},d))}));function b(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=m;var u={};for(var s in t)hasOwnProperty.call(t,s)&&(u[s]=t[s]);u.originalType=e,u[c]="string"==typeof e?e:a,o[1]=u;for(var i=2;i{r.d(t,{Z:()=>o});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var n=r(7462),a=r(7294),l=r(6010),o=r(2466),u=r(6550),s=r(1980),i=r(7392),d=r(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function p(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:r}=e;const n=(0,u.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=p(e),[o,u]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[s,i]=b({queryString:r,groupId:n}),[c,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),y=(()=>{const e=s??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{y&&u(y)}),[y]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);u(e),i(e),f(e)}),[i,f,l]),tabValues:l}}var y=r(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:u,selectValue:s,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),p=e=>{const t=e.currentTarget,r=d.indexOf(t),n=i[r].value;n!==u&&(c(t),s(n))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},i.map((e=>{let{value:t,label:r,attributes:o}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:u===t?0:-1,"aria-selected":u===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",h.tabItem,o?.className,{"tabs__item--active":u===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(g,(0,n.Z)({},e,t)))}function k(e){const t=(0,y.Z)();return a.createElement(w,(0,n.Z)({key:String(t)},e))}},6381:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>b,frontMatter:()=>u,metadata:()=>i,toc:()=>c});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),o=r(5162);const u={title:"http-urlencode-body-parser"},s=void 0,i={unversionedId:"middlewares/http-urlencode-body-parser",id:"middlewares/http-urlencode-body-parser",title:"http-urlencode-body-parser",description:"This middleware automatically parses HTTP requests with URL-encoded body (typically the result",source:"@site/docs/middlewares/http-urlencode-body-parser.md",sourceDirName:"middlewares",slug:"/middlewares/http-urlencode-body-parser",permalink:"/docs/middlewares/http-urlencode-body-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-urlencode-body-parser.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-urlencode-body-parser"},sidebar:"tutorialSidebar",previous:{title:"http-security-headers",permalink:"/docs/middlewares/http-security-headers"},next:{title:"http-urlencode-path-parser",permalink:"/docs/middlewares/http-urlencode-path-parser"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:c},m="wrapper";function b(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware automatically parses HTTP requests with URL-encoded body (typically the result\nof a form submit). Also handles gracefully broken URL encoding as ",(0,a.kt)("em",{parentName:"p"},"Unsupported Media Type")," (415 errors)"),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-urlencode-body-parser\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-urlencode-body-parser\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-urlencode-body-parser\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disableContentTypeError")," (",(0,a.kt)("inlineCode",{parentName:"li"},"boolean"),") (optional): Skip throwing 415 when ",(0,a.kt)("inlineCode",{parentName:"li"},"Content-Type")," is invalid. Default: ",(0,a.kt)("inlineCode",{parentName:"li"},"true"),", will default to ",(0,a.kt)("inlineCode",{parentName:"li"},"false")," in next major version.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpUrlEncodeBodyParser from '@middy/http-urlencode-body-parser'\n\nconst handler = middy((event, context) => {\n return event.body // propagates the body as response\n})\n\nhandler.use(httpHeaderNormalizer()).use(httpUrlEncodeBodyParser())\n\n// When Lambda runs the handler with a sample event...\nconst event = {\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded'\n },\n body: 'frappucino=muffin&goat%5B%5D=scone&pond=moose'\n}\n\nhandler(event, {}, (_, body) => {\n t.deepEqual(body, {\n frappucino: 'muffin',\n 'goat[]': 'scone',\n pond: 'moose'\n })\n})\n")))}b.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3151],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>b});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var s=n.createContext({}),i=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},d=function(e){var t=i(e.components);return n.createElement(s.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,s=e.parentName,d=u(e,["components","mdxType","originalType","parentName"]),c=i(r),m=a,b=c["".concat(s,".").concat(m)]||c[m]||p[m]||l;return r?n.createElement(b,o(o({ref:t},d),{},{components:r})):n.createElement(b,o({ref:t},d))}));function b(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=m;var u={};for(var s in t)hasOwnProperty.call(t,s)&&(u[s]=t[s]);u.originalType=e,u[c]="string"==typeof e?e:a,o[1]=u;for(var i=2;i{r.d(t,{Z:()=>o});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var n=r(7462),a=r(7294),l=r(6010),o=r(2466),u=r(6550),s=r(1980),i=r(7392),d=r(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function p(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:r}=e;const n=(0,u.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=p(e),[o,u]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[s,i]=b({queryString:r,groupId:n}),[c,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),y=(()=>{const e=s??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{y&&u(y)}),[y]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);u(e),i(e),f(e)}),[i,f,l]),tabValues:l}}var y=r(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:u,selectValue:s,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),p=e=>{const t=e.currentTarget,r=d.indexOf(t),n=i[r].value;n!==u&&(c(t),s(n))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},i.map((e=>{let{value:t,label:r,attributes:o}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:u===t?0:-1,"aria-selected":u===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",h.tabItem,o?.className,{"tabs__item--active":u===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(g,(0,n.Z)({},e,t)))}function k(e){const t=(0,y.Z)();return a.createElement(w,(0,n.Z)({key:String(t)},e))}},6381:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>b,frontMatter:()=>u,metadata:()=>i,toc:()=>c});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),o=r(5162);const u={title:"http-urlencode-body-parser"},s=void 0,i={unversionedId:"middlewares/http-urlencode-body-parser",id:"middlewares/http-urlencode-body-parser",title:"http-urlencode-body-parser",description:"This middleware automatically parses HTTP requests with URL-encoded body (typically the result",source:"@site/docs/middlewares/http-urlencode-body-parser.md",sourceDirName:"middlewares",slug:"/middlewares/http-urlencode-body-parser",permalink:"/docs/middlewares/http-urlencode-body-parser",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-urlencode-body-parser.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-urlencode-body-parser"},sidebar:"tutorialSidebar",previous:{title:"http-security-headers",permalink:"/docs/middlewares/http-security-headers"},next:{title:"http-urlencode-path-parser",permalink:"/docs/middlewares/http-urlencode-path-parser"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:c},m="wrapper";function b(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware automatically parses HTTP requests with URL-encoded body (typically the result\nof a form submit). Also handles gracefully broken URL encoding as ",(0,a.kt)("em",{parentName:"p"},"Unsupported Media Type")," (415 errors)"),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-urlencode-body-parser\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-urlencode-body-parser\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-urlencode-body-parser\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"disableContentTypeError")," (",(0,a.kt)("inlineCode",{parentName:"li"},"boolean"),") (optional): Skip throwing 415 when ",(0,a.kt)("inlineCode",{parentName:"li"},"Content-Type")," is invalid. Default: ",(0,a.kt)("inlineCode",{parentName:"li"},"true"),", will default to ",(0,a.kt)("inlineCode",{parentName:"li"},"false")," in next major version.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpUrlEncodeBodyParser from '@middy/http-urlencode-body-parser'\n\nconst handler = middy((event, context) => {\n return event.body // propagates the body as response\n})\n\nhandler.use(httpHeaderNormalizer()).use(httpUrlEncodeBodyParser())\n\n// When Lambda runs the handler with a sample event...\nconst event = {\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded'\n },\n body: 'frappucino=muffin&goat%5B%5D=scone&pond=moose'\n}\n\nhandler(event, {}, (_, body) => {\n t.deepEqual(body, {\n frappucino: 'muffin',\n 'goat[]': 'scone',\n pond: 'moose'\n })\n})\n")))}b.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/5a01598e.d98109f6.js b/assets/js/5a01598e.2fba9b4a.js similarity index 99% rename from assets/js/5a01598e.d98109f6.js rename to assets/js/5a01598e.2fba9b4a.js index 1be72c455..c89c21086 100644 --- a/assets/js/5a01598e.d98109f6.js +++ b/assets/js/5a01598e.2fba9b4a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4297],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>c});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var d=a.createContext({}),s=function(e){var t=a.useContext(d),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},p=function(e){var t=s(e.components);return a.createElement(d.Provider,{value:t},e.children)},u="mdxType",h={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,d=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),u=s(r),m=n,c=u["".concat(d,".").concat(m)]||u[m]||h[m]||l;return r?a.createElement(c,o(o({ref:t},p),{},{components:r})):a.createElement(c,o({ref:t},p))}));function c(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,o=new Array(l);o[0]=m;var i={};for(var d in t)hasOwnProperty.call(t,d)&&(i[d]=t[d]);i.originalType=e,i[u]="string"==typeof e?e:n,o[1]=i;for(var s=2;s{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>s});var a=r(7462),n=(r(7294),r(3905));const l={title:"Upgrade 3.x -> 4.x",sidebar_position:10},o=void 0,i={unversionedId:"upgrade/3-4",id:"upgrade/3-4",title:"Upgrade 3.x -> 4.x",description:"Version 4.x of Middy no longer supports Node.js versions 14.x. You are highly encouraged to move to Node.js 18.x.",source:"@site/docs/upgrade/3-4.md",sourceDirName:"upgrade",slug:"/upgrade/3-4",permalink:"/docs/upgrade/3-4",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/3-4.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:10,frontMatter:{title:"Upgrade 3.x -> 4.x",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"Upgrade",permalink:"/docs/category/upgrade"},next:{title:"Upgrade 2.x -> 3.x",permalink:"/docs/upgrade/2-3"}},d={},s=[{value:"Notable changes",id:"notable-changes",level:2},{value:"Core",id:"core",level:2},{value:"Util",id:"util",level:2},{value:"Middleware",id:"middleware",level:2},{value:"cloudwatch-metrics",id:"cloudwatch-metrics",level:3},{value:"do-not-wait-for-empty-event-loop",id:"do-not-wait-for-empty-event-loop",level:3},{value:"error-logger",id:"error-logger",level:3},{value:"event-normalizer",id:"event-normalizer",level:3},{value:"http-content-encoding",id:"http-content-encoding",level:3},{value:"http-content-negotiation",id:"http-content-negotiation",level:3},{value:"http-cors",id:"http-cors",level:3},{value:"http-error-handler",id:"http-error-handler",level:3},{value:"http-event-normalizer",id:"http-event-normalizer",level:3},{value:"http-header-normalizer",id:"http-header-normalizer",level:3},{value:"http-json-body-parser",id:"http-json-body-parser",level:3},{value:"http-multipart-body-parser",id:"http-multipart-body-parser",level:3},{value:"http-partial-response",id:"http-partial-response",level:3},{value:"http-response-serializer",id:"http-response-serializer",level:3},{value:"http-router",id:"http-router",level:3},{value:"http-security-headers",id:"http-security-headers",level:3},{value:"http-urlencode-body-parser",id:"http-urlencode-body-parser",level:3},{value:"http-urlencode-path-parser",id:"http-urlencode-path-parser",level:3},{value:"input-output-logger",id:"input-output-logger",level:3},{value:"rds-signer",id:"rds-signer",level:3},{value:"s3-object-response",id:"s3-object-response",level:3},{value:"secrets-manager",id:"secrets-manager",level:3},{value:"service-discovery",id:"service-discovery",level:3},{value:"sqs-partial-batch-failure",id:"sqs-partial-batch-failure",level:3},{value:"ssm",id:"ssm",level:3},{value:"sts",id:"sts",level:3},{value:"validator",id:"validator",level:3},{value:"warmup",id:"warmup",level:3},{value:"ws-json-body-parser",id:"ws-json-body-parser",level:3},{value:"ws-response",id:"ws-response",level:3},{value:"ws-router",id:"ws-router",level:3},{value:"Notes",id:"notes",level:2}],p={toc:s},u="wrapper";function h(e){let{components:t,...r}=e;return(0,n.kt)(u,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Version 4.x of Middy no longer supports Node.js versions 14.x. You are highly encouraged to move to Node.js 18.x."),(0,n.kt)("p",null,"Middy now uses AWS SDK v3 by default."),(0,n.kt)("h2",{id:"notable-changes"},"Notable changes"),(0,n.kt)("h2",{id:"core"},"Core"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Remove polyfill for ",(0,n.kt)("inlineCode",{parentName:"li"},"AbortControler")),(0,n.kt)("li",{parentName:"ul"},"Remove polyfill for ",(0,n.kt)("inlineCode",{parentName:"li"},"timers/promises"))),(0,n.kt)("h2",{id:"util"},"Util"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"normalizeResponse")," now will set the ",(0,n.kt)("inlineCode",{parentName:"li"},"statusCode")," to ",(0,n.kt)("inlineCode",{parentName:"li"},"200")," when casting to a new object or ",(0,n.kt)("inlineCode",{parentName:"li"},"500")," when missing ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h2",{id:"middleware"},"Middleware"),(0,n.kt)("h3",{id:"cloudwatch-metrics"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/cloudwatch-metrics"},"cloudwatch-metrics")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"do-not-wait-for-empty-event-loop"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/do-not-wait-for-empty-event-loop"},"do-not-wait-for-empty-event-loop")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"error-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/error-logger"},"error-logger")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/event-normalizer"},"event-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-content-encoding"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-encoding"},"http-content-encoding")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Removed body as stream support, will be brought back as a new middleware in a future middleware ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"http-content-negotiation"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-negotiation"},"http-content-negotiation")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-cors"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-cors"},"http-cors")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-error-handler"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-error-handler"},"http-error-handler")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-event-normalizer"},"http-event-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-header-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-header-normalizer"},"http-header-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-json-body-parser"},"http-json-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecate ",(0,n.kt)("inlineCode",{parentName:"li"},"event.rawBody")," ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("p",null,"You can add in an inline middleware as a workaround."),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"}," .before((request) => {\n request.event.rawBody = request.event.body\n })\n .use(httpJSONBodyParserMiddleware())\n")),(0,n.kt)("p",null,"See ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/issues/945"},"https://github.com/middyjs/middy/issues/945")," for discussion and reasoning."),(0,n.kt)("h3",{id:"http-multipart-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-multipart-body-parser"},"http-multipart-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Add new option to set ",(0,n.kt)("inlineCode",{parentName:"li"},"charset"))),(0,n.kt)("h3",{id:"http-partial-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-partial-response"},"http-partial-response")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-response-serializer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-response-serializer"},"http-response-serializer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-router"},(0,n.kt)("a",{parentName:"h3",href:"/docs/routers/http-router"},"http-router")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-security-headers"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-security-headers"},"http-security-headers")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-urlencode-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-body-parser"},"http-urlencode-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Now throws 422 when unable to parse JSON ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"http-urlencode-path-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-path-parser"},"http-urlencode-path-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"input-output-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/input-output-logger"},"input-output-logger")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"rds-signer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/rds-signer"},"rds-signer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"s3-object-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/s3-object-response"},"s3-object-response")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"secrets-manager"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/secrets-manager"},"secrets-manager")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"service-discovery"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/service-discovery"},"service-discovery")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"sqs-partial-batch-failure"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sqs-partial-batch-failure"},"sqs-partial-batch-failure")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"ssm"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ssm"},"ssm")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"sts"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sts"},"sts")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"validator"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/validator"},"validator")),(0,n.kt)("p",null,"We've put a lot of work into making this middleware bundle smaller and faster by default, while allowing for opting into more functionality."),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecate ",(0,n.kt)("inlineCode",{parentName:"li"},"inputSchema")," and ",(0,n.kt)("inlineCode",{parentName:"li"},"outputSchema")," options ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change")),(0,n.kt)("li",{parentName:"ul"},"Deprecated ",(0,n.kt)("inlineCode",{parentName:"li"},"i18nEnabled")," ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change")),(0,n.kt)("li",{parentName:"ul"},"Must now pass in ",(0,n.kt)("inlineCode",{parentName:"li"},"defaultLanguage")," localizations to ",(0,n.kt)("inlineCode",{parentName:"li"},"languages")," ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change")),(0,n.kt)("li",{parentName:"ul"},"Added in ",(0,n.kt)("inlineCode",{parentName:"li"},"ajv-error")," support"),(0,n.kt)("li",{parentName:"ul"},"Pulled ",(0,n.kt)("inlineCode",{parentName:"li"},"transpileSchema")," out of middleware to allow for tree shaking and pre-compile option ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change")),(0,n.kt)("li",{parentName:"ul"},"Added in ",(0,n.kt)("inlineCode",{parentName:"li"},"transpileLocale")," to allow for custom internationalization of error messages including ",(0,n.kt)("inlineCode",{parentName:"li"},"errorMessage"))),(0,n.kt)("p",null,"How to update use of middleware"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import validatorMiddleware from '@middy/validator'\n// 1. Import transpileSchema\nimport { transpileSchema } from '@middy/validator/transpile'\n\nexport const handler = middy(...)\n .use(validatorMiddleware({\n // 2. Wrap schemas with transpileSchema\n eventSchema: transpileSchema(eventJsonSchema)\n }))\n")),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import validatorMiddleware from '@middy/validator'\n// 1. Import localizations\nimport { en, fr } from 'ajv-ftl-i18n'\n\nexport const handler = middy(...)\n .use(validatorMiddleware({\n eventSchema: transpileSchema(eventJsonSchema),\n // 2. Add localizations in\n langauges: { en, fr }\n }))\n")),(0,n.kt)("h3",{id:"warmup"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/warmup"},"warmup")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"ws-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ws-json-body-parser"},"ws-json-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"ws-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ws-response"},"ws-response")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"ws-router"},(0,n.kt)("a",{parentName:"h3",href:"/docs/routers/ws-router"},"ws-router")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h2",{id:"notes"},"Notes"),(0,n.kt)("p",null,"None"))}h.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4297],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>c});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var d=a.createContext({}),s=function(e){var t=a.useContext(d),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},p=function(e){var t=s(e.components);return a.createElement(d.Provider,{value:t},e.children)},u="mdxType",h={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,d=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),u=s(r),m=n,c=u["".concat(d,".").concat(m)]||u[m]||h[m]||l;return r?a.createElement(c,o(o({ref:t},p),{},{components:r})):a.createElement(c,o({ref:t},p))}));function c(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,o=new Array(l);o[0]=m;var i={};for(var d in t)hasOwnProperty.call(t,d)&&(i[d]=t[d]);i.originalType=e,i[u]="string"==typeof e?e:n,o[1]=i;for(var s=2;s{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>s});var a=r(7462),n=(r(7294),r(3905));const l={title:"Upgrade 3.x -> 4.x",sidebar_position:10},o=void 0,i={unversionedId:"upgrade/3-4",id:"upgrade/3-4",title:"Upgrade 3.x -> 4.x",description:"Version 4.x of Middy no longer supports Node.js versions 14.x. You are highly encouraged to move to Node.js 18.x.",source:"@site/docs/upgrade/3-4.md",sourceDirName:"upgrade",slug:"/upgrade/3-4",permalink:"/docs/upgrade/3-4",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/3-4.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:10,frontMatter:{title:"Upgrade 3.x -> 4.x",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"Upgrade",permalink:"/docs/category/upgrade"},next:{title:"Upgrade 2.x -> 3.x",permalink:"/docs/upgrade/2-3"}},d={},s=[{value:"Notable changes",id:"notable-changes",level:2},{value:"Core",id:"core",level:2},{value:"Util",id:"util",level:2},{value:"Middleware",id:"middleware",level:2},{value:"cloudwatch-metrics",id:"cloudwatch-metrics",level:3},{value:"do-not-wait-for-empty-event-loop",id:"do-not-wait-for-empty-event-loop",level:3},{value:"error-logger",id:"error-logger",level:3},{value:"event-normalizer",id:"event-normalizer",level:3},{value:"http-content-encoding",id:"http-content-encoding",level:3},{value:"http-content-negotiation",id:"http-content-negotiation",level:3},{value:"http-cors",id:"http-cors",level:3},{value:"http-error-handler",id:"http-error-handler",level:3},{value:"http-event-normalizer",id:"http-event-normalizer",level:3},{value:"http-header-normalizer",id:"http-header-normalizer",level:3},{value:"http-json-body-parser",id:"http-json-body-parser",level:3},{value:"http-multipart-body-parser",id:"http-multipart-body-parser",level:3},{value:"http-partial-response",id:"http-partial-response",level:3},{value:"http-response-serializer",id:"http-response-serializer",level:3},{value:"http-router",id:"http-router",level:3},{value:"http-security-headers",id:"http-security-headers",level:3},{value:"http-urlencode-body-parser",id:"http-urlencode-body-parser",level:3},{value:"http-urlencode-path-parser",id:"http-urlencode-path-parser",level:3},{value:"input-output-logger",id:"input-output-logger",level:3},{value:"rds-signer",id:"rds-signer",level:3},{value:"s3-object-response",id:"s3-object-response",level:3},{value:"secrets-manager",id:"secrets-manager",level:3},{value:"service-discovery",id:"service-discovery",level:3},{value:"sqs-partial-batch-failure",id:"sqs-partial-batch-failure",level:3},{value:"ssm",id:"ssm",level:3},{value:"sts",id:"sts",level:3},{value:"validator",id:"validator",level:3},{value:"warmup",id:"warmup",level:3},{value:"ws-json-body-parser",id:"ws-json-body-parser",level:3},{value:"ws-response",id:"ws-response",level:3},{value:"ws-router",id:"ws-router",level:3},{value:"Notes",id:"notes",level:2}],p={toc:s},u="wrapper";function h(e){let{components:t,...r}=e;return(0,n.kt)(u,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Version 4.x of Middy no longer supports Node.js versions 14.x. You are highly encouraged to move to Node.js 18.x."),(0,n.kt)("p",null,"Middy now uses AWS SDK v3 by default."),(0,n.kt)("h2",{id:"notable-changes"},"Notable changes"),(0,n.kt)("h2",{id:"core"},"Core"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Remove polyfill for ",(0,n.kt)("inlineCode",{parentName:"li"},"AbortControler")),(0,n.kt)("li",{parentName:"ul"},"Remove polyfill for ",(0,n.kt)("inlineCode",{parentName:"li"},"timers/promises"))),(0,n.kt)("h2",{id:"util"},"Util"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"normalizeResponse")," now will set the ",(0,n.kt)("inlineCode",{parentName:"li"},"statusCode")," to ",(0,n.kt)("inlineCode",{parentName:"li"},"200")," when casting to a new object or ",(0,n.kt)("inlineCode",{parentName:"li"},"500")," when missing ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h2",{id:"middleware"},"Middleware"),(0,n.kt)("h3",{id:"cloudwatch-metrics"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/cloudwatch-metrics"},"cloudwatch-metrics")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"do-not-wait-for-empty-event-loop"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/do-not-wait-for-empty-event-loop"},"do-not-wait-for-empty-event-loop")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"error-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/error-logger"},"error-logger")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/event-normalizer"},"event-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-content-encoding"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-encoding"},"http-content-encoding")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Removed body as stream support, will be brought back as a new middleware in a future middleware ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"http-content-negotiation"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-negotiation"},"http-content-negotiation")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-cors"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-cors"},"http-cors")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-error-handler"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-error-handler"},"http-error-handler")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-event-normalizer"},"http-event-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-header-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-header-normalizer"},"http-header-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-json-body-parser"},"http-json-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecate ",(0,n.kt)("inlineCode",{parentName:"li"},"event.rawBody")," ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("p",null,"You can add in an inline middleware as a workaround."),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"}," .before((request) => {\n request.event.rawBody = request.event.body\n })\n .use(httpJSONBodyParserMiddleware())\n")),(0,n.kt)("p",null,"See ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/issues/945"},"https://github.com/middyjs/middy/issues/945")," for discussion and reasoning."),(0,n.kt)("h3",{id:"http-multipart-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-multipart-body-parser"},"http-multipart-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Add new option to set ",(0,n.kt)("inlineCode",{parentName:"li"},"charset"))),(0,n.kt)("h3",{id:"http-partial-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-partial-response"},"http-partial-response")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-response-serializer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-response-serializer"},"http-response-serializer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-router"},(0,n.kt)("a",{parentName:"h3",href:"/docs/routers/http-router"},"http-router")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-security-headers"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-security-headers"},"http-security-headers")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-urlencode-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-body-parser"},"http-urlencode-body-parser")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Now throws 422 when unable to parse JSON ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"http-urlencode-path-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-path-parser"},"http-urlencode-path-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"input-output-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/input-output-logger"},"input-output-logger")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"rds-signer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/rds-signer"},"rds-signer")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"s3-object-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/s3-object-response"},"s3-object-response")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"secrets-manager"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/secrets-manager"},"secrets-manager")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"service-discovery"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/service-discovery"},"service-discovery")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"sqs-partial-batch-failure"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sqs-partial-batch-failure"},"sqs-partial-batch-failure")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"ssm"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ssm"},"ssm")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"sts"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sts"},"sts")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"validator"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/validator"},"validator")),(0,n.kt)("p",null,"We've put a lot of work into making this middleware bundle smaller and faster by default, while allowing for opting into more functionality."),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Deprecate ",(0,n.kt)("inlineCode",{parentName:"li"},"inputSchema")," and ",(0,n.kt)("inlineCode",{parentName:"li"},"outputSchema")," options ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change")),(0,n.kt)("li",{parentName:"ul"},"Deprecated ",(0,n.kt)("inlineCode",{parentName:"li"},"i18nEnabled")," ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change")),(0,n.kt)("li",{parentName:"ul"},"Must now pass in ",(0,n.kt)("inlineCode",{parentName:"li"},"defaultLanguage")," localizations to ",(0,n.kt)("inlineCode",{parentName:"li"},"languages")," ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change")),(0,n.kt)("li",{parentName:"ul"},"Added in ",(0,n.kt)("inlineCode",{parentName:"li"},"ajv-error")," support"),(0,n.kt)("li",{parentName:"ul"},"Pulled ",(0,n.kt)("inlineCode",{parentName:"li"},"transpileSchema")," out of middleware to allow for tree shaking and pre-compile option ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change")),(0,n.kt)("li",{parentName:"ul"},"Added in ",(0,n.kt)("inlineCode",{parentName:"li"},"transpileLocale")," to allow for custom internationalization of error messages including ",(0,n.kt)("inlineCode",{parentName:"li"},"errorMessage"))),(0,n.kt)("p",null,"How to update use of middleware"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import validatorMiddleware from '@middy/validator'\n// 1. Import transpileSchema\nimport { transpileSchema } from '@middy/validator/transpile'\n\nexport const handler = middy(...)\n .use(validatorMiddleware({\n // 2. Wrap schemas with transpileSchema\n eventSchema: transpileSchema(eventJsonSchema)\n }))\n")),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import validatorMiddleware from '@middy/validator'\n// 1. Import localizations\nimport { en, fr } from 'ajv-ftl-i18n'\n\nexport const handler = middy(...)\n .use(validatorMiddleware({\n eventSchema: transpileSchema(eventJsonSchema),\n // 2. Add localizations in\n langauges: { en, fr }\n }))\n")),(0,n.kt)("h3",{id:"warmup"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/warmup"},"warmup")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"ws-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ws-json-body-parser"},"ws-json-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"ws-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ws-response"},"ws-response")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Updated to use AWS SDK v3 ",(0,n.kt)("strong",{parentName:"li"},"Breaking Change"))),(0,n.kt)("h3",{id:"ws-router"},(0,n.kt)("a",{parentName:"h3",href:"/docs/routers/ws-router"},"ws-router")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h2",{id:"notes"},"Notes"),(0,n.kt)("p",null,"None"))}h.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/5afe45f2.b4d5ffac.js b/assets/js/5afe45f2.0ad83ab9.js similarity index 98% rename from assets/js/5afe45f2.b4d5ffac.js rename to assets/js/5afe45f2.0ad83ab9.js index ff14f5174..c5604812c 100644 --- a/assets/js/5afe45f2.b4d5ffac.js +++ b/assets/js/5afe45f2.0ad83ab9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5938],{3905:(e,t,a)=>{a.d(t,{Zo:()=>d,kt:()=>f});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function o(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var s=n.createContext({}),u=function(e){var t=n.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},d=function(e){var t=u(e.components);return n.createElement(s.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},p=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),c=u(a),p=r,f=c["".concat(s,".").concat(p)]||c[p]||m[p]||l;return a?n.createElement(f,o(o({ref:t},d),{},{components:a})):n.createElement(f,o({ref:t},d))}));function f(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=a.length,o=new Array(l);o[0]=p;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[c]="string"==typeof e?e:r,o[1]=i;for(var u=2;u{a.d(t,{Z:()=>o});var n=a(7294),r=a(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:a,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,o),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>k});var n=a(7462),r=a(7294),l=a(6010),o=a(2466),i=a(6550),s=a(1980),u=a(7392),d=a(12);function c(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function m(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??c(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function p(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const n=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,s._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function b(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,l=m(e),[o,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[s,u]=f({queryString:a,groupId:n}),[c,b]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),y=(()=>{const e=s??c;return p({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{y&&i(y)}),[y]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var y=a(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function h(e){let{className:t,block:a,selectedValue:i,selectValue:s,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),m=e=>{const t=e.currentTarget,a=d.indexOf(t),n=u[a].value;n!==i&&(c(t),s(n))},p=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const a=d.indexOf(e.currentTarget)+1;t=d[a]??d[0];break}case"ArrowLeft":{const a=d.indexOf(e.currentTarget)-1;t=d[a]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:o}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:p,onClick:m},o,{className:(0,l.Z)("tabs__item",g.tabItem,o?.className,{"tabs__item--active":i===t})}),a??t)})))}function v(e){let{lazy:t,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",g.tabList)},r.createElement(h,(0,n.Z)({},e,t)),r.createElement(v,(0,n.Z)({},e,t)))}function k(e){const t=(0,y.Z)();return r.createElement(w,(0,n.Z)({key:String(t)},e))}},6179:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var n=a(7462),r=(a(7294),a(3905)),l=a(4866),o=a(5162);const i={title:"Getting started",position:2},s=void 0,u={unversionedId:"intro/getting-started",id:"intro/getting-started",title:"Getting started",description:"Install",source:"@site/docs/intro/02-getting-started.md",sourceDirName:"intro",slug:"/intro/getting-started",permalink:"/docs/intro/getting-started",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/02-getting-started.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:2,frontMatter:{title:"Getting started",position:2},sidebar:"tutorialSidebar",previous:{title:"Introduction",permalink:"/docs/"},next:{title:"How it works",permalink:"/docs/intro/how-it-works"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Usage",id:"usage",level:2},{value:"Example",id:"example",level:2}],m={toc:c},p="wrapper";function f(e){let{components:t,...a}=e;return(0,r.kt)(p,(0,n.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install middy, you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/core\n"))),(0,r.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/core\n"))),(0,r.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/core\n")))),(0,r.kt)("p",null,"If you are using TypeScript, you will also want to make sure that you have installed the ",(0,r.kt)("inlineCode",{parentName:"p"},"@types/aws-lambda")," peer-dependency:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save-dev @types/aws-lambda\n"))),(0,r.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add --dev @types/aws-lambda\n"))),(0,r.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add --save-dev @types/aws-lambda\n")))),(0,r.kt)("h2",{id:"usage"},"Usage"),(0,r.kt)("p",null,"As you will see in the next example, using middy is very\nsimple and requires just few steps:"),(0,r.kt)("ol",null,(0,r.kt)("li",{parentName:"ol"},"Write your Lambda handlers as usual, focusing mostly on implementing the bare\nbusiness logic for them."),(0,r.kt)("li",{parentName:"ol"},"Import ",(0,r.kt)("inlineCode",{parentName:"li"},"middy")," and all the middlewares you want to use."),(0,r.kt)("li",{parentName:"ol"},"Wrap your handler in the ",(0,r.kt)("inlineCode",{parentName:"li"},"middy()")," factory function. This will return a new\nenhanced instance of your original handler, to which you will be able to attach\nthe middlewares you need."),(0,r.kt)("li",{parentName:"ol"},"Attach all the middlewares you need using the function ",(0,r.kt)("inlineCode",{parentName:"li"},".use(somemiddleware())"))),(0,r.kt)("h2",{id:"example"},"Example"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport middleware1 from 'sample-middleware1'\nimport middleware2 from 'sample-middleware2'\nimport middleware3 from 'sample-middleware3'\n\nconst lambdaHandler = (event, context) => {\n /* your business logic */\n}\n\nexport const handler = middy(lambdaHandler)\n\nhandler\n .use(middleware1())\n .use(middleware2())\n .use(middleware3())\n\n")),(0,r.kt)("p",null,(0,r.kt)("inlineCode",{parentName:"p"},".use()")," takes a single middleware or an array of middlewares, so you can attach multiple middlewares in a single call:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},'import middy from "@middy/core"\nimport middleware1 from "sample-middleware1"\nimport middleware2 from "sample-middleware2"\nimport middleware3 from "sample-middleware3"\nconst middlewares = [middleware1(), middleware2(), middleware3()]\n\nconst lambdaHandler = (event, context) => {\n /* your business logic */\n};\n\nexport const handler = middy(lambdaHandler)\n\nhandler.use(middlewares)\n\n')),(0,r.kt)("p",null,"You can also attach ",(0,r.kt)("a",{parentName:"p",href:"#inline-middlewares"},"inline middlewares")," by using the functions ",(0,r.kt)("inlineCode",{parentName:"p"},".before"),", ",(0,r.kt)("inlineCode",{parentName:"p"},".after")," and ",(0,r.kt)("inlineCode",{parentName:"p"},".onError"),"."),(0,r.kt)("p",null,"For a more detailed use case and examples check the ",(0,r.kt)("a",{parentName:"p",href:"#writing-a-middleware"},"Writing a middleware section"),"."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5938],{3905:(e,t,a)=>{a.d(t,{Zo:()=>d,kt:()=>f});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function o(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var s=n.createContext({}),u=function(e){var t=n.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},d=function(e){var t=u(e.components);return n.createElement(s.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},p=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),c=u(a),p=r,f=c["".concat(s,".").concat(p)]||c[p]||m[p]||l;return a?n.createElement(f,o(o({ref:t},d),{},{components:a})):n.createElement(f,o({ref:t},d))}));function f(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=a.length,o=new Array(l);o[0]=p;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[c]="string"==typeof e?e:r,o[1]=i;for(var u=2;u{a.d(t,{Z:()=>o});var n=a(7294),r=a(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:a,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,o),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>k});var n=a(7462),r=a(7294),l=a(6010),o=a(2466),i=a(6550),s=a(1980),u=a(7392),d=a(12);function c(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function m(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??c(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function p(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const n=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,s._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function b(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,l=m(e),[o,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[s,u]=f({queryString:a,groupId:n}),[c,b]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),y=(()=>{const e=s??c;return p({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{y&&i(y)}),[y]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var y=a(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function h(e){let{className:t,block:a,selectedValue:i,selectValue:s,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),m=e=>{const t=e.currentTarget,a=d.indexOf(t),n=u[a].value;n!==i&&(c(t),s(n))},p=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const a=d.indexOf(e.currentTarget)+1;t=d[a]??d[0];break}case"ArrowLeft":{const a=d.indexOf(e.currentTarget)-1;t=d[a]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:o}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:p,onClick:m},o,{className:(0,l.Z)("tabs__item",g.tabItem,o?.className,{"tabs__item--active":i===t})}),a??t)})))}function v(e){let{lazy:t,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",g.tabList)},r.createElement(h,(0,n.Z)({},e,t)),r.createElement(v,(0,n.Z)({},e,t)))}function k(e){const t=(0,y.Z)();return r.createElement(w,(0,n.Z)({key:String(t)},e))}},6179:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var n=a(7462),r=(a(7294),a(3905)),l=a(4866),o=a(5162);const i={title:"Getting started",position:2},s=void 0,u={unversionedId:"intro/getting-started",id:"intro/getting-started",title:"Getting started",description:"Install",source:"@site/docs/intro/02-getting-started.md",sourceDirName:"intro",slug:"/intro/getting-started",permalink:"/docs/intro/getting-started",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/02-getting-started.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:2,frontMatter:{title:"Getting started",position:2},sidebar:"tutorialSidebar",previous:{title:"Introduction",permalink:"/docs/"},next:{title:"How it works",permalink:"/docs/intro/how-it-works"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Usage",id:"usage",level:2},{value:"Example",id:"example",level:2}],m={toc:c},p="wrapper";function f(e){let{components:t,...a}=e;return(0,r.kt)(p,(0,n.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install middy, you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/core\n"))),(0,r.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/core\n"))),(0,r.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/core\n")))),(0,r.kt)("p",null,"If you are using TypeScript, you will also want to make sure that you have installed the ",(0,r.kt)("inlineCode",{parentName:"p"},"@types/aws-lambda")," peer-dependency:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save-dev @types/aws-lambda\n"))),(0,r.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add --dev @types/aws-lambda\n"))),(0,r.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add --save-dev @types/aws-lambda\n")))),(0,r.kt)("h2",{id:"usage"},"Usage"),(0,r.kt)("p",null,"As you will see in the next example, using middy is very\nsimple and requires just few steps:"),(0,r.kt)("ol",null,(0,r.kt)("li",{parentName:"ol"},"Write your Lambda handlers as usual, focusing mostly on implementing the bare\nbusiness logic for them."),(0,r.kt)("li",{parentName:"ol"},"Import ",(0,r.kt)("inlineCode",{parentName:"li"},"middy")," and all the middlewares you want to use."),(0,r.kt)("li",{parentName:"ol"},"Wrap your handler in the ",(0,r.kt)("inlineCode",{parentName:"li"},"middy()")," factory function. This will return a new\nenhanced instance of your original handler, to which you will be able to attach\nthe middlewares you need."),(0,r.kt)("li",{parentName:"ol"},"Attach all the middlewares you need using the function ",(0,r.kt)("inlineCode",{parentName:"li"},".use(somemiddleware())"))),(0,r.kt)("h2",{id:"example"},"Example"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport middleware1 from 'sample-middleware1'\nimport middleware2 from 'sample-middleware2'\nimport middleware3 from 'sample-middleware3'\n\nconst lambdaHandler = (event, context) => {\n /* your business logic */\n}\n\nexport const handler = middy(lambdaHandler)\n\nhandler\n .use(middleware1())\n .use(middleware2())\n .use(middleware3())\n\n")),(0,r.kt)("p",null,(0,r.kt)("inlineCode",{parentName:"p"},".use()")," takes a single middleware or an array of middlewares, so you can attach multiple middlewares in a single call:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},'import middy from "@middy/core"\nimport middleware1 from "sample-middleware1"\nimport middleware2 from "sample-middleware2"\nimport middleware3 from "sample-middleware3"\nconst middlewares = [middleware1(), middleware2(), middleware3()]\n\nconst lambdaHandler = (event, context) => {\n /* your business logic */\n};\n\nexport const handler = middy(lambdaHandler)\n\nhandler.use(middlewares)\n\n')),(0,r.kt)("p",null,"You can also attach ",(0,r.kt)("a",{parentName:"p",href:"#inline-middlewares"},"inline middlewares")," by using the functions ",(0,r.kt)("inlineCode",{parentName:"p"},".before"),", ",(0,r.kt)("inlineCode",{parentName:"p"},".after")," and ",(0,r.kt)("inlineCode",{parentName:"p"},".onError"),"."),(0,r.kt)("p",null,"For a more detailed use case and examples check the ",(0,r.kt)("a",{parentName:"p",href:"#writing-a-middleware"},"Writing a middleware section"),"."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/5e80d65e.f2c4d70b.js b/assets/js/5e80d65e.88487dd4.js similarity index 97% rename from assets/js/5e80d65e.f2c4d70b.js rename to assets/js/5e80d65e.88487dd4.js index 364872c11..ade6ad712 100644 --- a/assets/js/5e80d65e.f2c4d70b.js +++ b/assets/js/5e80d65e.88487dd4.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1436],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var s=n.createContext({}),d=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},p=function(e){var t=d(e.components);return n.createElement(s.Provider,{value:t},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,s=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),c=d(r),f=o,m=c["".concat(s,".").concat(f)]||c[f]||u[f]||i;return r?n.createElement(m,a(a({ref:t},p),{},{components:r})):n.createElement(m,a({ref:t},p))}));function m(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=f;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[c]="string"==typeof e?e:o,a[1]=l;for(var d=2;d{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>l,toc:()=>d});var n=r(7462),o=(r(7294),r(3905));const i={title:"Hooks",position:2},a=void 0,l={unversionedId:"intro/hooks",id:"intro/hooks",title:"Hooks",description:"Middy provides hooks into it's core to allow for monitoring, setup, and cleaning that may not be possible within a middleware.",source:"@site/docs/intro/07-hooks.md",sourceDirName:"intro",slug:"/intro/hooks",permalink:"/docs/intro/hooks",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/07-hooks.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:7,frontMatter:{title:"Hooks",position:2},sidebar:"tutorialSidebar",previous:{title:"Use with TypeScript",permalink:"/docs/intro/typescript"},next:{title:"History",permalink:"/docs/intro/history"}},s={},d=[],p={toc:d},c="wrapper";function u(e){let{components:t,...r}=e;return(0,o.kt)(c,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Middy provides hooks into it's core to allow for monitoring, setup, and cleaning that may not be possible within a middleware."),(0,o.kt)("p",null,"In order of execution"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"beforePrefetch"),"(): Triggered once before middlewares are attached and prefetches are executed."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"requestStart"),"(): Triggered on every request before the first middleware."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"beforeMiddleware"),"/",(0,o.kt)("inlineCode",{parentName:"li"},"afterMiddleware"),"(fctName): Triggered before/after every ",(0,o.kt)("inlineCode",{parentName:"li"},"before"),", ",(0,o.kt)("inlineCode",{parentName:"li"},"after"),", and ",(0,o.kt)("inlineCode",{parentName:"li"},"onError")," middleware function. The function name is passed in, this is why all middlewares use a verbose naming pattern."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"beforeHandler"),"/",(0,o.kt)("inlineCode",{parentName:"li"},"afterHandler"),"(): Triggered before/after the handler."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"requestEnd"),"(request): Triggered right before the response is returned, including thrown errors.")),(0,o.kt)("p",null,"See ",(0,o.kt)("a",{parentName:"p",href:"https://middy.js.org/docs/best-practices/profiling"},"Profiling")," for example usage."))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1436],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var s=n.createContext({}),d=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},p=function(e){var t=d(e.components);return n.createElement(s.Provider,{value:t},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,s=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),c=d(r),f=o,m=c["".concat(s,".").concat(f)]||c[f]||u[f]||i;return r?n.createElement(m,a(a({ref:t},p),{},{components:r})):n.createElement(m,a({ref:t},p))}));function m(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=f;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[c]="string"==typeof e?e:o,a[1]=l;for(var d=2;d{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>l,toc:()=>d});var n=r(7462),o=(r(7294),r(3905));const i={title:"Hooks",position:2},a=void 0,l={unversionedId:"intro/hooks",id:"intro/hooks",title:"Hooks",description:"Middy provides hooks into it's core to allow for monitoring, setup, and cleaning that may not be possible within a middleware.",source:"@site/docs/intro/07-hooks.md",sourceDirName:"intro",slug:"/intro/hooks",permalink:"/docs/intro/hooks",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/07-hooks.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:7,frontMatter:{title:"Hooks",position:2},sidebar:"tutorialSidebar",previous:{title:"Use with TypeScript",permalink:"/docs/intro/typescript"},next:{title:"History",permalink:"/docs/intro/history"}},s={},d=[],p={toc:d},c="wrapper";function u(e){let{components:t,...r}=e;return(0,o.kt)(c,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Middy provides hooks into it's core to allow for monitoring, setup, and cleaning that may not be possible within a middleware."),(0,o.kt)("p",null,"In order of execution"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"beforePrefetch"),"(): Triggered once before middlewares are attached and prefetches are executed."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"requestStart"),"(): Triggered on every request before the first middleware."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"beforeMiddleware"),"/",(0,o.kt)("inlineCode",{parentName:"li"},"afterMiddleware"),"(fctName): Triggered before/after every ",(0,o.kt)("inlineCode",{parentName:"li"},"before"),", ",(0,o.kt)("inlineCode",{parentName:"li"},"after"),", and ",(0,o.kt)("inlineCode",{parentName:"li"},"onError")," middleware function. The function name is passed in, this is why all middlewares use a verbose naming pattern."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"beforeHandler"),"/",(0,o.kt)("inlineCode",{parentName:"li"},"afterHandler"),"(): Triggered before/after the handler."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"requestEnd"),"(request): Triggered right before the response is returned, including thrown errors.")),(0,o.kt)("p",null,"See ",(0,o.kt)("a",{parentName:"p",href:"https://middy.js.org/docs/best-practices/profiling"},"Profiling")," for example usage."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/632f0854.06ec75c4.js b/assets/js/632f0854.f41beb5f.js similarity index 97% rename from assets/js/632f0854.06ec75c4.js rename to assets/js/632f0854.f41beb5f.js index 7247393ae..9f306e2b3 100644 --- a/assets/js/632f0854.06ec75c4.js +++ b/assets/js/632f0854.f41beb5f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9997],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>y});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),d=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},c=function(e){var t=d(e.components);return r.createElement(s.Provider,{value:t},e.children)},m="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),m=d(n),u=a,y=m["".concat(s,".").concat(u)]||m[u]||p[u]||o;return n?r.createElement(y,i(i({ref:t},c),{},{components:n})):r.createElement(y,i({ref:t},c))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[m]="string"==typeof e?e:a,i[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>l,toc:()=>d});var r=n(7462),a=(n(7294),n(3905));const o={title:"Handle Timeouts",position:5},i=void 0,l={unversionedId:"writing-middlewares/timeouts",id:"writing-middlewares/timeouts",title:"Handle Timeouts",description:"When a lambda times out it throws an error that cannot be caught by middy. To work around this middy maintains an AbortController that can be signalled early to allow time to clean up and log the error properly.",source:"@site/docs/writing-middlewares/05-timeouts.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/timeouts",permalink:"/docs/writing-middlewares/timeouts",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/05-timeouts.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:5,frontMatter:{title:"Handle Timeouts",position:5},sidebar:"tutorialSidebar",previous:{title:"Internal Storage",permalink:"/docs/writing-middlewares/internal-storage"},next:{title:"More Examples",permalink:"/docs/writing-middlewares/more-examples"}},s={},d=[],c={toc:d},m="wrapper";function p(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"When a lambda times out it throws an error that cannot be caught by middy. To work around this middy maintains an ",(0,a.kt)("inlineCode",{parentName:"p"},"AbortController")," that can be signalled early to allow time to clean up and log the error properly."),(0,a.kt)("p",null,"You can set ",(0,a.kt)("inlineCode",{parentName:"p"},"timeoutEarlyInMillis")," to 0 to disable this functionality. If you want to override during testing, mock the lambda context to set ",(0,a.kt)("inlineCode",{parentName:"p"},"getRemainingTimeInMillis")," to a function that returns a very large value (e.g. ",(0,a.kt)("inlineCode",{parentName:"p"},"() => 99999"),")."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nconst lambdaHandler = (event, context, {signal}) => {\n signal.onabort = () => {\n // cancel events\n }\n // ... \n}\n\nexport const handler = middy(lambdaHandler, {\n timeoutEarlyInMillis: 50,\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9997],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>y});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),d=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},c=function(e){var t=d(e.components);return r.createElement(s.Provider,{value:t},e.children)},m="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),m=d(n),u=a,y=m["".concat(s,".").concat(u)]||m[u]||p[u]||o;return n?r.createElement(y,i(i({ref:t},c),{},{components:n})):r.createElement(y,i({ref:t},c))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[m]="string"==typeof e?e:a,i[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>l,toc:()=>d});var r=n(7462),a=(n(7294),n(3905));const o={title:"Handle Timeouts",position:5},i=void 0,l={unversionedId:"writing-middlewares/timeouts",id:"writing-middlewares/timeouts",title:"Handle Timeouts",description:"When a lambda times out it throws an error that cannot be caught by middy. To work around this middy maintains an AbortController that can be signalled early to allow time to clean up and log the error properly.",source:"@site/docs/writing-middlewares/05-timeouts.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/timeouts",permalink:"/docs/writing-middlewares/timeouts",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/05-timeouts.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:5,frontMatter:{title:"Handle Timeouts",position:5},sidebar:"tutorialSidebar",previous:{title:"Internal Storage",permalink:"/docs/writing-middlewares/internal-storage"},next:{title:"More Examples",permalink:"/docs/writing-middlewares/more-examples"}},s={},d=[],c={toc:d},m="wrapper";function p(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"When a lambda times out it throws an error that cannot be caught by middy. To work around this middy maintains an ",(0,a.kt)("inlineCode",{parentName:"p"},"AbortController")," that can be signalled early to allow time to clean up and log the error properly."),(0,a.kt)("p",null,"You can set ",(0,a.kt)("inlineCode",{parentName:"p"},"timeoutEarlyInMillis")," to 0 to disable this functionality. If you want to override during testing, mock the lambda context to set ",(0,a.kt)("inlineCode",{parentName:"p"},"getRemainingTimeInMillis")," to a function that returns a very large value (e.g. ",(0,a.kt)("inlineCode",{parentName:"p"},"() => 99999"),")."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nconst lambdaHandler = (event, context, {signal}) => {\n signal.onabort = () => {\n // cancel events\n }\n // ... \n}\n\nexport const handler = middy(lambdaHandler, {\n timeoutEarlyInMillis: 50,\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/646b055a.c24ecd6d.js b/assets/js/646b055a.6b13b76d.js similarity index 96% rename from assets/js/646b055a.c24ecd6d.js rename to assets/js/646b055a.6b13b76d.js index ba3b744a4..2e779ec08 100644 --- a/assets/js/646b055a.c24ecd6d.js +++ b/assets/js/646b055a.6b13b76d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5686],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),d=l(n),u=a,f=d["".concat(s,".").concat(u)]||d[u]||m[u]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[d]="string"==typeof e?e:a,i[1]=c;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"S3 Batch"},i=void 0,c={unversionedId:"events/s3-batch",id:"events/s3-batch",title:"S3 Batch",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/s3-batch.md",sourceDirName:"events",slug:"/events/s3-batch",permalink:"/docs/events/s3-batch",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3-batch.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"S3 Batch"},sidebar:"tutorialSidebar",previous:{title:"RDS",permalink:"/docs/events/rds"},next:{title:"S3 Object",permalink:"/docs/events/s3-object"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},d="wrapper";function m(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-s3-batch.html"},"Using AWS Lambda with Amazon S3 batch operations"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5686],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),d=l(n),u=a,f=d["".concat(s,".").concat(u)]||d[u]||m[u]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[d]="string"==typeof e?e:a,i[1]=c;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"S3 Batch"},i=void 0,c={unversionedId:"events/s3-batch",id:"events/s3-batch",title:"S3 Batch",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/s3-batch.md",sourceDirName:"events",slug:"/events/s3-batch",permalink:"/docs/events/s3-batch",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3-batch.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"S3 Batch"},sidebar:"tutorialSidebar",previous:{title:"RDS",permalink:"/docs/events/rds"},next:{title:"S3 Object",permalink:"/docs/events/s3-object"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},d="wrapper";function m(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-s3-batch.html"},"Using AWS Lambda with Amazon S3 batch operations"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/654635c7.9b67527b.js b/assets/js/654635c7.f9656a69.js similarity index 98% rename from assets/js/654635c7.9b67527b.js rename to assets/js/654635c7.f9656a69.js index 5e41eff56..50f788467 100644 --- a/assets/js/654635c7.9b67527b.js +++ b/assets/js/654635c7.f9656a69.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1338],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var u=n.createContext({}),s=function(e){var t=n.useContext(u),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},d=function(e){var t=s(e.components);return n.createElement(u.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,u=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),c=s(r),m=a,h=c["".concat(u,".").concat(m)]||c[m]||p[m]||l;return r?n.createElement(h,o(o({ref:t},d),{},{components:r})):n.createElement(h,o({ref:t},d))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=m;var i={};for(var u in t)hasOwnProperty.call(t,u)&&(i[u]=t[u]);i.originalType=e,i[c]="string"==typeof e?e:a,o[1]=i;for(var s=2;s{r.d(t,{Z:()=>o});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>N});var n=r(7462),a=r(7294),l=r(6010),o=r(2466),i=r(6550),u=r(1980),s=r(7392),d=r(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function p(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:r}=e;const n=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,u._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=p(e),[o,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[u,s]=h({queryString:r,groupId:n}),[c,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),b=(()=>{const e=u??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),s(e),f(e)}),[s,f,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:i,selectValue:u,tabValues:s}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),p=e=>{const t=e.currentTarget,r=d.indexOf(t),n=s[r].value;n!==i&&(c(t),u(n))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},s.map((e=>{let{value:t,label:r,attributes:o}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":i===t})}),r??t)})))}function k(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function g(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(k,(0,n.Z)({},e,t)))}function N(e){const t=(0,b.Z)();return a.createElement(g,(0,n.Z)({key:String(t)},e))}},3423:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>u,default:()=>h,frontMatter:()=>i,metadata:()=>s,toc:()=>c});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),o=r(5162);const i={title:"http-router"},u=void 0,s={unversionedId:"routers/http-router",id:"routers/http-router",title:"http-router",description:"This handler can route to requests to one of a nested handler based on method and path of an http event from API Gateway (REST or HTTP) or Elastic Load Balancer.",source:"@site/docs/routers/http-router.md",sourceDirName:"routers",slug:"/routers/http-router",permalink:"/docs/routers/http-router",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/routers/http-router.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-router"},sidebar:"tutorialSidebar",previous:{title:"Routers",permalink:"/docs/category/routers"},next:{title:"ws-router",permalink:"/docs/routers/ws-router"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:c},m="wrapper";function h(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This handler can route to requests to one of a nested handler based on ",(0,a.kt)("inlineCode",{parentName:"p"},"method")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"path")," of an http event from API Gateway (REST or HTTP) or Elastic Load Balancer."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-router\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-router\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-router\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"routes")," (array","[{method, path, handler}]",") (required): Array of route objects.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"method")," (string) (required): One of ",(0,a.kt)("inlineCode",{parentName:"li"},"GET"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"POST"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"PUT"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"PATCH"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"DELETE"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"OPTIONS")," and ",(0,a.kt)("inlineCode",{parentName:"li"},"ANY")," that will match to any method passed in"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"path")," (string) (required): AWS formatted path starting with ",(0,a.kt)("inlineCode",{parentName:"li"},"/"),". Variable: ",(0,a.kt)("inlineCode",{parentName:"li"},"/{id}/"),", Wildcard: ",(0,a.kt)("inlineCode",{parentName:"li"},"/{proxy+}")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"handler")," (function) (required): Any ",(0,a.kt)("inlineCode",{parentName:"li"},"handler(event, context)")," function")))),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"When using API Gateway it may be required to prefix ",(0,a.kt)("inlineCode",{parentName:"li"},"routes[].path")," with ",(0,a.kt)("inlineCode",{parentName:"li"},"/{stage}")," depending on your use case."),(0,a.kt)("li",{parentName:"ul"},"Errors should be handled as part of the router middleware stack ",(0,a.kt)("strong",{parentName:"li"},"or")," the lambdaHandler middleware stack. Handled errors in the later will trigger the ",(0,a.kt)("inlineCode",{parentName:"li"},"after")," middleware stack of the former."),(0,a.kt)("li",{parentName:"ul"},"Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"pathParameters")," will automatically be set if not already set")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpRouterHandler from '@middy/http-router'\nimport validatorMiddleware from '@middy/validator'\n\nconst getHandler = middy()\n .use(validatorMiddleware({eventSchema: {...} }))\n .handler((event, context) => {\n return {\n statusCode: 200,\n body: '{...}'\n }\n })\n\nconst postHandler = middy()\n .use(validatorMiddleware({eventSchema: {...} }))\n .handler((event, context) => {\n return {\n statusCode: 200,\n body: '{...}'\n }\n })\n\nconst routes = [\n {\n method: 'GET',\n path: '/user/{id}',\n handler: getHandler\n },\n {\n method: 'POST',\n path: '/user',\n handler: postHandler\n }\n]\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .handler(httpRouterHandler(routes))\n\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1338],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var u=n.createContext({}),s=function(e){var t=n.useContext(u),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},d=function(e){var t=s(e.components);return n.createElement(u.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,u=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),c=s(r),m=a,h=c["".concat(u,".").concat(m)]||c[m]||p[m]||l;return r?n.createElement(h,o(o({ref:t},d),{},{components:r})):n.createElement(h,o({ref:t},d))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=m;var i={};for(var u in t)hasOwnProperty.call(t,u)&&(i[u]=t[u]);i.originalType=e,i[c]="string"==typeof e?e:a,o[1]=i;for(var s=2;s{r.d(t,{Z:()=>o});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>N});var n=r(7462),a=r(7294),l=r(6010),o=r(2466),i=r(6550),u=r(1980),s=r(7392),d=r(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function p(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:r}=e;const n=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,u._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=p(e),[o,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[u,s]=h({queryString:r,groupId:n}),[c,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),b=(()=>{const e=u??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),s(e),f(e)}),[s,f,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:i,selectValue:u,tabValues:s}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),p=e=>{const t=e.currentTarget,r=d.indexOf(t),n=s[r].value;n!==i&&(c(t),u(n))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},s.map((e=>{let{value:t,label:r,attributes:o}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":i===t})}),r??t)})))}function k(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function g(e){const t=f(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(k,(0,n.Z)({},e,t)))}function N(e){const t=(0,b.Z)();return a.createElement(g,(0,n.Z)({key:String(t)},e))}},3423:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>u,default:()=>h,frontMatter:()=>i,metadata:()=>s,toc:()=>c});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),o=r(5162);const i={title:"http-router"},u=void 0,s={unversionedId:"routers/http-router",id:"routers/http-router",title:"http-router",description:"This handler can route to requests to one of a nested handler based on method and path of an http event from API Gateway (REST or HTTP) or Elastic Load Balancer.",source:"@site/docs/routers/http-router.md",sourceDirName:"routers",slug:"/routers/http-router",permalink:"/docs/routers/http-router",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/routers/http-router.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-router"},sidebar:"tutorialSidebar",previous:{title:"Routers",permalink:"/docs/category/routers"},next:{title:"ws-router",permalink:"/docs/routers/ws-router"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:c},m="wrapper";function h(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This handler can route to requests to one of a nested handler based on ",(0,a.kt)("inlineCode",{parentName:"p"},"method")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"path")," of an http event from API Gateway (REST or HTTP) or Elastic Load Balancer."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-router\n"))),(0,a.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-router\n"))),(0,a.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-router\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"routes")," (array","[{method, path, handler}]",") (required): Array of route objects.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"method")," (string) (required): One of ",(0,a.kt)("inlineCode",{parentName:"li"},"GET"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"POST"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"PUT"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"PATCH"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"DELETE"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"OPTIONS")," and ",(0,a.kt)("inlineCode",{parentName:"li"},"ANY")," that will match to any method passed in"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"path")," (string) (required): AWS formatted path starting with ",(0,a.kt)("inlineCode",{parentName:"li"},"/"),". Variable: ",(0,a.kt)("inlineCode",{parentName:"li"},"/{id}/"),", Wildcard: ",(0,a.kt)("inlineCode",{parentName:"li"},"/{proxy+}")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"handler")," (function) (required): Any ",(0,a.kt)("inlineCode",{parentName:"li"},"handler(event, context)")," function")))),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"When using API Gateway it may be required to prefix ",(0,a.kt)("inlineCode",{parentName:"li"},"routes[].path")," with ",(0,a.kt)("inlineCode",{parentName:"li"},"/{stage}")," depending on your use case."),(0,a.kt)("li",{parentName:"ul"},"Errors should be handled as part of the router middleware stack ",(0,a.kt)("strong",{parentName:"li"},"or")," the lambdaHandler middleware stack. Handled errors in the later will trigger the ",(0,a.kt)("inlineCode",{parentName:"li"},"after")," middleware stack of the former."),(0,a.kt)("li",{parentName:"ul"},"Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"pathParameters")," will automatically be set if not already set")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpRouterHandler from '@middy/http-router'\nimport validatorMiddleware from '@middy/validator'\n\nconst getHandler = middy()\n .use(validatorMiddleware({eventSchema: {...} }))\n .handler((event, context) => {\n return {\n statusCode: 200,\n body: '{...}'\n }\n })\n\nconst postHandler = middy()\n .use(validatorMiddleware({eventSchema: {...} }))\n .handler((event, context) => {\n return {\n statusCode: 200,\n body: '{...}'\n }\n })\n\nconst routes = [\n {\n method: 'GET',\n path: '/user/{id}',\n handler: getHandler\n },\n {\n method: 'POST',\n path: '/user',\n handler: postHandler\n }\n]\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .handler(httpRouterHandler(routes))\n\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/65ce35be.afe6c4e9.js b/assets/js/65ce35be.cbc94891.js similarity index 97% rename from assets/js/65ce35be.afe6c4e9.js rename to assets/js/65ce35be.cbc94891.js index 0e4da1d0c..41308b5fb 100644 --- a/assets/js/65ce35be.afe6c4e9.js +++ b/assets/js/65ce35be.cbc94891.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8002],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),c=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=c(e.components);return a.createElement(s.Provider,{value:t},e.children)},p="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},u=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,o=e.originalType,s=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),p=c(n),u=r,f=p["".concat(s,".").concat(u)]||p[u]||m[u]||o;return n?a.createElement(f,i(i({ref:t},d),{},{components:n})):a.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=n.length,i=new Array(o);i[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:r,i[1]=l;for(var c=2;c{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>l,toc:()=>c});var a=n(7462),r=(n(7294),n(3905));const o={title:"Kafka, Self-Managed"},i=void 0,l={unversionedId:"events/kafka-self-managed",id:"events/kafka-self-managed",title:"Kafka, Self-Managed",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/kafka-self-managed.md",sourceDirName:"events",slug:"/events/kafka-self-managed",permalink:"/docs/events/kafka-self-managed",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kafka-self-managed.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Kafka, Self-Managed"},sidebar:"tutorialSidebar",previous:{title:"Kafka, Managed Streaming (MSK)",permalink:"/docs/events/kafka-managed-streaming"},next:{title:"Kinesis Firehose",permalink:"/docs/events/kinesis-firehose"}},s={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],d={toc:c},p="wrapper";function m(e){let{components:t,...n}=e;return(0,r.kt)(p,(0,a.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,r.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html"},"Using Lambda with self-managed Apache Kafka"))),(0,r.kt)("h2",{id:"example"},"Example"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8002],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),c=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=c(e.components);return a.createElement(s.Provider,{value:t},e.children)},p="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},u=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,o=e.originalType,s=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),p=c(n),u=r,f=p["".concat(s,".").concat(u)]||p[u]||m[u]||o;return n?a.createElement(f,i(i({ref:t},d),{},{components:n})):a.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=n.length,i=new Array(o);i[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:r,i[1]=l;for(var c=2;c{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>l,toc:()=>c});var a=n(7462),r=(n(7294),n(3905));const o={title:"Kafka, Self-Managed"},i=void 0,l={unversionedId:"events/kafka-self-managed",id:"events/kafka-self-managed",title:"Kafka, Self-Managed",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/kafka-self-managed.md",sourceDirName:"events",slug:"/events/kafka-self-managed",permalink:"/docs/events/kafka-self-managed",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kafka-self-managed.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Kafka, Self-Managed"},sidebar:"tutorialSidebar",previous:{title:"Kafka, Managed Streaming (MSK)",permalink:"/docs/events/kafka-managed-streaming"},next:{title:"Kinesis Firehose",permalink:"/docs/events/kinesis-firehose"}},s={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],d={toc:c},p="wrapper";function m(e){let{components:t,...n}=e;return(0,r.kt)(p,(0,a.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,r.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html"},"Using Lambda with self-managed Apache Kafka"))),(0,r.kt)("h2",{id:"example"},"Example"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/667584a0.3ef7e5a9.js b/assets/js/667584a0.4a33e357.js similarity index 98% rename from assets/js/667584a0.3ef7e5a9.js rename to assets/js/667584a0.4a33e357.js index f17ddf9cc..31d5c0bde 100644 --- a/assets/js/667584a0.3ef7e5a9.js +++ b/assets/js/667584a0.4a33e357.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2600],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(n),u=a,f=d["".concat(l,".").concat(u)]||d[u]||m[u]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"SNS"},i=void 0,s={unversionedId:"events/sns",id:"events/sns",title:"SNS",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/sns.md",sourceDirName:"events",slug:"/events/sns",permalink:"/docs/events/sns",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/sns.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"SNS"},sidebar:"tutorialSidebar",previous:{title:"SES",permalink:"/docs/events/ses"},next:{title:"SQS",permalink:"/docs/events/sqs"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},d="wrapper";function m(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html"},"Using AWS Lambda with Amazon SNS"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2600],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(n),u=a,f=d["".concat(l,".").concat(u)]||d[u]||m[u]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"SNS"},i=void 0,s={unversionedId:"events/sns",id:"events/sns",title:"SNS",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/sns.md",sourceDirName:"events",slug:"/events/sns",permalink:"/docs/events/sns",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/sns.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"SNS"},sidebar:"tutorialSidebar",previous:{title:"SES",permalink:"/docs/events/ses"},next:{title:"SQS",permalink:"/docs/events/sqs"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},d="wrapper";function m(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html"},"Using AWS Lambda with Amazon SNS"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/68318e94.6c455450.js b/assets/js/68318e94.e3d34195.js similarity index 98% rename from assets/js/68318e94.6c455450.js rename to assets/js/68318e94.e3d34195.js index 5675688a9..c4ecdd7ac 100644 --- a/assets/js/68318e94.6c455450.js +++ b/assets/js/68318e94.e3d34195.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[811],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>y});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function i(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var l=a.createContext({}),s=function(e){var t=a.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},c=function(e){var t=s(e.components);return a.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,l=e.parentName,c=p(e,["components","mdxType","originalType","parentName"]),u=s(r),m=n,y=u["".concat(l,".").concat(m)]||u[m]||d[m]||o;return r?a.createElement(y,i(i({ref:t},c),{},{components:r})):a.createElement(y,i({ref:t},c))}));function y(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,i=new Array(o);i[0]=m;var p={};for(var l in t)hasOwnProperty.call(t,l)&&(p[l]=t[l]);p.originalType=e,p[u]="string"==typeof e?e:n,i[1]=p;for(var s=2;s{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>p,toc:()=>s});var a=r(7462),n=(r(7294),r(3905));const o={title:"API Gateway Authorizer"},i=void 0,p={unversionedId:"events/api-gateway-authorizer",id:"events/api-gateway-authorizer",title:"API Gateway Authorizer",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/api-gateway-authorizer.md",sourceDirName:"events",slug:"/events/api-gateway-authorizer",permalink:"/docs/events/api-gateway-authorizer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-authorizer.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"API Gateway Authorizer"},sidebar:"tutorialSidebar",previous:{title:"Alexa",permalink:"/docs/events/alexa"},next:{title:"API Gateway (HTTP)",permalink:"/docs/events/api-gateway-http"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],c={toc:s},u="wrapper";function d(e){let{components:t,...r}=e;return(0,n.kt)(u,(0,a.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("admonition",{type:"caution"},(0,n.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,n.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html"},"Working with AWS Lambda authorizers for HTTP APIs")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html"},"Input to an Amazon API Gateway Lambda authorizer"))),(0,n.kt)("h2",{id:"example"},"Example"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[811],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>y});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function i(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var l=a.createContext({}),s=function(e){var t=a.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},c=function(e){var t=s(e.components);return a.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,l=e.parentName,c=p(e,["components","mdxType","originalType","parentName"]),u=s(r),m=n,y=u["".concat(l,".").concat(m)]||u[m]||d[m]||o;return r?a.createElement(y,i(i({ref:t},c),{},{components:r})):a.createElement(y,i({ref:t},c))}));function y(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,i=new Array(o);i[0]=m;var p={};for(var l in t)hasOwnProperty.call(t,l)&&(p[l]=t[l]);p.originalType=e,p[u]="string"==typeof e?e:n,i[1]=p;for(var s=2;s{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>p,toc:()=>s});var a=r(7462),n=(r(7294),r(3905));const o={title:"API Gateway Authorizer"},i=void 0,p={unversionedId:"events/api-gateway-authorizer",id:"events/api-gateway-authorizer",title:"API Gateway Authorizer",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/api-gateway-authorizer.md",sourceDirName:"events",slug:"/events/api-gateway-authorizer",permalink:"/docs/events/api-gateway-authorizer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-authorizer.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"API Gateway Authorizer"},sidebar:"tutorialSidebar",previous:{title:"Alexa",permalink:"/docs/events/alexa"},next:{title:"API Gateway (HTTP)",permalink:"/docs/events/api-gateway-http"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],c={toc:s},u="wrapper";function d(e){let{components:t,...r}=e;return(0,n.kt)(u,(0,a.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("admonition",{type:"caution"},(0,n.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,n.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html"},"Working with AWS Lambda authorizers for HTTP APIs")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html"},"Input to an Amazon API Gateway Lambda authorizer"))),(0,n.kt)("h2",{id:"example"},"Example"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/687b60fb.de65fabf.js b/assets/js/687b60fb.ed2ed99b.js similarity index 98% rename from assets/js/687b60fb.de65fabf.js rename to assets/js/687b60fb.ed2ed99b.js index 474e965b9..fee9d9221 100644 --- a/assets/js/687b60fb.de65fabf.js +++ b/assets/js/687b60fb.ed2ed99b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7783],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>u});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function o(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var p=n.createContext({}),l=function(e){var t=n.useContext(p),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},m=function(e){var t=l(e.components);return n.createElement(p.Provider,{value:t},e.children)},s="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},h=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,i=e.originalType,p=e.parentName,m=d(e,["components","mdxType","originalType","parentName"]),s=l(a),h=r,u=s["".concat(p,".").concat(h)]||s[h]||c[h]||i;return a?n.createElement(u,o(o({ref:t},m),{},{components:a})):n.createElement(u,o({ref:t},m))}));function u(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=a.length,o=new Array(i);o[0]=h;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[s]="string"==typeof e?e:r,o[1]=d;for(var l=2;l{a.r(t),a.d(t,{assets:()=>p,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var n=a(7462),r=(a(7294),a(3905));const i={title:"Upgrade 0.x -> 1.x",sidebar_position:1e4},o=void 0,d={unversionedId:"upgrade/0-1",id:"upgrade/0-1",title:"Upgrade 0.x -> 1.x",description:"Independent packages structure",source:"@site/docs/upgrade/0-1.md",sourceDirName:"upgrade",slug:"/upgrade/0-1",permalink:"/docs/upgrade/0-1",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/0-1.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:1e4,frontMatter:{title:"Upgrade 0.x -> 1.x",sidebar_position:1e4},sidebar:"tutorialSidebar",previous:{title:"Upgrade 1.x -> 2.x",permalink:"/docs/upgrade/1-2"},next:{title:"AWS Event Examples",permalink:"/docs/category/aws-event-examples"}},p={},l=[{value:"Independent packages structure",id:"independent-packages-structure",level:2},{value:"Header normalization in http-header-normalizer",id:"header-normalization-in-http-header-normalizer",level:2},{value:"Node.js 10 and 12 now supported / Node.js 6 and 8 now dropped",id:"nodejs-10-and-12-now-supported--nodejs-6-and-8-now-dropped",level:2}],m={toc:l},s="wrapper";function c(e){let{components:t,...a}=e;return(0,r.kt)(s,(0,n.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h2",{id:"independent-packages-structure"},"Independent packages structure"),(0,r.kt)("p",null,"Version 1.x of Middy features decoupled independent packages published on npm under the ",(0,r.kt)("inlineCode",{parentName:"p"},"@middy")," namespace. The core middleware engine has been moved to ",(0,r.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/@middy/core"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/core"))," and all the other middlewares are moved into their own packages as well. This allows to only install the features that are needed and to keep your Lambda dependencies small. See the list below to check which packages you need based on the middlewares you use:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Core middleware functionality -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/core"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/core"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cache")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/cache"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/cache"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cors")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-cors"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-cors"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"doNotWaitForEmptyEventLoop")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/do-not-wait-for-empty-event-loop"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/do-not-wait-for-empty-event-loop"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpContentNegotiation")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-content-negotiation"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-content-negotiation"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpErrorHandler")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-error-handler"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-error-handler"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpEventNormalizer")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-event-normalizer"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-event-normalizer"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpHeaderNormalizer")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-header-normalizer"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-header-normalizer"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpMultipartBodyParser")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-json-body-parser"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-json-body-parser"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpPartialResponse")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-partial-response"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-partial-response"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"jsonBodyParser")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-json-body-parser"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-json-body-parser"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"s3KeyNormalizer")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/s3-key-normalizer"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/s3-key-normalizer"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"secretsManager")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/secrets-manager"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/secrets-manager"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ssm")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/ssm"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/ssm"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"validator")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/validator"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/validator"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"urlEncodeBodyParser")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-urlencode-body-parser"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-urlencode-body-parser"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"warmup")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/warmup"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/warmup")))),(0,r.kt)("h2",{id:"header-normalization-in-http-header-normalizer"},"Header normalization in ",(0,r.kt)("inlineCode",{parentName:"h2"},"http-header-normalizer")),(0,r.kt)("p",null,"In Middy 0.x the ",(0,r.kt)("inlineCode",{parentName:"p"},"httpHeaderNormalizer")," middleware normalizes HTTP header names into their own canonical format, for instance ",(0,r.kt)("inlineCode",{parentName:"p"},"Sec-WebSocket-Key")," (notice the casing). In Middy 1.x this behavior has been changed to provide header names in lowercase format (e.g. ",(0,r.kt)("inlineCode",{parentName:"p"},"sec-webSocket-key"),"). This new behavior is more consistent with what Node.js core ",(0,r.kt)("inlineCode",{parentName:"p"},"http")," package does and what other famous http frameworks like Express or Fastify do, so this is considered a more intuitive approach.\nWhen updating to Middy 1.x, make sure you double check all your references to HTTP headers and switch to the lowercase version to read them.\nAll the middy core modules have been already updated to support the new format, so you should worry only about your userland code."),(0,r.kt)("h2",{id:"nodejs-10-and-12-now-supported--nodejs-6-and-8-now-dropped"},"Node.js 10 and 12 now supported / Node.js 6 and 8 now dropped"),(0,r.kt)("p",null,"Version 1.x of Middy no longer supports Node.js versions 6.x and 8.x as these versions have been dropped by the AWS Lambda runtime itself and not supported anymore by the Node.js community. You are highly encouraged to move to Node.js 12 or 10, which are the new supported versions in Middy 1.x."))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7783],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>u});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function o(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var p=n.createContext({}),l=function(e){var t=n.useContext(p),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},m=function(e){var t=l(e.components);return n.createElement(p.Provider,{value:t},e.children)},s="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},h=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,i=e.originalType,p=e.parentName,m=d(e,["components","mdxType","originalType","parentName"]),s=l(a),h=r,u=s["".concat(p,".").concat(h)]||s[h]||c[h]||i;return a?n.createElement(u,o(o({ref:t},m),{},{components:a})):n.createElement(u,o({ref:t},m))}));function u(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=a.length,o=new Array(i);o[0]=h;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[s]="string"==typeof e?e:r,o[1]=d;for(var l=2;l{a.r(t),a.d(t,{assets:()=>p,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var n=a(7462),r=(a(7294),a(3905));const i={title:"Upgrade 0.x -> 1.x",sidebar_position:1e4},o=void 0,d={unversionedId:"upgrade/0-1",id:"upgrade/0-1",title:"Upgrade 0.x -> 1.x",description:"Independent packages structure",source:"@site/docs/upgrade/0-1.md",sourceDirName:"upgrade",slug:"/upgrade/0-1",permalink:"/docs/upgrade/0-1",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/0-1.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:1e4,frontMatter:{title:"Upgrade 0.x -> 1.x",sidebar_position:1e4},sidebar:"tutorialSidebar",previous:{title:"Upgrade 1.x -> 2.x",permalink:"/docs/upgrade/1-2"},next:{title:"AWS Event Examples",permalink:"/docs/category/aws-event-examples"}},p={},l=[{value:"Independent packages structure",id:"independent-packages-structure",level:2},{value:"Header normalization in http-header-normalizer",id:"header-normalization-in-http-header-normalizer",level:2},{value:"Node.js 10 and 12 now supported / Node.js 6 and 8 now dropped",id:"nodejs-10-and-12-now-supported--nodejs-6-and-8-now-dropped",level:2}],m={toc:l},s="wrapper";function c(e){let{components:t,...a}=e;return(0,r.kt)(s,(0,n.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h2",{id:"independent-packages-structure"},"Independent packages structure"),(0,r.kt)("p",null,"Version 1.x of Middy features decoupled independent packages published on npm under the ",(0,r.kt)("inlineCode",{parentName:"p"},"@middy")," namespace. The core middleware engine has been moved to ",(0,r.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/@middy/core"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/core"))," and all the other middlewares are moved into their own packages as well. This allows to only install the features that are needed and to keep your Lambda dependencies small. See the list below to check which packages you need based on the middlewares you use:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Core middleware functionality -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/core"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/core"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cache")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/cache"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/cache"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cors")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-cors"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-cors"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"doNotWaitForEmptyEventLoop")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/do-not-wait-for-empty-event-loop"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/do-not-wait-for-empty-event-loop"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpContentNegotiation")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-content-negotiation"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-content-negotiation"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpErrorHandler")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-error-handler"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-error-handler"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpEventNormalizer")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-event-normalizer"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-event-normalizer"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpHeaderNormalizer")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-header-normalizer"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-header-normalizer"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpMultipartBodyParser")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-json-body-parser"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-json-body-parser"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"httpPartialResponse")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-partial-response"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-partial-response"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"jsonBodyParser")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-json-body-parser"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-json-body-parser"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"s3KeyNormalizer")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/s3-key-normalizer"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/s3-key-normalizer"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"secretsManager")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/secrets-manager"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/secrets-manager"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ssm")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/ssm"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/ssm"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"validator")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/validator"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/validator"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"urlEncodeBodyParser")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/http-urlencode-body-parser"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/http-urlencode-body-parser"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"warmup")," -> ",(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@middy/warmup"},(0,r.kt)("inlineCode",{parentName:"a"},"@middy/warmup")))),(0,r.kt)("h2",{id:"header-normalization-in-http-header-normalizer"},"Header normalization in ",(0,r.kt)("inlineCode",{parentName:"h2"},"http-header-normalizer")),(0,r.kt)("p",null,"In Middy 0.x the ",(0,r.kt)("inlineCode",{parentName:"p"},"httpHeaderNormalizer")," middleware normalizes HTTP header names into their own canonical format, for instance ",(0,r.kt)("inlineCode",{parentName:"p"},"Sec-WebSocket-Key")," (notice the casing). In Middy 1.x this behavior has been changed to provide header names in lowercase format (e.g. ",(0,r.kt)("inlineCode",{parentName:"p"},"sec-webSocket-key"),"). This new behavior is more consistent with what Node.js core ",(0,r.kt)("inlineCode",{parentName:"p"},"http")," package does and what other famous http frameworks like Express or Fastify do, so this is considered a more intuitive approach.\nWhen updating to Middy 1.x, make sure you double check all your references to HTTP headers and switch to the lowercase version to read them.\nAll the middy core modules have been already updated to support the new format, so you should worry only about your userland code."),(0,r.kt)("h2",{id:"nodejs-10-and-12-now-supported--nodejs-6-and-8-now-dropped"},"Node.js 10 and 12 now supported / Node.js 6 and 8 now dropped"),(0,r.kt)("p",null,"Version 1.x of Middy no longer supports Node.js versions 6.x and 8.x as these versions have been dropped by the AWS Lambda runtime itself and not supported anymore by the Node.js community. You are highly encouraged to move to Node.js 12 or 10, which are the new supported versions in Middy 1.x."))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/6a1376e9.161bf142.js b/assets/js/6a1376e9.8cd23557.js similarity index 99% rename from assets/js/6a1376e9.161bf142.js rename to assets/js/6a1376e9.8cd23557.js index 74c24c1d3..59857b338 100644 --- a/assets/js/6a1376e9.161bf142.js +++ b/assets/js/6a1376e9.8cd23557.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8644],{3905:(e,t,a)=>{a.d(t,{Zo:()=>c,kt:()=>f});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function s(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var i=r.createContext({}),u=function(e){var t=r.useContext(i),a=t;return e&&(a="function"==typeof e?e(t):s(s({},t),e)),a},c=function(e){var t=u(e.components);return r.createElement(i.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,l=e.originalType,i=e.parentName,c=o(e,["components","mdxType","originalType","parentName"]),d=u(a),m=n,f=d["".concat(i,".").concat(m)]||d[m]||p[m]||l;return a?r.createElement(f,s(s({ref:t},c),{},{components:a})):r.createElement(f,s({ref:t},c))}));function f(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=a.length,s=new Array(l);s[0]=m;var o={};for(var i in t)hasOwnProperty.call(t,i)&&(o[i]=t[i]);o.originalType=e,o[d]="string"==typeof e?e:n,s[1]=o;for(var u=2;u{a.d(t,{Z:()=>s});var r=a(7294),n=a(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:a,className:s}=e;return r.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,s),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var r=a(7462),n=a(7294),l=a(6010),s=a(2466),o=a(6550),i=a(1980),u=a(7392),c=a(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:r,default:n}}=e;return{value:t,label:a,attributes:r,default:n}}))}function p(e){const{values:t,children:a}=e;return(0,n.useMemo)((()=>{const e=t??d(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function m(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const r=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,i._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function b(e){const{defaultValue:t,queryString:a=!1,groupId:r}=e,l=p(e),[s,o]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=a.find((e=>e.default))??a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[i,u]=f({queryString:a,groupId:r}),[d,b]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(a);return[r,(0,n.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:r}),h=(()=>{const e=i??d;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{h&&o(h)}),[h]);return{selectedValue:s,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var h=a(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:a,selectedValue:o,selectValue:i,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),p=e=>{const t=e.currentTarget,a=c.indexOf(t),r=u[a].value;r!==o&&(d(t),i(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const a=c.indexOf(e.currentTarget)+1;t=c[a]??c[0];break}case"ArrowLeft":{const a=c.indexOf(e.currentTarget)-1;t=c[a]??c[c.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:s}=e;return n.createElement("li",(0,r.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},s,{className:(0,l.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":o===t})}),a??t)})))}function g(e){let{lazy:t,children:a,selectedValue:r}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function k(e){const t=b(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,r.Z)({},e,t)),n.createElement(g,(0,r.Z)({},e,t)))}function w(e){const t=(0,h.Z)();return n.createElement(k,(0,r.Z)({key:String(t)},e))}},7886:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var r=a(7462),n=(a(7294),a(3905)),l=a(4866),s=a(5162);const o={title:"sqs-partial-batch-failure"},i=void 0,u={unversionedId:"middlewares/sqs-partial-batch-failure",id:"middlewares/sqs-partial-batch-failure",title:"sqs-partial-batch-failure",description:"Middleware for handling partially failed SQS batches.",source:"@site/docs/middlewares/sqs-partial-batch-failure.md",sourceDirName:"middlewares",slug:"/middlewares/sqs-partial-batch-failure",permalink:"/docs/middlewares/sqs-partial-batch-failure",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/sqs-partial-batch-failure.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"sqs-partial-batch-failure"},sidebar:"tutorialSidebar",previous:{title:"service-discovery",permalink:"/docs/middlewares/service-discovery"},next:{title:"ssm",permalink:"/docs/middlewares/ssm"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Important",id:"important",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},p,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Middleware for handling partially failed SQS batches."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/sqs-partial-batch-failure\n# Required for types only\nnpm install --save-dev @aws-sdk/client-sqs\n"))),(0,n.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/sqs-partial-batch-failure\n# Required for types only\nyarn add --dev @aws-sdk/client-sqs\n"))),(0,n.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/sqs-partial-batch-failure\n# Required for types only\npnpm add --save-dev @aws-sdk/client-sqs\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"logger")," (function) (optional): A function that will be called when a record fails to be processed. Default: ",(0,n.kt)("inlineCode",{parentName:"li"},"console.error"))),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport sqsBatch from '@middy/sqs-partial-batch-failure'\n\nconst lambdaHandler = (event, context) => {\n const recordPromises = event.Records.map(async (record, index) => {\n /* Custom message processing logic */\n return record\n })\n return Promise.allSettled(recordPromises)\n}\n\nexport const handler = middy(lambdaHandler).use(sqsBatch())\n")),(0,n.kt)("h2",{id:"important"},"Important"),(0,n.kt)("p",null,"The value ",(0,n.kt)("inlineCode",{parentName:"p"},"ReportBatchItemFailures")," must be added to your Lambda's ",(0,n.kt)("inlineCode",{parentName:"p"},"FunctionResponseTypes")," in the ",(0,n.kt)("inlineCode",{parentName:"p"},"EventSourceMapping"),". See ",(0,n.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting"},"Reporting batch item failures")," and ",(0,n.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html"},"Lambda EventSourceMapping")),(0,n.kt)("p",null,"When being used with ",(0,n.kt)("inlineCode",{parentName:"p"},"@middy/validator"),", ensure errors are caught and handled properly to avoid infinite loops."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8644],{3905:(e,t,a)=>{a.d(t,{Zo:()=>c,kt:()=>f});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function s(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var i=r.createContext({}),u=function(e){var t=r.useContext(i),a=t;return e&&(a="function"==typeof e?e(t):s(s({},t),e)),a},c=function(e){var t=u(e.components);return r.createElement(i.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,l=e.originalType,i=e.parentName,c=o(e,["components","mdxType","originalType","parentName"]),d=u(a),m=n,f=d["".concat(i,".").concat(m)]||d[m]||p[m]||l;return a?r.createElement(f,s(s({ref:t},c),{},{components:a})):r.createElement(f,s({ref:t},c))}));function f(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=a.length,s=new Array(l);s[0]=m;var o={};for(var i in t)hasOwnProperty.call(t,i)&&(o[i]=t[i]);o.originalType=e,o[d]="string"==typeof e?e:n,s[1]=o;for(var u=2;u{a.d(t,{Z:()=>s});var r=a(7294),n=a(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:a,className:s}=e;return r.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,s),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var r=a(7462),n=a(7294),l=a(6010),s=a(2466),o=a(6550),i=a(1980),u=a(7392),c=a(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:r,default:n}}=e;return{value:t,label:a,attributes:r,default:n}}))}function p(e){const{values:t,children:a}=e;return(0,n.useMemo)((()=>{const e=t??d(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function m(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const r=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,i._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(r.location.search);t.set(l,e),r.replace({...r.location,search:t.toString()})}),[l,r])]}function b(e){const{defaultValue:t,queryString:a=!1,groupId:r}=e,l=p(e),[s,o]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=a.find((e=>e.default))??a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:l}))),[i,u]=f({queryString:a,groupId:r}),[d,b]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,l]=(0,c.Nk)(a);return[r,(0,n.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:r}),h=(()=>{const e=i??d;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{h&&o(h)}),[h]);return{selectedValue:s,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var h=a(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:a,selectedValue:o,selectValue:i,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),p=e=>{const t=e.currentTarget,a=c.indexOf(t),r=u[a].value;r!==o&&(d(t),i(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const a=c.indexOf(e.currentTarget)+1;t=c[a]??c[0];break}case"ArrowLeft":{const a=c.indexOf(e.currentTarget)-1;t=c[a]??c[c.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:s}=e;return n.createElement("li",(0,r.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},s,{className:(0,l.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":o===t})}),a??t)})))}function g(e){let{lazy:t,children:a,selectedValue:r}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function k(e){const t=b(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,r.Z)({},e,t)),n.createElement(g,(0,r.Z)({},e,t)))}function w(e){const t=(0,h.Z)();return n.createElement(k,(0,r.Z)({key:String(t)},e))}},7886:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var r=a(7462),n=(a(7294),a(3905)),l=a(4866),s=a(5162);const o={title:"sqs-partial-batch-failure"},i=void 0,u={unversionedId:"middlewares/sqs-partial-batch-failure",id:"middlewares/sqs-partial-batch-failure",title:"sqs-partial-batch-failure",description:"Middleware for handling partially failed SQS batches.",source:"@site/docs/middlewares/sqs-partial-batch-failure.md",sourceDirName:"middlewares",slug:"/middlewares/sqs-partial-batch-failure",permalink:"/docs/middlewares/sqs-partial-batch-failure",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/sqs-partial-batch-failure.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"sqs-partial-batch-failure"},sidebar:"tutorialSidebar",previous:{title:"service-discovery",permalink:"/docs/middlewares/service-discovery"},next:{title:"ssm",permalink:"/docs/middlewares/ssm"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Important",id:"important",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},p,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Middleware for handling partially failed SQS batches."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/sqs-partial-batch-failure\n# Required for types only\nnpm install --save-dev @aws-sdk/client-sqs\n"))),(0,n.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/sqs-partial-batch-failure\n# Required for types only\nyarn add --dev @aws-sdk/client-sqs\n"))),(0,n.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/sqs-partial-batch-failure\n# Required for types only\npnpm add --save-dev @aws-sdk/client-sqs\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"logger")," (function) (optional): A function that will be called when a record fails to be processed. Default: ",(0,n.kt)("inlineCode",{parentName:"li"},"console.error"))),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport sqsBatch from '@middy/sqs-partial-batch-failure'\n\nconst lambdaHandler = (event, context) => {\n const recordPromises = event.Records.map(async (record, index) => {\n /* Custom message processing logic */\n return record\n })\n return Promise.allSettled(recordPromises)\n}\n\nexport const handler = middy(lambdaHandler).use(sqsBatch())\n")),(0,n.kt)("h2",{id:"important"},"Important"),(0,n.kt)("p",null,"The value ",(0,n.kt)("inlineCode",{parentName:"p"},"ReportBatchItemFailures")," must be added to your Lambda's ",(0,n.kt)("inlineCode",{parentName:"p"},"FunctionResponseTypes")," in the ",(0,n.kt)("inlineCode",{parentName:"p"},"EventSourceMapping"),". See ",(0,n.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting"},"Reporting batch item failures")," and ",(0,n.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html"},"Lambda EventSourceMapping")),(0,n.kt)("p",null,"When being used with ",(0,n.kt)("inlineCode",{parentName:"p"},"@middy/validator"),", ensure errors are caught and handled properly to avoid infinite loops."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/6c4d050a.ab9d1ee4.js b/assets/js/6c4d050a.23e81505.js similarity index 99% rename from assets/js/6c4d050a.ab9d1ee4.js rename to assets/js/6c4d050a.23e81505.js index 4f31774be..6b261f937 100644 --- a/assets/js/6c4d050a.ab9d1ee4.js +++ b/assets/js/6c4d050a.23e81505.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5512],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>h});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),u=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},d=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,s=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),c=u(r),m=n,h=c["".concat(s,".").concat(m)]||c[m]||p[m]||l;return r?a.createElement(h,o(o({ref:t},d),{},{components:r})):a.createElement(h,o({ref:t},d))}));function h(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,o=new Array(l);o[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[c]="string"==typeof e?e:n,o[1]=i;for(var u=2;u{r.d(t,{Z:()=>o});var a=r(7294),n=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var a=r(7462),n=r(7294),l=r(6010),o=r(2466),i=r(6550),s=r(1980),u=r(7392),d=r(12);function c(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:r}=e;const a=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,l=p(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,u]=h({queryString:r,groupId:a}),[c,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,d.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),b=(()=>{const e=s??c;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),f(e)}),[u,f,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:i,selectValue:s,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),p=e=>{const t=e.currentTarget,r=d.indexOf(t),a=u[r].value;a!==i&&(c(t),s(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:o}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":i===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:a}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function w(e){const t=f(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,a.Z)({},e,t)),n.createElement(g,(0,a.Z)({},e,t)))}function k(e){const t=(0,b.Z)();return n.createElement(w,(0,a.Z)({key:String(t)},e))}},3058:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var a=r(7462),n=(r(7294),r(3905)),l=r(4866),o=r(5162);const i={title:"http-header-normalizer"},s=void 0,u={unversionedId:"middlewares/http-header-normalizer",id:"middlewares/http-header-normalizer",title:"http-header-normalizer",description:"This middleware normalizes HTTP header names. By default, it normalizes to lowercase. It",source:"@site/docs/middlewares/http-header-normalizer.md",sourceDirName:"middlewares",slug:"/middlewares/http-header-normalizer",permalink:"/docs/middlewares/http-header-normalizer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-header-normalizer.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-header-normalizer"},sidebar:"tutorialSidebar",previous:{title:"http-event-normalizer",permalink:"/docs/middlewares/http-event-normalizer"},next:{title:"http-json-body-parser",permalink:"/docs/middlewares/http-json-body-parser"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:c},m="wrapper";function h(e){let{components:t,...r}=e;return(0,n.kt)(m,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"This middleware normalizes HTTP header names. By default, it normalizes to lowercase. It\ncan also normalize to canonical form."),(0,n.kt)("p",null,"API Gateway does not perform any normalization, so without this middleware headers\nare propagated to Lambda exactly as they were sent by the client. Headers names are\ncase insensitive, so normalization allows code reading header values to be simplified."),(0,n.kt)("p",null,"Other middlewares like ",(0,n.kt)("a",{parentName:"p",href:"#jsonbodyparser"},(0,n.kt)("inlineCode",{parentName:"a"},"jsonBodyParser"))," or ",(0,n.kt)("a",{parentName:"p",href:"#urlencodebodyparser"},(0,n.kt)("inlineCode",{parentName:"a"},"urlEncodeBodyParser")),"\nwill rely on headers to be one of the normalized formats, so if you want to support non-normalized headers in your\napp you have to use this middleware before those ones."),(0,n.kt)("p",null,"This middleware will copy the original headers in ",(0,n.kt)("inlineCode",{parentName:"p"},"event.rawHeaders"),"."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-header-normalizer\n"))),(0,n.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-header-normalizer\n"))),(0,n.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-header-normalizer\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"normalizeHeaderKey")," (function) (optional): a function that accepts an header name as a parameter and returns its\ncanonical representation."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"canonical")," (bool) (optional): if true, modifies the headers to canonical format, otherwise the headers are normalized to lowercase (default ",(0,n.kt)("inlineCode",{parentName:"li"},"false"),")")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler\n .use(httpHeaderNormalizer())\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5512],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>h});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),u=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},d=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,s=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),c=u(r),m=n,h=c["".concat(s,".").concat(m)]||c[m]||p[m]||l;return r?a.createElement(h,o(o({ref:t},d),{},{components:r})):a.createElement(h,o({ref:t},d))}));function h(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,o=new Array(l);o[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[c]="string"==typeof e?e:n,o[1]=i;for(var u=2;u{r.d(t,{Z:()=>o});var a=r(7294),n=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var a=r(7462),n=r(7294),l=r(6010),o=r(2466),i=r(6550),s=r(1980),u=r(7392),d=r(12);function c(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:r}=e;const a=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,l=p(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,u]=h({queryString:r,groupId:a}),[c,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,d.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),b=(()=>{const e=s??c;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),f(e)}),[u,f,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:i,selectValue:s,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),p=e=>{const t=e.currentTarget,r=d.indexOf(t),a=u[r].value;a!==i&&(c(t),s(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=d.indexOf(e.currentTarget)+1;t=d[r]??d[0];break}case"ArrowLeft":{const r=d.indexOf(e.currentTarget)-1;t=d[r]??d[d.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:o}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":i===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:a}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function w(e){const t=f(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,a.Z)({},e,t)),n.createElement(g,(0,a.Z)({},e,t)))}function k(e){const t=(0,b.Z)();return n.createElement(w,(0,a.Z)({key:String(t)},e))}},3058:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var a=r(7462),n=(r(7294),r(3905)),l=r(4866),o=r(5162);const i={title:"http-header-normalizer"},s=void 0,u={unversionedId:"middlewares/http-header-normalizer",id:"middlewares/http-header-normalizer",title:"http-header-normalizer",description:"This middleware normalizes HTTP header names. By default, it normalizes to lowercase. It",source:"@site/docs/middlewares/http-header-normalizer.md",sourceDirName:"middlewares",slug:"/middlewares/http-header-normalizer",permalink:"/docs/middlewares/http-header-normalizer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-header-normalizer.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-header-normalizer"},sidebar:"tutorialSidebar",previous:{title:"http-event-normalizer",permalink:"/docs/middlewares/http-event-normalizer"},next:{title:"http-json-body-parser",permalink:"/docs/middlewares/http-json-body-parser"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:c},m="wrapper";function h(e){let{components:t,...r}=e;return(0,n.kt)(m,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"This middleware normalizes HTTP header names. By default, it normalizes to lowercase. It\ncan also normalize to canonical form."),(0,n.kt)("p",null,"API Gateway does not perform any normalization, so without this middleware headers\nare propagated to Lambda exactly as they were sent by the client. Headers names are\ncase insensitive, so normalization allows code reading header values to be simplified."),(0,n.kt)("p",null,"Other middlewares like ",(0,n.kt)("a",{parentName:"p",href:"#jsonbodyparser"},(0,n.kt)("inlineCode",{parentName:"a"},"jsonBodyParser"))," or ",(0,n.kt)("a",{parentName:"p",href:"#urlencodebodyparser"},(0,n.kt)("inlineCode",{parentName:"a"},"urlEncodeBodyParser")),"\nwill rely on headers to be one of the normalized formats, so if you want to support non-normalized headers in your\napp you have to use this middleware before those ones."),(0,n.kt)("p",null,"This middleware will copy the original headers in ",(0,n.kt)("inlineCode",{parentName:"p"},"event.rawHeaders"),"."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-header-normalizer\n"))),(0,n.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-header-normalizer\n"))),(0,n.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-header-normalizer\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"normalizeHeaderKey")," (function) (optional): a function that accepts an header name as a parameter and returns its\ncanonical representation."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"canonical")," (bool) (optional): if true, modifies the headers to canonical format, otherwise the headers are normalized to lowercase (default ",(0,n.kt)("inlineCode",{parentName:"li"},"false"),")")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler\n .use(httpHeaderNormalizer())\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/70761510.38dbe55a.js b/assets/js/70761510.c7d94b0a.js similarity index 97% rename from assets/js/70761510.38dbe55a.js rename to assets/js/70761510.c7d94b0a.js index b3861efb4..fa8f6b98c 100644 --- a/assets/js/70761510.38dbe55a.js +++ b/assets/js/70761510.c7d94b0a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5024],{3905:(e,n,t)=>{t.d(n,{Zo:()=>d,kt:()=>b});var r=t(7294);function s(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function o(e){for(var n=1;n=0||(s[t]=e[t]);return s}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(s[t]=e[t])}return s}var l=r.createContext({}),c=function(e){var n=r.useContext(l),t=n;return e&&(t="function"==typeof e?e(n):o(o({},n),e)),t},d=function(e){var n=c(e.components);return r.createElement(l.Provider,{value:n},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var n=e.children;return r.createElement(r.Fragment,{},n)}},m=r.forwardRef((function(e,n){var t=e.components,s=e.mdxType,a=e.originalType,l=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),u=c(t),m=s,b=u["".concat(l,".").concat(m)]||u[m]||p[m]||a;return t?r.createElement(b,o(o({ref:n},d),{},{components:t})):r.createElement(b,o({ref:n},d))}));function b(e,n){var t=arguments,s=n&&n.mdxType;if("string"==typeof e||s){var a=t.length,o=new Array(a);o[0]=m;var i={};for(var l in n)hasOwnProperty.call(n,l)&&(i[l]=n[l]);i.originalType=e,i[u]="string"==typeof e?e:s,o[1]=i;for(var c=2;c{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>p,frontMatter:()=>a,metadata:()=>i,toc:()=>c});var r=t(7462),s=(t(7294),t(3905));const a={title:"Small node_modules",sidebar_position:6},o=void 0,i={unversionedId:"best-practices/small-node-modules",id:"best-practices/small-node-modules",title:"Small node_modules",description:"Using a bundler is the optimal solution, but can be complex depending on your setup.",source:"@site/docs/best-practices/06-small-node-modules.md",sourceDirName:"best-practices",slug:"/best-practices/small-node-modules",permalink:"/docs/best-practices/small-node-modules",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/06-small-node-modules.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:6,frontMatter:{title:"Small node_modules",sidebar_position:6},sidebar:"tutorialSidebar",previous:{title:"Bundling Lambda packages",permalink:"/docs/best-practices/bundling"},next:{title:"Profiling",permalink:"/docs/best-practices/profiling"}},l={},c=[],d={toc:c},u="wrapper";function p(e){let{components:n,...t}=e;return(0,s.kt)(u,(0,r.Z)({},d,t,{components:n,mdxType:"MDXLayout"}),(0,s.kt)("p",null,"Using a bundler is the optimal solution, but can be complex depending on your setup."),(0,s.kt)("p",null,"In this case you should remove excess files from your ",(0,s.kt)("inlineCode",{parentName:"p"},"node_modules")," directory to ensure it doesn't have anything excess shipped to AWS."),(0,s.kt)("p",null,"We put together a ",(0,s.kt)("inlineCode",{parentName:"p"},".yarnclean")," file you can check out and use as part of your CI/CD process:"),(0,s.kt)("pre",null,(0,s.kt)("code",{parentName:"pre",className:"language-git",metastring:'title=".yarnclean"',title:'".yarnclean"'},"# -- Middy.js --\n\n# Dependencies\n**/ajv/lib\n**/ajv/.runkit_examples.js\n**/ajv-errors/src\n**/ajv-formats/src\n**/ajv-formats-draft2019/.github\n**/ajv-formats-draft2019/.prettierrc.js\n**/ajv-formats-draft2019/index.test.js\n**/ajv-i18n/localize/.eslintrc.yml\n**/json-mask/bin\n**/json-mask/build\n**/qs/.github\n**/qs/dist\n**/qs/test\n**/qs/.editorconfig\n**/qs/.eslintrc\n**/qs/.nycrc\n**/qs/CHANGELOG.md\n\n# DevDependencies\n**/@types\n**/@serverless/event-mocks\n\n## Sub[/Sub] Dependencies\n**/bowser/src\n**/bowser/bundled.js\n**/dicer/bench\n**/dicer/test\n**/inherits/inherits_browser.js\n**/json-schema-traverse/.github\n**/json-schema-traverse/spec\n**/fast-deep-equal/es6\n**/fast-deep-equal/react.js\n**/querystring/test\n**/react-native-get-random-values/android\n**/react-native-get-random-values/ios\n**/react-native-get-random-values/index.web.js\n**/react-native-get-random-values/react-native-get-random-values.podspec\n**/setprototypeof/test\n**/tslib\n**/uri-js/dist/esnext\n**/url/.zuul.yml\n**/url/test.js\n**/uuid/bin\n\n# Builds\n*.ts\ntsconfig.json\n*.js.map\npackage-lock.json\nyarn.lock\n.travis.yml\n\n# Common\n.bin\n.cache\n.editorconfig\n.eslintignore\n.eslintrc\n.eslintrc.yml\n.gitattributes\n.npmignore\nAUTHORS\nLICENSE\n*.md\n*.txt\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5024],{3905:(e,n,t)=>{t.d(n,{Zo:()=>d,kt:()=>b});var r=t(7294);function s(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function o(e){for(var n=1;n=0||(s[t]=e[t]);return s}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(s[t]=e[t])}return s}var l=r.createContext({}),c=function(e){var n=r.useContext(l),t=n;return e&&(t="function"==typeof e?e(n):o(o({},n),e)),t},d=function(e){var n=c(e.components);return r.createElement(l.Provider,{value:n},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var n=e.children;return r.createElement(r.Fragment,{},n)}},m=r.forwardRef((function(e,n){var t=e.components,s=e.mdxType,a=e.originalType,l=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),u=c(t),m=s,b=u["".concat(l,".").concat(m)]||u[m]||p[m]||a;return t?r.createElement(b,o(o({ref:n},d),{},{components:t})):r.createElement(b,o({ref:n},d))}));function b(e,n){var t=arguments,s=n&&n.mdxType;if("string"==typeof e||s){var a=t.length,o=new Array(a);o[0]=m;var i={};for(var l in n)hasOwnProperty.call(n,l)&&(i[l]=n[l]);i.originalType=e,i[u]="string"==typeof e?e:s,o[1]=i;for(var c=2;c{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>p,frontMatter:()=>a,metadata:()=>i,toc:()=>c});var r=t(7462),s=(t(7294),t(3905));const a={title:"Small node_modules",sidebar_position:6},o=void 0,i={unversionedId:"best-practices/small-node-modules",id:"best-practices/small-node-modules",title:"Small node_modules",description:"Using a bundler is the optimal solution, but can be complex depending on your setup.",source:"@site/docs/best-practices/06-small-node-modules.md",sourceDirName:"best-practices",slug:"/best-practices/small-node-modules",permalink:"/docs/best-practices/small-node-modules",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/06-small-node-modules.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:6,frontMatter:{title:"Small node_modules",sidebar_position:6},sidebar:"tutorialSidebar",previous:{title:"Bundling Lambda packages",permalink:"/docs/best-practices/bundling"},next:{title:"Profiling",permalink:"/docs/best-practices/profiling"}},l={},c=[],d={toc:c},u="wrapper";function p(e){let{components:n,...t}=e;return(0,s.kt)(u,(0,r.Z)({},d,t,{components:n,mdxType:"MDXLayout"}),(0,s.kt)("p",null,"Using a bundler is the optimal solution, but can be complex depending on your setup."),(0,s.kt)("p",null,"In this case you should remove excess files from your ",(0,s.kt)("inlineCode",{parentName:"p"},"node_modules")," directory to ensure it doesn't have anything excess shipped to AWS."),(0,s.kt)("p",null,"We put together a ",(0,s.kt)("inlineCode",{parentName:"p"},".yarnclean")," file you can check out and use as part of your CI/CD process:"),(0,s.kt)("pre",null,(0,s.kt)("code",{parentName:"pre",className:"language-git",metastring:'title=".yarnclean"',title:'".yarnclean"'},"# -- Middy.js --\n\n# Dependencies\n**/ajv/lib\n**/ajv/.runkit_examples.js\n**/ajv-errors/src\n**/ajv-formats/src\n**/ajv-formats-draft2019/.github\n**/ajv-formats-draft2019/.prettierrc.js\n**/ajv-formats-draft2019/index.test.js\n**/ajv-i18n/localize/.eslintrc.yml\n**/json-mask/bin\n**/json-mask/build\n**/qs/.github\n**/qs/dist\n**/qs/test\n**/qs/.editorconfig\n**/qs/.eslintrc\n**/qs/.nycrc\n**/qs/CHANGELOG.md\n\n# DevDependencies\n**/@types\n**/@serverless/event-mocks\n\n## Sub[/Sub] Dependencies\n**/bowser/src\n**/bowser/bundled.js\n**/dicer/bench\n**/dicer/test\n**/inherits/inherits_browser.js\n**/json-schema-traverse/.github\n**/json-schema-traverse/spec\n**/fast-deep-equal/es6\n**/fast-deep-equal/react.js\n**/querystring/test\n**/react-native-get-random-values/android\n**/react-native-get-random-values/ios\n**/react-native-get-random-values/index.web.js\n**/react-native-get-random-values/react-native-get-random-values.podspec\n**/setprototypeof/test\n**/tslib\n**/uri-js/dist/esnext\n**/url/.zuul.yml\n**/url/test.js\n**/uuid/bin\n\n# Builds\n*.ts\ntsconfig.json\n*.js.map\npackage-lock.json\nyarn.lock\n.travis.yml\n\n# Common\n.bin\n.cache\n.editorconfig\n.eslintignore\n.eslintrc\n.eslintrc.yml\n.gitattributes\n.npmignore\nAUTHORS\nLICENSE\n*.md\n*.txt\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/7076eee1.de0042ad.js b/assets/js/7076eee1.cd172609.js similarity index 99% rename from assets/js/7076eee1.de0042ad.js rename to assets/js/7076eee1.cd172609.js index 666538460..dfbb4910c 100644 --- a/assets/js/7076eee1.de0042ad.js +++ b/assets/js/7076eee1.cd172609.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[481],{3905:(e,t,r)=>{r.d(t,{Zo:()=>s,kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),l=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},s=function(e){var t=l(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,s=d(e,["components","mdxType","originalType","parentName"]),m=l(r),u=a,h=m["".concat(p,".").concat(u)]||m[u]||c[u]||o;return r?n.createElement(h,i(i({ref:t},s),{},{components:r})):n.createElement(h,i({ref:t},s))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var l=2;l{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var n=r(7462),a=(r(7294),r(3905));const o={title:"Application Load Balancer"},i=void 0,d={unversionedId:"events/application-load-balancer",id:"events/application-load-balancer",title:"Application Load Balancer",description:"Same as API Gateway (REST)",source:"@site/docs/events/application-load-balancer.md",sourceDirName:"events",slug:"/events/application-load-balancer",permalink:"/docs/events/application-load-balancer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/application-load-balancer.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Application Load Balancer"},sidebar:"tutorialSidebar",previous:{title:"API Gateway (WebSocket)",permalink:"/docs/events/api-gateway-ws"},next:{title:"AppSync",permalink:"/docs/events/appsync"}},p={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:l},m="wrapper";function c(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},s,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Same as API Gateway (REST)"),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html"},"Using AWS Lambda with an Application Load Balancer"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpRouterHandler from '@middy/http-router'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer'\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport warmupMiddleware from 'warmup'\n\nimport { handler as getHandler } from './handlers/get-user.js'\nimport { handler as postHandler } from './handlers/get-user.js'\n\nconst routes = [\n {\n method: 'GET',\n path: '/user/{id}',\n handler: getHandler\n },\n {\n method: 'POST',\n path: '/user',\n handler: postHandler\n }\n]\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n default: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(httpErrorHandlerMiddleware())\n .handler(httpRouterHandler(routes))\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[481],{3905:(e,t,r)=>{r.d(t,{Zo:()=>s,kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),l=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},s=function(e){var t=l(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,s=d(e,["components","mdxType","originalType","parentName"]),m=l(r),u=a,h=m["".concat(p,".").concat(u)]||m[u]||c[u]||o;return r?n.createElement(h,i(i({ref:t},s),{},{components:r})):n.createElement(h,i({ref:t},s))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var l=2;l{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var n=r(7462),a=(r(7294),r(3905));const o={title:"Application Load Balancer"},i=void 0,d={unversionedId:"events/application-load-balancer",id:"events/application-load-balancer",title:"Application Load Balancer",description:"Same as API Gateway (REST)",source:"@site/docs/events/application-load-balancer.md",sourceDirName:"events",slug:"/events/application-load-balancer",permalink:"/docs/events/application-load-balancer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/application-load-balancer.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Application Load Balancer"},sidebar:"tutorialSidebar",previous:{title:"API Gateway (WebSocket)",permalink:"/docs/events/api-gateway-ws"},next:{title:"AppSync",permalink:"/docs/events/appsync"}},p={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:l},m="wrapper";function c(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},s,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Same as API Gateway (REST)"),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html"},"Using AWS Lambda with an Application Load Balancer"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpRouterHandler from '@middy/http-router'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer'\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport warmupMiddleware from 'warmup'\n\nimport { handler as getHandler } from './handlers/get-user.js'\nimport { handler as postHandler } from './handlers/get-user.js'\n\nconst routes = [\n {\n method: 'GET',\n path: '/user/{id}',\n handler: getHandler\n },\n {\n method: 'POST',\n path: '/user',\n handler: postHandler\n }\n]\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n default: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(httpErrorHandlerMiddleware())\n .handler(httpRouterHandler(routes))\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/71d5009c.100b4d7e.js b/assets/js/71d5009c.db7fb811.js similarity index 98% rename from assets/js/71d5009c.100b4d7e.js rename to assets/js/71d5009c.db7fb811.js index ca4ff6316..ea923c499 100644 --- a/assets/js/71d5009c.100b4d7e.js +++ b/assets/js/71d5009c.db7fb811.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2193],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),d=s(n),m=o,f=d["".concat(l,".").concat(m)]||d[m]||u[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[d]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"Config"},i=void 0,c={unversionedId:"events/config",id:"events/config",title:"Config",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/config.md",sourceDirName:"events",slug:"/events/config",permalink:"/docs/events/config",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/config.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Config"},sidebar:"tutorialSidebar",previous:{title:"Cognito",permalink:"/docs/events/cognito"},next:{title:"Connect",permalink:"/docs/events/connect"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},d="wrapper";function u(e){let{components:t,...n}=e;return(0,o.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-config.html"},"Using AWS Lambda with AWS Config"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2193],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),d=s(n),m=o,f=d["".concat(l,".").concat(m)]||d[m]||u[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[d]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"Config"},i=void 0,c={unversionedId:"events/config",id:"events/config",title:"Config",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/config.md",sourceDirName:"events",slug:"/events/config",permalink:"/docs/events/config",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/config.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Config"},sidebar:"tutorialSidebar",previous:{title:"Cognito",permalink:"/docs/events/cognito"},next:{title:"Connect",permalink:"/docs/events/connect"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},d="wrapper";function u(e){let{components:t,...n}=e;return(0,o.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-config.html"},"Using AWS Lambda with AWS Config"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/73083085.1fde57f0.js b/assets/js/73083085.f21b6b50.js similarity index 98% rename from assets/js/73083085.1fde57f0.js rename to assets/js/73083085.f21b6b50.js index d874d3052..7216df36c 100644 --- a/assets/js/73083085.1fde57f0.js +++ b/assets/js/73083085.f21b6b50.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8365],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),s=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},l=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,l=d(e,["components","mdxType","originalType","parentName"]),m=s(r),u=a,y=m["".concat(p,".").concat(u)]||m[u]||c[u]||o;return r?n.createElement(y,i(i({ref:t},l),{},{components:r})):n.createElement(y,i({ref:t},l))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var s=2;s{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>d,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"API Gateway (REST)"},i=void 0,d={unversionedId:"events/api-gateway-rest",id:"events/api-gateway-rest",title:"API Gateway (REST)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/api-gateway-rest.md",sourceDirName:"events",slug:"/events/api-gateway-rest",permalink:"/docs/events/api-gateway-rest",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-rest.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"API Gateway (REST)"},sidebar:"tutorialSidebar",previous:{title:"API Gateway (HTTP)",permalink:"/docs/events/api-gateway-http"},next:{title:"API Gateway (WebSocket)",permalink:"/docs/events/api-gateway-ws"}},p={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],l={toc:s},m="wrapper";function c(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html"},"Using AWS Lambda with Amazon API Gateway")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html"},"Working with REST APIs"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer'\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n defaultContentType: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .use(httpErrorHandlerMiddleware())\n .handler((event, context, { signal }) => {\n // ...\n })\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8365],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),s=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},l=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,l=d(e,["components","mdxType","originalType","parentName"]),m=s(r),u=a,y=m["".concat(p,".").concat(u)]||m[u]||c[u]||o;return r?n.createElement(y,i(i({ref:t},l),{},{components:r})):n.createElement(y,i({ref:t},l))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var s=2;s{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>d,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"API Gateway (REST)"},i=void 0,d={unversionedId:"events/api-gateway-rest",id:"events/api-gateway-rest",title:"API Gateway (REST)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/api-gateway-rest.md",sourceDirName:"events",slug:"/events/api-gateway-rest",permalink:"/docs/events/api-gateway-rest",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-rest.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"API Gateway (REST)"},sidebar:"tutorialSidebar",previous:{title:"API Gateway (HTTP)",permalink:"/docs/events/api-gateway-http"},next:{title:"API Gateway (WebSocket)",permalink:"/docs/events/api-gateway-ws"}},p={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],l={toc:s},m="wrapper";function c(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html"},"Using AWS Lambda with Amazon API Gateway")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html"},"Working with REST APIs"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer'\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n defaultContentType: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .use(httpErrorHandlerMiddleware())\n .handler((event, context, { signal }) => {\n // ...\n })\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/7745d517.d1f12e22.js b/assets/js/7745d517.94a5a733.js similarity index 99% rename from assets/js/7745d517.d1f12e22.js rename to assets/js/7745d517.94a5a733.js index 57c013a38..d9265073d 100644 --- a/assets/js/7745d517.d1f12e22.js +++ b/assets/js/7745d517.94a5a733.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1702],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),u=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},c=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,c=o(e,["components","mdxType","originalType","parentName"]),d=u(n),m=r,f=d["".concat(s,".").concat(m)]||d[m]||p[m]||l;return n?a.createElement(f,i(i({ref:t},c),{},{components:n})):a.createElement(f,i({ref:t},c))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=m;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[d]="string"==typeof e?e:r,i[1]=o;for(var u=2;u{n.d(t,{Z:()=>i});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var a=n(7462),r=n(7294),l=n(6010),i=n(2466),o=n(6550),s=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=p(e),[i,o]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,u]=f({queryString:n,groupId:a}),[d,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,c.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),g=(()=>{const e=s??d;return m({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var g=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:n,selectedValue:o,selectValue:s,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),a=u[n].value;a!==o&&(d(t),s(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:i}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",h.tabItem,i?.className,{"tabs__item--active":o===t})}),n??t)})))}function y(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function v(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},r.createElement(k,(0,a.Z)({},e,t)),r.createElement(y,(0,a.Z)({},e,t)))}function w(e){const t=(0,g.Z)();return r.createElement(v,(0,a.Z)({key:String(t)},e))}},2426:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),i=n(5162);const o={title:"appconfig"},s=void 0,u={unversionedId:"middlewares/appconfig",id:"middlewares/appconfig",title:"appconfig",description:"Fetches AppConfig stored configuration and parses out JSON.",source:"@site/docs/middlewares/appconfig.md",sourceDirName:"middlewares",slug:"/middlewares/appconfig",permalink:"/docs/middlewares/appconfig",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/appconfig.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"appconfig"},sidebar:"tutorialSidebar",previous:{title:"Third-party middlewares",permalink:"/docs/middlewares/third-party"},next:{title:"cloudwatch-metrics",permalink:"/docs/middlewares/cloudwatch-metrics"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Fetches AppConfig stored configuration and parses out JSON."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/appconfig\nnpm install --save-dev @aws-sdk/client-appconfig\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/appconfig\nyarn add --dev @aws-sdk/client-appconfig\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/appconfig\npnpm add --save-dev @aws-sdk/client-appconfig\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"AppConfigClient"),"): AppConfigClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-appconfig"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to AppConfigClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"appconfig"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"appconfig:GetConfiguration"))),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport appConfig from '@middy/appconfig'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n appConfig({\n fetchData: {\n config: {\n Application: '...',\n ClientId: '...',\n Configuration: '...',\n Environment: '...'\n }\n }\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-appconfig")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1702],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),u=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},c=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,c=o(e,["components","mdxType","originalType","parentName"]),d=u(n),m=r,f=d["".concat(s,".").concat(m)]||d[m]||p[m]||l;return n?a.createElement(f,i(i({ref:t},c),{},{components:n})):a.createElement(f,i({ref:t},c))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=m;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[d]="string"==typeof e?e:r,i[1]=o;for(var u=2;u{n.d(t,{Z:()=>i});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var a=n(7462),r=n(7294),l=n(6010),i=n(2466),o=n(6550),s=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=p(e),[i,o]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,u]=f({queryString:n,groupId:a}),[d,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,c.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),g=(()=>{const e=s??d;return m({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var g=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:n,selectedValue:o,selectValue:s,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),a=u[n].value;a!==o&&(d(t),s(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:i}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",h.tabItem,i?.className,{"tabs__item--active":o===t})}),n??t)})))}function y(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function v(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},r.createElement(k,(0,a.Z)({},e,t)),r.createElement(y,(0,a.Z)({},e,t)))}function w(e){const t=(0,g.Z)();return r.createElement(v,(0,a.Z)({key:String(t)},e))}},2426:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),i=n(5162);const o={title:"appconfig"},s=void 0,u={unversionedId:"middlewares/appconfig",id:"middlewares/appconfig",title:"appconfig",description:"Fetches AppConfig stored configuration and parses out JSON.",source:"@site/docs/middlewares/appconfig.md",sourceDirName:"middlewares",slug:"/middlewares/appconfig",permalink:"/docs/middlewares/appconfig",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/appconfig.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"appconfig"},sidebar:"tutorialSidebar",previous:{title:"Third-party middlewares",permalink:"/docs/middlewares/third-party"},next:{title:"cloudwatch-metrics",permalink:"/docs/middlewares/cloudwatch-metrics"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Fetches AppConfig stored configuration and parses out JSON."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/appconfig\nnpm install --save-dev @aws-sdk/client-appconfig\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/appconfig\nyarn add --dev @aws-sdk/client-appconfig\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/appconfig\npnpm add --save-dev @aws-sdk/client-appconfig\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"AppConfigClient"),"): AppConfigClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-appconfig"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to AppConfigClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"appconfig"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"appconfig:GetConfiguration"))),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport appConfig from '@middy/appconfig'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n appConfig({\n fetchData: {\n config: {\n Application: '...',\n ClientId: '...',\n Configuration: '...',\n Environment: '...'\n }\n }\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-appconfig")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/79674995.3a486d0a.js b/assets/js/79674995.1930ae6b.js similarity index 96% rename from assets/js/79674995.3a486d0a.js rename to assets/js/79674995.1930ae6b.js index bb7035fdf..3e548714b 100644 --- a/assets/js/79674995.3a486d0a.js +++ b/assets/js/79674995.1930ae6b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8200],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),u=s(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[u]="string"==typeof e?e:o,i[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"CloudFormation"},i=void 0,l={unversionedId:"events/cloud-formation",id:"events/cloud-formation",title:"CloudFormation",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cloud-formation.md",sourceDirName:"events",slug:"/events/cloud-formation",permalink:"/docs/events/cloud-formation",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-formation.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"CloudFormation"},sidebar:"tutorialSidebar",previous:{title:"AppSync",permalink:"/docs/events/appsync"},next:{title:"CloudFront Lambda@Edge",permalink:"/docs/events/cloud-front"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudformation.html"},"Using AWS Lambda with AWS CloudFormation"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8200],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),u=s(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[u]="string"==typeof e?e:o,i[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"CloudFormation"},i=void 0,l={unversionedId:"events/cloud-formation",id:"events/cloud-formation",title:"CloudFormation",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cloud-formation.md",sourceDirName:"events",slug:"/events/cloud-formation",permalink:"/docs/events/cloud-formation",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-formation.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"CloudFormation"},sidebar:"tutorialSidebar",previous:{title:"AppSync",permalink:"/docs/events/appsync"},next:{title:"CloudFront Lambda@Edge",permalink:"/docs/events/cloud-front"}},c={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudformation.html"},"Using AWS Lambda with AWS CloudFormation"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/796ad5a5.c7f65a53.js b/assets/js/796ad5a5.58567ee9.js similarity index 96% rename from assets/js/796ad5a5.c7f65a53.js rename to assets/js/796ad5a5.58567ee9.js index 0101f66d5..ede02e735 100644 --- a/assets/js/796ad5a5.c7f65a53.js +++ b/assets/js/796ad5a5.58567ee9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6172],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>y});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},s=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,s=p(e,["components","mdxType","originalType","parentName"]),u=l(n),m=a,y=u["".concat(c,".").concat(m)]||u[m]||d[m]||o;return n?r.createElement(y,i(i({ref:t},s),{},{components:n})):r.createElement(y,i({ref:t},s))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var p={};for(var c in t)hasOwnProperty.call(t,c)&&(p[c]=t[c]);p.originalType=e,p[u]="string"==typeof e?e:a,i[1]=p;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>p,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"AppSync"},i=void 0,p={unversionedId:"events/appsync",id:"events/appsync",title:"AppSync",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/appsync.md",sourceDirName:"events",slug:"/events/appsync",permalink:"/docs/events/appsync",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/appsync.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"AppSync"},sidebar:"tutorialSidebar",previous:{title:"Application Load Balancer",permalink:"/docs/events/application-load-balancer"},next:{title:"CloudFormation",permalink:"/docs/events/cloud-formation"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html"},"Using AWS Lambda with AppSync"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6172],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>y});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},s=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,s=p(e,["components","mdxType","originalType","parentName"]),u=l(n),m=a,y=u["".concat(c,".").concat(m)]||u[m]||d[m]||o;return n?r.createElement(y,i(i({ref:t},s),{},{components:n})):r.createElement(y,i({ref:t},s))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var p={};for(var c in t)hasOwnProperty.call(t,c)&&(p[c]=t[c]);p.originalType=e,p[u]="string"==typeof e?e:a,i[1]=p;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>p,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"AppSync"},i=void 0,p={unversionedId:"events/appsync",id:"events/appsync",title:"AppSync",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/appsync.md",sourceDirName:"events",slug:"/events/appsync",permalink:"/docs/events/appsync",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/appsync.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"AppSync"},sidebar:"tutorialSidebar",previous:{title:"Application Load Balancer",permalink:"/docs/events/application-load-balancer"},next:{title:"CloudFormation",permalink:"/docs/events/cloud-formation"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html"},"Using AWS Lambda with AppSync"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/7cb784f6.79267881.js b/assets/js/7cb784f6.d9482abd.js similarity index 99% rename from assets/js/7cb784f6.79267881.js rename to assets/js/7cb784f6.d9482abd.js index bc59dcc87..8ad68a64f 100644 --- a/assets/js/7cb784f6.79267881.js +++ b/assets/js/7cb784f6.d9482abd.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[711],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function l(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),d=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},h=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),u=d(r),h=n,m=u["".concat(s,".").concat(h)]||u[h]||c[h]||o;return r?a.createElement(m,l(l({ref:t},p),{},{components:r})):a.createElement(m,l({ref:t},p))}));function m(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,l=new Array(o);l[0]=h;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[u]="string"==typeof e?e:n,l[1]=i;for(var d=2;d{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>l,default:()=>c,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var a=r(7462),n=(r(7294),r(3905));const o={title:"Upgrade 1.x -> 2.x",sidebar_position:1e3},l=void 0,i={unversionedId:"upgrade/1-2",id:"upgrade/1-2",title:"Upgrade 1.x -> 2.x",description:"Version 2.x of Middy no longer supports Node.js versions 10.x. You are highly encouraged to move to Node.js 14.x,",source:"@site/docs/upgrade/1-2.md",sourceDirName:"upgrade",slug:"/upgrade/1-2",permalink:"/docs/upgrade/1-2",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/1-2.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:1e3,frontMatter:{title:"Upgrade 1.x -> 2.x",sidebar_position:1e3},sidebar:"tutorialSidebar",previous:{title:"Upgrade 2.x -> 3.x",permalink:"/docs/upgrade/2-3"},next:{title:"Upgrade 0.x -> 1.x",permalink:"/docs/upgrade/0-1"}},s={},d=[{value:"Core",id:"core",level:2},{value:"Middleware",id:"middleware",level:2},{value:"cache",id:"cache",level:3},{value:"db-manager",id:"db-manager",level:3},{value:"do-not-wait-for-empty-event-loop",id:"do-not-wait-for-empty-event-loop",level:3},{value:"function-shield",id:"function-shield",level:3},{value:"http-content-negotiation",id:"http-content-negotiation",level:3},{value:"http-cors",id:"http-cors",level:3},{value:"http-error-handler",id:"http-error-handler",level:3},{value:"http-event-normalizer",id:"http-event-normalizer",level:3},{value:"http-header-normalizer",id:"http-header-normalizer",level:3},{value:"http-json-body-parser",id:"http-json-body-parser",level:3},{value:"http-multipart-body-parser",id:"http-multipart-body-parser",level:3},{value:"http-partial-response",id:"http-partial-response",level:3},{value:"http-response-serializer",id:"http-response-serializer",level:3},{value:"http-security-headers",id:"http-security-headers",level:3},{value:"http-urlencode-body-parser",id:"http-urlencode-body-parser",level:3},{value:"http-urlencode-path-parser",id:"http-urlencode-path-parser",level:3},{value:"input-output-logger",id:"input-output-logger",level:3},{value:"rds-signer",id:"rds-signer",level:3},{value:"s3-key-normalizer",id:"s3-key-normalizer",level:3},{value:"s3-object-response",id:"s3-object-response",level:3},{value:"secrets-manager",id:"secrets-manager",level:3},{value:"sqs-json-body-parser",id:"sqs-json-body-parser",level:3},{value:"sqs-partial-batch-failure",id:"sqs-partial-batch-failure",level:3},{value:"ssm",id:"ssm",level:3},{value:"sts",id:"sts",level:3},{value:"validator",id:"validator",level:3},{value:"warmup",id:"warmup",level:3}],p={toc:d},u="wrapper";function c(e){let{components:t,...r}=e;return(0,n.kt)(u,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Version 2.x of Middy no longer supports Node.js versions 10.x. You are highly encouraged to move to Node.js 14.x,\nwhich support ES6 modules by default (",(0,n.kt)("inlineCode",{parentName:"p"},"export"),"), optional chaining (",(0,n.kt)("inlineCode",{parentName:"p"},"?."),") and nullish coalescing operator (",(0,n.kt)("inlineCode",{parentName:"p"},"??"),") natively."),(0,n.kt)("h2",{id:"core"},"Core"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"In handler ",(0,n.kt)("inlineCode",{parentName:"li"},"callback(err, response)")," have been removed for ",(0,n.kt)("inlineCode",{parentName:"li"},"async/await")," support",(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"return response")," to trigger ",(0,n.kt)("inlineCode",{parentName:"li"},"after")," middleware stack"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"throw new Error(...)")," to trigger ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," middleware stack"))),(0,n.kt)("li",{parentName:"ul"},"In middleware ",(0,n.kt)("inlineCode",{parentName:"li"},"next(err)")," has been removed for ",(0,n.kt)("inlineCode",{parentName:"li"},"async/await")," support",(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"throw new Error(...)")," to trigger ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," middleware stack"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"return response")," to ",(0,n.kt)("strong",{parentName:"li"},"short circuit")," any middleware stack and respond. v1.x currently throws an error when something is returned")))),(0,n.kt)("h2",{id:"middleware"},"Middleware"),(0,n.kt)("h3",{id:"cache"},"cache"),(0,n.kt)("p",null,"Deprecated. Too generic and had low usage."),(0,n.kt)("p",null,"However, you can use the following if needed:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"const { createHash } = require('crypto')\n\nmodule.exports = (opts) => {\n const storage = {}\n const defaults = {\n calculateCacheId: async (event) => createHash('md5').update(JSON.stringify(event)).digest('hex'),\n getValue: async (key) => storage[key],\n setValue: async (key, value) => {\n storage[key] = value\n }\n }\n\n const options = { ...defaults, ...opts }\n let currentCacheKey\n\n const cacheMiddlewareBefore = async (request) => {\n const cacheKey = await options.calculateCacheId(request.event)\n const response = await options.getValue(cacheKey)\n if (response) {\n return response\n }\n request.internal.cacheKey = cacheKey\n }\n\n const cacheMiddlewareAfter = async (request) => {\n await options.setValue(request.internal.cacheKey, request.response)\n }\n \n return {\n before: cacheMiddlewareBefore,\n after: cacheMiddlewareAfter\n }\n}\n")),(0,n.kt)("h3",{id:"db-manager"},"db-manager"),(0,n.kt)("p",null,"Deprecated. Too generic and had low usage. You can check out ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/willfarrell/middy-rds"},"middy-rds")," as a\npossible alternative or example on building your own replacement."),(0,n.kt)("h3",{id:"do-not-wait-for-empty-event-loop"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/do-not-wait-for-empty-event-loop"},"do-not-wait-for-empty-event-loop")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"function-shield"},"function-shield"),(0,n.kt)("p",null,"Deprecated. Only supported up to Node v10."),(0,n.kt)("h3",{id:"http-content-negotiation"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-negotiation"},"http-content-negotiation")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-cors"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-cors"},"http-cors")),(0,n.kt)("p",null,"Added new options to support more headers"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"methods"),(0,n.kt)("li",{parentName:"ul"},"exposeHeaders"),(0,n.kt)("li",{parentName:"ul"},"requestHeaders"),(0,n.kt)("li",{parentName:"ul"},"requestMethods")),(0,n.kt)("h3",{id:"http-error-handler"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-error-handler"},"http-error-handler")),(0,n.kt)("p",null,"Added in support to honour httpError.expose. Errors with statusCode >= 500 are no longer applied to response by default.\nAdded new option to catch any non-http and statusCode >= 500 errors"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"fallbackMessage")),(0,n.kt)("h3",{id:"http-event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-event-normalizer"},"http-event-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-header-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-header-normalizer"},"http-header-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-json-body-parser"},"http-json-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-multipart-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-multipart-body-parser"},"http-multipart-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-partial-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-partial-response"},"http-partial-response")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-response-serializer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-response-serializer"},"http-response-serializer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-security-headers"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-security-headers"},"http-security-headers")),(0,n.kt)("p",null,"No longer adds ",(0,n.kt)("inlineCode",{parentName:"p"},"statusCode:500")," when there is no response."),(0,n.kt)("h3",{id:"http-urlencode-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-body-parser"},"http-urlencode-body-parser")),(0,n.kt)("p",null,"Remove ",(0,n.kt)("inlineCode",{parentName:"p"},"extended")," option. Only uses ",(0,n.kt)("inlineCode",{parentName:"p"},"qs")," as the parser, formally enabled by options ",(0,n.kt)("inlineCode",{parentName:"p"},"{extended: true}"),"."),(0,n.kt)("h3",{id:"http-urlencode-path-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-path-parser"},"http-urlencode-path-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"input-output-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/input-output-logger"},"input-output-logger")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Now additionally logs response from the ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," middleware stack"),(0,n.kt)("li",{parentName:"ul"},"Support for omiting within nested arrays"),(0,n.kt)("li",{parentName:"ul"},"Add in support for ",(0,n.kt)("inlineCode",{parentName:"li"},"replacer")," to be passed into ",(0,n.kt)("inlineCode",{parentName:"li"},"JSON.stringify()"))),(0,n.kt)("h3",{id:"rds-signer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/rds-signer"},"rds-signer")),(0,n.kt)("p",null,"New middleware to fetch RDS credential used when connecting with IAM roles. This was built into ",(0,n.kt)("inlineCode",{parentName:"p"},"db-manager"),"."),(0,n.kt)("h3",{id:"s3-key-normalizer"},"s3-key-normalizer"),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"s3-object-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/s3-object-response"},"s3-object-response")),(0,n.kt)("p",null,"New middleware to fetch and respond to S3 Object Get request event."),(0,n.kt)("h3",{id:"secrets-manager"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/secrets-manager"},"secrets-manager")),(0,n.kt)("p",null,"Refactored, see documentation"),(0,n.kt)("h3",{id:"sqs-json-body-parser"},"sqs-json-body-parser"),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"sqs-partial-batch-failure"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sqs-partial-batch-failure"},"sqs-partial-batch-failure")),(0,n.kt)("p",null,"Replaced option ",(0,n.kt)("inlineCode",{parentName:"p"},"sqs")," with ",(0,n.kt)("inlineCode",{parentName:"p"},"AwsClient")," and added in more options for control."),(0,n.kt)("h3",{id:"ssm"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ssm"},"ssm")),(0,n.kt)("p",null,"Refactored, see documentation"),(0,n.kt)("h3",{id:"sts"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sts"},"sts")),(0,n.kt)("p",null,"New middleware to fetch assume role credentials."),(0,n.kt)("h3",{id:"validator"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/validator"},"validator")),(0,n.kt)("p",null,"Upgraded ",(0,n.kt)("inlineCode",{parentName:"p"},"ajv")," and it's plugins to support JSON Schema Draft 2020-12 specification. Defaults were change because of this."),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Plugin ",(0,n.kt)("inlineCode",{parentName:"li"},"ajv-keywords")," removed from being included by default because it's quite a large package and usually only one keyword is used."),(0,n.kt)("li",{parentName:"ul"},"Plugin ",(0,n.kt)("inlineCode",{parentName:"li"},"ajv-errors")," removed from included by default because it conflicts with ",(0,n.kt)("inlineCode",{parentName:"li"},"ajv-i18n")," when dealing with custom messages for multiple languages")),(0,n.kt)("h3",{id:"warmup"},"warmup"),(0,n.kt)("p",null,"Deprecated. This was a work round for a missing feature in AWS Lambda. AWS added in the ability to use ",(0,n.kt)("a",{parentName:"p",href:"https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/"},"provisioned concurrency"),"\non 2019-12-03, removing the need for this work around."),(0,n.kt)("p",null,"However, you can use the following if needed:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"middy(lambdaHandler)\n .before((request) => {\n if (request.event.source === 'serverless-plugin-warmup') {\n console.log('Exiting early via warmup Middleware')\n return 'warmup'\n }\n })\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[711],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function l(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),d=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},h=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),u=d(r),h=n,m=u["".concat(s,".").concat(h)]||u[h]||c[h]||o;return r?a.createElement(m,l(l({ref:t},p),{},{components:r})):a.createElement(m,l({ref:t},p))}));function m(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,l=new Array(o);l[0]=h;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[u]="string"==typeof e?e:n,l[1]=i;for(var d=2;d{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>l,default:()=>c,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var a=r(7462),n=(r(7294),r(3905));const o={title:"Upgrade 1.x -> 2.x",sidebar_position:1e3},l=void 0,i={unversionedId:"upgrade/1-2",id:"upgrade/1-2",title:"Upgrade 1.x -> 2.x",description:"Version 2.x of Middy no longer supports Node.js versions 10.x. You are highly encouraged to move to Node.js 14.x,",source:"@site/docs/upgrade/1-2.md",sourceDirName:"upgrade",slug:"/upgrade/1-2",permalink:"/docs/upgrade/1-2",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/1-2.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:1e3,frontMatter:{title:"Upgrade 1.x -> 2.x",sidebar_position:1e3},sidebar:"tutorialSidebar",previous:{title:"Upgrade 2.x -> 3.x",permalink:"/docs/upgrade/2-3"},next:{title:"Upgrade 0.x -> 1.x",permalink:"/docs/upgrade/0-1"}},s={},d=[{value:"Core",id:"core",level:2},{value:"Middleware",id:"middleware",level:2},{value:"cache",id:"cache",level:3},{value:"db-manager",id:"db-manager",level:3},{value:"do-not-wait-for-empty-event-loop",id:"do-not-wait-for-empty-event-loop",level:3},{value:"function-shield",id:"function-shield",level:3},{value:"http-content-negotiation",id:"http-content-negotiation",level:3},{value:"http-cors",id:"http-cors",level:3},{value:"http-error-handler",id:"http-error-handler",level:3},{value:"http-event-normalizer",id:"http-event-normalizer",level:3},{value:"http-header-normalizer",id:"http-header-normalizer",level:3},{value:"http-json-body-parser",id:"http-json-body-parser",level:3},{value:"http-multipart-body-parser",id:"http-multipart-body-parser",level:3},{value:"http-partial-response",id:"http-partial-response",level:3},{value:"http-response-serializer",id:"http-response-serializer",level:3},{value:"http-security-headers",id:"http-security-headers",level:3},{value:"http-urlencode-body-parser",id:"http-urlencode-body-parser",level:3},{value:"http-urlencode-path-parser",id:"http-urlencode-path-parser",level:3},{value:"input-output-logger",id:"input-output-logger",level:3},{value:"rds-signer",id:"rds-signer",level:3},{value:"s3-key-normalizer",id:"s3-key-normalizer",level:3},{value:"s3-object-response",id:"s3-object-response",level:3},{value:"secrets-manager",id:"secrets-manager",level:3},{value:"sqs-json-body-parser",id:"sqs-json-body-parser",level:3},{value:"sqs-partial-batch-failure",id:"sqs-partial-batch-failure",level:3},{value:"ssm",id:"ssm",level:3},{value:"sts",id:"sts",level:3},{value:"validator",id:"validator",level:3},{value:"warmup",id:"warmup",level:3}],p={toc:d},u="wrapper";function c(e){let{components:t,...r}=e;return(0,n.kt)(u,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Version 2.x of Middy no longer supports Node.js versions 10.x. You are highly encouraged to move to Node.js 14.x,\nwhich support ES6 modules by default (",(0,n.kt)("inlineCode",{parentName:"p"},"export"),"), optional chaining (",(0,n.kt)("inlineCode",{parentName:"p"},"?."),") and nullish coalescing operator (",(0,n.kt)("inlineCode",{parentName:"p"},"??"),") natively."),(0,n.kt)("h2",{id:"core"},"Core"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"In handler ",(0,n.kt)("inlineCode",{parentName:"li"},"callback(err, response)")," have been removed for ",(0,n.kt)("inlineCode",{parentName:"li"},"async/await")," support",(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"return response")," to trigger ",(0,n.kt)("inlineCode",{parentName:"li"},"after")," middleware stack"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"throw new Error(...)")," to trigger ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," middleware stack"))),(0,n.kt)("li",{parentName:"ul"},"In middleware ",(0,n.kt)("inlineCode",{parentName:"li"},"next(err)")," has been removed for ",(0,n.kt)("inlineCode",{parentName:"li"},"async/await")," support",(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"throw new Error(...)")," to trigger ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," middleware stack"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"return response")," to ",(0,n.kt)("strong",{parentName:"li"},"short circuit")," any middleware stack and respond. v1.x currently throws an error when something is returned")))),(0,n.kt)("h2",{id:"middleware"},"Middleware"),(0,n.kt)("h3",{id:"cache"},"cache"),(0,n.kt)("p",null,"Deprecated. Too generic and had low usage."),(0,n.kt)("p",null,"However, you can use the following if needed:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"const { createHash } = require('crypto')\n\nmodule.exports = (opts) => {\n const storage = {}\n const defaults = {\n calculateCacheId: async (event) => createHash('md5').update(JSON.stringify(event)).digest('hex'),\n getValue: async (key) => storage[key],\n setValue: async (key, value) => {\n storage[key] = value\n }\n }\n\n const options = { ...defaults, ...opts }\n let currentCacheKey\n\n const cacheMiddlewareBefore = async (request) => {\n const cacheKey = await options.calculateCacheId(request.event)\n const response = await options.getValue(cacheKey)\n if (response) {\n return response\n }\n request.internal.cacheKey = cacheKey\n }\n\n const cacheMiddlewareAfter = async (request) => {\n await options.setValue(request.internal.cacheKey, request.response)\n }\n \n return {\n before: cacheMiddlewareBefore,\n after: cacheMiddlewareAfter\n }\n}\n")),(0,n.kt)("h3",{id:"db-manager"},"db-manager"),(0,n.kt)("p",null,"Deprecated. Too generic and had low usage. You can check out ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/willfarrell/middy-rds"},"middy-rds")," as a\npossible alternative or example on building your own replacement."),(0,n.kt)("h3",{id:"do-not-wait-for-empty-event-loop"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/do-not-wait-for-empty-event-loop"},"do-not-wait-for-empty-event-loop")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"function-shield"},"function-shield"),(0,n.kt)("p",null,"Deprecated. Only supported up to Node v10."),(0,n.kt)("h3",{id:"http-content-negotiation"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-content-negotiation"},"http-content-negotiation")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-cors"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-cors"},"http-cors")),(0,n.kt)("p",null,"Added new options to support more headers"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"methods"),(0,n.kt)("li",{parentName:"ul"},"exposeHeaders"),(0,n.kt)("li",{parentName:"ul"},"requestHeaders"),(0,n.kt)("li",{parentName:"ul"},"requestMethods")),(0,n.kt)("h3",{id:"http-error-handler"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-error-handler"},"http-error-handler")),(0,n.kt)("p",null,"Added in support to honour httpError.expose. Errors with statusCode >= 500 are no longer applied to response by default.\nAdded new option to catch any non-http and statusCode >= 500 errors"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"fallbackMessage")),(0,n.kt)("h3",{id:"http-event-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-event-normalizer"},"http-event-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-header-normalizer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-header-normalizer"},"http-header-normalizer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-json-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-json-body-parser"},"http-json-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-multipart-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-multipart-body-parser"},"http-multipart-body-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-partial-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-partial-response"},"http-partial-response")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-response-serializer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-response-serializer"},"http-response-serializer")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"http-security-headers"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-security-headers"},"http-security-headers")),(0,n.kt)("p",null,"No longer adds ",(0,n.kt)("inlineCode",{parentName:"p"},"statusCode:500")," when there is no response."),(0,n.kt)("h3",{id:"http-urlencode-body-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-body-parser"},"http-urlencode-body-parser")),(0,n.kt)("p",null,"Remove ",(0,n.kt)("inlineCode",{parentName:"p"},"extended")," option. Only uses ",(0,n.kt)("inlineCode",{parentName:"p"},"qs")," as the parser, formally enabled by options ",(0,n.kt)("inlineCode",{parentName:"p"},"{extended: true}"),"."),(0,n.kt)("h3",{id:"http-urlencode-path-parser"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/http-urlencode-path-parser"},"http-urlencode-path-parser")),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"input-output-logger"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/input-output-logger"},"input-output-logger")),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Now additionally logs response from the ",(0,n.kt)("inlineCode",{parentName:"li"},"onError")," middleware stack"),(0,n.kt)("li",{parentName:"ul"},"Support for omiting within nested arrays"),(0,n.kt)("li",{parentName:"ul"},"Add in support for ",(0,n.kt)("inlineCode",{parentName:"li"},"replacer")," to be passed into ",(0,n.kt)("inlineCode",{parentName:"li"},"JSON.stringify()"))),(0,n.kt)("h3",{id:"rds-signer"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/rds-signer"},"rds-signer")),(0,n.kt)("p",null,"New middleware to fetch RDS credential used when connecting with IAM roles. This was built into ",(0,n.kt)("inlineCode",{parentName:"p"},"db-manager"),"."),(0,n.kt)("h3",{id:"s3-key-normalizer"},"s3-key-normalizer"),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"s3-object-response"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/s3-object-response"},"s3-object-response")),(0,n.kt)("p",null,"New middleware to fetch and respond to S3 Object Get request event."),(0,n.kt)("h3",{id:"secrets-manager"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/secrets-manager"},"secrets-manager")),(0,n.kt)("p",null,"Refactored, see documentation"),(0,n.kt)("h3",{id:"sqs-json-body-parser"},"sqs-json-body-parser"),(0,n.kt)("p",null,"No change"),(0,n.kt)("h3",{id:"sqs-partial-batch-failure"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sqs-partial-batch-failure"},"sqs-partial-batch-failure")),(0,n.kt)("p",null,"Replaced option ",(0,n.kt)("inlineCode",{parentName:"p"},"sqs")," with ",(0,n.kt)("inlineCode",{parentName:"p"},"AwsClient")," and added in more options for control."),(0,n.kt)("h3",{id:"ssm"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/ssm"},"ssm")),(0,n.kt)("p",null,"Refactored, see documentation"),(0,n.kt)("h3",{id:"sts"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/sts"},"sts")),(0,n.kt)("p",null,"New middleware to fetch assume role credentials."),(0,n.kt)("h3",{id:"validator"},(0,n.kt)("a",{parentName:"h3",href:"/docs/middlewares/validator"},"validator")),(0,n.kt)("p",null,"Upgraded ",(0,n.kt)("inlineCode",{parentName:"p"},"ajv")," and it's plugins to support JSON Schema Draft 2020-12 specification. Defaults were change because of this."),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"Plugin ",(0,n.kt)("inlineCode",{parentName:"li"},"ajv-keywords")," removed from being included by default because it's quite a large package and usually only one keyword is used."),(0,n.kt)("li",{parentName:"ul"},"Plugin ",(0,n.kt)("inlineCode",{parentName:"li"},"ajv-errors")," removed from included by default because it conflicts with ",(0,n.kt)("inlineCode",{parentName:"li"},"ajv-i18n")," when dealing with custom messages for multiple languages")),(0,n.kt)("h3",{id:"warmup"},"warmup"),(0,n.kt)("p",null,"Deprecated. This was a work round for a missing feature in AWS Lambda. AWS added in the ability to use ",(0,n.kt)("a",{parentName:"p",href:"https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/"},"provisioned concurrency"),"\non 2019-12-03, removing the need for this work around."),(0,n.kt)("p",null,"However, you can use the following if needed:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"middy(lambdaHandler)\n .before((request) => {\n if (request.event.source === 'serverless-plugin-warmup') {\n console.log('Exiting early via warmup Middleware')\n return 'warmup'\n }\n })\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/89ce8835.47aa201b.js b/assets/js/89ce8835.f3c8c103.js similarity index 96% rename from assets/js/89ce8835.47aa201b.js rename to assets/js/89ce8835.f3c8c103.js index 04bc27517..46bdf1afd 100644 --- a/assets/js/89ce8835.47aa201b.js +++ b/assets/js/89ce8835.f3c8c103.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1955],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),u=s(n),m=o,f=u["".concat(l,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[u]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"Cognito"},i=void 0,c={unversionedId:"events/cognito",id:"events/cognito",title:"Cognito",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cognito.md",sourceDirName:"events",slug:"/events/cognito",permalink:"/docs/events/cognito",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cognito.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Cognito"},sidebar:"tutorialSidebar",previous:{title:"CodePipeline",permalink:"/docs/events/code-pipeline"},next:{title:"Config",permalink:"/docs/events/config"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cognito.html"},"Using AWS Lambda with Amazon Cognito"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1955],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),u=s(n),m=o,f=u["".concat(l,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[u]="string"==typeof e?e:o,i[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const a={title:"Cognito"},i=void 0,c={unversionedId:"events/cognito",id:"events/cognito",title:"Cognito",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/cognito.md",sourceDirName:"events",slug:"/events/cognito",permalink:"/docs/events/cognito",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cognito.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Cognito"},sidebar:"tutorialSidebar",previous:{title:"CodePipeline",permalink:"/docs/events/code-pipeline"},next:{title:"Config",permalink:"/docs/events/config"}},l={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:s},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cognito.html"},"Using AWS Lambda with Amazon Cognito"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/949815f5.d58e4cbd.js b/assets/js/949815f5.a8f4512d.js similarity index 97% rename from assets/js/949815f5.d58e4cbd.js rename to assets/js/949815f5.a8f4512d.js index 631e51a21..001425f8e 100644 --- a/assets/js/949815f5.d58e4cbd.js +++ b/assets/js/949815f5.a8f4512d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8394],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},m=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,m=s(e,["components","mdxType","originalType","parentName"]),d=c(n),u=a,f=d["".concat(l,".").concat(u)]||d[u]||p[u]||o;return n?r.createElement(f,i(i({ref:t},m),{},{components:n})):r.createElement(f,i({ref:t},m))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"Kafka, Managed Streaming (MSK)"},i=void 0,s={unversionedId:"events/kafka-managed-streaming",id:"events/kafka-managed-streaming",title:"Kafka, Managed Streaming (MSK)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/kafka-managed-streaming.md",sourceDirName:"events",slug:"/events/kafka-managed-streaming",permalink:"/docs/events/kafka-managed-streaming",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kafka-managed-streaming.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Kafka, Managed Streaming (MSK)"},sidebar:"tutorialSidebar",previous:{title:"Internet of things (IoT)",permalink:"/docs/events/iot"},next:{title:"Kafka, Self-Managed",permalink:"/docs/events/kafka-self-managed"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],m={toc:c},d="wrapper";function p(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html"},"Using Lambda with Amazon MSK"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8394],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},m=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,m=s(e,["components","mdxType","originalType","parentName"]),d=c(n),u=a,f=d["".concat(l,".").concat(u)]||d[u]||p[u]||o;return n?r.createElement(f,i(i({ref:t},m),{},{components:n})):r.createElement(f,i({ref:t},m))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"Kafka, Managed Streaming (MSK)"},i=void 0,s={unversionedId:"events/kafka-managed-streaming",id:"events/kafka-managed-streaming",title:"Kafka, Managed Streaming (MSK)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/kafka-managed-streaming.md",sourceDirName:"events",slug:"/events/kafka-managed-streaming",permalink:"/docs/events/kafka-managed-streaming",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kafka-managed-streaming.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Kafka, Managed Streaming (MSK)"},sidebar:"tutorialSidebar",previous:{title:"Internet of things (IoT)",permalink:"/docs/events/iot"},next:{title:"Kafka, Self-Managed",permalink:"/docs/events/kafka-self-managed"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],m={toc:c},d="wrapper";function p(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html"},"Using Lambda with Amazon MSK"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/958c573d.2d2b6ecd.js b/assets/js/958c573d.77e843f7.js similarity index 97% rename from assets/js/958c573d.2d2b6ecd.js rename to assets/js/958c573d.77e843f7.js index f967e4b94..efcc52e33 100644 --- a/assets/js/958c573d.2d2b6ecd.js +++ b/assets/js/958c573d.77e843f7.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8786],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>b});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},d=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=l(n),d=a,b=m["".concat(c,".").concat(d)]||m[d]||u[d]||o;return n?r.createElement(b,i(i({ref:t},p),{},{components:n})):r.createElement(b,i({ref:t},p))}));function b(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=d;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[m]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"S3 Object"},i=void 0,s={unversionedId:"events/s3-object",id:"events/s3-object",title:"S3 Object",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/s3-object.md",sourceDirName:"events",slug:"/events/s3-object",permalink:"/docs/events/s3-object",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3-object.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"S3 Object"},sidebar:"tutorialSidebar",previous:{title:"S3 Batch",permalink:"/docs/events/s3-batch"},next:{title:"S3",permalink:"/docs/events/s3"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},m="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html"},"Transforming S3 Objects with S3 Object Lambda")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AmazonS3/latest/userguide/transforming-objects.html"},"Transforming objects with S3 Object Lambda"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport s3ObjectResponseMiddleware from '@middy/s3-object-response'\nimport {captureAWSv3Client, captureHTTPsGlobal} from 'aws-xray-sdk-core'\n\nexport const handler = middy()\n .use(s3ObjectResponseMiddleware({\n awsClientCapture: captureAWSv3Client,\n httpsCapture: captureHTTPsGlobal,\n bodyType: 'promise'\n }))\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8786],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>b});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},d=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=l(n),d=a,b=m["".concat(c,".").concat(d)]||m[d]||u[d]||o;return n?r.createElement(b,i(i({ref:t},p),{},{components:n})):r.createElement(b,i({ref:t},p))}));function b(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=d;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[m]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"S3 Object"},i=void 0,s={unversionedId:"events/s3-object",id:"events/s3-object",title:"S3 Object",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/s3-object.md",sourceDirName:"events",slug:"/events/s3-object",permalink:"/docs/events/s3-object",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3-object.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"S3 Object"},sidebar:"tutorialSidebar",previous:{title:"S3 Batch",permalink:"/docs/events/s3-batch"},next:{title:"S3",permalink:"/docs/events/s3"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},m="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html"},"Transforming S3 Objects with S3 Object Lambda")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AmazonS3/latest/userguide/transforming-objects.html"},"Transforming objects with S3 Object Lambda"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport s3ObjectResponseMiddleware from '@middy/s3-object-response'\nimport {captureAWSv3Client, captureHTTPsGlobal} from 'aws-xray-sdk-core'\n\nexport const handler = middy()\n .use(s3ObjectResponseMiddleware({\n awsClientCapture: captureAWSv3Client,\n httpsCapture: captureHTTPsGlobal,\n bodyType: 'promise'\n }))\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/9d43f09c.9b2a94bd.js b/assets/js/9d43f09c.7cd276a1.js similarity index 98% rename from assets/js/9d43f09c.9b2a94bd.js rename to assets/js/9d43f09c.7cd276a1.js index 4beb05c10..d18e20eeb 100644 --- a/assets/js/9d43f09c.9b2a94bd.js +++ b/assets/js/9d43f09c.7cd276a1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8591],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),d=l(n),m=a,f=d["".concat(s,".").concat(m)]||d[m]||u[m]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[d]="string"==typeof e?e:a,i[1]=c;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"EC2"},i=void 0,c={unversionedId:"events/ec2",id:"events/ec2",title:"EC2",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/ec2.md",sourceDirName:"events",slug:"/events/ec2",permalink:"/docs/events/ec2",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/ec2.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"EC2"},sidebar:"tutorialSidebar",previous:{title:"DynamoDB",permalink:"/docs/events/dynamodb"},next:{title:"EventBridge",permalink:"/docs/events/event-bridge"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},d="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-ec2.html"},"Using AWS Lambda with Amazon EC2"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8591],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),d=l(n),m=a,f=d["".concat(s,".").concat(m)]||d[m]||u[m]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[d]="string"==typeof e?e:a,i[1]=c;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"EC2"},i=void 0,c={unversionedId:"events/ec2",id:"events/ec2",title:"EC2",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/ec2.md",sourceDirName:"events",slug:"/events/ec2",permalink:"/docs/events/ec2",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/ec2.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"EC2"},sidebar:"tutorialSidebar",previous:{title:"DynamoDB",permalink:"/docs/events/dynamodb"},next:{title:"EventBridge",permalink:"/docs/events/event-bridge"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},d="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-ec2.html"},"Using AWS Lambda with Amazon EC2"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/9d560f77.06aa42ef.js b/assets/js/9d560f77.71e7accb.js similarity index 96% rename from assets/js/9d560f77.06aa42ef.js rename to assets/js/9d560f77.71e7accb.js index 5943233d8..59974383a 100644 --- a/assets/js/9d560f77.06aa42ef.js +++ b/assets/js/9d560f77.71e7accb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[310],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>y});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),d=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},s=function(e){var t=d(e.components);return r.createElement(c.Provider,{value:t},e.children)},m="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),m=d(n),u=o,y=m["".concat(c,".").concat(u)]||m[u]||p[u]||a;return n?r.createElement(y,i(i({ref:t},s),{},{components:n})):r.createElement(y,i({ref:t},s))}));function y(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=u;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[m]="string"==typeof e?e:o,i[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>d});var r=n(7462),o=(n(7294),n(3905));const a={title:"DynamoDB"},i=void 0,l={unversionedId:"events/dynamodb",id:"events/dynamodb",title:"DynamoDB",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/dynamodb.md",sourceDirName:"events",slug:"/events/dynamodb",permalink:"/docs/events/dynamodb",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/dynamodb.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"DynamoDB"},sidebar:"tutorialSidebar",previous:{title:"DocumentDB",permalink:"/docs/events/documentdb"},next:{title:"EC2",permalink:"/docs/events/ec2"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:d},m="wrapper";function p(e){let{components:t,...n}=e;return(0,o.kt)(m,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html"},"Using AWS Lambda with Amazon DynamoDB"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[310],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>y});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),d=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},s=function(e){var t=d(e.components);return r.createElement(c.Provider,{value:t},e.children)},m="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),m=d(n),u=o,y=m["".concat(c,".").concat(u)]||m[u]||p[u]||a;return n?r.createElement(y,i(i({ref:t},s),{},{components:n})):r.createElement(y,i({ref:t},s))}));function y(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=u;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[m]="string"==typeof e?e:o,i[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>l,toc:()=>d});var r=n(7462),o=(n(7294),n(3905));const a={title:"DynamoDB"},i=void 0,l={unversionedId:"events/dynamodb",id:"events/dynamodb",title:"DynamoDB",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/dynamodb.md",sourceDirName:"events",slug:"/events/dynamodb",permalink:"/docs/events/dynamodb",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/dynamodb.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"DynamoDB"},sidebar:"tutorialSidebar",previous:{title:"DocumentDB",permalink:"/docs/events/documentdb"},next:{title:"EC2",permalink:"/docs/events/ec2"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:d},m="wrapper";function p(e){let{components:t,...n}=e;return(0,o.kt)(m,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html"},"Using AWS Lambda with Amazon DynamoDB"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/a0697f1b.f36f9581.js b/assets/js/a0697f1b.73adca83.js similarity index 99% rename from assets/js/a0697f1b.f36f9581.js rename to assets/js/a0697f1b.73adca83.js index feda2c5cb..380caea7e 100644 --- a/assets/js/a0697f1b.f36f9581.js +++ b/assets/js/a0697f1b.73adca83.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5258],{3905:(e,t,r)=>{r.d(t,{Zo:()=>s,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),l=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},s=function(e){var t=l(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,s=d(e,["components","mdxType","originalType","parentName"]),m=l(r),u=a,y=m["".concat(p,".").concat(u)]||m[u]||c[u]||o;return r?n.createElement(y,i(i({ref:t},s),{},{components:r})):n.createElement(y,i({ref:t},s))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var l=2;l{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var n=r(7462),a=(r(7294),r(3905));const o={title:"VPC Lattice"},i=void 0,d={unversionedId:"events/vpc-lattice",id:"events/vpc-lattice",title:"VPC Lattice",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/vpc-lattice.md",sourceDirName:"events",slug:"/events/vpc-lattice",permalink:"/docs/events/vpc-lattice",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/vpc-lattice.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"VPC Lattice"},sidebar:"tutorialSidebar",previous:{title:"SQS",permalink:"/docs/events/sqs"},next:{title:"WorkMail",permalink:"/docs/events/workmail"}},p={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:l},m="wrapper";function c(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},s,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("p",null,"We recommend using ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-event-normalizer")," if you place to use any of the following: ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-json-body-parser"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-multipart-body-parser"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-urlencode-body-parser"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-partial-response")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-vpc-lattice.html"},"Using AWS Lambda with Amazon VPC Lattice"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer' // required\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n default: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .use(httpErrorHandlerMiddleware())\n .handler((event, context, { signal }) => {\n // ...\n })\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5258],{3905:(e,t,r)=>{r.d(t,{Zo:()=>s,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),l=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},s=function(e){var t=l(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,s=d(e,["components","mdxType","originalType","parentName"]),m=l(r),u=a,y=m["".concat(p,".").concat(u)]||m[u]||c[u]||o;return r?n.createElement(y,i(i({ref:t},s),{},{components:r})):n.createElement(y,i({ref:t},s))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var l=2;l{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var n=r(7462),a=(r(7294),r(3905));const o={title:"VPC Lattice"},i=void 0,d={unversionedId:"events/vpc-lattice",id:"events/vpc-lattice",title:"VPC Lattice",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/vpc-lattice.md",sourceDirName:"events",slug:"/events/vpc-lattice",permalink:"/docs/events/vpc-lattice",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/vpc-lattice.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"VPC Lattice"},sidebar:"tutorialSidebar",previous:{title:"SQS",permalink:"/docs/events/sqs"},next:{title:"WorkMail",permalink:"/docs/events/workmail"}},p={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:l},m="wrapper";function c(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},s,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("p",null,"We recommend using ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-event-normalizer")," if you place to use any of the following: ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-json-body-parser"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-multipart-body-parser"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-urlencode-body-parser"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-partial-response")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-vpc-lattice.html"},"Using AWS Lambda with Amazon VPC Lattice"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer' // required\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n default: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .use(httpErrorHandlerMiddleware())\n .handler((event, context, { signal }) => {\n // ...\n })\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/a07e9812.bfc6b093.js b/assets/js/a07e9812.9bccf14f.js similarity index 98% rename from assets/js/a07e9812.bfc6b093.js rename to assets/js/a07e9812.9bccf14f.js index ad6387b2b..cfbc22052 100644 --- a/assets/js/a07e9812.bfc6b093.js +++ b/assets/js/a07e9812.9bccf14f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2511],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var l=n.createContext({}),c=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=c(e.components);return n.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(r),u=a,f=d["".concat(l,".").concat(u)]||d[u]||m[u]||o;return r?n.createElement(f,i(i({ref:t},p),{},{components:r})):n.createElement(f,i({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var n=r(7462),a=(r(7294),r(3905));const o={title:"RDS"},i=void 0,s={unversionedId:"events/rds",id:"events/rds",title:"RDS",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/rds.md",sourceDirName:"events",slug:"/events/rds",permalink:"/docs/events/rds",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/rds.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"RDS"},sidebar:"tutorialSidebar",previous:{title:"MQ",permalink:"/docs/events/mq"},next:{title:"S3 Batch",permalink:"/docs/events/s3-batch"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},d="wrapper";function m(e){let{components:t,...r}=e;return(0,a.kt)(d,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-rds.html"},"Using AWS Lambda with Amazon RDS"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware()) // RDS -> SNS -> Lambda\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2511],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var l=n.createContext({}),c=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=c(e.components);return n.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(r),u=a,f=d["".concat(l,".").concat(u)]||d[u]||m[u]||o;return r?n.createElement(f,i(i({ref:t},p),{},{components:r})):n.createElement(f,i({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var n=r(7462),a=(r(7294),r(3905));const o={title:"RDS"},i=void 0,s={unversionedId:"events/rds",id:"events/rds",title:"RDS",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/rds.md",sourceDirName:"events",slug:"/events/rds",permalink:"/docs/events/rds",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/rds.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"RDS"},sidebar:"tutorialSidebar",previous:{title:"MQ",permalink:"/docs/events/mq"},next:{title:"S3 Batch",permalink:"/docs/events/s3-batch"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},d="wrapper";function m(e){let{components:t,...r}=e;return(0,a.kt)(d,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-rds.html"},"Using AWS Lambda with Amazon RDS"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware()) // RDS -> SNS -> Lambda\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/a17e0e42.c6d30fa6.js b/assets/js/a17e0e42.f3a0075a.js similarity index 99% rename from assets/js/a17e0e42.c6d30fa6.js rename to assets/js/a17e0e42.f3a0075a.js index 9c0674433..4ce89c7eb 100644 --- a/assets/js/a17e0e42.c6d30fa6.js +++ b/assets/js/a17e0e42.f3a0075a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2201],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var o=a.createContext({}),u=function(e){var t=a.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=u(e.components);return a.createElement(o.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),c=u(n),m=r,f=c["".concat(o,".").concat(m)]||c[m]||p[m]||l;return n?a.createElement(f,i(i({ref:t},d),{},{components:n})):a.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=m;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[c]="string"==typeof e?e:r,i[1]=s;for(var u=2;u{n.d(t,{Z:()=>i});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var a=n(7462),r=n(7294),l=n(6010),i=n(2466),s=n(6550),o=n(1980),u=n(7392),d=n(12);function c(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??c(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=p(e),[i,s]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:n,groupId:a}),[c,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),k=(()=>{const e=o??c;return m({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{k&&s(k)}),[k]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var k=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=d.indexOf(t),a=u[n].value;a!==s&&(c(t),o(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=d.indexOf(e.currentTarget)+1;t=d[n]??d[0];break}case"ArrowLeft":{const n=d.indexOf(e.currentTarget)-1;t=d[n]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:i}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",h.tabItem,i?.className,{"tabs__item--active":s===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function g(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},r.createElement(y,(0,a.Z)({},e,t)),r.createElement(v,(0,a.Z)({},e,t)))}function N(e){const t=(0,k.Z)();return r.createElement(g,(0,a.Z)({key:String(t)},e))}},6951:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>f,frontMatter:()=>s,metadata:()=>u,toc:()=>c});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),i=n(5162);const s={title:"s3"},o=void 0,u={unversionedId:"middlewares/s3",id:"middlewares/s3",title:"s3",description:"Fetches S3 stored configuration and parses out JSON.",source:"@site/docs/middlewares/s3.md",sourceDirName:"middlewares",slug:"/middlewares/s3",permalink:"/docs/middlewares/s3",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/s3.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"s3"},sidebar:"tutorialSidebar",previous:{title:"s3-object-response",permalink:"/docs/middlewares/s3-object-response"},next:{title:"secrets-manager",permalink:"/docs/middlewares/secrets-manager"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:c},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Fetches S3 stored configuration and parses out JSON."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/s3\nnpm install --save-dev @aws-sdk/client-s3\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/s3\nyarn add --dev @aws-sdk/client-s3\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/s3\npnpm add --save-dev @aws-sdk/client-s3\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"S3Client"),"): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-appconfig"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to S3Client class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"s3"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"s3:GetObject")),(0,r.kt)("li",{parentName:"ul"},"If the file is stored without ",(0,r.kt)("inlineCode",{parentName:"li"},"ContentType"),", you can set it on the response using ",(0,r.kt)("inlineCode",{parentName:"li"},"ResponseContentType")," as part of the input")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport s3 from '@middy/s3'\n\nconst handler = middy((event, context) => {\n console.log(context.config)\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n s3({\n fetchData: {\n config: {\n Bucket: '...',\n Key: '...'\n }\n },\n setToContext: true\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-s3")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2201],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var o=a.createContext({}),u=function(e){var t=a.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=u(e.components);return a.createElement(o.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),c=u(n),m=r,f=c["".concat(o,".").concat(m)]||c[m]||p[m]||l;return n?a.createElement(f,i(i({ref:t},d),{},{components:n})):a.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=m;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[c]="string"==typeof e?e:r,i[1]=s;for(var u=2;u{n.d(t,{Z:()=>i});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var a=n(7462),r=n(7294),l=n(6010),i=n(2466),s=n(6550),o=n(1980),u=n(7392),d=n(12);function c(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??c(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,s.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=p(e),[i,s]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:n,groupId:a}),[c,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),k=(()=>{const e=o??c;return m({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{k&&s(k)}),[k]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);s(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var k=n(2389);const h={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:c}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=d.indexOf(t),a=u[n].value;a!==s&&(c(t),o(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=d.indexOf(e.currentTarget)+1;t=d[n]??d[0];break}case"ArrowLeft":{const n=d.indexOf(e.currentTarget)-1;t=d[n]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:i}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",h.tabItem,i?.className,{"tabs__item--active":s===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function g(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",h.tabList)},r.createElement(y,(0,a.Z)({},e,t)),r.createElement(v,(0,a.Z)({},e,t)))}function N(e){const t=(0,k.Z)();return r.createElement(g,(0,a.Z)({key:String(t)},e))}},6951:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>f,frontMatter:()=>s,metadata:()=>u,toc:()=>c});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),i=n(5162);const s={title:"s3"},o=void 0,u={unversionedId:"middlewares/s3",id:"middlewares/s3",title:"s3",description:"Fetches S3 stored configuration and parses out JSON.",source:"@site/docs/middlewares/s3.md",sourceDirName:"middlewares",slug:"/middlewares/s3",permalink:"/docs/middlewares/s3",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/s3.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"s3"},sidebar:"tutorialSidebar",previous:{title:"s3-object-response",permalink:"/docs/middlewares/s3-object-response"},next:{title:"secrets-manager",permalink:"/docs/middlewares/secrets-manager"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:c},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Fetches S3 stored configuration and parses out JSON."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/s3\nnpm install --save-dev @aws-sdk/client-s3\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/s3\nyarn add --dev @aws-sdk/client-s3\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/s3\npnpm add --save-dev @aws-sdk/client-s3\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"S3Client"),"): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-appconfig"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to S3Client class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Internal key where secrets are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"s3"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"s3:GetObject")),(0,r.kt)("li",{parentName:"ul"},"If the file is stored without ",(0,r.kt)("inlineCode",{parentName:"li"},"ContentType"),", you can set it on the response using ",(0,r.kt)("inlineCode",{parentName:"li"},"ResponseContentType")," as part of the input")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport s3 from '@middy/s3'\n\nconst handler = middy((event, context) => {\n console.log(context.config)\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n s3({\n fetchData: {\n config: {\n Bucket: '...',\n Key: '...'\n }\n },\n setToContext: true\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-s3")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/a2b2d33a.fdf1530c.js b/assets/js/a2b2d33a.d803edd2.js similarity index 96% rename from assets/js/a2b2d33a.fdf1530c.js rename to assets/js/a2b2d33a.d803edd2.js index 0563edc45..42b78c1f2 100644 --- a/assets/js/a2b2d33a.fdf1530c.js +++ b/assets/js/a2b2d33a.d803edd2.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8974],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var l=n.createContext({}),c=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},p=function(e){var t=c(e.components);return n.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(r),u=i,f=d["".concat(l,".").concat(u)]||d[u]||m[u]||o;return r?n.createElement(f,a(a({ref:t},p),{},{components:r})):n.createElement(f,a({ref:t},p))}));function f(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=r.length,a=new Array(o);a[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:i,a[1]=s;for(var c=2;c{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var n=r(7462),i=(r(7294),r(3905));const o={title:"More Examples",position:6},a=void 0,s={unversionedId:"writing-middlewares/more-examples",id:"writing-middlewares/more-examples",title:"More Examples",description:"Check the code for existing middlewares to see more examples on how to write a middleware.",source:"@site/docs/writing-middlewares/06-more-examples.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/more-examples",permalink:"/docs/writing-middlewares/more-examples",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/06-more-examples.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:6,frontMatter:{title:"More Examples",position:6},sidebar:"tutorialSidebar",previous:{title:"Handle Timeouts",permalink:"/docs/writing-middlewares/timeouts"},next:{title:"With TypeScript",permalink:"/docs/writing-middlewares/with-typescript"}},l={},c=[],p={toc:c},d="wrapper";function m(e){let{components:t,...r}=e;return(0,i.kt)(d,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Check the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/tree/main/packages"},"code for existing middlewares")," to see more examples on how to write a middleware."))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8974],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var l=n.createContext({}),c=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},p=function(e){var t=c(e.components);return n.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(r),u=i,f=d["".concat(l,".").concat(u)]||d[u]||m[u]||o;return r?n.createElement(f,a(a({ref:t},p),{},{components:r})):n.createElement(f,a({ref:t},p))}));function f(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=r.length,a=new Array(o);a[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:i,a[1]=s;for(var c=2;c{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var n=r(7462),i=(r(7294),r(3905));const o={title:"More Examples",position:6},a=void 0,s={unversionedId:"writing-middlewares/more-examples",id:"writing-middlewares/more-examples",title:"More Examples",description:"Check the code for existing middlewares to see more examples on how to write a middleware.",source:"@site/docs/writing-middlewares/06-more-examples.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/more-examples",permalink:"/docs/writing-middlewares/more-examples",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/06-more-examples.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:6,frontMatter:{title:"More Examples",position:6},sidebar:"tutorialSidebar",previous:{title:"Handle Timeouts",permalink:"/docs/writing-middlewares/timeouts"},next:{title:"With TypeScript",permalink:"/docs/writing-middlewares/with-typescript"}},l={},c=[],p={toc:c},d="wrapper";function m(e){let{components:t,...r}=e;return(0,i.kt)(d,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Check the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/tree/main/packages"},"code for existing middlewares")," to see more examples on how to write a middleware."))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/a3787fd8.f6583fae.js b/assets/js/a3787fd8.54c96d3f.js similarity index 98% rename from assets/js/a3787fd8.f6583fae.js rename to assets/js/a3787fd8.54c96d3f.js index b3e36521d..7bc529374 100644 --- a/assets/js/a3787fd8.f6583fae.js +++ b/assets/js/a3787fd8.54c96d3f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9576],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var l=n.createContext({}),s=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},p=function(e){var t=s(e.components);return n.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,l=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),u=s(r),f=o,m=u["".concat(l,".").concat(f)]||u[f]||d[f]||i;return r?n.createElement(m,a(a({ref:t},p),{},{components:r})):n.createElement(m,a({ref:t},p))}));function m(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=f;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[u]="string"==typeof e?e:o,a[1]=c;for(var s=2;s{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>c,toc:()=>s});var n=r(7462),o=(r(7294),r(3905));const i={title:"Influence"},a=void 0,c={unversionedId:"intro/influence",id:"intro/influence",title:"Influence",description:"Middy has been one of the first projects to encourage the adoption of middlewares to simplify code reuse and best practices within the context of Lambda.",source:"@site/docs/intro/08-influence.md",sourceDirName:"intro",slug:"/intro/influence",permalink:"/docs/intro/influence",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-influence.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:8,frontMatter:{title:"Influence"},sidebar:"tutorialSidebar",previous:{title:"History",permalink:"/docs/intro/history"},next:{title:"Utilities",permalink:"/docs/intro/utilities"}},l={},s=[],p={toc:s},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Middy has been one of the first projects to encourage the adoption of middlewares to simplify code reuse and best practices within the context of Lambda."),(0,o.kt)("p",null,"Since middy started to gain popularity in the Node.js ecosystem, we have seen some independent projects taking the same ideas to other ecosystems:"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},".Net port ",(0,o.kt)("a",{parentName:"li",href:"https://github.com/VoxelGroup/Voxel.MiddyNet"},"Voxel.MiddyNet")," ",(0,o.kt)("a",{parentName:"li",href:"https://twitter.com/vgaltes/status/1366371605337825284"},"@vgaltes")),(0,o.kt)("li",{parentName:"ul"},"GoLang port ",(0,o.kt)("a",{parentName:"li",href:"https://github.com/mefellows/vesper"},"Vesper"))),(0,o.kt)("p",null,"Do you have a similar project? Let us know."))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9576],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var l=n.createContext({}),s=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},p=function(e){var t=s(e.components);return n.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,l=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),u=s(r),f=o,m=u["".concat(l,".").concat(f)]||u[f]||d[f]||i;return r?n.createElement(m,a(a({ref:t},p),{},{components:r})):n.createElement(m,a({ref:t},p))}));function m(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=f;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[u]="string"==typeof e?e:o,a[1]=c;for(var s=2;s{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>c,toc:()=>s});var n=r(7462),o=(r(7294),r(3905));const i={title:"Influence"},a=void 0,c={unversionedId:"intro/influence",id:"intro/influence",title:"Influence",description:"Middy has been one of the first projects to encourage the adoption of middlewares to simplify code reuse and best practices within the context of Lambda.",source:"@site/docs/intro/08-influence.md",sourceDirName:"intro",slug:"/intro/influence",permalink:"/docs/intro/influence",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-influence.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:8,frontMatter:{title:"Influence"},sidebar:"tutorialSidebar",previous:{title:"History",permalink:"/docs/intro/history"},next:{title:"Utilities",permalink:"/docs/intro/utilities"}},l={},s=[],p={toc:s},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Middy has been one of the first projects to encourage the adoption of middlewares to simplify code reuse and best practices within the context of Lambda."),(0,o.kt)("p",null,"Since middy started to gain popularity in the Node.js ecosystem, we have seen some independent projects taking the same ideas to other ecosystems:"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},".Net port ",(0,o.kt)("a",{parentName:"li",href:"https://github.com/VoxelGroup/Voxel.MiddyNet"},"Voxel.MiddyNet")," ",(0,o.kt)("a",{parentName:"li",href:"https://twitter.com/vgaltes/status/1366371605337825284"},"@vgaltes")),(0,o.kt)("li",{parentName:"ul"},"GoLang port ",(0,o.kt)("a",{parentName:"li",href:"https://github.com/mefellows/vesper"},"Vesper"))),(0,o.kt)("p",null,"Do you have a similar project? Let us know."))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/a7630442.617094e2.js b/assets/js/a7630442.be7749ba.js similarity index 96% rename from assets/js/a7630442.617094e2.js rename to assets/js/a7630442.be7749ba.js index c9b0583cd..6bb271d99 100644 --- a/assets/js/a7630442.617094e2.js +++ b/assets/js/a7630442.be7749ba.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9502],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),p=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=p(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,c=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(r),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||i;return r?n.createElement(f,a(a({ref:t},l),{},{components:r})):n.createElement(f,a({ref:t},l))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,a[1]=s;for(var p=2;p{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var n=r(7462),o=(r(7294),r(3905));const i={title:"Sponsoring"},a=void 0,s={unversionedId:"intro/sponsoring",id:"intro/sponsoring",title:"Sponsoring",description:"If Middy is adding value to your project or organization and you would like to support its long term maintenance, becoming a sponsor is a great way to do that.",source:"@site/docs/intro/11-sponsoring.md",sourceDirName:"intro",slug:"/intro/sponsoring",permalink:"/docs/intro/sponsoring",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/11-sponsoring.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:11,frontMatter:{title:"Sponsoring"},sidebar:"tutorialSidebar",previous:{title:"Contributing",permalink:"/docs/intro/contributing"},next:{title:"Middlewares",permalink:"/docs/category/middlewares"}},c={},p=[],l={toc:p},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"If Middy is adding value to your project or organization and you would like to support its long term maintenance, becoming a sponsor is a great way to do that."),(0,o.kt)("p",null,(0,o.kt)("a",{parentName:"p",href:"https://github.com/sponsors/willfarrell"},"GitHub Sponsors")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9502],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),p=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=p(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,c=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(r),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||i;return r?n.createElement(f,a(a({ref:t},l),{},{components:r})):n.createElement(f,a({ref:t},l))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,a[1]=s;for(var p=2;p{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var n=r(7462),o=(r(7294),r(3905));const i={title:"Sponsoring"},a=void 0,s={unversionedId:"intro/sponsoring",id:"intro/sponsoring",title:"Sponsoring",description:"If Middy is adding value to your project or organization and you would like to support its long term maintenance, becoming a sponsor is a great way to do that.",source:"@site/docs/intro/11-sponsoring.md",sourceDirName:"intro",slug:"/intro/sponsoring",permalink:"/docs/intro/sponsoring",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/11-sponsoring.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:11,frontMatter:{title:"Sponsoring"},sidebar:"tutorialSidebar",previous:{title:"Contributing",permalink:"/docs/intro/contributing"},next:{title:"Middlewares",permalink:"/docs/category/middlewares"}},c={},p=[],l={toc:p},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"If Middy is adding value to your project or organization and you would like to support its long term maintenance, becoming a sponsor is a great way to do that."),(0,o.kt)("p",null,(0,o.kt)("a",{parentName:"p",href:"https://github.com/sponsors/willfarrell"},"GitHub Sponsors")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/a7c9f8b5.b764346a.js b/assets/js/a7c9f8b5.02e8e9fe.js similarity index 98% rename from assets/js/a7c9f8b5.b764346a.js rename to assets/js/a7c9f8b5.02e8e9fe.js index 624da45ad..7e8dd7a17 100644 --- a/assets/js/a7c9f8b5.b764346a.js +++ b/assets/js/a7c9f8b5.02e8e9fe.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5898],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(n),m=a,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"SES"},i=void 0,s={unversionedId:"events/ses",id:"events/ses",title:"SES",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/ses.md",sourceDirName:"events",slug:"/events/ses",permalink:"/docs/events/ses",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/ses.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"SES"},sidebar:"tutorialSidebar",previous:{title:"Secrets Manager",permalink:"/docs/events/secrets-manager"},next:{title:"SNS",permalink:"/docs/events/sns"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-ses.html"},"Using AWS Lambda with Amazon SES"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5898],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(n),m=a,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"SES"},i=void 0,s={unversionedId:"events/ses",id:"events/ses",title:"SES",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/ses.md",sourceDirName:"events",slug:"/events/ses",permalink:"/docs/events/ses",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/ses.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"SES"},sidebar:"tutorialSidebar",previous:{title:"Secrets Manager",permalink:"/docs/events/secrets-manager"},next:{title:"SNS",permalink:"/docs/events/sns"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-ses.html"},"Using AWS Lambda with Amazon SES"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/a8e9225e.fa253a56.js b/assets/js/a8e9225e.5a257153.js similarity index 99% rename from assets/js/a8e9225e.fa253a56.js rename to assets/js/a8e9225e.5a257153.js index 4eeae60f2..de7f52042 100644 --- a/assets/js/a8e9225e.fa253a56.js +++ b/assets/js/a8e9225e.5a257153.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9319],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function l(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,s=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),u=d(n),m=r,f=u["".concat(s,".").concat(m)]||u[m]||c[m]||i;return n?a.createElement(f,l(l({ref:t},p),{},{components:n})):a.createElement(f,l({ref:t},p))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,l=new Array(i);l[0]=m;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[u]="string"==typeof e?e:r,l[1]=o;for(var d=2;d{n.d(t,{Z:()=>l});var a=n(7294),r=n(6010);const i={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:n,className:l}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(i.tabItem,l),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>v});var a=n(7462),r=n(7294),i=n(6010),l=n(2466),o=n(6550),s=n(1980),d=n(7392),p=n(12);function u(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function c(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??u(n);return function(e){const t=(0,d.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(i),(0,r.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(a.location.search);t.set(i,e),a.replace({...a.location,search:t.toString()})}),[i,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,i=c(e),[l,o]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:i}))),[s,d]=f({queryString:n,groupId:a}),[u,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,i]=(0,p.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:a}),g=(()=>{const e=s??u;return m({value:e,tabValues:i})?e:null})();(0,r.useLayoutEffect)((()=>{g&&o(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),h(e)}),[d,h,i]),tabValues:i}}var g=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:o,selectValue:s,tabValues:d}=e;const p=[],{blockElementScrollPositionUntilNextRender:u}=(0,l.o5)(),c=e=>{const t=e.currentTarget,n=p.indexOf(t),a=d[n].value;a!==o&&(u(t),s(a))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=p.indexOf(e.currentTarget)+1;t=p[n]??p[0];break}case"ArrowLeft":{const n=p.indexOf(e.currentTarget)-1;t=p[n]??p[p.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.Z)("tabs",{"tabs--block":n},t)},d.map((e=>{let{value:t,label:n,attributes:l}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:c},l,{className:(0,i.Z)("tabs__item",b.tabItem,l?.className,{"tabs__item--active":o===t})}),n??t)})))}function k(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},i.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function N(e){const t=h(e);return r.createElement("div",{className:(0,i.Z)("tabs-container",b.tabList)},r.createElement(y,(0,a.Z)({},e,t)),r.createElement(k,(0,a.Z)({},e,t)))}function v(e){const t=(0,g.Z)();return r.createElement(N,(0,a.Z)({key:String(t)},e))}},1468:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>d,toc:()=>u});var a=n(7462),r=(n(7294),n(3905)),i=n(4866),l=n(5162);const o={title:"http-content-negotiation"},s=void 0,d={unversionedId:"middlewares/http-content-negotiation",id:"middlewares/http-content-negotiation",title:"http-content-negotiation",description:"This middleware parses Accept-* headers and provides utilities for HTTP content negotiation (charset, encoding, language and media type).",source:"@site/docs/middlewares/http-content-negotiation.md",sourceDirName:"middlewares",slug:"/middlewares/http-content-negotiation",permalink:"/docs/middlewares/http-content-negotiation",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-content-negotiation.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-content-negotiation"},sidebar:"tutorialSidebar",previous:{title:"http-content-encoding",permalink:"/docs/middlewares/http-content-encoding"},next:{title:"http-cors",permalink:"/docs/middlewares/http-cors"}},p={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:u},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This middleware parses ",(0,r.kt)("inlineCode",{parentName:"p"},"Accept-*")," headers and provides utilities for ",(0,r.kt)("a",{parentName:"p",href:"https://tools.ietf.org/html/rfc7231#section-5.3"},"HTTP content negotiation")," (charset, encoding, language and media type)."),(0,r.kt)("p",null,"By default the middleware parses charsets (",(0,r.kt)("inlineCode",{parentName:"p"},"Accept-Charset"),"), languages (",(0,r.kt)("inlineCode",{parentName:"p"},"Accept-Language"),"), encodings (",(0,r.kt)("inlineCode",{parentName:"p"},"Accept-Encoding"),") and media types (",(0,r.kt)("inlineCode",{parentName:"p"},"Accept"),") during the\n",(0,r.kt)("inlineCode",{parentName:"p"},"before")," phase and expands the ",(0,r.kt)("inlineCode",{parentName:"p"},"event")," object by adding the following properties:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredCharsets")," (",(0,r.kt)("inlineCode",{parentName:"li"},"array"),") - The list of charsets that can be safely used by the app (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredCharset")," (",(0,r.kt)("inlineCode",{parentName:"li"},"string"),") - The preferred charset (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredEncodings")," (",(0,r.kt)("inlineCode",{parentName:"li"},"array"),") - The list of encodings that can be safely used by the app (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredEncoding")," (",(0,r.kt)("inlineCode",{parentName:"li"},"string"),") - The preferred encoding (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredLanguages")," (",(0,r.kt)("inlineCode",{parentName:"li"},"array"),") - The list of languages that can be safely used by the app (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredLanguage")," (",(0,r.kt)("inlineCode",{parentName:"li"},"string"),") - The preferred language (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredMediaTypes")," (",(0,r.kt)("inlineCode",{parentName:"li"},"array"),") - The list of media types that can be safely used by the app (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredMediaType")," (",(0,r.kt)("inlineCode",{parentName:"li"},"string"),") - The preferred media types (as the result of the negotiation)")),(0,r.kt)("p",null,"This middleware expects the headers in canonical format, so it should be attached after the ",(0,r.kt)("a",{parentName:"p",href:"#httpheadernormalizer"},(0,r.kt)("inlineCode",{parentName:"a"},"httpHeaderNormalizer"))," middleware.\nIt also can throw an HTTP exception, so it can be convenient to use it in combination with the ",(0,r.kt)("a",{parentName:"p",href:"#httperrorhandler"},(0,r.kt)("inlineCode",{parentName:"a"},"httpErrorHandler")),"."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(i.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-content-negotiation\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-content-negotiation\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-content-negotiation\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"parseCharsets")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - Allows enabling/disabling the charsets parsing"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"availableCharsets")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),") - Allows defining the list of charsets supported by the Lambda function"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"parseEncodings")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - Allows enabling/disabling the encodings parsing"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"availableEncodings")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),") - Allows defining the list of encodings supported by the Lambda function"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"parseLanguages")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - Allows enabling/disabling the languages parsing"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"availableLanguages")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),") - Allows defining the list of languages supported by the Lambda function"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"parseMediaTypes")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - Allows enabling/disabling the media types parsing"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"availableMediaTypes")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),") - Allows defining the list of media types supported by the Lambda function"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"failOnMismatch")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - If set to true it will throw an HTTP ",(0,r.kt)("inlineCode",{parentName:"li"},"NotAcceptable")," (406) exception when the negotiation fails for one of the headers (e.g. none of the languages requested are supported by the app)")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpContentNegotiation from '@middy/http-content-negotiation'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpErrorHandler from '@middy/http-error-handler'\n\nexport const handler = middy((event, context) => {\n let message, body\n\n switch (event.preferredLanguage) {\n case 'it-it':\n message = 'Ciao Mondo'\n break\n case 'fr-fr':\n message = 'Bonjour le monde'\n break\n default:\n message = 'Hello world'\n }\n\n switch (event.preferredMediaType) {\n case 'application/xml':\n body = `${message}`\n break\n case 'application/yaml':\n body = `---\\nmessage: ${message}`\n break\n case 'application/json':\n body = JSON.stringify({ message })\n break\n default:\n body = message\n }\n\n return {\n statusCode: 200,\n body\n }\n})\n\nhandler\n .use(httpHeaderNormalizer())\n .use(httpContentNegotiation({\n parseCharsets: false,\n parseEncodings: false,\n availableLanguages: ['it-it', 'fr-fr', 'en'],\n availableMediaTypes: ['application/xml', 'application/yaml', 'application/json', 'text/plain']\n }))\n .use(httpErrorHandler())\n\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9319],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function l(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,s=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),u=d(n),m=r,f=u["".concat(s,".").concat(m)]||u[m]||c[m]||i;return n?a.createElement(f,l(l({ref:t},p),{},{components:n})):a.createElement(f,l({ref:t},p))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,l=new Array(i);l[0]=m;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[u]="string"==typeof e?e:r,l[1]=o;for(var d=2;d{n.d(t,{Z:()=>l});var a=n(7294),r=n(6010);const i={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:n,className:l}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(i.tabItem,l),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>v});var a=n(7462),r=n(7294),i=n(6010),l=n(2466),o=n(6550),s=n(1980),d=n(7392),p=n(12);function u(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function c(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??u(n);return function(e){const t=(0,d.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(i),(0,r.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(a.location.search);t.set(i,e),a.replace({...a.location,search:t.toString()})}),[i,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,i=c(e),[l,o]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:i}))),[s,d]=f({queryString:n,groupId:a}),[u,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,i]=(0,p.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:a}),g=(()=>{const e=s??u;return m({value:e,tabValues:i})?e:null})();(0,r.useLayoutEffect)((()=>{g&&o(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),h(e)}),[d,h,i]),tabValues:i}}var g=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:o,selectValue:s,tabValues:d}=e;const p=[],{blockElementScrollPositionUntilNextRender:u}=(0,l.o5)(),c=e=>{const t=e.currentTarget,n=p.indexOf(t),a=d[n].value;a!==o&&(u(t),s(a))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=p.indexOf(e.currentTarget)+1;t=p[n]??p[0];break}case"ArrowLeft":{const n=p.indexOf(e.currentTarget)-1;t=p[n]??p[p.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.Z)("tabs",{"tabs--block":n},t)},d.map((e=>{let{value:t,label:n,attributes:l}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:c},l,{className:(0,i.Z)("tabs__item",b.tabItem,l?.className,{"tabs__item--active":o===t})}),n??t)})))}function k(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},i.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function N(e){const t=h(e);return r.createElement("div",{className:(0,i.Z)("tabs-container",b.tabList)},r.createElement(y,(0,a.Z)({},e,t)),r.createElement(k,(0,a.Z)({},e,t)))}function v(e){const t=(0,g.Z)();return r.createElement(N,(0,a.Z)({key:String(t)},e))}},1468:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>d,toc:()=>u});var a=n(7462),r=(n(7294),n(3905)),i=n(4866),l=n(5162);const o={title:"http-content-negotiation"},s=void 0,d={unversionedId:"middlewares/http-content-negotiation",id:"middlewares/http-content-negotiation",title:"http-content-negotiation",description:"This middleware parses Accept-* headers and provides utilities for HTTP content negotiation (charset, encoding, language and media type).",source:"@site/docs/middlewares/http-content-negotiation.md",sourceDirName:"middlewares",slug:"/middlewares/http-content-negotiation",permalink:"/docs/middlewares/http-content-negotiation",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-content-negotiation.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-content-negotiation"},sidebar:"tutorialSidebar",previous:{title:"http-content-encoding",permalink:"/docs/middlewares/http-content-encoding"},next:{title:"http-cors",permalink:"/docs/middlewares/http-cors"}},p={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:u},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This middleware parses ",(0,r.kt)("inlineCode",{parentName:"p"},"Accept-*")," headers and provides utilities for ",(0,r.kt)("a",{parentName:"p",href:"https://tools.ietf.org/html/rfc7231#section-5.3"},"HTTP content negotiation")," (charset, encoding, language and media type)."),(0,r.kt)("p",null,"By default the middleware parses charsets (",(0,r.kt)("inlineCode",{parentName:"p"},"Accept-Charset"),"), languages (",(0,r.kt)("inlineCode",{parentName:"p"},"Accept-Language"),"), encodings (",(0,r.kt)("inlineCode",{parentName:"p"},"Accept-Encoding"),") and media types (",(0,r.kt)("inlineCode",{parentName:"p"},"Accept"),") during the\n",(0,r.kt)("inlineCode",{parentName:"p"},"before")," phase and expands the ",(0,r.kt)("inlineCode",{parentName:"p"},"event")," object by adding the following properties:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredCharsets")," (",(0,r.kt)("inlineCode",{parentName:"li"},"array"),") - The list of charsets that can be safely used by the app (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredCharset")," (",(0,r.kt)("inlineCode",{parentName:"li"},"string"),") - The preferred charset (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredEncodings")," (",(0,r.kt)("inlineCode",{parentName:"li"},"array"),") - The list of encodings that can be safely used by the app (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredEncoding")," (",(0,r.kt)("inlineCode",{parentName:"li"},"string"),") - The preferred encoding (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredLanguages")," (",(0,r.kt)("inlineCode",{parentName:"li"},"array"),") - The list of languages that can be safely used by the app (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredLanguage")," (",(0,r.kt)("inlineCode",{parentName:"li"},"string"),") - The preferred language (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredMediaTypes")," (",(0,r.kt)("inlineCode",{parentName:"li"},"array"),") - The list of media types that can be safely used by the app (as the result of the negotiation)"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"preferredMediaType")," (",(0,r.kt)("inlineCode",{parentName:"li"},"string"),") - The preferred media types (as the result of the negotiation)")),(0,r.kt)("p",null,"This middleware expects the headers in canonical format, so it should be attached after the ",(0,r.kt)("a",{parentName:"p",href:"#httpheadernormalizer"},(0,r.kt)("inlineCode",{parentName:"a"},"httpHeaderNormalizer"))," middleware.\nIt also can throw an HTTP exception, so it can be convenient to use it in combination with the ",(0,r.kt)("a",{parentName:"p",href:"#httperrorhandler"},(0,r.kt)("inlineCode",{parentName:"a"},"httpErrorHandler")),"."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(i.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-content-negotiation\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-content-negotiation\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-content-negotiation\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"parseCharsets")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - Allows enabling/disabling the charsets parsing"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"availableCharsets")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),") - Allows defining the list of charsets supported by the Lambda function"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"parseEncodings")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - Allows enabling/disabling the encodings parsing"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"availableEncodings")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),") - Allows defining the list of encodings supported by the Lambda function"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"parseLanguages")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - Allows enabling/disabling the languages parsing"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"availableLanguages")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),") - Allows defining the list of languages supported by the Lambda function"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"parseMediaTypes")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - Allows enabling/disabling the media types parsing"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"availableMediaTypes")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),") - Allows defining the list of media types supported by the Lambda function"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"failOnMismatch")," (defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),") - If set to true it will throw an HTTP ",(0,r.kt)("inlineCode",{parentName:"li"},"NotAcceptable")," (406) exception when the negotiation fails for one of the headers (e.g. none of the languages requested are supported by the app)")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpContentNegotiation from '@middy/http-content-negotiation'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpErrorHandler from '@middy/http-error-handler'\n\nexport const handler = middy((event, context) => {\n let message, body\n\n switch (event.preferredLanguage) {\n case 'it-it':\n message = 'Ciao Mondo'\n break\n case 'fr-fr':\n message = 'Bonjour le monde'\n break\n default:\n message = 'Hello world'\n }\n\n switch (event.preferredMediaType) {\n case 'application/xml':\n body = `${message}`\n break\n case 'application/yaml':\n body = `---\\nmessage: ${message}`\n break\n case 'application/json':\n body = JSON.stringify({ message })\n break\n default:\n body = message\n }\n\n return {\n statusCode: 200,\n body\n }\n})\n\nhandler\n .use(httpHeaderNormalizer())\n .use(httpContentNegotiation({\n parseCharsets: false,\n parseEncodings: false,\n availableLanguages: ['it-it', 'fr-fr', 'en'],\n availableMediaTypes: ['application/xml', 'application/yaml', 'application/json', 'text/plain']\n }))\n .use(httpErrorHandler())\n\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/acb7d57c.df5217f6.js b/assets/js/acb7d57c.83cb61c6.js similarity index 96% rename from assets/js/acb7d57c.df5217f6.js rename to assets/js/acb7d57c.83cb61c6.js index b16f90270..7d2f3f995 100644 --- a/assets/js/acb7d57c.df5217f6.js +++ b/assets/js/acb7d57c.83cb61c6.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1819],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function c(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var a=n.createContext({}),p=function(e){var t=n.useContext(a),r=t;return e&&(r="function"==typeof e?e(t):c(c({},t),e)),r},l=function(e){var t=p(e.components);return n.createElement(a.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,a=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(r),m=o,f=u["".concat(a,".").concat(m)]||u[m]||d[m]||i;return r?n.createElement(f,c(c({ref:t},l),{},{components:r})):n.createElement(f,c({ref:t},l))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,c=new Array(i);c[0]=m;var s={};for(var a in t)hasOwnProperty.call(t,a)&&(s[a]=t[a]);s.originalType=e,s[u]="string"==typeof e?e:o,c[1]=s;for(var p=2;p{r.r(t),r.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var n=r(7462),o=(r(7294),r(3905));const i={title:"Intro",sidebar_position:1},c=void 0,s={unversionedId:"best-practices/intro",id:"best-practices/intro",title:"Intro",description:"In this section you will find some common tips and tricks to ensure you don't hit any performance or security issues.",source:"@site/docs/best-practices/01-intro.md",sourceDirName:"best-practices",slug:"/best-practices/intro",permalink:"/docs/best-practices/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:1,frontMatter:{title:"Intro",sidebar_position:1},sidebar:"tutorialSidebar",previous:{title:"Best Practices",permalink:"/docs/category/best-practices"},next:{title:"Connection reuse",permalink:"/docs/best-practices/connection-reuse"}},a={},p=[],l={toc:p},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"In this section you will find some common tips and tricks to ensure you don't hit any performance or security issues."),(0,o.kt)("p",null,"Did we miss something? Let us know."))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1819],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function c(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var a=n.createContext({}),p=function(e){var t=n.useContext(a),r=t;return e&&(r="function"==typeof e?e(t):c(c({},t),e)),r},l=function(e){var t=p(e.components);return n.createElement(a.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,a=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(r),m=o,f=u["".concat(a,".").concat(m)]||u[m]||d[m]||i;return r?n.createElement(f,c(c({ref:t},l),{},{components:r})):n.createElement(f,c({ref:t},l))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,c=new Array(i);c[0]=m;var s={};for(var a in t)hasOwnProperty.call(t,a)&&(s[a]=t[a]);s.originalType=e,s[u]="string"==typeof e?e:o,c[1]=s;for(var p=2;p{r.r(t),r.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var n=r(7462),o=(r(7294),r(3905));const i={title:"Intro",sidebar_position:1},c=void 0,s={unversionedId:"best-practices/intro",id:"best-practices/intro",title:"Intro",description:"In this section you will find some common tips and tricks to ensure you don't hit any performance or security issues.",source:"@site/docs/best-practices/01-intro.md",sourceDirName:"best-practices",slug:"/best-practices/intro",permalink:"/docs/best-practices/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:1,frontMatter:{title:"Intro",sidebar_position:1},sidebar:"tutorialSidebar",previous:{title:"Best Practices",permalink:"/docs/category/best-practices"},next:{title:"Connection reuse",permalink:"/docs/best-practices/connection-reuse"}},a={},p=[],l={toc:p},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"In this section you will find some common tips and tricks to ensure you don't hit any performance or security issues."),(0,o.kt)("p",null,"Did we miss something? Let us know."))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/ace0032f.83bd6b48.js b/assets/js/ace0032f.a8f83d05.js similarity index 98% rename from assets/js/ace0032f.83bd6b48.js rename to assets/js/ace0032f.a8f83d05.js index 1554ddd51..37ab902de 100644 --- a/assets/js/ace0032f.83bd6b48.js +++ b/assets/js/ace0032f.a8f83d05.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2521],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),l=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=l(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(r),f=o,m=u["".concat(c,".").concat(f)]||u[f]||d[f]||a;return r?n.createElement(m,i(i({ref:t},p),{},{components:r})):n.createElement(m,i({ref:t},p))}));function m(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=f;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var n=r(7462),o=(r(7294),r(3905));const a={title:"Serverless Stack"},i=void 0,s={unversionedId:"integrations/serverless-stack",id:"integrations/serverless-stack",title:"Serverless Stack",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/serverless-stack.md",sourceDirName:"integrations",slug:"/integrations/serverless-stack",permalink:"/docs/integrations/serverless-stack",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/serverless-stack.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Serverless Stack"},sidebar:"tutorialSidebar",previous:{title:"Serverless Framework",permalink:"/docs/integrations/serverless-framework"},next:{title:"Best Practices",permalink:"/docs/category/best-practices"}},c={},l=[],p={toc:l},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2521],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),l=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=l(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(r),f=o,m=u["".concat(c,".").concat(f)]||u[f]||d[f]||a;return r?n.createElement(m,i(i({ref:t},p),{},{components:r})):n.createElement(m,i({ref:t},p))}));function m(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=f;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var n=r(7462),o=(r(7294),r(3905));const a={title:"Serverless Stack"},i=void 0,s={unversionedId:"integrations/serverless-stack",id:"integrations/serverless-stack",title:"Serverless Stack",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/serverless-stack.md",sourceDirName:"integrations",slug:"/integrations/serverless-stack",permalink:"/docs/integrations/serverless-stack",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/serverless-stack.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Serverless Stack"},sidebar:"tutorialSidebar",previous:{title:"Serverless Framework",permalink:"/docs/integrations/serverless-framework"},next:{title:"Best Practices",permalink:"/docs/category/best-practices"}},c={},l=[],p={toc:l},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/ad1e712e.5822815e.js b/assets/js/ad1e712e.6d1d596b.js similarity index 99% rename from assets/js/ad1e712e.5822815e.js rename to assets/js/ad1e712e.6d1d596b.js index 419181a04..7995bb861 100644 --- a/assets/js/ad1e712e.5822815e.js +++ b/assets/js/ad1e712e.6d1d596b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9235],{3905:(e,t,a)=>{a.d(t,{Zo:()=>p,kt:()=>h});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var l=r.createContext({}),d=function(e){var t=r.useContext(l),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},p=function(e){var t=d(e.components);return r.createElement(l.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,i=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=d(a),u=n,h=m["".concat(l,".").concat(u)]||m[u]||c[u]||i;return a?r.createElement(h,o(o({ref:t},p),{},{components:a})):r.createElement(h,o({ref:t},p))}));function h(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var i=a.length,o=new Array(i);o[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[m]="string"==typeof e?e:n,o[1]=s;for(var d=2;d{a.r(t),a.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>s,toc:()=>d});var r=a(7462),n=(a(7294),a(3905));const i={title:"Official middlewares",sidebar_position:0},o=void 0,s={unversionedId:"middlewares/intro",id:"middlewares/intro",title:"Official middlewares",description:"Middy comes with a series of additional (opt-in) plugins that are officially maintained by the core team and kept in sync with every release of the core package.",source:"@site/docs/middlewares/00-intro.md",sourceDirName:"middlewares",slug:"/middlewares/intro",permalink:"/docs/middlewares/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/00-intro.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:0,frontMatter:{title:"Official middlewares",sidebar_position:0},sidebar:"tutorialSidebar",previous:{title:"Middlewares",permalink:"/docs/category/middlewares"},next:{title:"Third-party middlewares",permalink:"/docs/middlewares/third-party"}},l={},d=[{value:"Misc",id:"misc",level:2},{value:"Request Transformation",id:"request-transformation",level:2},{value:"Response Transformation",id:"response-transformation",level:2},{value:"Fetch Data",id:"fetch-data",level:2}],p={toc:d},m="wrapper";function c(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},p,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Middy comes with a series of additional (opt-in) plugins that are officially maintained by the core team and kept in sync with every release of the core package."),(0,n.kt)("p",null,"These middleware focus on common use cases when using Lambda with other AWS services."),(0,n.kt)("p",null,"Each middleware should do a single task. We try to balance each to be as performant as possible while meeting the majority of developer needs."),(0,n.kt)("h2",{id:"misc"},"Misc"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/cloudwatch-metrics"},(0,n.kt)("inlineCode",{parentName:"a"},"cloudwatch-metrics")),": Hydrates lambda's ",(0,n.kt)("inlineCode",{parentName:"li"},"context.metrics")," property with an instance of AWS MetricLogger"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/do-not-wait-for-empty-event-loop"},(0,n.kt)("inlineCode",{parentName:"a"},"do-not-wait-for-empty-event-loop")),": Sets callbackWaitsForEmptyEventLoop property to false"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/error-logger"},(0,n.kt)("inlineCode",{parentName:"a"},"error-logger")),": Logs errors"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/input-output-logger"},(0,n.kt)("inlineCode",{parentName:"a"},"input-output-logger")),": Logs request and response"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/warmup"},(0,n.kt)("inlineCode",{parentName:"a"},"warmup")),": Used to pre-warm a lambda function")),(0,n.kt)("h2",{id:"request-transformation"},"Request Transformation"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/event-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"event-normalizer")),": Middleware for iterating through an AWS event records, parsing and normalizing nested events."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-content-negotiation"},(0,n.kt)("inlineCode",{parentName:"a"},"http-content-negotiation")),": Parses ",(0,n.kt)("inlineCode",{parentName:"li"},"Accept-*")," headers and provides utilities for content negotiation (charset, encoding, language and media type) for HTTP requests"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-event-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"http-event-normalizer")),": Normalizes HTTP events by adding an empty object for ",(0,n.kt)("inlineCode",{parentName:"li"},"queryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"li"},"multiValueQueryStringParameters")," or ",(0,n.kt)("inlineCode",{parentName:"li"},"pathParameters")," if they are missing."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-header-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"http-header-normalizer")),": Normalizes HTTP header names to their canonical format"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-json-body-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"http-json-body-parser")),": Automatically parses HTTP requests with JSON body and converts the body into an object. Also handles gracefully broken JSON if used in combination of\n",(0,n.kt)("inlineCode",{parentName:"li"},"httpErrorHandler"),"."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-multipart-body-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"http-multipart-body-parser")),": Automatically parses HTTP requests with content type ",(0,n.kt)("inlineCode",{parentName:"li"},"multipart/form-data")," and converts the body into an object."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-urlencode-body-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"http-urlencode-body-parser")),": Automatically parses HTTP requests with URL encoded body (typically the result of a form submit)."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-urlencode-path-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"http-urlencode-path-parser")),": Automatically parses HTTP requests with URL encoded path."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/validator"},(0,n.kt)("inlineCode",{parentName:"a"},"validator")),": Automatically validates incoming events and outgoing responses against custom schemas."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/ws-json-body-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"ws-json-body-parser")),": Automatically parses WebSocket requests with JSON message and converts the message into an object.")),(0,n.kt)("h2",{id:"response-transformation"},"Response Transformation"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-content-encoding"},(0,n.kt)("inlineCode",{parentName:"a"},"http-content-encoding")),": Sets HTTP Content-Encoding header on response and compresses response body"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-cors"},(0,n.kt)("inlineCode",{parentName:"a"},"http-cors")),": Sets HTTP CORS headers on response"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-error-handler"},(0,n.kt)("inlineCode",{parentName:"a"},"http-error-handler")),": Creates a proper HTTP response for errors that are created with the ",(0,n.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/http-errors"},"http-errors")," module and represents proper HTTP errors."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-security-headers"},(0,n.kt)("inlineCode",{parentName:"a"},"http-security-headers")),": Applies best practice security headers to responses. It's a simplified port of HelmetJS."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-partial-response"},(0,n.kt)("inlineCode",{parentName:"a"},"http-partial-response")),": Filter response objects attributes based on query string parameters."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-response-serializer"},(0,n.kt)("inlineCode",{parentName:"a"},"http-response-serializer")),": HTTP response serializer."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/sqs-partial-batch-failure"},(0,n.kt)("inlineCode",{parentName:"a"},"sqs-partial-batch-failure")),": Handles partially failed SQS batches."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/ws-response"},(0,n.kt)("inlineCode",{parentName:"a"},"ws-response")),": Forwards response to WebSocket endpoint.")),(0,n.kt)("h2",{id:"fetch-data"},"Fetch Data"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/appconfig"},(0,n.kt)("inlineCode",{parentName:"a"},"appconfig")),": Fetch JSON configurations from AppConfig."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/dynamodb"},(0,n.kt)("inlineCode",{parentName:"a"},"dynamodb")),": Fetch configurations from DynamoDB."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/rds-signer"},(0,n.kt)("inlineCode",{parentName:"a"},"rds-signer")),": Fetches token for connecting to RDS with IAM users."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/s3"},(0,n.kt)("inlineCode",{parentName:"a"},"s3")),": Fetch JSON configurations from S3."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/s3-object-response"},(0,n.kt)("inlineCode",{parentName:"a"},"s3-object-response")),": Gets and write S3 object response."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/secrets-manager"},(0,n.kt)("inlineCode",{parentName:"a"},"secrets-manager")),": Fetches parameters from ",(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html"},"AWS Secrets Manager"),"."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/service-discovery"},(0,n.kt)("inlineCode",{parentName:"a"},"service-discovery")),": Fetches Service Discovery instances to be used when connecting to other AWS services."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/ssm"},(0,n.kt)("inlineCode",{parentName:"a"},"ssm")),": Fetches parameters from ",(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html"},"AWS Systems Manager Parameter Store"),"."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},(0,n.kt)("inlineCode",{parentName:"a"},"sts")),": Fetches credentials to assumes IAM roles for connection to other AWS services.")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9235],{3905:(e,t,a)=>{a.d(t,{Zo:()=>p,kt:()=>h});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var l=r.createContext({}),d=function(e){var t=r.useContext(l),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},p=function(e){var t=d(e.components);return r.createElement(l.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,i=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=d(a),u=n,h=m["".concat(l,".").concat(u)]||m[u]||c[u]||i;return a?r.createElement(h,o(o({ref:t},p),{},{components:a})):r.createElement(h,o({ref:t},p))}));function h(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var i=a.length,o=new Array(i);o[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[m]="string"==typeof e?e:n,o[1]=s;for(var d=2;d{a.r(t),a.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>s,toc:()=>d});var r=a(7462),n=(a(7294),a(3905));const i={title:"Official middlewares",sidebar_position:0},o=void 0,s={unversionedId:"middlewares/intro",id:"middlewares/intro",title:"Official middlewares",description:"Middy comes with a series of additional (opt-in) plugins that are officially maintained by the core team and kept in sync with every release of the core package.",source:"@site/docs/middlewares/00-intro.md",sourceDirName:"middlewares",slug:"/middlewares/intro",permalink:"/docs/middlewares/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/00-intro.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:0,frontMatter:{title:"Official middlewares",sidebar_position:0},sidebar:"tutorialSidebar",previous:{title:"Middlewares",permalink:"/docs/category/middlewares"},next:{title:"Third-party middlewares",permalink:"/docs/middlewares/third-party"}},l={},d=[{value:"Misc",id:"misc",level:2},{value:"Request Transformation",id:"request-transformation",level:2},{value:"Response Transformation",id:"response-transformation",level:2},{value:"Fetch Data",id:"fetch-data",level:2}],p={toc:d},m="wrapper";function c(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},p,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Middy comes with a series of additional (opt-in) plugins that are officially maintained by the core team and kept in sync with every release of the core package."),(0,n.kt)("p",null,"These middleware focus on common use cases when using Lambda with other AWS services."),(0,n.kt)("p",null,"Each middleware should do a single task. We try to balance each to be as performant as possible while meeting the majority of developer needs."),(0,n.kt)("h2",{id:"misc"},"Misc"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/cloudwatch-metrics"},(0,n.kt)("inlineCode",{parentName:"a"},"cloudwatch-metrics")),": Hydrates lambda's ",(0,n.kt)("inlineCode",{parentName:"li"},"context.metrics")," property with an instance of AWS MetricLogger"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/do-not-wait-for-empty-event-loop"},(0,n.kt)("inlineCode",{parentName:"a"},"do-not-wait-for-empty-event-loop")),": Sets callbackWaitsForEmptyEventLoop property to false"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/error-logger"},(0,n.kt)("inlineCode",{parentName:"a"},"error-logger")),": Logs errors"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/input-output-logger"},(0,n.kt)("inlineCode",{parentName:"a"},"input-output-logger")),": Logs request and response"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/warmup"},(0,n.kt)("inlineCode",{parentName:"a"},"warmup")),": Used to pre-warm a lambda function")),(0,n.kt)("h2",{id:"request-transformation"},"Request Transformation"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/event-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"event-normalizer")),": Middleware for iterating through an AWS event records, parsing and normalizing nested events."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-content-negotiation"},(0,n.kt)("inlineCode",{parentName:"a"},"http-content-negotiation")),": Parses ",(0,n.kt)("inlineCode",{parentName:"li"},"Accept-*")," headers and provides utilities for content negotiation (charset, encoding, language and media type) for HTTP requests"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-event-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"http-event-normalizer")),": Normalizes HTTP events by adding an empty object for ",(0,n.kt)("inlineCode",{parentName:"li"},"queryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"li"},"multiValueQueryStringParameters")," or ",(0,n.kt)("inlineCode",{parentName:"li"},"pathParameters")," if they are missing."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-header-normalizer"},(0,n.kt)("inlineCode",{parentName:"a"},"http-header-normalizer")),": Normalizes HTTP header names to their canonical format"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-json-body-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"http-json-body-parser")),": Automatically parses HTTP requests with JSON body and converts the body into an object. Also handles gracefully broken JSON if used in combination of\n",(0,n.kt)("inlineCode",{parentName:"li"},"httpErrorHandler"),"."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-multipart-body-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"http-multipart-body-parser")),": Automatically parses HTTP requests with content type ",(0,n.kt)("inlineCode",{parentName:"li"},"multipart/form-data")," and converts the body into an object."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-urlencode-body-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"http-urlencode-body-parser")),": Automatically parses HTTP requests with URL encoded body (typically the result of a form submit)."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-urlencode-path-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"http-urlencode-path-parser")),": Automatically parses HTTP requests with URL encoded path."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/validator"},(0,n.kt)("inlineCode",{parentName:"a"},"validator")),": Automatically validates incoming events and outgoing responses against custom schemas."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/ws-json-body-parser"},(0,n.kt)("inlineCode",{parentName:"a"},"ws-json-body-parser")),": Automatically parses WebSocket requests with JSON message and converts the message into an object.")),(0,n.kt)("h2",{id:"response-transformation"},"Response Transformation"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-content-encoding"},(0,n.kt)("inlineCode",{parentName:"a"},"http-content-encoding")),": Sets HTTP Content-Encoding header on response and compresses response body"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-cors"},(0,n.kt)("inlineCode",{parentName:"a"},"http-cors")),": Sets HTTP CORS headers on response"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-error-handler"},(0,n.kt)("inlineCode",{parentName:"a"},"http-error-handler")),": Creates a proper HTTP response for errors that are created with the ",(0,n.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/http-errors"},"http-errors")," module and represents proper HTTP errors."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-security-headers"},(0,n.kt)("inlineCode",{parentName:"a"},"http-security-headers")),": Applies best practice security headers to responses. It's a simplified port of HelmetJS."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-partial-response"},(0,n.kt)("inlineCode",{parentName:"a"},"http-partial-response")),": Filter response objects attributes based on query string parameters."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/http-response-serializer"},(0,n.kt)("inlineCode",{parentName:"a"},"http-response-serializer")),": HTTP response serializer."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/sqs-partial-batch-failure"},(0,n.kt)("inlineCode",{parentName:"a"},"sqs-partial-batch-failure")),": Handles partially failed SQS batches."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/ws-response"},(0,n.kt)("inlineCode",{parentName:"a"},"ws-response")),": Forwards response to WebSocket endpoint.")),(0,n.kt)("h2",{id:"fetch-data"},"Fetch Data"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/appconfig"},(0,n.kt)("inlineCode",{parentName:"a"},"appconfig")),": Fetch JSON configurations from AppConfig."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/dynamodb"},(0,n.kt)("inlineCode",{parentName:"a"},"dynamodb")),": Fetch configurations from DynamoDB."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/rds-signer"},(0,n.kt)("inlineCode",{parentName:"a"},"rds-signer")),": Fetches token for connecting to RDS with IAM users."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/s3"},(0,n.kt)("inlineCode",{parentName:"a"},"s3")),": Fetch JSON configurations from S3."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/s3-object-response"},(0,n.kt)("inlineCode",{parentName:"a"},"s3-object-response")),": Gets and write S3 object response."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/secrets-manager"},(0,n.kt)("inlineCode",{parentName:"a"},"secrets-manager")),": Fetches parameters from ",(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html"},"AWS Secrets Manager"),"."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/service-discovery"},(0,n.kt)("inlineCode",{parentName:"a"},"service-discovery")),": Fetches Service Discovery instances to be used when connecting to other AWS services."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/ssm"},(0,n.kt)("inlineCode",{parentName:"a"},"ssm")),": Fetches parameters from ",(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html"},"AWS Systems Manager Parameter Store"),"."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},(0,n.kt)("inlineCode",{parentName:"a"},"sts")),": Fetches credentials to assumes IAM roles for connection to other AWS services.")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/aecdbf7e.f7131078.js b/assets/js/aecdbf7e.5a246d8b.js similarity index 98% rename from assets/js/aecdbf7e.f7131078.js rename to assets/js/aecdbf7e.5a246d8b.js index 67c7c1c57..b8c6e20ce 100644 --- a/assets/js/aecdbf7e.f7131078.js +++ b/assets/js/aecdbf7e.5a246d8b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1073],{3905:(e,t,r)=>{r.d(t,{Zo:()=>u,kt:()=>f});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function l(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),c=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},u=function(e){var t=c(e.components);return a.createElement(s.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},p=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,s=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),d=c(r),p=n,f=d["".concat(s,".").concat(p)]||d[p]||m[p]||o;return r?a.createElement(f,l(l({ref:t},u),{},{components:r})):a.createElement(f,l({ref:t},u))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,l=new Array(o);l[0]=p;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[d]="string"==typeof e?e:n,l[1]=i;for(var c=2;c{r.d(t,{Z:()=>l});var a=r(7294),n=r(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:r,className:l}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(o.tabItem,l),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var a=r(7462),n=r(7294),o=r(6010),l=r(2466),i=r(6550),s=r(1980),c=r(7392),u=r(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function m(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??d(r);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function p(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const a=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(a.location.search);t.set(o,e),a.replace({...a.location,search:t.toString()})}),[o,a])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,o=m(e),[l,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:o}))),[s,c]=f({queryString:r,groupId:a}),[d,h]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,u.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&o.set(e)}),[r,o])]}({groupId:a}),b=(()=>{const e=s??d;return p({value:e,tabValues:o})?e:null})();(0,n.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),h(e)}),[c,h,o]),tabValues:o}}var b=r(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:r,selectedValue:i,selectValue:s,tabValues:c}=e;const u=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),m=e=>{const t=e.currentTarget,r=u.indexOf(t),a=c[r].value;a!==i&&(d(t),s(a))},p=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const r=u.indexOf(e.currentTarget)+1;t=u[r]??u[0];break}case"ArrowLeft":{const r=u.indexOf(e.currentTarget)-1;t=u[r]??u[u.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":r},t)},c.map((e=>{let{value:t,label:r,attributes:l}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>u.push(e),onKeyDown:p,onClick:m},l,{className:(0,o.Z)("tabs__item",g.tabItem,l?.className,{"tabs__item--active":i===t})}),r??t)})))}function w(e){let{lazy:t,children:r,selectedValue:a}=e;const o=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function v(e){const t=h(e);return n.createElement("div",{className:(0,o.Z)("tabs-container",g.tabList)},n.createElement(y,(0,a.Z)({},e,t)),n.createElement(w,(0,a.Z)({},e,t)))}function k(e){const t=(0,b.Z)();return n.createElement(v,(0,a.Z)({key:String(t)},e))}},7676:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>u,contentTitle:()=>s,default:()=>f,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var a=r(7462),n=(r(7294),r(3905)),o=r(4866),l=r(5162);const i={title:"cloudwatch-metrics"},s=void 0,c={unversionedId:"middlewares/cloudwatch-metrics",id:"middlewares/cloudwatch-metrics",title:"cloudwatch-metrics",description:"This middleware hydrates lambda's context.metrics property with an instance of MetricLogger. This instance can be used to easily generate custom metrics from Lambda functions without requiring custom batching code, making blocking network requests or relying on 3rd party software.",source:"@site/docs/middlewares/cloudwatch-metrics.md",sourceDirName:"middlewares",slug:"/middlewares/cloudwatch-metrics",permalink:"/docs/middlewares/cloudwatch-metrics",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/cloudwatch-metrics.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"cloudwatch-metrics"},sidebar:"tutorialSidebar",previous:{title:"appconfig",permalink:"/docs/middlewares/appconfig"},next:{title:"do-not-wait-for-empty-event-loop",permalink:"/docs/middlewares/do-not-wait-for-empty-event-loop"}},u={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],m={toc:d},p="wrapper";function f(e){let{components:t,...r}=e;return(0,n.kt)(p,(0,a.Z)({},m,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"This middleware hydrates lambda's ",(0,n.kt)("inlineCode",{parentName:"p"},"context.metrics")," property with an instance of ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/awslabs/aws-embedded-metrics-node#metriclogger"},"MetricLogger"),". This instance can be used to easily generate custom metrics from Lambda functions without requiring custom batching code, making blocking network requests or relying on 3rd party software."),(0,n.kt)("p",null,"Metrics collected with this logger are then available for querying within ",(0,n.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html"},"AWS CloudWatch Log Insights")),(0,n.kt)("p",null,"You can explore all the MetricLogger APIs following ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/awslabs/aws-embedded-metrics-node"},"aws-embedded-metrics")," documentation."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/cloudwatch-metrics\n"))),(0,n.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/cloudwatch-metrics\n"))),(0,n.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/cloudwatch-metrics\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"namespace")," (",(0,n.kt)("inlineCode",{parentName:"li"},"string"),") (optional): Defaults to ",(0,n.kt)("inlineCode",{parentName:"li"},"aws-embedded-metrics"),". Sets the CloudWatch ",(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace"},"namespace")," that extracted metrics should be published to."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"dimensions")," (",(0,n.kt)("inlineCode",{parentName:"li"},"Record | Record[]"),") (optional): Explicitly overrides all dimensions. This will remove the default dimensions. You can provide an empty array to record all metrics without dimensions. For dimensions defaults and configuration see the ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/awslabs/aws-embedded-metrics-node/tree/v4.1.0#configuration"},"aws-embedded-metrics docs"),".")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"const middy = require('@middy/core')\nconst cloudwatchMetrics = require('@middy/cloudwatch-metrics')\n\nconst handler = middy((event, context) => {\n context.metrics.putMetric('ProcessingLatency', 100, 'Milliseconds')\n context.metrics.setProperty(\n 'RequestId',\n '422b1569-16f6-4a03-b8f0-fe3fd9b100f8'\n )\n})\n\nhandler.use(\n cloudwatchMetrics({\n namespace: 'myAppliction',\n dimensions: [{ Action: 'Buy' }]\n })\n)\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1073],{3905:(e,t,r)=>{r.d(t,{Zo:()=>u,kt:()=>f});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function l(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),c=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},u=function(e){var t=c(e.components);return a.createElement(s.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},p=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,s=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),d=c(r),p=n,f=d["".concat(s,".").concat(p)]||d[p]||m[p]||o;return r?a.createElement(f,l(l({ref:t},u),{},{components:r})):a.createElement(f,l({ref:t},u))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,l=new Array(o);l[0]=p;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[d]="string"==typeof e?e:n,l[1]=i;for(var c=2;c{r.d(t,{Z:()=>l});var a=r(7294),n=r(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:r,className:l}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(o.tabItem,l),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var a=r(7462),n=r(7294),o=r(6010),l=r(2466),i=r(6550),s=r(1980),c=r(7392),u=r(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function m(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??d(r);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function p(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const a=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(a.location.search);t.set(o,e),a.replace({...a.location,search:t.toString()})}),[o,a])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,o=m(e),[l,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:o}))),[s,c]=f({queryString:r,groupId:a}),[d,h]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,u.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&o.set(e)}),[r,o])]}({groupId:a}),b=(()=>{const e=s??d;return p({value:e,tabValues:o})?e:null})();(0,n.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),h(e)}),[c,h,o]),tabValues:o}}var b=r(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:r,selectedValue:i,selectValue:s,tabValues:c}=e;const u=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),m=e=>{const t=e.currentTarget,r=u.indexOf(t),a=c[r].value;a!==i&&(d(t),s(a))},p=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const r=u.indexOf(e.currentTarget)+1;t=u[r]??u[0];break}case"ArrowLeft":{const r=u.indexOf(e.currentTarget)-1;t=u[r]??u[u.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":r},t)},c.map((e=>{let{value:t,label:r,attributes:l}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>u.push(e),onKeyDown:p,onClick:m},l,{className:(0,o.Z)("tabs__item",g.tabItem,l?.className,{"tabs__item--active":i===t})}),r??t)})))}function w(e){let{lazy:t,children:r,selectedValue:a}=e;const o=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function v(e){const t=h(e);return n.createElement("div",{className:(0,o.Z)("tabs-container",g.tabList)},n.createElement(y,(0,a.Z)({},e,t)),n.createElement(w,(0,a.Z)({},e,t)))}function k(e){const t=(0,b.Z)();return n.createElement(v,(0,a.Z)({key:String(t)},e))}},7676:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>u,contentTitle:()=>s,default:()=>f,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var a=r(7462),n=(r(7294),r(3905)),o=r(4866),l=r(5162);const i={title:"cloudwatch-metrics"},s=void 0,c={unversionedId:"middlewares/cloudwatch-metrics",id:"middlewares/cloudwatch-metrics",title:"cloudwatch-metrics",description:"This middleware hydrates lambda's context.metrics property with an instance of MetricLogger. This instance can be used to easily generate custom metrics from Lambda functions without requiring custom batching code, making blocking network requests or relying on 3rd party software.",source:"@site/docs/middlewares/cloudwatch-metrics.md",sourceDirName:"middlewares",slug:"/middlewares/cloudwatch-metrics",permalink:"/docs/middlewares/cloudwatch-metrics",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/cloudwatch-metrics.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"cloudwatch-metrics"},sidebar:"tutorialSidebar",previous:{title:"appconfig",permalink:"/docs/middlewares/appconfig"},next:{title:"do-not-wait-for-empty-event-loop",permalink:"/docs/middlewares/do-not-wait-for-empty-event-loop"}},u={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],m={toc:d},p="wrapper";function f(e){let{components:t,...r}=e;return(0,n.kt)(p,(0,a.Z)({},m,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"This middleware hydrates lambda's ",(0,n.kt)("inlineCode",{parentName:"p"},"context.metrics")," property with an instance of ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/awslabs/aws-embedded-metrics-node#metriclogger"},"MetricLogger"),". This instance can be used to easily generate custom metrics from Lambda functions without requiring custom batching code, making blocking network requests or relying on 3rd party software."),(0,n.kt)("p",null,"Metrics collected with this logger are then available for querying within ",(0,n.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html"},"AWS CloudWatch Log Insights")),(0,n.kt)("p",null,"You can explore all the MetricLogger APIs following ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/awslabs/aws-embedded-metrics-node"},"aws-embedded-metrics")," documentation."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/cloudwatch-metrics\n"))),(0,n.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/cloudwatch-metrics\n"))),(0,n.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/cloudwatch-metrics\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"namespace")," (",(0,n.kt)("inlineCode",{parentName:"li"},"string"),") (optional): Defaults to ",(0,n.kt)("inlineCode",{parentName:"li"},"aws-embedded-metrics"),". Sets the CloudWatch ",(0,n.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace"},"namespace")," that extracted metrics should be published to."),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"dimensions")," (",(0,n.kt)("inlineCode",{parentName:"li"},"Record | Record[]"),") (optional): Explicitly overrides all dimensions. This will remove the default dimensions. You can provide an empty array to record all metrics without dimensions. For dimensions defaults and configuration see the ",(0,n.kt)("a",{parentName:"li",href:"https://github.com/awslabs/aws-embedded-metrics-node/tree/v4.1.0#configuration"},"aws-embedded-metrics docs"),".")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"const middy = require('@middy/core')\nconst cloudwatchMetrics = require('@middy/cloudwatch-metrics')\n\nconst handler = middy((event, context) => {\n context.metrics.putMetric('ProcessingLatency', 100, 'Milliseconds')\n context.metrics.setProperty(\n 'RequestId',\n '422b1569-16f6-4a03-b8f0-fe3fd9b100f8'\n )\n})\n\nhandler.use(\n cloudwatchMetrics({\n namespace: 'myAppliction',\n dimensions: [{ Action: 'Buy' }]\n })\n)\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b3edb814.72cb5225.js b/assets/js/b3edb814.f75e0244.js similarity index 98% rename from assets/js/b3edb814.72cb5225.js rename to assets/js/b3edb814.f75e0244.js index 5f92fd194..502e41943 100644 --- a/assets/js/b3edb814.72cb5225.js +++ b/assets/js/b3edb814.f75e0244.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3786],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function s(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var o=a.createContext({}),u=function(e){var t=a.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):s(s({},t),e)),n},c=function(e){var t=u(e.components);return a.createElement(o.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),d=u(n),m=r,f=d["".concat(o,".").concat(m)]||d[m]||p[m]||l;return n?a.createElement(f,s(s({ref:t},c),{},{components:n})):a.createElement(f,s({ref:t},c))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,s=new Array(l);s[0]=m;var i={};for(var o in t)hasOwnProperty.call(t,o)&&(i[o]=t[o]);i.originalType=e,i[d]="string"==typeof e?e:r,s[1]=i;for(var u=2;u{n.d(t,{Z:()=>s});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:n,className:s}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,s),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var a=n(7462),r=n(7294),l=n(6010),s=n(2466),i=n(6550),o=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=p(e),[s,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:n,groupId:a}),[d,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,c.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),h=(()=>{const e=o??d;return m({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{h&&i(h)}),[h]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var h=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:n,selectedValue:i,selectValue:o,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),a=u[n].value;a!==i&&(d(t),o(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:s}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},s,{className:(0,l.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":i===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function g(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},r.createElement(k,(0,a.Z)({},e,t)),r.createElement(v,(0,a.Z)({},e,t)))}function w(e){const t=(0,h.Z)();return r.createElement(g,(0,a.Z)({key:String(t)},e))}},6995:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),s=n(5162);const i={title:"sts"},o=void 0,u={unversionedId:"middlewares/sts",id:"middlewares/sts",title:"sts",description:"Fetches STS credentials to be used when connecting to other AWS services.",source:"@site/docs/middlewares/sts.md",sourceDirName:"middlewares",slug:"/middlewares/sts",permalink:"/docs/middlewares/sts",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/sts.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"sts"},sidebar:"tutorialSidebar",previous:{title:"ssm",permalink:"/docs/middlewares/ssm"},next:{title:"validator",permalink:"/docs/middlewares/validator"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Fetches STS credentials to be used when connecting to other AWS services."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/sts\nnpm install --save-dev @aws-sdk/client-sts\n"))),(0,r.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/sts\nyarn add --dev @aws-sdk/client-sts\n"))),(0,r.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/sts\npnpm add --save-dev @aws-sdk/client-sts\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"STSClient"),"): STSClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-sts"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to STSClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (optional): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"sts"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"sts:AssumeRole")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport sts from '@middy/sts'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n sts({\n fetchData: {\n assumeRole: {\n RoleArn: '...',\n RoleSessionName: '' // optional\n }\n }\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-sts")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3786],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function s(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var o=a.createContext({}),u=function(e){var t=a.useContext(o),n=t;return e&&(n="function"==typeof e?e(t):s(s({},t),e)),n},c=function(e){var t=u(e.components);return a.createElement(o.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),d=u(n),m=r,f=d["".concat(o,".").concat(m)]||d[m]||p[m]||l;return n?a.createElement(f,s(s({ref:t},c),{},{components:n})):a.createElement(f,s({ref:t},c))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,s=new Array(l);s[0]=m;var i={};for(var o in t)hasOwnProperty.call(t,o)&&(i[o]=t[o]);i.originalType=e,i[d]="string"==typeof e?e:r,s[1]=i;for(var u=2;u{n.d(t,{Z:()=>s});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:n,className:s}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,s),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var a=n(7462),r=n(7294),l=n(6010),s=n(2466),i=n(6550),o=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=p(e),[s,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:n,groupId:a}),[d,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,c.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),h=(()=>{const e=o??d;return m({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{h&&i(h)}),[h]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var h=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:n,selectedValue:i,selectValue:o,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),a=u[n].value;a!==i&&(d(t),o(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:s}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},s,{className:(0,l.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":i===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function g(e){const t=b(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},r.createElement(k,(0,a.Z)({},e,t)),r.createElement(v,(0,a.Z)({},e,t)))}function w(e){const t=(0,h.Z)();return r.createElement(g,(0,a.Z)({key:String(t)},e))}},6995:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),s=n(5162);const i={title:"sts"},o=void 0,u={unversionedId:"middlewares/sts",id:"middlewares/sts",title:"sts",description:"Fetches STS credentials to be used when connecting to other AWS services.",source:"@site/docs/middlewares/sts.md",sourceDirName:"middlewares",slug:"/middlewares/sts",permalink:"/docs/middlewares/sts",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/sts.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"sts"},sidebar:"tutorialSidebar",previous:{title:"ssm",permalink:"/docs/middlewares/ssm"},next:{title:"validator",permalink:"/docs/middlewares/validator"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Fetches STS credentials to be used when connecting to other AWS services."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/sts\nnpm install --save-dev @aws-sdk/client-sts\n"))),(0,r.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/sts\nyarn add --dev @aws-sdk/client-sts\n"))),(0,r.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/sts\npnpm add --save-dev @aws-sdk/client-sts\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"STSClient"),"): STSClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-sts"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to STSClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (optional): Enable XRay by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"sts"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store credentials to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"sts:AssumeRole")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport sts from '@middy/sts'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n})\n\nhandler.use(\n sts({\n fetchData: {\n assumeRole: {\n RoleArn: '...',\n RoleSessionName: '' // optional\n }\n }\n })\n)\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-sts")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b5163cd3.1e47df5a.js b/assets/js/b5163cd3.6e88002d.js similarity index 98% rename from assets/js/b5163cd3.1e47df5a.js rename to assets/js/b5163cd3.6e88002d.js index f36ada194..05366d3a6 100644 --- a/assets/js/b5163cd3.1e47df5a.js +++ b/assets/js/b5163cd3.6e88002d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4751],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>m});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),p=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=p(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,c=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(r),f=o,m=u["".concat(c,".").concat(f)]||u[f]||d[f]||i;return r?n.createElement(m,a(a({ref:t},l),{},{components:r})):n.createElement(m,a({ref:t},l))}));function m(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=f;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,a[1]=s;for(var p=2;p{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var n=r(7462),o=(r(7294),r(3905));const i={title:"Integrations",position:1},a=void 0,s={unversionedId:"integrations/intro",id:"integrations/intro",title:"Integrations",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/01-intro.md",sourceDirName:"integrations",slug:"/integrations/intro",permalink:"/docs/integrations/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:1,frontMatter:{title:"Integrations",position:1},sidebar:"tutorialSidebar",previous:{title:"Integrations",permalink:"/docs/category/integrations"},next:{title:"AWS Relational Database Service (RDS)",permalink:"/docs/integrations/RDS"}},c={},p=[],l={toc:p},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4751],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>m});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),p=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=p(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,c=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(r),f=o,m=u["".concat(c,".").concat(f)]||u[f]||d[f]||i;return r?n.createElement(m,a(a({ref:t},l),{},{components:r})):n.createElement(m,a({ref:t},l))}));function m(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=f;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,a[1]=s;for(var p=2;p{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var n=r(7462),o=(r(7294),r(3905));const i={title:"Integrations",position:1},a=void 0,s={unversionedId:"integrations/intro",id:"integrations/intro",title:"Integrations",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/01-intro.md",sourceDirName:"integrations",slug:"/integrations/intro",permalink:"/docs/integrations/intro",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:1,frontMatter:{title:"Integrations",position:1},sidebar:"tutorialSidebar",previous:{title:"Integrations",permalink:"/docs/category/integrations"},next:{title:"AWS Relational Database Service (RDS)",permalink:"/docs/integrations/RDS"}},c={},p=[],l={toc:p},u="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b5584809.6170aa3e.js b/assets/js/b5584809.beef6247.js similarity index 96% rename from assets/js/b5584809.6170aa3e.js rename to assets/js/b5584809.beef6247.js index 01ed7a6ce..4498099b9 100644 --- a/assets/js/b5584809.6170aa3e.js +++ b/assets/js/b5584809.beef6247.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2803],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>d});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),l=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=l(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(r),f=o,d=u["".concat(c,".").concat(f)]||u[f]||m[f]||a;return r?n.createElement(d,i(i({ref:t},p),{},{components:r})):n.createElement(d,i({ref:t},p))}));function d(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=f;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var n=r(7462),o=(r(7294),r(3905));const a={title:"Serverless Framework"},i=void 0,s={unversionedId:"integrations/serverless-framework",id:"integrations/serverless-framework",title:"Serverless Framework",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/serverless-framework.md",sourceDirName:"integrations",slug:"/integrations/serverless-framework",permalink:"/docs/integrations/serverless-framework",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/serverless-framework.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Serverless Framework"},sidebar:"tutorialSidebar",previous:{title:"Pino",permalink:"/docs/integrations/pino"},next:{title:"Serverless Stack",permalink:"/docs/integrations/serverless-stack"}},c={},l=[],p={toc:l},u="wrapper";function m(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("p",null,"TODO comment about serverless-warmup"))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2803],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>d});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var c=n.createContext({}),l=function(e){var t=n.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=l(e.components);return n.createElement(c.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(r),f=o,d=u["".concat(c,".").concat(f)]||u[f]||m[f]||a;return r?n.createElement(d,i(i({ref:t},p),{},{components:r})):n.createElement(d,i({ref:t},p))}));function d(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=f;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var n=r(7462),o=(r(7294),r(3905));const a={title:"Serverless Framework"},i=void 0,s={unversionedId:"integrations/serverless-framework",id:"integrations/serverless-framework",title:"Serverless Framework",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/serverless-framework.md",sourceDirName:"integrations",slug:"/integrations/serverless-framework",permalink:"/docs/integrations/serverless-framework",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/serverless-framework.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Serverless Framework"},sidebar:"tutorialSidebar",previous:{title:"Pino",permalink:"/docs/integrations/pino"},next:{title:"Serverless Stack",permalink:"/docs/integrations/serverless-stack"}},c={},l=[],p={toc:l},u="wrapper";function m(e){let{components:t,...r}=e;return(0,o.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("p",null,"TODO comment about serverless-warmup"))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b5aee65c.69e37ea2.js b/assets/js/b5aee65c.d320533a.js similarity index 99% rename from assets/js/b5aee65c.69e37ea2.js rename to assets/js/b5aee65c.d320533a.js index 710f37633..eb598e398 100644 --- a/assets/js/b5aee65c.69e37ea2.js +++ b/assets/js/b5aee65c.d320533a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4510],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>g});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var p=r.createContext({}),d=function(e){var t=r.useContext(p),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},m=function(e){var t=d(e.components);return r.createElement(p.Provider,{value:t},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},s=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,p=e.parentName,m=o(e,["components","mdxType","originalType","parentName"]),c=d(n),s=a,g=c["".concat(p,".").concat(s)]||c[s]||u[s]||l;return n?r.createElement(g,i(i({ref:t},m),{},{components:n})):r.createElement(g,i({ref:t},m))}));function g(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,i=new Array(l);i[0]=s;var o={};for(var p in t)hasOwnProperty.call(t,p)&&(o[p]=t[p]);o.originalType=e,o[c]="string"==typeof e?e:a,i[1]=o;for(var d=2;d{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>u,frontMatter:()=>l,metadata:()=>o,toc:()=>d});var r=n(7462),a=(n(7294),n(3905));const l={title:"Release Cycle"},i=void 0,o={unversionedId:"intro/release-cycle",id:"intro/release-cycle",title:"Release Cycle",description:"Each major release has a two (2) month Alpha period, one (1) month Beta, before a full release and becomes Stable.",source:"@site/docs/intro/09-release-cycle.md",sourceDirName:"intro",slug:"/intro/release-cycle",permalink:"/docs/intro/release-cycle",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/09-release-cycle.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:9,frontMatter:{title:"Release Cycle"},sidebar:"tutorialSidebar",previous:{title:"Utilities",permalink:"/docs/intro/utilities"},next:{title:"Contributing",permalink:"/docs/intro/contributing"}},p={},d=[],m={toc:d},c="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(c,(0,r.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Each major release has a two (2) month ",(0,a.kt)("inlineCode",{parentName:"p"},"Alpha")," period, one (1) month ",(0,a.kt)("inlineCode",{parentName:"p"},"Beta"),", before a full release and becomes ",(0,a.kt)("inlineCode",{parentName:"p"},"Stable"),".\nEach release goes into ",(0,a.kt)("inlineCode",{parentName:"p"},"Maintenance")," after nine (9) months, as the next release enters ",(0,a.kt)("inlineCode",{parentName:"p"},"Alpha"),".\nThis time period is chosen for alignment with AWS Lambda ",(0,a.kt)("inlineCode",{parentName:"p"},"nodejs")," runtime releases.\nAll Node.js Long-Term Support (LTS) releases that have AWS Lambda runtimes are supported."),(0,a.kt)("table",null,(0,a.kt)("thead",{parentName:"table"},(0,a.kt)("tr",{parentName:"thead"},(0,a.kt)("th",{parentName:"tr",align:null},"Version"),(0,a.kt)("th",{parentName:"tr",align:null},"Status"),(0,a.kt)("th",{parentName:"tr",align:null},"Alpha Release"),(0,a.kt)("th",{parentName:"tr",align:null},"Stable Release"),(0,a.kt)("th",{parentName:"tr",align:null},"End-of-Life"))),(0,a.kt)("tbody",{parentName:"table"},(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v5"),(0,a.kt)("td",{parentName:"tr",align:null},"Scoping"),(0,a.kt)("td",{parentName:"tr",align:null},"2023-06-01"),(0,a.kt)("td",{parentName:"tr",align:null},"2023-09-01"),(0,a.kt)("td",{parentName:"tr",align:null},"2025-04-30")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v4"),(0,a.kt)("td",{parentName:"tr",align:null},"Stable"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-10-17"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-11-24"),(0,a.kt)("td",{parentName:"tr",align:null},"2023-09-11")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v3"),(0,a.kt)("td",{parentName:"tr",align:null},"Deprecated"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-01-04"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-05-12"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-12-31")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v2"),(0,a.kt)("td",{parentName:"tr",align:null},"Deprecated"),(0,a.kt)("td",{parentName:"tr",align:null},"2021-01-24"),(0,a.kt)("td",{parentName:"tr",align:null},"2021-04-01"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-05-12")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v1"),(0,a.kt)("td",{parentName:"tr",align:null},"Deprecated"),(0,a.kt)("td",{parentName:"tr",align:null},"2018-05-20"),(0,a.kt)("td",{parentName:"tr",align:null},"2020-04-25"),(0,a.kt)("td",{parentName:"tr",align:null},"2021-04-01")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v0"),(0,a.kt)("td",{parentName:"tr",align:null},"Deprecated"),(0,a.kt)("td",{parentName:"tr",align:null},"2017-08-03"),(0,a.kt)("td",{parentName:"tr",align:null},"2017-09-04"),(0,a.kt)("td",{parentName:"tr",align:null},"2020-04-25")))),(0,a.kt)("p",null,"Dates are subject to change."),(0,a.kt)("p",null,"If your organization requires a longer maintenance period of Middy, please reach out."))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4510],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>g});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var p=r.createContext({}),d=function(e){var t=r.useContext(p),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},m=function(e){var t=d(e.components);return r.createElement(p.Provider,{value:t},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},s=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,p=e.parentName,m=o(e,["components","mdxType","originalType","parentName"]),c=d(n),s=a,g=c["".concat(p,".").concat(s)]||c[s]||u[s]||l;return n?r.createElement(g,i(i({ref:t},m),{},{components:n})):r.createElement(g,i({ref:t},m))}));function g(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,i=new Array(l);i[0]=s;var o={};for(var p in t)hasOwnProperty.call(t,p)&&(o[p]=t[p]);o.originalType=e,o[c]="string"==typeof e?e:a,i[1]=o;for(var d=2;d{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>u,frontMatter:()=>l,metadata:()=>o,toc:()=>d});var r=n(7462),a=(n(7294),n(3905));const l={title:"Release Cycle"},i=void 0,o={unversionedId:"intro/release-cycle",id:"intro/release-cycle",title:"Release Cycle",description:"Each major release has a two (2) month Alpha period, one (1) month Beta, before a full release and becomes Stable.",source:"@site/docs/intro/09-release-cycle.md",sourceDirName:"intro",slug:"/intro/release-cycle",permalink:"/docs/intro/release-cycle",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/09-release-cycle.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:9,frontMatter:{title:"Release Cycle"},sidebar:"tutorialSidebar",previous:{title:"Utilities",permalink:"/docs/intro/utilities"},next:{title:"Contributing",permalink:"/docs/intro/contributing"}},p={},d=[],m={toc:d},c="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(c,(0,r.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Each major release has a two (2) month ",(0,a.kt)("inlineCode",{parentName:"p"},"Alpha")," period, one (1) month ",(0,a.kt)("inlineCode",{parentName:"p"},"Beta"),", before a full release and becomes ",(0,a.kt)("inlineCode",{parentName:"p"},"Stable"),".\nEach release goes into ",(0,a.kt)("inlineCode",{parentName:"p"},"Maintenance")," after nine (9) months, as the next release enters ",(0,a.kt)("inlineCode",{parentName:"p"},"Alpha"),".\nThis time period is chosen for alignment with AWS Lambda ",(0,a.kt)("inlineCode",{parentName:"p"},"nodejs")," runtime releases.\nAll Node.js Long-Term Support (LTS) releases that have AWS Lambda runtimes are supported."),(0,a.kt)("table",null,(0,a.kt)("thead",{parentName:"table"},(0,a.kt)("tr",{parentName:"thead"},(0,a.kt)("th",{parentName:"tr",align:null},"Version"),(0,a.kt)("th",{parentName:"tr",align:null},"Status"),(0,a.kt)("th",{parentName:"tr",align:null},"Alpha Release"),(0,a.kt)("th",{parentName:"tr",align:null},"Stable Release"),(0,a.kt)("th",{parentName:"tr",align:null},"End-of-Life"))),(0,a.kt)("tbody",{parentName:"table"},(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v5"),(0,a.kt)("td",{parentName:"tr",align:null},"Scoping"),(0,a.kt)("td",{parentName:"tr",align:null},"2023-06-01"),(0,a.kt)("td",{parentName:"tr",align:null},"2023-09-01"),(0,a.kt)("td",{parentName:"tr",align:null},"2025-04-30")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v4"),(0,a.kt)("td",{parentName:"tr",align:null},"Stable"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-10-17"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-11-24"),(0,a.kt)("td",{parentName:"tr",align:null},"2023-09-11")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v3"),(0,a.kt)("td",{parentName:"tr",align:null},"Deprecated"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-01-04"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-05-12"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-12-31")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v2"),(0,a.kt)("td",{parentName:"tr",align:null},"Deprecated"),(0,a.kt)("td",{parentName:"tr",align:null},"2021-01-24"),(0,a.kt)("td",{parentName:"tr",align:null},"2021-04-01"),(0,a.kt)("td",{parentName:"tr",align:null},"2022-05-12")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v1"),(0,a.kt)("td",{parentName:"tr",align:null},"Deprecated"),(0,a.kt)("td",{parentName:"tr",align:null},"2018-05-20"),(0,a.kt)("td",{parentName:"tr",align:null},"2020-04-25"),(0,a.kt)("td",{parentName:"tr",align:null},"2021-04-01")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},"v0"),(0,a.kt)("td",{parentName:"tr",align:null},"Deprecated"),(0,a.kt)("td",{parentName:"tr",align:null},"2017-08-03"),(0,a.kt)("td",{parentName:"tr",align:null},"2017-09-04"),(0,a.kt)("td",{parentName:"tr",align:null},"2020-04-25")))),(0,a.kt)("p",null,"Dates are subject to change."),(0,a.kt)("p",null,"If your organization requires a longer maintenance period of Middy, please reach out."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b6105e9b.e789fa38.js b/assets/js/b6105e9b.557a1893.js similarity index 98% rename from assets/js/b6105e9b.e789fa38.js rename to assets/js/b6105e9b.557a1893.js index 9dea49efa..09a411601 100644 --- a/assets/js/b6105e9b.e789fa38.js +++ b/assets/js/b6105e9b.557a1893.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8471],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var p=r.createContext({}),c=function(e){var t=r.useContext(p),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},s=function(e){var t=c(e.components);return r.createElement(p.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,i=e.originalType,p=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),d=c(n),u=o,f=d["".concat(p,".").concat(u)]||d[u]||m[u]||i;return n?r.createElement(f,a(a({ref:t},s),{},{components:n})):r.createElement(f,a({ref:t},s))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=n.length,a=new Array(i);a[0]=u;var l={};for(var p in t)hasOwnProperty.call(t,p)&&(l[p]=t[p]);l.originalType=e,l[d]="string"==typeof e?e:o,a[1]=l;for(var c=2;c{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>a,default:()=>m,frontMatter:()=>i,metadata:()=>l,toc:()=>c});var r=n(7462),o=(n(7294),n(3905));const i={title:"CodePipeline"},a=void 0,l={unversionedId:"events/code-pipeline",id:"events/code-pipeline",title:"CodePipeline",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/code-pipeline.md",sourceDirName:"events",slug:"/events/code-pipeline",permalink:"/docs/events/code-pipeline",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/code-pipeline.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"CodePipeline"},sidebar:"tutorialSidebar",previous:{title:"Code Commit",permalink:"/docs/events/code-commit"},next:{title:"Cognito",permalink:"/docs/events/cognito"}},p={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:c},d="wrapper";function m(e){let{components:t,...n}=e;return(0,o.kt)(d,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-codepipeline.html"},"Using AWS Lambda with AWS CodePipeline"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8471],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var p=r.createContext({}),c=function(e){var t=r.useContext(p),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},s=function(e){var t=c(e.components);return r.createElement(p.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,i=e.originalType,p=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),d=c(n),u=o,f=d["".concat(p,".").concat(u)]||d[u]||m[u]||i;return n?r.createElement(f,a(a({ref:t},s),{},{components:n})):r.createElement(f,a({ref:t},s))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=n.length,a=new Array(i);a[0]=u;var l={};for(var p in t)hasOwnProperty.call(t,p)&&(l[p]=t[p]);l.originalType=e,l[d]="string"==typeof e?e:o,a[1]=l;for(var c=2;c{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>a,default:()=>m,frontMatter:()=>i,metadata:()=>l,toc:()=>c});var r=n(7462),o=(n(7294),n(3905));const i={title:"CodePipeline"},a=void 0,l={unversionedId:"events/code-pipeline",id:"events/code-pipeline",title:"CodePipeline",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/code-pipeline.md",sourceDirName:"events",slug:"/events/code-pipeline",permalink:"/docs/events/code-pipeline",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/code-pipeline.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"CodePipeline"},sidebar:"tutorialSidebar",previous:{title:"Code Commit",permalink:"/docs/events/code-commit"},next:{title:"Cognito",permalink:"/docs/events/cognito"}},p={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],s={toc:c},d="wrapper";function m(e){let{components:t,...n}=e;return(0,o.kt)(d,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-codepipeline.html"},"Using AWS Lambda with AWS CodePipeline"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b6b85ed9.f25bfd5e.js b/assets/js/b6b85ed9.7d6341ca.js similarity index 99% rename from assets/js/b6b85ed9.f25bfd5e.js rename to assets/js/b6b85ed9.7d6341ca.js index b0d9f9187..b90dd1966 100644 --- a/assets/js/b6b85ed9.f25bfd5e.js +++ b/assets/js/b6b85ed9.7d6341ca.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6476],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),u=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},c=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),d=u(n),m=a,f=d["".concat(s,".").concat(m)]||d[m]||p[m]||o;return n?r.createElement(f,i(i({ref:t},c),{},{components:n})):r.createElement(f,i({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[d]="string"==typeof e?e:a,i[1]=l;for(var u=2;u{n.d(t,{Z:()=>i});var r=n(7294),a=n(6010);const o={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(o.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var r=n(7462),a=n(7294),o=n(6010),i=n(2466),l=n(6550),s=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,l.k6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(o),(0,a.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=p(e),[i,l]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[s,u]=f({queryString:n,groupId:r}),[d,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),h=(()=>{const e=s??d;return m({value:e,tabValues:o})?e:null})();(0,a.useLayoutEffect)((()=>{h&&l(h)}),[h]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),b(e)}),[u,b,o]),tabValues:o}}var h=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:l,selectValue:s,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),r=u[n].value;r!==l&&(d(t),s(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:i}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:l===t?0:-1,"aria-selected":l===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},i,{className:(0,o.Z)("tabs__item",g.tabItem,i?.className,{"tabs__item--active":l===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function k(e){const t=b(e);return a.createElement("div",{className:(0,o.Z)("tabs-container",g.tabList)},a.createElement(y,(0,r.Z)({},e,t)),a.createElement(v,(0,r.Z)({},e,t)))}function N(e){const t=(0,h.Z)();return a.createElement(k,(0,r.Z)({key:String(t)},e))}},3976:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>f,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),o=n(4866),i=n(5162);const l={title:"http-content-encoding"},s=void 0,u={unversionedId:"middlewares/http-content-encoding",id:"middlewares/http-content-encoding",title:"http-content-encoding",description:"This middleware take the preferredEncoding output from @middy/http-content-negotiation and applies the encoding to response.body when a string.",source:"@site/docs/middlewares/http-content-encoding.md",sourceDirName:"middlewares",slug:"/middlewares/http-content-encoding",permalink:"/docs/middlewares/http-content-encoding",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-content-encoding.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-content-encoding"},sidebar:"tutorialSidebar",previous:{title:"event-normalizer",permalink:"/docs/middlewares/event-normalizer"},next:{title:"http-content-negotiation",permalink:"/docs/middlewares/http-content-negotiation"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Using streams",id:"using-streams",level:3}],p={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware take the ",(0,a.kt)("inlineCode",{parentName:"p"},"preferredEncoding")," output from ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-content-negotiation")," and applies the encoding to ",(0,a.kt)("inlineCode",{parentName:"p"},"response.body")," when a string."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-content-encoding\n"))),(0,a.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-content-encoding\n"))),(0,a.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-content-encoding\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"br")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"{}"),"): ",(0,a.kt)("inlineCode",{parentName:"li"},"zlib.createBrotliCompress")," ",(0,a.kt)("a",{parentName:"li",href:"https://nodejs.org/api/zlib.html#zlib_class_brotlioptions"},"brotliOptions")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"gzip")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"{}"),"): ",(0,a.kt)("inlineCode",{parentName:"li"},"zlib.createGzip")," ",(0,a.kt)("a",{parentName:"li",href:"https://nodejs.org/api/zlib.html#zlib_class_options"},"gzipOptions")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"deflate")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"{}"),"): ",(0,a.kt)("inlineCode",{parentName:"li"},"zlib.createDeflate")," ",(0,a.kt)("a",{parentName:"li",href:"https://nodejs.org/api/zlib.html#zlib_class_options"},"deflateOptions")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"overridePreferredEncoding")," (array","[string]",") (optional): Override the preferred encoding order, most browsers prefer ",(0,a.kt)("inlineCode",{parentName:"li"},"gzip")," over ",(0,a.kt)("inlineCode",{parentName:"li"},"br"),", even though ",(0,a.kt)("inlineCode",{parentName:"li"},"br")," has higher compression. Default: ",(0,a.kt)("inlineCode",{parentName:"li"},"[]"))),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("strong",{parentName:"li"},"Important")," For ",(0,a.kt)("inlineCode",{parentName:"li"},"br")," encoding NodeJS defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"11"),". Levels ",(0,a.kt)("inlineCode",{parentName:"li"},"10")," & ",(0,a.kt)("inlineCode",{parentName:"li"},"11")," have been shown to have lower performance for the level of compression they apply. Testing is recommended to ensure the right balance of compression & performance.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpContentNegotiation from '@middy/http-content-negotiation'\nimport httpContentEncoding from '@middy/http-content-encoding'\nimport { constants } from 'node:zlib'\n\nexport const handler = middy()\n .use(httpContentNegotiation())\n .use(httpContentEncoding({\n br: {\n params: {\n [constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT, // adjusted for UTF-8 text\n [constants.BROTLI_PARAM_QUALITY]: 7\n }\n },\n overridePreferredEncoding: ['br', 'gzip', 'deflate']\n })\n .handler((event, context) => {\n return {\n statusCode: 200,\n body: '{...}'\n }\n })\n")),(0,a.kt)("h3",{id:"using-streams"},"Using streams"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpContentNegotiation from '@middy/http-content-negotiation'\nimport httpContentEncoding from '@middy/http-content-encoding'\nimport { constants } from 'node:zlib'\nimport { createReadableStream } from '@datastream/core'\n\nexport const handler = middy({ streamifyResponse: true })\n .use(httpContentNegotiation())\n .use(httpContentEncoding({\n br: {\n params: {\n [constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT, // adjusted for UTF-8 text\n [constants.BROTLI_PARAM_QUALITY]: 7\n }\n },\n overridePreferredEncoding: ['br', 'gzip', 'deflate']\n })\n .handler((event, context) => {\n return {\n statusCode: 200,\n body: createReadableStream('{...}')\n }\n })\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6476],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),u=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},c=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),d=u(n),m=a,f=d["".concat(s,".").concat(m)]||d[m]||p[m]||o;return n?r.createElement(f,i(i({ref:t},c),{},{components:n})):r.createElement(f,i({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[d]="string"==typeof e?e:a,i[1]=l;for(var u=2;u{n.d(t,{Z:()=>i});var r=n(7294),a=n(6010);const o={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(o.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var r=n(7462),a=n(7294),o=n(6010),i=n(2466),l=n(6550),s=n(1980),u=n(7392),c=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,l.k6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(o),(0,a.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=p(e),[i,l]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[s,u]=f({queryString:n,groupId:r}),[d,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),h=(()=>{const e=s??d;return m({value:e,tabValues:o})?e:null})();(0,a.useLayoutEffect)((()=>{h&&l(h)}),[h]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),b(e)}),[u,b,o]),tabValues:o}}var h=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function y(e){let{className:t,block:n,selectedValue:l,selectValue:s,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),p=e=>{const t=e.currentTarget,n=c.indexOf(t),r=u[n].value;r!==l&&(d(t),s(r))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:i}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:l===t?0:-1,"aria-selected":l===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},i,{className:(0,o.Z)("tabs__item",g.tabItem,i?.className,{"tabs__item--active":l===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function k(e){const t=b(e);return a.createElement("div",{className:(0,o.Z)("tabs-container",g.tabList)},a.createElement(y,(0,r.Z)({},e,t)),a.createElement(v,(0,r.Z)({},e,t)))}function N(e){const t=(0,h.Z)();return a.createElement(k,(0,r.Z)({key:String(t)},e))}},3976:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>f,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),o=n(4866),i=n(5162);const l={title:"http-content-encoding"},s=void 0,u={unversionedId:"middlewares/http-content-encoding",id:"middlewares/http-content-encoding",title:"http-content-encoding",description:"This middleware take the preferredEncoding output from @middy/http-content-negotiation and applies the encoding to response.body when a string.",source:"@site/docs/middlewares/http-content-encoding.md",sourceDirName:"middlewares",slug:"/middlewares/http-content-encoding",permalink:"/docs/middlewares/http-content-encoding",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-content-encoding.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-content-encoding"},sidebar:"tutorialSidebar",previous:{title:"event-normalizer",permalink:"/docs/middlewares/event-normalizer"},next:{title:"http-content-negotiation",permalink:"/docs/middlewares/http-content-negotiation"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Using streams",id:"using-streams",level:3}],p={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware take the ",(0,a.kt)("inlineCode",{parentName:"p"},"preferredEncoding")," output from ",(0,a.kt)("inlineCode",{parentName:"p"},"@middy/http-content-negotiation")," and applies the encoding to ",(0,a.kt)("inlineCode",{parentName:"p"},"response.body")," when a string."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-content-encoding\n"))),(0,a.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-content-encoding\n"))),(0,a.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-content-encoding\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"br")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"{}"),"): ",(0,a.kt)("inlineCode",{parentName:"li"},"zlib.createBrotliCompress")," ",(0,a.kt)("a",{parentName:"li",href:"https://nodejs.org/api/zlib.html#zlib_class_brotlioptions"},"brotliOptions")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"gzip")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"{}"),"): ",(0,a.kt)("inlineCode",{parentName:"li"},"zlib.createGzip")," ",(0,a.kt)("a",{parentName:"li",href:"https://nodejs.org/api/zlib.html#zlib_class_options"},"gzipOptions")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"deflate")," (object) (default ",(0,a.kt)("inlineCode",{parentName:"li"},"{}"),"): ",(0,a.kt)("inlineCode",{parentName:"li"},"zlib.createDeflate")," ",(0,a.kt)("a",{parentName:"li",href:"https://nodejs.org/api/zlib.html#zlib_class_options"},"deflateOptions")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"overridePreferredEncoding")," (array","[string]",") (optional): Override the preferred encoding order, most browsers prefer ",(0,a.kt)("inlineCode",{parentName:"li"},"gzip")," over ",(0,a.kt)("inlineCode",{parentName:"li"},"br"),", even though ",(0,a.kt)("inlineCode",{parentName:"li"},"br")," has higher compression. Default: ",(0,a.kt)("inlineCode",{parentName:"li"},"[]"))),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("strong",{parentName:"li"},"Important")," For ",(0,a.kt)("inlineCode",{parentName:"li"},"br")," encoding NodeJS defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"11"),". Levels ",(0,a.kt)("inlineCode",{parentName:"li"},"10")," & ",(0,a.kt)("inlineCode",{parentName:"li"},"11")," have been shown to have lower performance for the level of compression they apply. Testing is recommended to ensure the right balance of compression & performance.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpContentNegotiation from '@middy/http-content-negotiation'\nimport httpContentEncoding from '@middy/http-content-encoding'\nimport { constants } from 'node:zlib'\n\nexport const handler = middy()\n .use(httpContentNegotiation())\n .use(httpContentEncoding({\n br: {\n params: {\n [constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT, // adjusted for UTF-8 text\n [constants.BROTLI_PARAM_QUALITY]: 7\n }\n },\n overridePreferredEncoding: ['br', 'gzip', 'deflate']\n })\n .handler((event, context) => {\n return {\n statusCode: 200,\n body: '{...}'\n }\n })\n")),(0,a.kt)("h3",{id:"using-streams"},"Using streams"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpContentNegotiation from '@middy/http-content-negotiation'\nimport httpContentEncoding from '@middy/http-content-encoding'\nimport { constants } from 'node:zlib'\nimport { createReadableStream } from '@datastream/core'\n\nexport const handler = middy({ streamifyResponse: true })\n .use(httpContentNegotiation())\n .use(httpContentEncoding({\n br: {\n params: {\n [constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT, // adjusted for UTF-8 text\n [constants.BROTLI_PARAM_QUALITY]: 7\n }\n },\n overridePreferredEncoding: ['br', 'gzip', 'deflate']\n })\n .handler((event, context) => {\n return {\n statusCode: 200,\n body: createReadableStream('{...}')\n }\n })\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b83c886a.7f89d2ab.js b/assets/js/b83c886a.61ddda43.js similarity index 96% rename from assets/js/b83c886a.7f89d2ab.js rename to assets/js/b83c886a.61ddda43.js index 2b8945153..7dd435acf 100644 --- a/assets/js/b83c886a.7f89d2ab.js +++ b/assets/js/b83c886a.61ddda43.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8931],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var s=n.createContext({}),u=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=u(e.components);return n.createElement(s.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,s=e.parentName,l=c(e,["components","mdxType","originalType","parentName"]),p=u(r),m=o,f=p["".concat(s,".").concat(m)]||p[m]||d[m]||i;return r?n.createElement(f,a(a({ref:t},l),{},{components:r})):n.createElement(f,a({ref:t},l))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=m;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[p]="string"==typeof e?e:o,a[1]=c;for(var u=2;u{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var n=r(7462),o=(r(7294),r(3905));const i={title:"Contributing"},a=void 0,c={unversionedId:"intro/contributing",id:"intro/contributing",title:"Contributing",description:"In the spirit of Open Source Software, everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.",source:"@site/docs/intro/10-contributing.md",sourceDirName:"intro",slug:"/intro/contributing",permalink:"/docs/intro/contributing",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/10-contributing.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:10,frontMatter:{title:"Contributing"},sidebar:"tutorialSidebar",previous:{title:"Release Cycle",permalink:"/docs/intro/release-cycle"},next:{title:"Sponsoring",permalink:"/docs/intro/sponsoring"}},s={},u=[],l={toc:u},p="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(p,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"In the spirit of Open Source Software, everyone is very welcome to contribute to this repository. Feel free to ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/issues"},"raise issues")," or to ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/pulls"},"submit Pull Requests"),"."),(0,o.kt)("p",null,"Before contributing to the project, make sure to have a look at our ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/blob/main/.github/CONTRIBUTING.md"},"Code of Conduct"),"."))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8931],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var s=n.createContext({}),u=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},l=function(e){var t=u(e.components);return n.createElement(s.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,i=e.originalType,s=e.parentName,l=c(e,["components","mdxType","originalType","parentName"]),p=u(r),m=o,f=p["".concat(s,".").concat(m)]||p[m]||d[m]||i;return r?n.createElement(f,a(a({ref:t},l),{},{components:r})):n.createElement(f,a({ref:t},l))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=r.length,a=new Array(i);a[0]=m;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[p]="string"==typeof e?e:o,a[1]=c;for(var u=2;u{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>d,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var n=r(7462),o=(r(7294),r(3905));const i={title:"Contributing"},a=void 0,c={unversionedId:"intro/contributing",id:"intro/contributing",title:"Contributing",description:"In the spirit of Open Source Software, everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.",source:"@site/docs/intro/10-contributing.md",sourceDirName:"intro",slug:"/intro/contributing",permalink:"/docs/intro/contributing",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/10-contributing.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:10,frontMatter:{title:"Contributing"},sidebar:"tutorialSidebar",previous:{title:"Release Cycle",permalink:"/docs/intro/release-cycle"},next:{title:"Sponsoring",permalink:"/docs/intro/sponsoring"}},s={},u=[],l={toc:u},p="wrapper";function d(e){let{components:t,...r}=e;return(0,o.kt)(p,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"In the spirit of Open Source Software, everyone is very welcome to contribute to this repository. Feel free to ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/issues"},"raise issues")," or to ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/pulls"},"submit Pull Requests"),"."),(0,o.kt)("p",null,"Before contributing to the project, make sure to have a look at our ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/blob/main/.github/CONTRIBUTING.md"},"Code of Conduct"),"."))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b9c75af0.759b3f4d.js b/assets/js/b9c75af0.73ff87ef.js similarity index 96% rename from assets/js/b9c75af0.759b3f4d.js rename to assets/js/b9c75af0.73ff87ef.js index 78dfc69c9..eb12f5410 100644 --- a/assets/js/b9c75af0.759b3f4d.js +++ b/assets/js/b9c75af0.73ff87ef.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4504],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},m="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,a=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=c(n),u=i,f=m["".concat(l,".").concat(u)]||m[u]||d[u]||a;return n?r.createElement(f,o(o({ref:t},p),{},{components:n})):r.createElement(f,o({ref:t},p))}));function f(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=n.length,o=new Array(a);o[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[m]="string"==typeof e?e:i,o[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>c});var r=n(7462),i=(n(7294),n(3905));const a={title:"Kinesis Streams"},o=void 0,s={unversionedId:"events/kinesis-streams",id:"events/kinesis-streams",title:"Kinesis Streams",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/kinesis-streams.md",sourceDirName:"events",slug:"/events/kinesis-streams",permalink:"/docs/events/kinesis-streams",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kinesis-streams.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Kinesis Streams"},sidebar:"tutorialSidebar",previous:{title:"Kinesis Firehose",permalink:"/docs/events/kinesis-firehose"},next:{title:"Lex",permalink:"/docs/events/lex"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},m="wrapper";function d(e){let{components:t,...n}=e;return(0,i.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,i.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html"},"Using AWS Lambda with Amazon Kinesis"))),(0,i.kt)("h2",{id:"example"},"Example"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4504],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},m="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,a=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=c(n),u=i,f=m["".concat(l,".").concat(u)]||m[u]||d[u]||a;return n?r.createElement(f,o(o({ref:t},p),{},{components:n})):r.createElement(f,o({ref:t},p))}));function f(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=n.length,o=new Array(a);o[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[m]="string"==typeof e?e:i,o[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>c});var r=n(7462),i=(n(7294),n(3905));const a={title:"Kinesis Streams"},o=void 0,s={unversionedId:"events/kinesis-streams",id:"events/kinesis-streams",title:"Kinesis Streams",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/kinesis-streams.md",sourceDirName:"events",slug:"/events/kinesis-streams",permalink:"/docs/events/kinesis-streams",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kinesis-streams.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Kinesis Streams"},sidebar:"tutorialSidebar",previous:{title:"Kinesis Firehose",permalink:"/docs/events/kinesis-firehose"},next:{title:"Lex",permalink:"/docs/events/lex"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},m="wrapper";function d(e){let{components:t,...n}=e;return(0,i.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,i.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html"},"Using AWS Lambda with Amazon Kinesis"))),(0,i.kt)("h2",{id:"example"},"Example"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport eventNormalizerMiddleware from '@middy/event-normalizer'\n\nexport const handler = middy()\n .use(eventNormalizerMiddleware())\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/bff6c11b.f742b4ac.js b/assets/js/bff6c11b.a48b1a39.js similarity index 97% rename from assets/js/bff6c11b.f742b4ac.js rename to assets/js/bff6c11b.a48b1a39.js index 5ea838424..ac33e90a3 100644 --- a/assets/js/bff6c11b.f742b4ac.js +++ b/assets/js/bff6c11b.a48b1a39.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4785],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>y});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),p=c(n),m=a,y=p["".concat(l,".").concat(m)]||p[m]||u[m]||o;return n?r.createElement(y,i(i({ref:t},d),{},{components:n})):r.createElement(y,i({ref:t},d))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"API Gateway (WebSocket)"},i=void 0,s={unversionedId:"events/api-gateway-ws",id:"events/api-gateway-ws",title:"API Gateway (WebSocket)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/api-gateway-ws.md",sourceDirName:"events",slug:"/events/api-gateway-ws",permalink:"/docs/events/api-gateway-ws",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-ws.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"API Gateway (WebSocket)"},sidebar:"tutorialSidebar",previous:{title:"API Gateway (REST)",permalink:"/docs/events/api-gateway-rest"},next:{title:"Application Load Balancer",permalink:"/docs/events/application-load-balancer"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],d={toc:c},p="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html"},"Using AWS Lambda with Amazon API Gateway")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html"},"Working with WebSocket APIs"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsJsonBodyParserMiddleware from '@middy/ws-json-body-parser'\nimport wsResponseMiddleware from '@middy/ws-response'\nimport wsRouterHandler from '@middy/ws-router'\n\nimport { handler as connectHandler } from './handlers/connect.js'\nimport { handler as disconnectHandler } from './handlers/disconnect.js'\nimport { handler as defaultHandler } from './handlers/default.js'\n\nconst routes = [\n {\n routeKey: '$connect',\n handler: connectHandler\n },\n {\n routeKey: '$disconnect',\n handler: disconnectHandler\n },\n {\n routeKey: 'default',\n handler: defaultHandler\n }\n]\n\nexport const handler = middy()\n .use(wsJsonBodyParserMiddleware())\n .use(wsResponseMiddleware())\n .handler(wsRouterHandler(routes))\n\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4785],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>y});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),p=c(n),m=a,y=p["".concat(l,".").concat(m)]||p[m]||u[m]||o;return n?r.createElement(y,i(i({ref:t},d),{},{components:n})):r.createElement(y,i({ref:t},d))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"API Gateway (WebSocket)"},i=void 0,s={unversionedId:"events/api-gateway-ws",id:"events/api-gateway-ws",title:"API Gateway (WebSocket)",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/api-gateway-ws.md",sourceDirName:"events",slug:"/events/api-gateway-ws",permalink:"/docs/events/api-gateway-ws",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-ws.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"API Gateway (WebSocket)"},sidebar:"tutorialSidebar",previous:{title:"API Gateway (REST)",permalink:"/docs/events/api-gateway-rest"},next:{title:"Application Load Balancer",permalink:"/docs/events/application-load-balancer"}},l={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],d={toc:c},p="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html"},"Using AWS Lambda with Amazon API Gateway")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html"},"Working with WebSocket APIs"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsJsonBodyParserMiddleware from '@middy/ws-json-body-parser'\nimport wsResponseMiddleware from '@middy/ws-response'\nimport wsRouterHandler from '@middy/ws-router'\n\nimport { handler as connectHandler } from './handlers/connect.js'\nimport { handler as disconnectHandler } from './handlers/disconnect.js'\nimport { handler as defaultHandler } from './handlers/default.js'\n\nconst routes = [\n {\n routeKey: '$connect',\n handler: connectHandler\n },\n {\n routeKey: '$disconnect',\n handler: disconnectHandler\n },\n {\n routeKey: 'default',\n handler: defaultHandler\n }\n]\n\nexport const handler = middy()\n .use(wsJsonBodyParserMiddleware())\n .use(wsResponseMiddleware())\n .handler(wsRouterHandler(routes))\n\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/c0ad98a5.9f41a48f.js b/assets/js/c0ad98a5.1121a23e.js similarity index 98% rename from assets/js/c0ad98a5.9f41a48f.js rename to assets/js/c0ad98a5.1121a23e.js index a66054ef6..f30345a18 100644 --- a/assets/js/c0ad98a5.9f41a48f.js +++ b/assets/js/c0ad98a5.1121a23e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2932],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var i=n.createContext({}),u=function(e){var t=n.useContext(i),r=t;return e&&(r="function"==typeof e?e(t):s(s({},t),e)),r},p=function(e){var t=u(e.components);return n.createElement(i.Provider,{value:t},e.children)},c="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),c=u(r),m=a,f=c["".concat(i,".").concat(m)]||c[m]||d[m]||l;return r?n.createElement(f,s(s({ref:t},p),{},{components:r})):n.createElement(f,s({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,s=new Array(l);s[0]=m;var o={};for(var i in t)hasOwnProperty.call(t,i)&&(o[i]=t[i]);o.originalType=e,o[c]="string"==typeof e?e:a,s[1]=o;for(var u=2;u{r.d(t,{Z:()=>s});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:r,className:s}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,s),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var n=r(7462),a=r(7294),l=r(6010),s=r(2466),o=r(6550),i=r(1980),u=r(7392),p=r(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function d(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const n=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,i._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function b(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=d(e),[s,o]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[i,u]=f({queryString:r,groupId:n}),[c,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,p.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),h=(()=>{const e=i??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{h&&o(h)}),[h]);return{selectedValue:s,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var h=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:o,selectValue:i,tabValues:u}=e;const p=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),d=e=>{const t=e.currentTarget,r=p.indexOf(t),n=u[r].value;n!==o&&(c(t),i(n))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=p.indexOf(e.currentTarget)+1;t=p[r]??p[0];break}case"ArrowLeft":{const r=p.indexOf(e.currentTarget)-1;t=p[r]??p[p.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:s}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:d},s,{className:(0,l.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":o===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=b(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(g,(0,n.Z)({},e,t)))}function k(e){const t=(0,h.Z)();return a.createElement(w,(0,n.Z)({key:String(t)},e))}},5535:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>c});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),s=r(5162);const o={title:"http-partial-response"},i=void 0,u={unversionedId:"middlewares/http-partial-response",id:"middlewares/http-partial-response",title:"http-partial-response",description:"Filtering the data returned in an object or JSON stringified response has never been so easy. Add the httpPartialResponse middleware to your middleware chain, specify a custom filteringKeyName if you want to and that's it. Any consumer of your API will be able to filter your JSON response by adding a querystring key with the fields to filter such as fields=firstname,lastname.",source:"@site/docs/middlewares/http-partial-response.md",sourceDirName:"middlewares",slug:"/middlewares/http-partial-response",permalink:"/docs/middlewares/http-partial-response",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-partial-response.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-partial-response"},sidebar:"tutorialSidebar",previous:{title:"http-multipart-body-parser",permalink:"/docs/middlewares/http-multipart-body-parser"},next:{title:"http-response-serializer",permalink:"/docs/middlewares/http-response-serializer"}},p={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:c},m="wrapper";function f(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Filtering the data returned in an object or JSON stringified response has never been so easy. Add the ",(0,a.kt)("inlineCode",{parentName:"p"},"httpPartialResponse")," middleware to your middleware chain, specify a custom ",(0,a.kt)("inlineCode",{parentName:"p"},"filteringKeyName")," if you want to and that's it. Any consumer of your API will be able to filter your JSON response by adding a querystring key with the fields to filter such as ",(0,a.kt)("inlineCode",{parentName:"p"},"fields=firstname,lastname"),"."),(0,a.kt)("p",null,"This middleware is based on the awesome ",(0,a.kt)("inlineCode",{parentName:"p"},"json-mask")," package written by ",(0,a.kt)("a",{parentName:"p",href:"https://github.com/nemtsov"},"Yuriy Nemtsov")),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-partial-response\n"))),(0,a.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-partial-response\n"))),(0,a.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-partial-response\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"filteringKeyName")," (",(0,a.kt)("inlineCode",{parentName:"li"},"string"),") (optional): defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"fields")," the querystring key that will be used to filter the response.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpPartialResponse from '@middy/http-partial-response'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n body: {\n firstname: 'John',\n lastname: 'Doe',\n gender: 'male',\n age: 30,\n address: {\n street: 'Avenue des Champs-\xc9lys\xe9es',\n city: 'Paris'\n }\n }\n }\n\n return response\n})\n\nhandler.use(httpPartialResponse())\n\nconst event = {\n queryStringParameters: {\n fields: 'firstname,lastname'\n }\n}\n\nhandler(event, {}, (_, response) => {\n expect(response.body).toEqual({\n firstname: 'John',\n lastname: 'Doe'\n })\n})\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2932],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var i=n.createContext({}),u=function(e){var t=n.useContext(i),r=t;return e&&(r="function"==typeof e?e(t):s(s({},t),e)),r},p=function(e){var t=u(e.components);return n.createElement(i.Provider,{value:t},e.children)},c="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),c=u(r),m=a,f=c["".concat(i,".").concat(m)]||c[m]||d[m]||l;return r?n.createElement(f,s(s({ref:t},p),{},{components:r})):n.createElement(f,s({ref:t},p))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,s=new Array(l);s[0]=m;var o={};for(var i in t)hasOwnProperty.call(t,i)&&(o[i]=t[i]);o.originalType=e,o[c]="string"==typeof e?e:a,s[1]=o;for(var u=2;u{r.d(t,{Z:()=>s});var n=r(7294),a=r(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:r,className:s}=e;return n.createElement("div",{role:"tabpanel",className:(0,a.Z)(l.tabItem,s),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>k});var n=r(7462),a=r(7294),l=r(6010),s=r(2466),o=r(6550),i=r(1980),u=r(7392),p=r(12);function c(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}function d(e){const{values:t,children:r}=e;return(0,a.useMemo)((()=>{const e=t??c(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const n=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,i._X)(l),(0,a.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function b(e){const{defaultValue:t,queryString:r=!1,groupId:n}=e,l=d(e),[s,o]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[i,u]=f({queryString:r,groupId:n}),[c,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,p.Nk)(r);return[n,(0,a.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:n}),h=(()=>{const e=i??c;return m({value:e,tabValues:l})?e:null})();(0,a.useLayoutEffect)((()=>{h&&o(h)}),[h]);return{selectedValue:s,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,l]),tabValues:l}}var h=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:o,selectValue:i,tabValues:u}=e;const p=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),d=e=>{const t=e.currentTarget,r=p.indexOf(t),n=u[r].value;n!==o&&(c(t),i(n))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=p.indexOf(e.currentTarget)+1;t=p[r]??p[0];break}case"ArrowLeft":{const r=p.indexOf(e.currentTarget)-1;t=p[r]??p[p.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:s}=e;return a.createElement("li",(0,n.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:d},s,{className:(0,l.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":o===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:n}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=b(e);return a.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},a.createElement(v,(0,n.Z)({},e,t)),a.createElement(g,(0,n.Z)({},e,t)))}function k(e){const t=(0,h.Z)();return a.createElement(w,(0,n.Z)({key:String(t)},e))}},5535:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>c});var n=r(7462),a=(r(7294),r(3905)),l=r(4866),s=r(5162);const o={title:"http-partial-response"},i=void 0,u={unversionedId:"middlewares/http-partial-response",id:"middlewares/http-partial-response",title:"http-partial-response",description:"Filtering the data returned in an object or JSON stringified response has never been so easy. Add the httpPartialResponse middleware to your middleware chain, specify a custom filteringKeyName if you want to and that's it. Any consumer of your API will be able to filter your JSON response by adding a querystring key with the fields to filter such as fields=firstname,lastname.",source:"@site/docs/middlewares/http-partial-response.md",sourceDirName:"middlewares",slug:"/middlewares/http-partial-response",permalink:"/docs/middlewares/http-partial-response",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-partial-response.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-partial-response"},sidebar:"tutorialSidebar",previous:{title:"http-multipart-body-parser",permalink:"/docs/middlewares/http-multipart-body-parser"},next:{title:"http-response-serializer",permalink:"/docs/middlewares/http-response-serializer"}},p={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:c},m="wrapper";function f(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Filtering the data returned in an object or JSON stringified response has never been so easy. Add the ",(0,a.kt)("inlineCode",{parentName:"p"},"httpPartialResponse")," middleware to your middleware chain, specify a custom ",(0,a.kt)("inlineCode",{parentName:"p"},"filteringKeyName")," if you want to and that's it. Any consumer of your API will be able to filter your JSON response by adding a querystring key with the fields to filter such as ",(0,a.kt)("inlineCode",{parentName:"p"},"fields=firstname,lastname"),"."),(0,a.kt)("p",null,"This middleware is based on the awesome ",(0,a.kt)("inlineCode",{parentName:"p"},"json-mask")," package written by ",(0,a.kt)("a",{parentName:"p",href:"https://github.com/nemtsov"},"Yuriy Nemtsov")),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-partial-response\n"))),(0,a.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-partial-response\n"))),(0,a.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-partial-response\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"filteringKeyName")," (",(0,a.kt)("inlineCode",{parentName:"li"},"string"),") (optional): defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"fields")," the querystring key that will be used to filter the response.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpPartialResponse from '@middy/http-partial-response'\n\nconst handler = middy((event, context) => {\n const response = {\n statusCode: 200,\n body: {\n firstname: 'John',\n lastname: 'Doe',\n gender: 'male',\n age: 30,\n address: {\n street: 'Avenue des Champs-\xc9lys\xe9es',\n city: 'Paris'\n }\n }\n }\n\n return response\n})\n\nhandler.use(httpPartialResponse())\n\nconst event = {\n queryStringParameters: {\n fields: 'firstname,lastname'\n }\n}\n\nhandler(event, {}, (_, response) => {\n expect(response.body).toEqual({\n firstname: 'John',\n lastname: 'Doe'\n })\n})\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/c1378803.51b6a1c8.js b/assets/js/c1378803.51b6a1c8.js new file mode 100644 index 000000000..a4f946b56 --- /dev/null +++ b/assets/js/c1378803.51b6a1c8.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7450],{3905:(e,t,a)=>{a.d(t,{Zo:()=>d,kt:()=>h});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var s=n.createContext({}),c=function(e){var t=n.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},d=function(e){var t=c(e.components);return n.createElement(s.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,o=e.originalType,s=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),p=c(a),m=r,h=p["".concat(s,".").concat(m)]||p[m]||u[m]||o;return a?n.createElement(h,l(l({ref:t},d),{},{components:a})):n.createElement(h,l({ref:t},d))}));function h(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=a.length,l=new Array(o);l[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[p]="string"==typeof e?e:r,l[1]=i;for(var c=2;c{a.d(t,{Z:()=>l});var n=a(7294),r=a(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:a,className:l}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(o.tabItem,l),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>v});var n=a(7462),r=a(7294),o=a(6010),l=a(2466),i=a(6550),s=a(1980),c=a(7392),d=a(12);function p(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function u(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??p(a);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function m(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:a}=e;const n=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,s._X)(o),(0,r.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(n.location.search);t.set(o,e),n.replace({...n.location,search:t.toString()})}),[o,n])]}function g(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,o=u(e),[l,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[s,c]=h({queryString:a,groupId:n}),[p,g]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,o]=(0,d.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&o.set(e)}),[a,o])]}({groupId:n}),y=(()=>{const e=s??p;return m({value:e,tabValues:o})?e:null})();(0,r.useLayoutEffect)((()=>{y&&i(y)}),[y]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),g(e)}),[c,g,o]),tabValues:o}}var y=a(2389);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function b(e){let{className:t,block:a,selectedValue:i,selectValue:s,tabValues:c}=e;const d=[],{blockElementScrollPositionUntilNextRender:p}=(0,l.o5)(),u=e=>{const t=e.currentTarget,a=d.indexOf(t),n=c[a].value;n!==i&&(p(t),s(n))},m=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const a=d.indexOf(e.currentTarget)+1;t=d[a]??d[0];break}case"ArrowLeft":{const a=d.indexOf(e.currentTarget)-1;t=d[a]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":a},t)},c.map((e=>{let{value:t,label:a,attributes:l}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:m,onClick:u},l,{className:(0,o.Z)("tabs__item",f.tabItem,l?.className,{"tabs__item--active":i===t})}),a??t)})))}function k(e){let{lazy:t,children:a,selectedValue:n}=e;const o=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=g(e);return r.createElement("div",{className:(0,o.Z)("tabs-container",f.tabList)},r.createElement(b,(0,n.Z)({},e,t)),r.createElement(k,(0,n.Z)({},e,t)))}function v(e){const t=(0,y.Z)();return r.createElement(w,(0,n.Z)({key:String(t)},e))}},9310:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>p});var n=a(7462),r=(a(7294),a(3905)),o=a(4866),l=a(5162);const i={title:"Powertools for AWS Lambda"},s=void 0,c={unversionedId:"integrations/lambda-powertools",id:"integrations/lambda-powertools",title:"Powertools for AWS Lambda",description:"Powertools for AWS is a developer toolkit to implement Serverless best practices and increase developer velocity.",source:"@site/docs/integrations/lambda-powertools.md",sourceDirName:"integrations",slug:"/integrations/lambda-powertools",permalink:"/docs/integrations/lambda-powertools",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/lambda-powertools.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Powertools for AWS Lambda"},sidebar:"tutorialSidebar",previous:{title:"Apollo Server",permalink:"/docs/integrations/apollo-server"},next:{title:"Pino",permalink:"/docs/integrations/pino"}},d={},p=[{value:"Intro",id:"intro",level:2},{value:"Logger",id:"logger",level:2},{value:"Install",id:"install",level:3},{value:"Options",id:"options",level:3},{value:"Sample usage",id:"sample-usage",level:3},{value:"Tracer",id:"tracer",level:2},{value:"Install",id:"install-1",level:3},{value:"Options",id:"options-1",level:3},{value:"Sample usage",id:"sample-usage-1",level:3},{value:"Metrics",id:"metrics",level:2},{value:"Install",id:"install-2",level:3},{value:"Options",id:"options-2",level:3},{value:"Sample usage",id:"sample-usage-2",level:3},{value:"Idempotency",id:"idempotency",level:2},{value:"Install",id:"install-3",level:3},{value:"Options",id:"options-3",level:3},{value:"Sample usage",id:"sample-usage-3",level:3},{value:"Best practices",id:"best-practices",level:2},{value:"Using multiple utilities",id:"using-multiple-utilities",level:3},{value:"Cleaning up on early returns",id:"cleaning-up-on-early-returns",level:3}],u={toc:p},m="wrapper";function h(e){let{components:t,...a}=e;return(0,r.kt)(m,(0,n.Z)({},u,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Powertools for AWS is a developer toolkit to implement Serverless ",(0,r.kt)("a",{parentName:"p",href:"https://s12d.com/middy-intro"},"best practices and increase developer velocity"),"."),(0,r.kt)("p",null,"You can use Powertools for AWS in both TypeScript and JavaScript code bases."),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"Powertools officially supports ",(0,r.kt)("inlineCode",{parentName:"p"},"@middy/core")," v3.x only. In most cases when using Node.js 16 or higher you can use Powertools with ",(0,r.kt)("inlineCode",{parentName:"p"},"@middy/core")," v4.x, however support is provided on a best-effort basis and we recommend using ",(0,r.kt)("inlineCode",{parentName:"p"},"@middy/core")," v3.x.")),(0,r.kt)("h2",{id:"intro"},"Intro"),(0,r.kt)("p",null,"Powertools is a collection of utilities that can be used independently or together to help you build production-ready serverless applications. Currently, Powertools provides the following utilities that are compatible with Middy:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://s12d.com/middy-logger"},(0,r.kt)("strong",{parentName:"a"},"Logger"))," - Structured logging made easier with a middleware to capture key fields from the Lambda context, cold starts, and more. Compatible with Amazon CloudWatch, Datadog, and more."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://s12d.com/middy-tracer"},(0,r.kt)("strong",{parentName:"a"},"Tracer"))," - An opinionated wrapper around AWS X-Ray SDK for Node.js with a middleware to automatically capture traces for function invocations, HTTP requests, and AWS SDK calls, and more."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://s12d.com/middy-metrics"},(0,r.kt)("strong",{parentName:"a"},"Metrics"))," - Create Amazon CloudWatch custom metrics asynchronously with a middleware that takes care of capturing cold starts, and flushes metrics to CloudWatch in ",(0,r.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html"},"EMF-formatted")," batches."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://s12d.com/middy-idempotency"},(0,r.kt)("strong",{parentName:"a"},"Idempotency"))," - Middleware to make your Lambda functions idempotent and prevent duplicate execution based on payload content.")),(0,r.kt)("h2",{id:"logger"},"Logger"),(0,r.kt)("p",null,"Key features:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Capturing key fields from the Lambda context, cold starts, and structure logging output as JSON."),(0,r.kt)("li",{parentName:"ul"},"Logging Lambda invocation events when instructed (disabled by default)."),(0,r.kt)("li",{parentName:"ul"},"Printing all the logs only for a percentage of invocations via log sampling (disabled by default)."),(0,r.kt)("li",{parentName:"ul"},"Appending additional keys to structured logs at any point in time."),(0,r.kt)("li",{parentName:"ul"},"Providing a custom log formatter (Bring Your Own Formatter) to output logs in a structure compatible with your organization\u2019s Logging RFC.")),(0,r.kt)("h3",{id:"install"},"Install"),(0,r.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @aws-lambda-powertools/logger\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @aws-lambda-powertools/logger\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @aws-lambda-powertools/logger\n")))),(0,r.kt)("h3",{id:"options"},"Options"),(0,r.kt)("p",null,"Class constructor accepts the following options, which are all optional:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"logLevel")," (string|LogLevel): Log level to use. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"INFO"),", but you can use any of the following values: ",(0,r.kt)("inlineCode",{parentName:"li"},"SILENT"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"DEBUG"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"INFO"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"WARN"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"ERROR"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"CRITICAL"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"serviceName")," (string): Service name to use that will be used in all log statements. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"service_undefined"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"sampleRateValue")," (number): number between ",(0,r.kt)("inlineCode",{parentName:"li"},"0.0")," and ",(0,r.kt)("inlineCode",{parentName:"li"},"1")," to determine the sample rate for debug logging. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"0")," (no debub logging).")),(0,r.kt)("p",null,"Middleware accepts the following options:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"logger")," (Logger) (required): An instance of the Logger class."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"option")," (object) (optional): An object with the following keys:",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"logEvent")," (boolean) (optional): Whether to log the Lambda invocation event. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"clearState")," (boolean) (optional): Whether to clear the logger state after each invocation. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),".")))),(0,r.kt)("h3",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core';\nimport { Logger, injectLambdaContext } from '@aws-lambda-powertools/logger';\n\nconst logger = new Logger({ serviceName: 'serverlessAirline' });\n\nconst lambdaHandler = async (_event, _context) => {\n logger.info('This is an INFO log with some context', {\n foo: {\n bar: 'baz'\n }\n });\n};\n\nexport const handler = middy(lambdaHandler)\n .use(injectLambdaContext(logger));\n")),(0,r.kt)("p",null,"The above code will output the following log:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "cold_start": true,\n "function_arn": "arn:aws:lambda:eu-west-1:123456789012:function:shopping-cart-api-lambda-prod-eu-west-1",\n "function_memory_size": 128,\n "function_request_id": "c6af9ac6-7b61-11e6-9a41-93e812345678",\n "function_name": "shopping-cart-api-lambda-prod-eu-west-1",\n "level": "INFO",\n "message": "This is an INFO log with some context",\n "foo": {\n "bar": "baz"\n },\n "service": "serverlessAirline",\n "timestamp": "2021-12-12T21:21:08.921Z",\n "xray_trace_id": "abcdef123456abcdef123456abcdef123456"\n}\n')),(0,r.kt)("p",null,"As you can see, the log entry includes several fields that are automatically captured by the Logger utility, and that can help you better understand the context of the log entry. For example, the ",(0,r.kt)("inlineCode",{parentName:"p"},"cold_start")," field indicates whether the Lambda function was cold started or not, and the ",(0,r.kt)("inlineCode",{parentName:"p"},"xray_trace_id")," field contains the AWS X-Ray trace ID for the Lambda invocation. This is useful when you're troubleshooting a problem and want to correlate the logs with the traces."),(0,r.kt)("p",null,"The Logger utility also allows you to append arbitary keys to the log entry at both ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#appending-persistent-additional-log-keys-and-values"},"the global level"),", at the ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#clearing-all-state"},"invocation level"),", and at the ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#appending-additional-data-to-a-single-log-item"},"single log level"),". For example, there might be some keys that you want to include in all log entries, such as the ",(0,r.kt)("inlineCode",{parentName:"p"},"environment")," key to differentiate between the ",(0,r.kt)("inlineCode",{parentName:"p"},"prod")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"dev")," environments, or in other cases you might want to include some keys only for a specific log entry, such as the ",(0,r.kt)("inlineCode",{parentName:"p"},"customer_id")," key to identify the customer that triggered the Lambda invocation."),(0,r.kt)("p",null,"Additionally, you can also configure Logger to ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#log-incoming-event"},"log the Lambda invocation event"),", which can be useful when you're troubleshooting a problem and want to see the event that triggered the Lambda invocation. Finally, Logger allows you to ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#custom-log-formatter-bring-your-own-formatter"},"define a custom log formatter")," to output logs in a different JSON structure from the default one. This is useful when you want to output logs in a structure that is compatible with your organization's requirements."),(0,r.kt)("h2",{id:"tracer"},"Tracer"),(0,r.kt)("p",null,"Key features:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Auto-capturing cold start and service name as annotations, and responses or full exceptions as metadata."),(0,r.kt)("li",{parentName:"ul"},"Automatically tracing HTTP(S) clients and generating segments for each request."),(0,r.kt)("li",{parentName:"ul"},"Supporting tracing functions via decorators, middleware, and manual instrumentation."),(0,r.kt)("li",{parentName:"ul"},"Supporting tracing AWS SDK v2 and v3 via AWS X-Ray SDK for Node.js."),(0,r.kt)("li",{parentName:"ul"},"Auto-disable tracing when not running in the Lambda environment.")),(0,r.kt)("h3",{id:"install-1"},"Install"),(0,r.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @aws-lambda-powertools/tracer\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @aws-lambda-powertools/tracer\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @aws-lambda-powertools/tracer\n")))),(0,r.kt)("h3",{id:"options-1"},"Options"),(0,r.kt)("p",null,"Class constructor accepts the following options, which are all optional:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"serviceName")," (string): Service name to use that will be used in all log statements. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"service_undefined"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"enabled")," (boolean): Whether to enable tracing. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"captureHTTPsRequests")," (boolean): Whether to capture outgoing HTTP(S) requests as segment metadata. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),".")),(0,r.kt)("p",null,"Middleware accepts the following options:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"tracer")," (Tracer) (required): An instance of the Tracer class."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"option")," (object) (optional): An object with the following keys:",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"captureResponse")," (boolean) (optional): Whether to capture the Lambda invocation result as segment metadata. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),".")))),(0,r.kt)("h3",{id:"sample-usage-1"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core';\nimport { Tracer, captureLambdaHandler } from '@aws-lambda-powertools/tracer';\nimport { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';\n\nconst tracer = new Tracer({\n serviceName: 'serverlessAirline'\n});\n\nconst client = tracer.captureAWSv3Client(\n new SecretsManagerClient({})\n);\n\nconst lambdaHandler = async (_event, _context) => {\n tracer.putAnnotation('successfulBooking', true);\n};\n\nexport const handler = middy(lambdaHandler)\n .use(captureLambdaHandler(tracer));\n")),(0,r.kt)("p",null,"The above code instructs the Tracer utility to create a custom segment named ",(0,r.kt)("inlineCode",{parentName:"p"},"## index.handler")," and to add an annotation to it with the key ",(0,r.kt)("inlineCode",{parentName:"p"},"successfulBooking")," and the value ",(0,r.kt)("inlineCode",{parentName:"p"},"true"),". The segment name is automatically generated based on the handler name, and the ",(0,r.kt)("inlineCode",{parentName:"p"},"##")," prefix is used to indicate that this is a custom segment. The Tracer utility also automatically captures the cold start and service name as annotations, and the Lambda invocation result or any error thrown ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#annotations-metadata"},"as metadata"),". The segment data will be automatically sent to AWS X-Ray when the Lambda function completes its execution."),(0,r.kt)("p",null,"Tracer also automatically ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#tracing-http-requests"},"captures and traces any outgoing HTTP(S) requests")," made by the Lambda function. For example, if your function makes a request to a custom API, the Tracer utility will automatically create a segment for that request which will appear in your trace data and service map. Additionally, it will also ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#patching-aws-sdk-clients"},"capture any AWS SDK calls")," made by the function, and do the same for them."),(0,r.kt)("h2",{id:"metrics"},"Metrics"),(0,r.kt)("p",null,"Key features:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Aggregating up to 100 metrics using a single ",(0,r.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html"},"CloudWatch EMF")," object."),(0,r.kt)("li",{parentName:"ul"},"Validating your metrics against common metric definitions mistakes (for example, metric unit, values, max dimensions, max metrics)."),(0,r.kt)("li",{parentName:"ul"},"Metrics are created asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency."),(0,r.kt)("li",{parentName:"ul"},"Creating a one-off metric with different dimensions.")),(0,r.kt)("p",null,"If you're new to Amazon CloudWatch, there are a few terms like ",(0,r.kt)("inlineCode",{parentName:"p"},"Namespace"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"Dimensions"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"Unit"),", etc, that you must be aware of before you start using the Metrics utility. To learn more about these terms, see the ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#terminologies"},"documentation on PowerTools Metrics"),"."),(0,r.kt)("h3",{id:"install-2"},"Install"),(0,r.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @aws-lambda-powertools/metrics\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @aws-lambda-powertools/metrics\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @aws-lambda-powertools/metrics\n")))),(0,r.kt)("h3",{id:"options-2"},"Options"),(0,r.kt)("p",null,"Class constructor accepts the following options, which are all optional:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"serviceName")," (string): Service name to use that will be used in all log statements. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"service_undefined"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"defaultNamespace")," (string): Default namespace to use for all metrics. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"default_namespace"),".")),(0,r.kt)("p",null,"Middleware accepts the following options:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"metrics")," (Metric) (required): An instance of the Metrics class."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"option")," (object) (optional): An object with the following keys:",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"throwOnEmptyMetrics")," (boolean) (optional): Whether to throw an error if no metrics were added. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"captureColdStartMetric")," (boolean) (optional): Whether to capture the cold start metric. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),".")))),(0,r.kt)("h3",{id:"sample-usage-2"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core';\nimport { Metrics, MetricUnits, logMetrics } from '@aws-lambda-powertools/metrics';\n\nconst metrics = new Metrics({\n namespace: 'serverlessAirline',\n serviceName: 'orders'\n});\n\nconst lambdaHandler = async (_event: unknown, _context: unknown): Promise => {\n metrics.addMetric('successfulBooking', MetricUnits.Count, 1);\n};\n\nexport const handler = middy(lambdaHandler)\n .use(logMetrics(metrics));\n")),(0,r.kt)("p",null,"The above code will output a CloudWatch EMF object similar to the following:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "successfulBooking": 1.0,\n "_aws": {\n "Timestamp": 1592234975665,\n "CloudWatchMetrics": [{\n "Namespace": "successfulBooking",\n "Dimensions": [\n [ "service" ]\n ],\n "Metrics": [{\n "Name": "successfulBooking",\n "Unit": "Count"\n }]\n }],\n "service": "orders"\n }\n}\n')),(0,r.kt)("p",null,"This EMF object will be sent to CloudWatch asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency."),(0,r.kt)("p",null,"The Metrics utility supports ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-high-resolution-metrics"},"high-resolution metrics")," as well as ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-multi-value-metrics"},"multi-value metrics"),". It also allows you to add ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-default-dimensions"},"default dimensions")," that are used in all the metrics emitted by your application or ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#single-metric-with-different-dimensions"},"create a one-off metric")," with different dimensions."),(0,r.kt)("h2",{id:"idempotency"},"Idempotency"),(0,r.kt)("p",null,"Key features:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Prevent Lambda handler from executing more than once on the same event payload during a time window"),(0,r.kt)("li",{parentName:"ul"},"Ensure Lambda handler returns the same result when called with the same payload"),(0,r.kt)("li",{parentName:"ul"},"Select a subset of the event as the idempotency key using JMESPath expressions"),(0,r.kt)("li",{parentName:"ul"},"Set a time window in which records with the same payload should be considered duplicates"),(0,r.kt)("li",{parentName:"ul"},"Expires in-progress executions if the Lambda function times out halfway through")),(0,r.kt)("p",null,"The property of idempotency means that an operation does not cause additional side effects if it is called more than once with the same input parameters. Idempotent operations will return the same result when they are called multiple times with the same parameters. This makes idempotent operations safe to retry."),(0,r.kt)("h3",{id:"install-3"},"Install"),(0,r.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n")))),(0,r.kt)("h3",{id:"options-3"},"Options"),(0,r.kt)("p",null,"Middleware accepts the following options:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"persistenceStore")," (",(0,r.kt)("a",{parentName:"li",href:"https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_idempotency.persistence.BasePersistenceLayer.html"},(0,r.kt)("inlineCode",{parentName:"a"},"BasePersistenceLayer")),"): Class used to interact with a ",(0,r.kt)("a",{parentName:"li",href:"https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/#persistence-layers"},"persistence store"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"config")," (",(0,r.kt)("a",{parentName:"li",href:"https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_idempotency.index.IdempotencyConfig.html"},(0,r.kt)("inlineCode",{parentName:"a"},"IdempotencyConfig")),") (optional): Configuration object to customize the ",(0,r.kt)("a",{parentName:"li",href:"https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/#customizing-the-default-behavior"},"default behavior")," of the idempotency feature.")),(0,r.kt)("h3",{id:"sample-usage-3"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core';\nimport { randomUUID } from 'node:crypto';\nimport { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware';\nimport { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';\n\nconst persistenceStore = new DynamoDBPersistenceLayer({\n tableName: 'idempotencyTableName',\n});\n\nconst createSubscriptionPayment = async (\n event\n) => {\n // ... create payment\n return {\n id: randomUUID(),\n productId: event.productId,\n };\n};\n\nexport const handler = middy(\n async (event, _context) => {\n try {\n const payment = await createSubscriptionPayment(event);\n\n return {\n paymentId: payment.id,\n message: 'success',\n statusCode: 200,\n };\n } catch (error) {\n throw new Error('Error creating payment');\n }\n }\n).use(\n makeHandlerIdempotent({\n persistenceStore,\n })\n);\n")),(0,r.kt)("h2",{id:"best-practices"},"Best practices"),(0,r.kt)("h3",{id:"using-multiple-utilities"},"Using multiple utilities"),(0,r.kt)("p",null,"You can use multiple Powertools utilities in your Lambda function by chaining the respective middlewares together. When doing so the Powertools team recommends that you place the Tracer middleware at the top of the middleware chain, followed by the Logger and any other middlewares."),(0,r.kt)("p",null,"This is because the Tracer middleware will create a new segment for each Lambda invocation, and the Logger might want to log the event that triggered the Lambda invocation. With this placement you will be able to have a segment that closely matches the actual duration of your Lambda function, and you will be able to see the event that triggered the function invocation before it's potentially modified by other middlewares."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"export const handler = middy(() => { /* ... */ })\n .use(captureLambdaHandler(tracer))\n .use(injectLambdaContext(logger, { logEvent: true }))\n .use(logMetrics(metrics, { captureColdStartMetric: true }));\n")),(0,r.kt)("h3",{id:"cleaning-up-on-early-returns"},"Cleaning up on early returns"),(0,r.kt)("p",null,"As discussed in the ",(0,r.kt)("a",{parentName:"p",href:"/docs/intro/early-interrupt"},"early return section"),", some middlewares might need to stop the whole execution flow and return a response immediately. In this case, if you are writing your own middleware that will work with the Powertools utilities, you must make sure to clean up the utilities before returning."),(0,r.kt)("p",null,"For example, if you are using the Tracer utility, you must make sure to call the ",(0,r.kt)("inlineCode",{parentName:"p"},"close")," method so that the Tracer can properly close the current segment and send it to X-Ray. Likewise, if you are using the Metrics utility, it's a good practice to call the ",(0,r.kt)("inlineCode",{parentName:"p"},"clearMetrics")," method so that the Metrics utility can emit the metrics that were stored in the buffer and avoid you losing any data."),(0,r.kt)("p",null,"Following the example described in the linked section, you can clean up all the utilities by doing the following:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import { cleanupMiddlewares } from '@aws-lambda-powertools/commons';\n\n// some function that calculates the cache id based on the current event\nconst calculateCacheId = (event) => {\n /* ... */\n}\nconst storage = {}\n\n// middleware\nconst cacheMiddleware = (options) => {\n let cacheKey\n\n const cacheMiddlewareBefore = async (request) => {\n cacheKey = options.calculateCacheId(request.event)\n if (options.storage.hasOwnProperty(cacheKey)) {\n // clean up the Powertools utilities before returning\n cleanupMiddlewares()\n\n // exits early and returns the value from the cache if it's already there\n return options.storage[cacheKey]\n }\n }\n\n const cacheMiddlewareAfter = async (request) => {\n // stores the calculated response in the cache\n options.storage[cacheKey] = request.response\n }\n\n return {\n before: cacheMiddlewareBefore,\n after: cacheMiddlewareAfter\n }\n}\n\n// sample usage\nconst handler = middy((event, context) => {\n /* ... */\n})\n.use(captureLambdaHandler(tracer))\n.use(injectLambdaContext(logger, { logEvent: true }))\n.use(logMetrics(metrics, { captureColdStartMetric: true }))\n.use(\n cacheMiddleware({\n calculateCacheId,\n storage\n })\n);\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/c1378803.d9244ce8.js b/assets/js/c1378803.d9244ce8.js deleted file mode 100644 index 2f7eaf749..000000000 --- a/assets/js/c1378803.d9244ce8.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7450],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>h});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var s=n.createContext({}),c=function(e){var t=n.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},u=function(e){var t=c(e.components);return n.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,o=e.originalType,s=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),d=c(a),m=r,h=d["".concat(s,".").concat(m)]||d[m]||p[m]||o;return a?n.createElement(h,l(l({ref:t},u),{},{components:a})):n.createElement(h,l({ref:t},u))}));function h(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=a.length,l=new Array(o);l[0]=m;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[d]="string"==typeof e?e:r,l[1]=i;for(var c=2;c{a.d(t,{Z:()=>l});var n=a(7294),r=a(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:a,className:l}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(o.tabItem,l),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>v});var n=a(7462),r=a(7294),o=a(6010),l=a(2466),i=a(6550),s=a(1980),c=a(7392),u=a(12);function d(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function p(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??d(a);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function m(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:a}=e;const n=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,s._X)(o),(0,r.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(n.location.search);t.set(o,e),n.replace({...n.location,search:t.toString()})}),[o,n])]}function g(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,o=p(e),[l,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[s,c]=h({queryString:a,groupId:n}),[d,g]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,o]=(0,u.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&o.set(e)}),[a,o])]}({groupId:n}),f=(()=>{const e=s??d;return m({value:e,tabValues:o})?e:null})();(0,r.useLayoutEffect)((()=>{f&&i(f)}),[f]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),g(e)}),[c,g,o]),tabValues:o}}var f=a(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:a,selectedValue:i,selectValue:s,tabValues:c}=e;const u=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),p=e=>{const t=e.currentTarget,a=u.indexOf(t),n=c[a].value;n!==i&&(d(t),s(n))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const a=u.indexOf(e.currentTarget)+1;t=u[a]??u[0];break}case"ArrowLeft":{const a=u.indexOf(e.currentTarget)-1;t=u[a]??u[u.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":a},t)},c.map((e=>{let{value:t,label:a,attributes:l}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>u.push(e),onKeyDown:m,onClick:p},l,{className:(0,o.Z)("tabs__item",b.tabItem,l?.className,{"tabs__item--active":i===t})}),a??t)})))}function y(e){let{lazy:t,children:a,selectedValue:n}=e;const o=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function w(e){const t=g(e);return r.createElement("div",{className:(0,o.Z)("tabs-container",b.tabList)},r.createElement(k,(0,n.Z)({},e,t)),r.createElement(y,(0,n.Z)({},e,t)))}function v(e){const t=(0,f.Z)();return r.createElement(w,(0,n.Z)({key:String(t)},e))}},9310:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>u,contentTitle:()=>s,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=a(7462),r=(a(7294),a(3905)),o=a(4866),l=a(5162);const i={title:"Powertools for AWS Lambda"},s=void 0,c={unversionedId:"integrations/lambda-powertools",id:"integrations/lambda-powertools",title:"Powertools for AWS Lambda",description:"Powertools for AWS is a developer toolkit to implement Serverless best practices and increase developer velocity.",source:"@site/docs/integrations/lambda-powertools.md",sourceDirName:"integrations",slug:"/integrations/lambda-powertools",permalink:"/docs/integrations/lambda-powertools",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/lambda-powertools.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Powertools for AWS Lambda"},sidebar:"tutorialSidebar",previous:{title:"Apollo Server",permalink:"/docs/integrations/apollo-server"},next:{title:"Pino",permalink:"/docs/integrations/pino"}},u={},d=[{value:"Intro",id:"intro",level:2},{value:"Logger",id:"logger",level:2},{value:"Install",id:"install",level:3},{value:"Options",id:"options",level:3},{value:"Sample usage",id:"sample-usage",level:3},{value:"Tracer",id:"tracer",level:2},{value:"Install",id:"install-1",level:3},{value:"Options",id:"options-1",level:3},{value:"Sample usage",id:"sample-usage-1",level:3},{value:"Metrics",id:"metrics",level:2},{value:"Install",id:"install-2",level:3},{value:"Options",id:"options-2",level:3},{value:"Sample usage",id:"sample-usage-2",level:3},{value:"Best practices",id:"best-practices",level:2},{value:"Using multiple utilities",id:"using-multiple-utilities",level:3},{value:"Cleaning up on early returns",id:"cleaning-up-on-early-returns",level:3}],p={toc:d},m="wrapper";function h(e){let{components:t,...a}=e;return(0,r.kt)(m,(0,n.Z)({},p,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"Powertools for AWS is a developer toolkit to implement Serverless ",(0,r.kt)("a",{parentName:"p",href:"https://s12d.com/middy-intro"},"best practices and increase developer velocity"),"."),(0,r.kt)("p",null,"You can use Powertools for AWS in both TypeScript and JavaScript code bases."),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"Powertools officially supports ",(0,r.kt)("inlineCode",{parentName:"p"},"@middy/core")," v3.x only. In most cases when using Node.js 16 or higher you can use Powertools with ",(0,r.kt)("inlineCode",{parentName:"p"},"@middy/core")," v4.x, however support is provided on a best-effort basis and we recommend using ",(0,r.kt)("inlineCode",{parentName:"p"},"@middy/core")," v3.x.")),(0,r.kt)("h2",{id:"intro"},"Intro"),(0,r.kt)("p",null,"Powertools is a collection of utilities that can be used independently or together to help you build production-ready serverless applications. Currently, Powertools provides the following utilities that are compatible with Middy:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://s12d.com/middy-logger"},(0,r.kt)("strong",{parentName:"a"},"Logger"))," - Structured logging made easier with a middleware to capture key fields from the Lambda context, cold starts, and more. Compatible with Amazon CloudWatch, Datadog, and more."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://s12d.com/middy-tracer"},(0,r.kt)("strong",{parentName:"a"},"Tracer"))," - An opinionated wrapper around AWS X-Ray SDK for Node.js with a middleware to automatically capture traces for function invocations, HTTP requests, and AWS SDK calls, and more."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://s12d.com/middy-metrics"},(0,r.kt)("strong",{parentName:"a"},"Metrics"))," - Create Amazon CloudWatch custom metrics asynchronously with a middleware that takes care of capturing cold starts, and flushes metrics to CloudWatch in ",(0,r.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html"},"EMF-formatted")," batches.")),(0,r.kt)("h2",{id:"logger"},"Logger"),(0,r.kt)("p",null,"Key features:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Capturing key fields from the Lambda context, cold starts, and structure logging output as JSON."),(0,r.kt)("li",{parentName:"ul"},"Logging Lambda invocation events when instructed (disabled by default)."),(0,r.kt)("li",{parentName:"ul"},"Printing all the logs only for a percentage of invocations via log sampling (disabled by default)."),(0,r.kt)("li",{parentName:"ul"},"Appending additional keys to structured logs at any point in time."),(0,r.kt)("li",{parentName:"ul"},"Providing a custom log formatter (Bring Your Own Formatter) to output logs in a structure compatible with your organization\u2019s Logging RFC.")),(0,r.kt)("h3",{id:"install"},"Install"),(0,r.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @aws-lambda-powertools/logger\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @aws-lambda-powertools/logger\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @aws-lambda-powertools/logger\n")))),(0,r.kt)("h3",{id:"options"},"Options"),(0,r.kt)("p",null,"Class constructor accepts the following options, which are all optional:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"logLevel")," (string|LogLevel): Log level to use. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"INFO"),", but you can use any of the following values: ",(0,r.kt)("inlineCode",{parentName:"li"},"SILENT"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"DEBUG"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"INFO"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"WARN"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"ERROR"),", ",(0,r.kt)("inlineCode",{parentName:"li"},"CRITICAL"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"serviceName")," (string): Service name to use that will be used in all log statements. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"service_undefined"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"sampleRateValue")," (number): number between ",(0,r.kt)("inlineCode",{parentName:"li"},"0.0")," and ",(0,r.kt)("inlineCode",{parentName:"li"},"1")," to determine the sample rate for debug logging. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"0")," (no debub logging).")),(0,r.kt)("p",null,"Middleware accepts the following options:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"logger")," (Logger) (required): An instance of the Logger class."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"option")," (object) (optional): An object with the following keys:",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"logEvent")," (boolean) (optional): Whether to log the Lambda invocation event. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"clearState")," (boolean) (optional): Whether to clear the logger state after each invocation. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),".")))),(0,r.kt)("h3",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core';\nimport { Logger, injectLambdaContext } from '@aws-lambda-powertools/logger';\n\nconst logger = new Logger({ service: 'serverlessAirline' });\n\nconst lambdaHandler = async (_event, _context) => {\n logger.info('This is an INFO log with some context', {\n foo: {\n bar: 'baz'\n }\n });\n};\n\nexport const handler = middy(lambdaHandler)\n .use(injectLambdaContext(logger));\n")),(0,r.kt)("p",null,"The above code will output the following log:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "cold_start": true,\n "function_arn": "arn:aws:lambda:eu-west-1:123456789012:function:shopping-cart-api-lambda-prod-eu-west-1",\n "function_memory_size": 128,\n "function_request_id": "c6af9ac6-7b61-11e6-9a41-93e812345678",\n "function_name": "shopping-cart-api-lambda-prod-eu-west-1",\n "level": "INFO",\n "message": "This is an INFO log with some context",\n "foo": {\n "bar": "baz"\n },\n "service": "serverlessAirline",\n "timestamp": "2021-12-12T21:21:08.921Z",\n "xray_trace_id": "abcdef123456abcdef123456abcdef123456"\n}\n')),(0,r.kt)("p",null,"As you can see, the log entry includes several fields that are automatically captured by the Logger utility, and that can help you better understand the context of the log entry. For example, the ",(0,r.kt)("inlineCode",{parentName:"p"},"cold_start")," field indicates whether the Lambda function was cold started or not, and the ",(0,r.kt)("inlineCode",{parentName:"p"},"xray_trace_id")," field contains the AWS X-Ray trace ID for the Lambda invocation. This is useful when you're troubleshooting a problem and want to correlate the logs with the traces."),(0,r.kt)("p",null,"The Logger utility also allows you to append arbitary keys to the log entry at both ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#appending-persistent-additional-log-keys-and-values"},"the global level"),", at the ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#clearing-all-state"},"invocation level"),", and at the ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#appending-additional-data-to-a-single-log-item"},"single log level"),". For example, there might be some keys that you want to include in all log entries, such as the ",(0,r.kt)("inlineCode",{parentName:"p"},"environment")," key to differentiate between the ",(0,r.kt)("inlineCode",{parentName:"p"},"prod")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"dev")," environments, or in other cases you might want to include some keys only for a specific log entry, such as the ",(0,r.kt)("inlineCode",{parentName:"p"},"customer_id")," key to identify the customer that triggered the Lambda invocation."),(0,r.kt)("p",null,"Additionally, you can also configure Logger to ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#log-incoming-event"},"log the Lambda invocation event"),", which can be useful when you're troubleshooting a problem and want to see the event that triggered the Lambda invocation. Finally, Logger allows you to ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#custom-log-formatter-bring-your-own-formatter"},"define a custom log formatter")," to output logs in a different JSON structure from the default one. This is useful when you want to output logs in a structure that is compatible with your organization's requirements."),(0,r.kt)("h2",{id:"tracer"},"Tracer"),(0,r.kt)("p",null,"Key features:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Auto-capturing cold start and service name as annotations, and responses or full exceptions as metadata."),(0,r.kt)("li",{parentName:"ul"},"Automatically tracing HTTP(S) clients and generating segments for each request."),(0,r.kt)("li",{parentName:"ul"},"Supporting tracing functions via decorators, middleware, and manual instrumentation."),(0,r.kt)("li",{parentName:"ul"},"Supporting tracing AWS SDK v2 and v3 via AWS X-Ray SDK for Node.js."),(0,r.kt)("li",{parentName:"ul"},"Auto-disable tracing when not running in the Lambda environment.")),(0,r.kt)("h3",{id:"install-1"},"Install"),(0,r.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @aws-lambda-powertools/tracer\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @aws-lambda-powertools/tracer\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @aws-lambda-powertools/tracer\n")))),(0,r.kt)("h3",{id:"options-1"},"Options"),(0,r.kt)("p",null,"Class constructor accepts the following options, which are all optional:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"serviceName")," (string): Service name to use that will be used in all log statements. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"service_undefined"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"enabled")," (boolean): Whether to enable tracing. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"captureHTTPsRequests")," (boolean): Whether to capture outgoing HTTP(S) requests as segment metadata. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),".")),(0,r.kt)("p",null,"Middleware accepts the following options:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"tracer")," (Tracer) (required): An instance of the Tracer class."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"option")," (object) (optional): An object with the following keys:",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"captureResponse")," (boolean) (optional): Whether to capture the Lambda invocation result as segment metadata. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),".")))),(0,r.kt)("h3",{id:"sample-usage-1"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core';\nimport { Tracer, captureLambdaHandler } from '@aws-lambda-powertools/tracer';\nimport { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';\n\nconst tracer = new Tracer({\n serviceName: 'serverlessAirline'\n});\n\nconst client = tracer.captureAWSv3Client(\n new SecretsManagerClient({})\n);\n\nconst lambdaHandler = async (_event, _context) => {\n tracer.putAnnotation('successfulBooking', true);\n};\n\nexport const handler = middy(lambdaHandler)\n .use(captureLambdaHandler(tracer));\n")),(0,r.kt)("p",null,"The above code instructs the Tracer utility to create a custom segment named ",(0,r.kt)("inlineCode",{parentName:"p"},"## index.handler")," and to add an annotation to it with the key ",(0,r.kt)("inlineCode",{parentName:"p"},"successfulBooking")," and the value ",(0,r.kt)("inlineCode",{parentName:"p"},"true"),". The segment name is automatically generated based on the handler name, and the ",(0,r.kt)("inlineCode",{parentName:"p"},"##")," prefix is used to indicate that this is a custom segment. The Tracer utility also automatically captures the cold start and service name as annotations, and the Lambda invocation result or any error thrown ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#annotations-metadata"},"as metadata"),". The segment data will be automatically sent to AWS X-Ray when the Lambda function completes its execution."),(0,r.kt)("p",null,"Tracer also automatically ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#tracing-http-requests"},"captures and traces any outgoing HTTP(S) requests")," made by the Lambda function. For example, if your function makes a request to a custom API, the Tracer utility will automatically create a segment for that request which will appear in your trace data and service map. Additionally, it will also ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#patching-aws-sdk-clients"},"capture any AWS SDK calls")," made by the function, and do the same for them."),(0,r.kt)("h2",{id:"metrics"},"Metrics"),(0,r.kt)("p",null,"Key features:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Aggregating up to 100 metrics using a single ",(0,r.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html"},"CloudWatch EMF")," object."),(0,r.kt)("li",{parentName:"ul"},"Validating your metrics against common metric definitions mistakes (for example, metric unit, values, max dimensions, max metrics)."),(0,r.kt)("li",{parentName:"ul"},"Metrics are created asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency."),(0,r.kt)("li",{parentName:"ul"},"Creating a one-off metric with different dimensions.")),(0,r.kt)("p",null,"If you're new to Amazon CloudWatch, there are a few terms like ",(0,r.kt)("inlineCode",{parentName:"p"},"Namespace"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"Dimensions"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"Unit"),", etc, that you must be aware of before you start using the Metrics utility. To learn more about these terms, see the ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#terminologies"},"documentation on PowerTools Metrics"),"."),(0,r.kt)("h3",{id:"install-2"},"Install"),(0,r.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @aws-lambda-powertools/metrics\n"))),(0,r.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @aws-lambda-powertools/metrics\n"))),(0,r.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @aws-lambda-powertools/metrics\n")))),(0,r.kt)("h3",{id:"options-2"},"Options"),(0,r.kt)("p",null,"Class constructor accepts the following options, which are all optional:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"serviceName")," (string): Service name to use that will be used in all log statements. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"service_undefined"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"defaultNamespace")," (string): Default namespace to use for all metrics. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"default_namespace"),".")),(0,r.kt)("p",null,"Middleware accepts the following options:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"metrics")," (Metric) (required): An instance of the Metrics class."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"option")," (object) (optional): An object with the following keys:",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"throwOnEmptyMetrics")," (boolean) (optional): Whether to throw an error if no metrics were added. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"captureColdStartMetric")," (boolean) (optional): Whether to capture the cold start metric. Defaults to ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),".")))),(0,r.kt)("h3",{id:"sample-usage-2"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core';\nimport { Metrics, MetricUnits, logMetrics } from '@aws-lambda-powertools/metrics';\n\nconst metrics = new Metrics({\n namespace: 'serverlessAirline',\n serviceName: 'orders'\n});\n\nconst lambdaHandler = async (_event: unknown, _context: unknown): Promise => {\n metrics.addMetric('successfulBooking', MetricUnits.Count, 1);\n};\n\nexport const handler = middy(lambdaHandler)\n .use(logMetrics(metrics));\n")),(0,r.kt)("p",null,"The above code will output a CloudWatch EMF object similar to the following:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "successfulBooking": 1.0,\n "_aws": {\n "Timestamp": 1592234975665,\n "CloudWatchMetrics": [{\n "Namespace": "successfulBooking",\n "Dimensions": [\n [ "service" ]\n ],\n "Metrics": [{\n "Name": "successfulBooking",\n "Unit": "Count"\n }]\n }],\n "service": "orders"\n }\n}\n')),(0,r.kt)("p",null,"This EMF object will be sent to CloudWatch asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency."),(0,r.kt)("p",null,"The Metrics utility supports ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-high-resolution-metrics"},"high-resolution metrics")," as well as ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-multi-value-metrics"},"multi-value metrics"),". It also allows you to add ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-default-dimensions"},"default dimensions")," that are used in all the metrics emitted by your application or ",(0,r.kt)("a",{parentName:"p",href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#single-metric-with-different-dimensions"},"create a one-off metric")," with different dimensions."),(0,r.kt)("h2",{id:"best-practices"},"Best practices"),(0,r.kt)("h3",{id:"using-multiple-utilities"},"Using multiple utilities"),(0,r.kt)("p",null,"You can use multiple Powertools utilities in your Lambda function by chaining the respective middlewares together. When doing so the Powertools team recommends that you place the Tracer middleware at the top of the middleware chain, followed by the Logger and any other middlewares."),(0,r.kt)("p",null,"This is because the Tracer middleware will create a new segment for each Lambda invocation, and the Logger might want to log the event that triggered the Lambda invocation. With this placement you will be able to have a segment that closely matches the actual duration of your Lambda function, and you will be able to see the event that triggered the function invocation before it's potentially modified by other middlewares."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"export const handler = middy(() => { /* ... */ })\n .use(captureLambdaHandler(tracer))\n .use(injectLambdaContext(logger, { logEvent: true }))\n .use(logMetrics(metrics, { captureColdStartMetric: true }));\n")),(0,r.kt)("h3",{id:"cleaning-up-on-early-returns"},"Cleaning up on early returns"),(0,r.kt)("p",null,"As discussed in the ",(0,r.kt)("a",{parentName:"p",href:"/docs/intro/early-interrupt"},"early return section"),", some middlewares might need to stop the whole execution flow and return a response immediately. In this case, if you are writing your own middleware that will work with the Powertools utilities, you must make sure to clean up the utilities before returning."),(0,r.kt)("p",null,"For example, if you are using the Tracer utility, you must make sure to call the ",(0,r.kt)("inlineCode",{parentName:"p"},"close")," method so that the Tracer can properly close the current segment and send it to X-Ray. Likewise, if you are using the Metrics utility, it's a good practice to call the ",(0,r.kt)("inlineCode",{parentName:"p"},"clearMetrics")," method so that the Metrics utility can emit the metrics that were stored in the buffer and avoid you losing any data."),(0,r.kt)("p",null,"Following the example described in the linked section, you can clean up all the utilities by doing the following:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import { cleanupMiddlewares } from '@aws-lambda-powertools/commons';\n\n// some function that calculates the cache id based on the current event\nconst calculateCacheId = (event) => {\n /* ... */\n}\nconst storage = {}\n\n// middleware\nconst cacheMiddleware = (options) => {\n let cacheKey\n\n const cacheMiddlewareBefore = async (request) => {\n cacheKey = options.calculateCacheId(request.event)\n if (options.storage.hasOwnProperty(cacheKey)) {\n // clean up the Powertools utilities before returning\n cleanupMiddlewares()\n\n // exits early and returns the value from the cache if it's already there\n return options.storage[cacheKey]\n }\n }\n\n const cacheMiddlewareAfter = async (request) => {\n // stores the calculated response in the cache\n options.storage[cacheKey] = request.response\n }\n\n return {\n before: cacheMiddlewareBefore,\n after: cacheMiddlewareAfter\n }\n}\n\n// sample usage\nconst handler = middy((event, context) => {\n /* ... */\n})\n.use(captureLambdaHandler(tracer))\n.use(injectLambdaContext(logger, { logEvent: true }))\n.use(logMetrics(metrics, { captureColdStartMetric: true }))\n.use(\n cacheMiddleware({\n calculateCacheId,\n storage\n })\n);\n")))}h.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/c21432a2.cf09302b.js b/assets/js/c21432a2.124b7e43.js similarity index 98% rename from assets/js/c21432a2.cf09302b.js rename to assets/js/c21432a2.124b7e43.js index 21db2f741..6ec6e89e3 100644 --- a/assets/js/c21432a2.cf09302b.js +++ b/assets/js/c21432a2.124b7e43.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1570],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>y});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),d=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},m=function(e){var t=d(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,m=s(e,["components","mdxType","originalType","parentName"]),p=d(n),u=a,y=p["".concat(l,".").concat(u)]||p[u]||c[u]||o;return n?r.createElement(y,i(i({ref:t},m),{},{components:n})):r.createElement(y,i({ref:t},m))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:a,i[1]=s;for(var d=2;d{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>s,toc:()=>d});var r=n(7462),a=(n(7294),n(3905));const o={title:"Streamify Response",position:5},i=void 0,s={unversionedId:"intro/streamify-response",id:"intro/streamify-response",title:"Streamify Response",description:"Middy also supports streamed responses.",source:"@site/docs/intro/06-streamify-response.md",sourceDirName:"intro",slug:"/intro/streamify-response",permalink:"/docs/intro/streamify-response",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-streamify-response.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:6,frontMatter:{title:"Streamify Response",position:5},sidebar:"tutorialSidebar",previous:{title:"Handling Errors",permalink:"/docs/intro/handling-errors"},next:{title:"Testing",permalink:"/docs/intro/testing"}},l={},d=[{value:"Lambda Function URL Example",id:"lambda-function-url-example",level:2},{value:"Lambda InvokeWithResponseStream Example",id:"lambda-invokewithresponsestream-example",level:2},{value:"Requesting Lambda",id:"requesting-lambda",level:3}],m={toc:d},p="wrapper";function c(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Middy also supports streamed responses."),(0,a.kt)("blockquote",null,(0,a.kt)("p",{parentName:"blockquote"},"You can progressively stream response payloads through Lambda function URLs, including as an Amazon CloudFront origin, along with using the AWS SDK or using Lambda\u2019s invoke API. You can not use Amazon API Gateway and Application Load Balancer to progressively stream response payloads, but you can use the functionality to return larger payloads. (",(0,a.kt)("a",{parentName:"p",href:"https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/"},"https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/"),")")),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},"Set ",(0,a.kt)("inlineCode",{parentName:"li"},"streamifyResponse: true")," into middy options"),(0,a.kt)("li",{parentName:"ol"},"a. For HTTP Events return using an HTTP event response with the body as a string or ReadableStream.\nb. For InvokeWithResponseStream Events return a response with a string or ReadableStream.")),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"API Gateway: If you're getting a ",(0,a.kt)("inlineCode",{parentName:"li"},"500")," status code. Be sure to set your integration to ",(0,a.kt)("inlineCode",{parentName:"li"},"HTTP_PROXY")," over ",(0,a.kt)("inlineCode",{parentName:"li"},"LAMBDA_PROXY")," and enable Function URL on the lambda."),(0,a.kt)("li",{parentName:"ul"},"Function URLs: If receiving no content and non-200 status code are being converted to ",(0,a.kt)("inlineCode",{parentName:"li"},"200"),". Be sure to set ",(0,a.kt)("inlineCode",{parentName:"li"},"Invoke Mode")," to ",(0,a.kt)("inlineCode",{parentName:"li"},"RESPONSE_STREAM")," over ",(0,a.kt)("inlineCode",{parentName:"li"},"BUFFERED"),".")),(0,a.kt)("h2",{id:"lambda-function-url-example"},"Lambda Function URL Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { createReadableStream } from '@datastream/core'\n\nexport const handler = middy({ streamifyResponse: true }).handler(\n (event, context) => {\n return {\n statusCode: 200,\n headers: {\n 'Content-Type': 'text/csv'\n },\n body: createReadableStream('...') // or string\n }\n }\n)\n")),(0,a.kt)("h2",{id:"lambda-invokewithresponsestream-example"},"Lambda InvokeWithResponseStream Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { createReadableStream } from '@datastream/core'\n\nexport const handler = middy({ streamifyResponse: true }).handler(\n (event, context) => {\n return createReadableStream('...') // or string\n }\n)\n")),(0,a.kt)("h3",{id:"requesting-lambda"},"Requesting Lambda"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import {\n LambdaClient,\n InvokeWithResponseStreamCommand\n} from '@aws-sdk/client-lambda'\n\nconst lambda = new LambdaClient()\n\nconst res = await lambda.send(\n new InvokeWithResponseStreamCommand({\n FunctionName: 'function-name',\n Payload: JSON.stringify({...})\n })\n)\n\nconst decoder = new TextDecoder('utf-8')\nlet body = ''\nfor await (const chunk of res.EventStream) {\n if (chunk?.PayloadChunk?.Payload) {\n body += decoder.decode(Buffer.from(chunk.PayloadChunk.Payload))\n }\n}\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1570],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>y});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),d=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},m=function(e){var t=d(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,m=s(e,["components","mdxType","originalType","parentName"]),p=d(n),u=a,y=p["".concat(l,".").concat(u)]||p[u]||c[u]||o;return n?r.createElement(y,i(i({ref:t},m),{},{components:n})):r.createElement(y,i({ref:t},m))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:a,i[1]=s;for(var d=2;d{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>s,toc:()=>d});var r=n(7462),a=(n(7294),n(3905));const o={title:"Streamify Response",position:5},i=void 0,s={unversionedId:"intro/streamify-response",id:"intro/streamify-response",title:"Streamify Response",description:"Middy also supports streamed responses.",source:"@site/docs/intro/06-streamify-response.md",sourceDirName:"intro",slug:"/intro/streamify-response",permalink:"/docs/intro/streamify-response",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-streamify-response.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:6,frontMatter:{title:"Streamify Response",position:5},sidebar:"tutorialSidebar",previous:{title:"Handling Errors",permalink:"/docs/intro/handling-errors"},next:{title:"Testing",permalink:"/docs/intro/testing"}},l={},d=[{value:"Lambda Function URL Example",id:"lambda-function-url-example",level:2},{value:"Lambda InvokeWithResponseStream Example",id:"lambda-invokewithresponsestream-example",level:2},{value:"Requesting Lambda",id:"requesting-lambda",level:3}],m={toc:d},p="wrapper";function c(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Middy also supports streamed responses."),(0,a.kt)("blockquote",null,(0,a.kt)("p",{parentName:"blockquote"},"You can progressively stream response payloads through Lambda function URLs, including as an Amazon CloudFront origin, along with using the AWS SDK or using Lambda\u2019s invoke API. You can not use Amazon API Gateway and Application Load Balancer to progressively stream response payloads, but you can use the functionality to return larger payloads. (",(0,a.kt)("a",{parentName:"p",href:"https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/"},"https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/"),")")),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},"Set ",(0,a.kt)("inlineCode",{parentName:"li"},"streamifyResponse: true")," into middy options"),(0,a.kt)("li",{parentName:"ol"},"a. For HTTP Events return using an HTTP event response with the body as a string or ReadableStream.\nb. For InvokeWithResponseStream Events return a response with a string or ReadableStream.")),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"API Gateway: If you're getting a ",(0,a.kt)("inlineCode",{parentName:"li"},"500")," status code. Be sure to set your integration to ",(0,a.kt)("inlineCode",{parentName:"li"},"HTTP_PROXY")," over ",(0,a.kt)("inlineCode",{parentName:"li"},"LAMBDA_PROXY")," and enable Function URL on the lambda."),(0,a.kt)("li",{parentName:"ul"},"Function URLs: If receiving no content and non-200 status code are being converted to ",(0,a.kt)("inlineCode",{parentName:"li"},"200"),". Be sure to set ",(0,a.kt)("inlineCode",{parentName:"li"},"Invoke Mode")," to ",(0,a.kt)("inlineCode",{parentName:"li"},"RESPONSE_STREAM")," over ",(0,a.kt)("inlineCode",{parentName:"li"},"BUFFERED"),".")),(0,a.kt)("h2",{id:"lambda-function-url-example"},"Lambda Function URL Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { createReadableStream } from '@datastream/core'\n\nexport const handler = middy({ streamifyResponse: true }).handler(\n (event, context) => {\n return {\n statusCode: 200,\n headers: {\n 'Content-Type': 'text/csv'\n },\n body: createReadableStream('...') // or string\n }\n }\n)\n")),(0,a.kt)("h2",{id:"lambda-invokewithresponsestream-example"},"Lambda InvokeWithResponseStream Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { createReadableStream } from '@datastream/core'\n\nexport const handler = middy({ streamifyResponse: true }).handler(\n (event, context) => {\n return createReadableStream('...') // or string\n }\n)\n")),(0,a.kt)("h3",{id:"requesting-lambda"},"Requesting Lambda"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import {\n LambdaClient,\n InvokeWithResponseStreamCommand\n} from '@aws-sdk/client-lambda'\n\nconst lambda = new LambdaClient()\n\nconst res = await lambda.send(\n new InvokeWithResponseStreamCommand({\n FunctionName: 'function-name',\n Payload: JSON.stringify({...})\n })\n)\n\nconst decoder = new TextDecoder('utf-8')\nlet body = ''\nfor await (const chunk of res.EventStream) {\n if (chunk?.PayloadChunk?.Payload) {\n body += decoder.decode(Buffer.from(chunk.PayloadChunk.Payload))\n }\n}\n")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/c2371ba7.013ad864.js b/assets/js/c2371ba7.beb8837f.js similarity index 99% rename from assets/js/c2371ba7.013ad864.js rename to assets/js/c2371ba7.beb8837f.js index 472750de8..b68fd783c 100644 --- a/assets/js/c2371ba7.013ad864.js +++ b/assets/js/c2371ba7.beb8837f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7724],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function l(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),u=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,i=e.originalType,s=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),d=u(n),m=a,f=d["".concat(s,".").concat(m)]||d[m]||c[m]||i;return n?r.createElement(f,l(l({ref:t},p),{},{components:n})):r.createElement(f,l({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=n.length,l=new Array(i);l[0]=m;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[d]="string"==typeof e?e:a,l[1]=o;for(var u=2;u{n.d(t,{Z:()=>l});var r=n(7294),a=n(6010);const i={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:n,className:l}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(i.tabItem,l),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7462),a=n(7294),i=n(6010),l=n(2466),o=n(6550),s=n(1980),u=n(7392),p=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function c(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.k6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(i),(0,a.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(r.location.search);t.set(i,e),r.replace({...r.location,search:t.toString()})}),[i,r])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,i=c(e),[l,o]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:i}))),[s,u]=f({queryString:n,groupId:r}),[d,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,i]=(0,p.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:r}),b=(()=>{const e=s??d;return m({value:e,tabValues:i})?e:null})();(0,a.useLayoutEffect)((()=>{b&&o(b)}),[b]);return{selectedValue:l,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),h(e)}),[u,h,i]),tabValues:i}}var b=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:n,selectedValue:o,selectValue:s,tabValues:u}=e;const p=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),c=e=>{const t=e.currentTarget,n=p.indexOf(t),r=u[n].value;r!==o&&(d(t),s(r))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=p.indexOf(e.currentTarget)+1;t=p[n]??p[0];break}case"ArrowLeft":{const n=p.indexOf(e.currentTarget)-1;t=p[n]??p[p.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:l}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:c},l,{className:(0,i.Z)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":o===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},i.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function k(e){const t=h(e);return a.createElement("div",{className:(0,i.Z)("tabs-container",y.tabList)},a.createElement(g,(0,r.Z)({},e,t)),a.createElement(v,(0,r.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return a.createElement(k,(0,r.Z)({key:String(t)},e))}},6933:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),i=n(4866),l=n(5162);const o={title:"http-response-serializer"},s=void 0,u={unversionedId:"middlewares/http-response-serializer",id:"middlewares/http-response-serializer",title:"http-response-serializer",description:"The Http Serializer middleware lets you define serialization mechanisms based on the current content negotiation.",source:"@site/docs/middlewares/http-response-serializer.md",sourceDirName:"middlewares",slug:"/middlewares/http-response-serializer",permalink:"/docs/middlewares/http-response-serializer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-response-serializer.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-response-serializer"},sidebar:"tutorialSidebar",previous:{title:"http-partial-response",permalink:"/docs/middlewares/http-partial-response"},next:{title:"http-security-headers",permalink:"/docs/middlewares/http-security-headers"}},p={},d=[{value:"Install",id:"install",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Serializer Functions",id:"serializer-functions",level:2},{value:"Content Type Negotiation",id:"content-type-negotiation",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"The Http Serializer middleware lets you define serialization mechanisms based on the current content negotiation."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(i.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-response-serializer\n"))),(0,a.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-response-serializer\n"))),(0,a.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-response-serializer\n")))),(0,a.kt)("h2",{id:"configuration"},"Configuration"),(0,a.kt)("p",null,"The middleware is configured by defining some ",(0,a.kt)("inlineCode",{parentName:"p"},"serializers"),"."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"{\n serializers: [\n {\n regex: /^application\\/xml$/,\n serializer: ({ body }) => `${body}`,\n },\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n },\n {\n regex: /^text\\/plain$/,\n serializer: ({ body }) => body\n }\n ],\n default: 'application/json'\n}\n")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"default")," (optional) option is used if the request and handler don't specify what type is wanted."),(0,a.kt)("h2",{id:"serializer-functions"},"Serializer Functions"),(0,a.kt)("p",null,"When a matching serializer is found, the ",(0,a.kt)("inlineCode",{parentName:"p"},"Content-Type")," header is set and the serializer function is run."),(0,a.kt)("p",null,"The function is passed the entire ",(0,a.kt)("inlineCode",{parentName:"p"},"response")," object, and should return either a string or an object."),(0,a.kt)("p",null,"If a string is returned, the ",(0,a.kt)("inlineCode",{parentName:"p"},"body")," attribute of the response is updated."),(0,a.kt)("p",null,"If an object with a ",(0,a.kt)("inlineCode",{parentName:"p"},"body")," attribute is returned, the entire response object is replaced. This is useful if you want to manipulate headers or add additional attributes in the Lambda response."),(0,a.kt)("h2",{id:"content-type-negotiation"},"Content Type Negotiation"),(0,a.kt)("p",null,"The header is not the only way the middleware decides which serializer to execute."),(0,a.kt)("p",null,"The content type is determined in the following order:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"event.requiredContentType")," -- allows the handler to override everything else"),(0,a.kt)("li",{parentName:"ul"},"The ",(0,a.kt)("inlineCode",{parentName:"li"},"Accept")," header via ",(0,a.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/accept"},"accept")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"event.preferredContentType")," -- allows the handler to override the default, but lets the request ask first"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"default")," middleware configuration")),(0,a.kt)("p",null,"All options allow for multiple types to be specified in your order of preference, and the first matching serializer will be executed.\nWhen planning to use ",(0,a.kt)("inlineCode",{parentName:"p"},"Accept"),", an external input, it is recommended to validate that it is an expected value."),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpResponseSerializer from '@middy/http-response-serializer'\n\nconst handler = middy((event, context) => {\n const body = 'Hello World'\n\n return {\n statusCode: 200,\n body\n }\n})\n\nhandler\n .use(httpResponseSerializer({\n serializers: [\n {\n regex: /^application\\/xml$/,\n serializer: ({ body }) => `${body}`,\n },\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n },\n {\n regex: /^text\\/plain$/,\n serializer: ({ body }) => body\n }\n ],\n defaultContentType: 'application/json'\n }))\n\nconst event = {\n headers: {\n 'Accept': 'application/xml;q=0.9, text/x-dvi; q=0.8, text/x-c'\n }\n}\n\nhandler(event, {}, (_, response) => {\n t.is(response.body,'Hello World')\n})\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7724],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function l(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),u=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,i=e.originalType,s=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),d=u(n),m=a,f=d["".concat(s,".").concat(m)]||d[m]||c[m]||i;return n?r.createElement(f,l(l({ref:t},p),{},{components:n})):r.createElement(f,l({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=n.length,l=new Array(i);l[0]=m;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[d]="string"==typeof e?e:a,l[1]=o;for(var u=2;u{n.d(t,{Z:()=>l});var r=n(7294),a=n(6010);const i={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:n,className:l}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(i.tabItem,l),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7462),a=n(7294),i=n(6010),l=n(2466),o=n(6550),s=n(1980),u=n(7392),p=n(12);function d(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function c(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.k6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(i),(0,a.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(r.location.search);t.set(i,e),r.replace({...r.location,search:t.toString()})}),[i,r])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,i=c(e),[l,o]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:i}))),[s,u]=f({queryString:n,groupId:r}),[d,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,i]=(0,p.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:r}),b=(()=>{const e=s??d;return m({value:e,tabValues:i})?e:null})();(0,a.useLayoutEffect)((()=>{b&&o(b)}),[b]);return{selectedValue:l,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),h(e)}),[u,h,i]),tabValues:i}}var b=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:n,selectedValue:o,selectValue:s,tabValues:u}=e;const p=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),c=e=>{const t=e.currentTarget,n=p.indexOf(t),r=u[n].value;r!==o&&(d(t),s(r))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=p.indexOf(e.currentTarget)+1;t=p[n]??p[0];break}case"ArrowLeft":{const n=p.indexOf(e.currentTarget)-1;t=p[n]??p[p.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.Z)("tabs",{"tabs--block":n},t)},u.map((e=>{let{value:t,label:n,attributes:l}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:c},l,{className:(0,i.Z)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":o===t})}),n??t)})))}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},i.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function k(e){const t=h(e);return a.createElement("div",{className:(0,i.Z)("tabs-container",y.tabList)},a.createElement(g,(0,r.Z)({},e,t)),a.createElement(v,(0,r.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return a.createElement(k,(0,r.Z)({key:String(t)},e))}},6933:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var r=n(7462),a=(n(7294),n(3905)),i=n(4866),l=n(5162);const o={title:"http-response-serializer"},s=void 0,u={unversionedId:"middlewares/http-response-serializer",id:"middlewares/http-response-serializer",title:"http-response-serializer",description:"The Http Serializer middleware lets you define serialization mechanisms based on the current content negotiation.",source:"@site/docs/middlewares/http-response-serializer.md",sourceDirName:"middlewares",slug:"/middlewares/http-response-serializer",permalink:"/docs/middlewares/http-response-serializer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-response-serializer.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-response-serializer"},sidebar:"tutorialSidebar",previous:{title:"http-partial-response",permalink:"/docs/middlewares/http-partial-response"},next:{title:"http-security-headers",permalink:"/docs/middlewares/http-security-headers"}},p={},d=[{value:"Install",id:"install",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Serializer Functions",id:"serializer-functions",level:2},{value:"Content Type Negotiation",id:"content-type-negotiation",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:d},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"The Http Serializer middleware lets you define serialization mechanisms based on the current content negotiation."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(i.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-response-serializer\n"))),(0,a.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-response-serializer\n"))),(0,a.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-response-serializer\n")))),(0,a.kt)("h2",{id:"configuration"},"Configuration"),(0,a.kt)("p",null,"The middleware is configured by defining some ",(0,a.kt)("inlineCode",{parentName:"p"},"serializers"),"."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"{\n serializers: [\n {\n regex: /^application\\/xml$/,\n serializer: ({ body }) => `${body}`,\n },\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n },\n {\n regex: /^text\\/plain$/,\n serializer: ({ body }) => body\n }\n ],\n default: 'application/json'\n}\n")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"default")," (optional) option is used if the request and handler don't specify what type is wanted."),(0,a.kt)("h2",{id:"serializer-functions"},"Serializer Functions"),(0,a.kt)("p",null,"When a matching serializer is found, the ",(0,a.kt)("inlineCode",{parentName:"p"},"Content-Type")," header is set and the serializer function is run."),(0,a.kt)("p",null,"The function is passed the entire ",(0,a.kt)("inlineCode",{parentName:"p"},"response")," object, and should return either a string or an object."),(0,a.kt)("p",null,"If a string is returned, the ",(0,a.kt)("inlineCode",{parentName:"p"},"body")," attribute of the response is updated."),(0,a.kt)("p",null,"If an object with a ",(0,a.kt)("inlineCode",{parentName:"p"},"body")," attribute is returned, the entire response object is replaced. This is useful if you want to manipulate headers or add additional attributes in the Lambda response."),(0,a.kt)("h2",{id:"content-type-negotiation"},"Content Type Negotiation"),(0,a.kt)("p",null,"The header is not the only way the middleware decides which serializer to execute."),(0,a.kt)("p",null,"The content type is determined in the following order:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"event.requiredContentType")," -- allows the handler to override everything else"),(0,a.kt)("li",{parentName:"ul"},"The ",(0,a.kt)("inlineCode",{parentName:"li"},"Accept")," header via ",(0,a.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/accept"},"accept")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"event.preferredContentType")," -- allows the handler to override the default, but lets the request ask first"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"default")," middleware configuration")),(0,a.kt)("p",null,"All options allow for multiple types to be specified in your order of preference, and the first matching serializer will be executed.\nWhen planning to use ",(0,a.kt)("inlineCode",{parentName:"p"},"Accept"),", an external input, it is recommended to validate that it is an expected value."),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpResponseSerializer from '@middy/http-response-serializer'\n\nconst handler = middy((event, context) => {\n const body = 'Hello World'\n\n return {\n statusCode: 200,\n body\n }\n})\n\nhandler\n .use(httpResponseSerializer({\n serializers: [\n {\n regex: /^application\\/xml$/,\n serializer: ({ body }) => `${body}`,\n },\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n },\n {\n regex: /^text\\/plain$/,\n serializer: ({ body }) => body\n }\n ],\n defaultContentType: 'application/json'\n }))\n\nconst event = {\n headers: {\n 'Accept': 'application/xml;q=0.9, text/x-dvi; q=0.8, text/x-c'\n }\n}\n\nhandler(event, {}, (_, response) => {\n t.is(response.body,'Hello World')\n})\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/c4fefc0c.6862ddf7.js b/assets/js/c4fefc0c.2de5ccfb.js similarity index 98% rename from assets/js/c4fefc0c.6862ddf7.js rename to assets/js/c4fefc0c.2de5ccfb.js index 6f447d990..a93920172 100644 --- a/assets/js/c4fefc0c.6862ddf7.js +++ b/assets/js/c4fefc0c.2de5ccfb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7812],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>m});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},u=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},y=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),p=l(n),y=a,m=p["".concat(c,".").concat(y)]||p[y]||d[y]||o;return n?r.createElement(m,i(i({ref:t},u),{},{components:n})):r.createElement(m,i({ref:t},u))}));function m(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=y;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[p]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"Internal Context",sidebar_position:3},i=void 0,s={unversionedId:"best-practices/internal-context",id:"best-practices/internal-context",title:"Internal Context",description:"Middy is built to be async even at it's core. Middlewares can set promises to internal.",source:"@site/docs/best-practices/03-internal-context.md",sourceDirName:"best-practices",slug:"/best-practices/internal-context",permalink:"/docs/best-practices/internal-context",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/03-internal-context.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:3,frontMatter:{title:"Internal Context",sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"Connection reuse",permalink:"/docs/best-practices/connection-reuse"},next:{title:"Bundling Lambda packages",permalink:"/docs/best-practices/bundling"}},c={},l=[],u={toc:l},p="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Middy is built to be async even at it's core. Middlewares can set promises to ",(0,a.kt)("inlineCode",{parentName:"p"},"internal"),".\nThis approach allows them to be resolved together just when you need them."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport {getInternal} from '@middy/util'\n\nconst config = {\n internal: new Proxy({}, {\n get: (target, prop, receiver) => {\n // ...\n return Reflect.get(...arguments)\n },\n set: (obj, prop, value) => {\n // ... ie if `prop` changes, trigger something\n obj[prop] = value\n return true\n }\n })\n}\n\nexport const handler = middy()\n // Incase you want to add values on to internal directly\n .before((async (request) => {\n request.internal = {\n env: process.env.NODE_ENV\n }\n }))\n .use(sts(...))\n .use(ssm(...))\n .use(rdsSigner(...))\n .use(secretsManager(...))\n .before(async (request) => {\n // internal == { key: 'value' }\n\n // Map with same name\n Object.assign(request.context, await getInternal(['key'], request)) \n // -> context == { key: 'value'}\n\n // Map to new name\n Object.assign(request.context, await getInternal({'newKey':'key'}, request))\n // -> context == { newKey: 'value'}\n\n // get all the values, only if you really need to, \n // but you should only request what you need for the handler\n Object.assign(request.context, await getInternal(true, request))\n // -> context == { key: 'value'}\n })\n .handler(async (event, context, { signal }) => {\n \n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7812],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>m});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},u=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},y=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),p=l(n),y=a,m=p["".concat(c,".").concat(y)]||p[y]||d[y]||o;return n?r.createElement(m,i(i({ref:t},u),{},{components:n})):r.createElement(m,i({ref:t},u))}));function m(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=y;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[p]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={title:"Internal Context",sidebar_position:3},i=void 0,s={unversionedId:"best-practices/internal-context",id:"best-practices/internal-context",title:"Internal Context",description:"Middy is built to be async even at it's core. Middlewares can set promises to internal.",source:"@site/docs/best-practices/03-internal-context.md",sourceDirName:"best-practices",slug:"/best-practices/internal-context",permalink:"/docs/best-practices/internal-context",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/03-internal-context.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:3,frontMatter:{title:"Internal Context",sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"Connection reuse",permalink:"/docs/best-practices/connection-reuse"},next:{title:"Bundling Lambda packages",permalink:"/docs/best-practices/bundling"}},c={},l=[],u={toc:l},p="wrapper";function d(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Middy is built to be async even at it's core. Middlewares can set promises to ",(0,a.kt)("inlineCode",{parentName:"p"},"internal"),".\nThis approach allows them to be resolved together just when you need them."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport {getInternal} from '@middy/util'\n\nconst config = {\n internal: new Proxy({}, {\n get: (target, prop, receiver) => {\n // ...\n return Reflect.get(...arguments)\n },\n set: (obj, prop, value) => {\n // ... ie if `prop` changes, trigger something\n obj[prop] = value\n return true\n }\n })\n}\n\nexport const handler = middy()\n // Incase you want to add values on to internal directly\n .before((async (request) => {\n request.internal = {\n env: process.env.NODE_ENV\n }\n }))\n .use(sts(...))\n .use(ssm(...))\n .use(rdsSigner(...))\n .use(secretsManager(...))\n .before(async (request) => {\n // internal == { key: 'value' }\n\n // Map with same name\n Object.assign(request.context, await getInternal(['key'], request)) \n // -> context == { key: 'value'}\n\n // Map to new name\n Object.assign(request.context, await getInternal({'newKey':'key'}, request))\n // -> context == { newKey: 'value'}\n\n // get all the values, only if you really need to, \n // but you should only request what you need for the handler\n Object.assign(request.context, await getInternal(true, request))\n // -> context == { key: 'value'}\n })\n .handler(async (event, context, { signal }) => {\n \n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/cc16eb0f.b86f83f1.js b/assets/js/cc16eb0f.d33249f9.js similarity index 98% rename from assets/js/cc16eb0f.b86f83f1.js rename to assets/js/cc16eb0f.d33249f9.js index 5d0774509..6a91055f3 100644 --- a/assets/js/cc16eb0f.b86f83f1.js +++ b/assets/js/cc16eb0f.d33249f9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5893],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),c=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=c(e.components);return r.createElement(s.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},d=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),m=c(n),d=a,f=m["".concat(s,".").concat(d)]||m[d]||u[d]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=d;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[m]="string"==typeof e?e:a,i[1]=l;for(var c=2;c{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>l,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"Lex"},i=void 0,l={unversionedId:"events/lex",id:"events/lex",title:"Lex",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/lex.md",sourceDirName:"events",slug:"/events/lex",permalink:"/docs/events/lex",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/lex.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Lex"},sidebar:"tutorialSidebar",previous:{title:"Kinesis Streams",permalink:"/docs/events/kinesis-streams"},next:{title:"MQ",permalink:"/docs/events/mq"}},s={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},m="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-lex.html"},"Using AWS Lambda with Amazon Lex")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html"},"Using an AWS Lambda function")," with Amazon Lex V2")),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5893],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),c=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=c(e.components);return r.createElement(s.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},d=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),m=c(n),d=a,f=m["".concat(s,".").concat(d)]||m[d]||u[d]||o;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=d;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[m]="string"==typeof e?e:a,i[1]=l;for(var c=2;c{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>l,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"Lex"},i=void 0,l={unversionedId:"events/lex",id:"events/lex",title:"Lex",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/lex.md",sourceDirName:"events",slug:"/events/lex",permalink:"/docs/events/lex",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/lex.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Lex"},sidebar:"tutorialSidebar",previous:{title:"Kinesis Streams",permalink:"/docs/events/kinesis-streams"},next:{title:"MQ",permalink:"/docs/events/mq"}},s={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:c},m="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-lex.html"},"Using AWS Lambda with Amazon Lex")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html"},"Using an AWS Lambda function")," with Amazon Lex V2")),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/cd47eedf.75584d30.js b/assets/js/cd47eedf.c1d1bc66.js similarity index 98% rename from assets/js/cd47eedf.75584d30.js rename to assets/js/cd47eedf.c1d1bc66.js index a71c86f87..9ed0b445e 100644 --- a/assets/js/cd47eedf.75584d30.js +++ b/assets/js/cd47eedf.c1d1bc66.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4388],{3905:(e,r,t)=>{t.d(r,{Zo:()=>d,kt:()=>h});var n=t(7294);function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function a(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var l=n.createContext({}),p=function(e){var r=n.useContext(l),t=r;return e&&(t="function"==typeof e?e(r):i(i({},r),e)),t},d=function(e){var r=p(e.components);return n.createElement(l.Provider,{value:r},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var r=e.children;return n.createElement(n.Fragment,{},r)}},m=n.forwardRef((function(e,r){var t=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),c=p(t),m=o,h=c["".concat(l,".").concat(m)]||c[m]||u[m]||a;return t?n.createElement(h,i(i({ref:r},d),{},{components:t})):n.createElement(h,i({ref:r},d))}));function h(e,r){var t=arguments,o=r&&r.mdxType;if("string"==typeof e||o){var a=t.length,i=new Array(a);i[0]=m;var s={};for(var l in r)hasOwnProperty.call(r,l)&&(s[l]=r[l]);s.originalType=e,s[c]="string"==typeof e?e:o,i[1]=s;for(var p=2;p{t.r(r),t.d(r,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>s,toc:()=>p});var n=t(7462),o=(t(7294),t(3905));const a={title:"Handling Errors",position:5},i=void 0,s={unversionedId:"intro/handling-errors",id:"intro/handling-errors",title:"Handling Errors",description:"But, what happens when there is an error?",source:"@site/docs/intro/05-handling-errors.md",sourceDirName:"intro",slug:"/intro/handling-errors",permalink:"/docs/intro/handling-errors",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/05-handling-errors.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:5,frontMatter:{title:"Handling Errors",position:5},sidebar:"tutorialSidebar",previous:{title:"Early return",permalink:"/docs/intro/early-interrupt"},next:{title:"Streamify Response",permalink:"/docs/intro/streamify-response"}},l={},p=[],d={toc:p},c="wrapper";function u(e){let{components:r,...t}=e;return(0,o.kt)(c,(0,n.Z)({},d,t,{components:r,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"But, what happens when there is an error?"),(0,o.kt)("p",null,"When there is an error, the regular control flow is stopped and the execution is\nmoved back to all the middlewares that implemented a special phase called ",(0,o.kt)("inlineCode",{parentName:"p"},"onError"),", following\nthe same order as ",(0,o.kt)("inlineCode",{parentName:"p"},"after"),"."),(0,o.kt)("p",null,"Every ",(0,o.kt)("inlineCode",{parentName:"p"},"onError")," middleware can decide to handle the error and create a proper response or\nto delegate the error to the next middleware."),(0,o.kt)("p",null,"When a middleware handles the error and creates a response, the execution is still propagated to all the other\nerror middlewares and they have a chance to update or replace the response as\nneeded. At the end of the error middlewares sequence, the response is returned\nto the user."),(0,o.kt)("p",null,"If no middleware manages the error, the Lambda execution fails reporting the unmanaged error."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"// Initialize response\nrequest.response = request.response ?? {}\n\n// Add to response\nrequest.response.add = 'more'\n\n// Override an error\nrequest.error = new Error('...')\n\n// handle the error\nreturn request.response\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4388],{3905:(e,r,t)=>{t.d(r,{Zo:()=>d,kt:()=>h});var n=t(7294);function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function a(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var l=n.createContext({}),p=function(e){var r=n.useContext(l),t=r;return e&&(t="function"==typeof e?e(r):i(i({},r),e)),t},d=function(e){var r=p(e.components);return n.createElement(l.Provider,{value:r},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var r=e.children;return n.createElement(n.Fragment,{},r)}},m=n.forwardRef((function(e,r){var t=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),c=p(t),m=o,h=c["".concat(l,".").concat(m)]||c[m]||u[m]||a;return t?n.createElement(h,i(i({ref:r},d),{},{components:t})):n.createElement(h,i({ref:r},d))}));function h(e,r){var t=arguments,o=r&&r.mdxType;if("string"==typeof e||o){var a=t.length,i=new Array(a);i[0]=m;var s={};for(var l in r)hasOwnProperty.call(r,l)&&(s[l]=r[l]);s.originalType=e,s[c]="string"==typeof e?e:o,i[1]=s;for(var p=2;p{t.r(r),t.d(r,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>s,toc:()=>p});var n=t(7462),o=(t(7294),t(3905));const a={title:"Handling Errors",position:5},i=void 0,s={unversionedId:"intro/handling-errors",id:"intro/handling-errors",title:"Handling Errors",description:"But, what happens when there is an error?",source:"@site/docs/intro/05-handling-errors.md",sourceDirName:"intro",slug:"/intro/handling-errors",permalink:"/docs/intro/handling-errors",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/05-handling-errors.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:5,frontMatter:{title:"Handling Errors",position:5},sidebar:"tutorialSidebar",previous:{title:"Early return",permalink:"/docs/intro/early-interrupt"},next:{title:"Streamify Response",permalink:"/docs/intro/streamify-response"}},l={},p=[],d={toc:p},c="wrapper";function u(e){let{components:r,...t}=e;return(0,o.kt)(c,(0,n.Z)({},d,t,{components:r,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"But, what happens when there is an error?"),(0,o.kt)("p",null,"When there is an error, the regular control flow is stopped and the execution is\nmoved back to all the middlewares that implemented a special phase called ",(0,o.kt)("inlineCode",{parentName:"p"},"onError"),", following\nthe same order as ",(0,o.kt)("inlineCode",{parentName:"p"},"after"),"."),(0,o.kt)("p",null,"Every ",(0,o.kt)("inlineCode",{parentName:"p"},"onError")," middleware can decide to handle the error and create a proper response or\nto delegate the error to the next middleware."),(0,o.kt)("p",null,"When a middleware handles the error and creates a response, the execution is still propagated to all the other\nerror middlewares and they have a chance to update or replace the response as\nneeded. At the end of the error middlewares sequence, the response is returned\nto the user."),(0,o.kt)("p",null,"If no middleware manages the error, the Lambda execution fails reporting the unmanaged error."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"// Initialize response\nrequest.response = request.response ?? {}\n\n// Add to response\nrequest.response.add = 'more'\n\n// Override an error\nrequest.error = new Error('...')\n\n// handle the error\nreturn request.response\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/ce7003dc.c827c8ed.js b/assets/js/ce7003dc.a6a19c66.js similarity index 97% rename from assets/js/ce7003dc.c827c8ed.js rename to assets/js/ce7003dc.a6a19c66.js index 7a2c4055d..47320b5ff 100644 --- a/assets/js/ce7003dc.c827c8ed.js +++ b/assets/js/ce7003dc.a6a19c66.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9071],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var s=r.createContext({}),d=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},c=function(e){var t=d(e.components);return r.createElement(s.Provider,{value:t},e.children)},p="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,o=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),p=d(n),u=i,f=p["".concat(s,".").concat(u)]||p[u]||m[u]||o;return n?r.createElement(f,a(a({ref:t},c),{},{components:n})):r.createElement(f,a({ref:t},c))}));function f(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=n.length,a=new Array(o);a[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:i,a[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>l,toc:()=>d});var r=n(7462),i=(n(7294),n(3905));const o={title:"Inline Middlewares",position:3},a=void 0,l={unversionedId:"writing-middlewares/inline-middlewares",id:"writing-middlewares/inline-middlewares",title:"Inline Middlewares",description:"Sometimes you want to create handlers that serve a very small need and that are not",source:"@site/docs/writing-middlewares/03-inline-middlewares.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/inline-middlewares",permalink:"/docs/writing-middlewares/inline-middlewares",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/03-inline-middlewares.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:3,frontMatter:{title:"Inline Middlewares",position:3},sidebar:"tutorialSidebar",previous:{title:"Configurable Middlewares",permalink:"/docs/writing-middlewares/configurable-middlewares"},next:{title:"Internal Storage",permalink:"/docs/writing-middlewares/internal-storage"}},s={},d=[],c={toc:d},p="wrapper";function m(e){let{components:t,...n}=e;return(0,i.kt)(p,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Sometimes you want to create handlers that serve a very small need and that are not\nnecessarily re-usable. In such cases, you probably will need to hook only into one of\nthe different phases (",(0,i.kt)("inlineCode",{parentName:"p"},"before"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"onError"),")."),(0,i.kt)("p",null,"In these cases you can use ",(0,i.kt)("strong",{parentName:"p"},"inline middlewares")," which are shortcut functions to hook\nlogic into Middy's control flow."),(0,i.kt)("p",null,"Let's see how inline middlewares work with a simple example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy((event, context) => {\n // do stuff\n })\n .before(async (request) => {\n // do something in the before phase\n })\n .after(async (request) => {\n // do something in the after phase\n })\n .onError(async (request) => {\n // do something in the on error phase\n })\n")),(0,i.kt)("p",null,"As you can see above, a middy instance also exposes the ",(0,i.kt)("inlineCode",{parentName:"p"},"before"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"onError"),"\nmethods to allow you to quickly hook in simple inline middlewares."))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9071],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var s=r.createContext({}),d=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},c=function(e){var t=d(e.components);return r.createElement(s.Provider,{value:t},e.children)},p="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,o=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),p=d(n),u=i,f=p["".concat(s,".").concat(u)]||p[u]||m[u]||o;return n?r.createElement(f,a(a({ref:t},c),{},{components:n})):r.createElement(f,a({ref:t},c))}));function f(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=n.length,a=new Array(o);a[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:i,a[1]=l;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>l,toc:()=>d});var r=n(7462),i=(n(7294),n(3905));const o={title:"Inline Middlewares",position:3},a=void 0,l={unversionedId:"writing-middlewares/inline-middlewares",id:"writing-middlewares/inline-middlewares",title:"Inline Middlewares",description:"Sometimes you want to create handlers that serve a very small need and that are not",source:"@site/docs/writing-middlewares/03-inline-middlewares.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/inline-middlewares",permalink:"/docs/writing-middlewares/inline-middlewares",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/03-inline-middlewares.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:3,frontMatter:{title:"Inline Middlewares",position:3},sidebar:"tutorialSidebar",previous:{title:"Configurable Middlewares",permalink:"/docs/writing-middlewares/configurable-middlewares"},next:{title:"Internal Storage",permalink:"/docs/writing-middlewares/internal-storage"}},s={},d=[],c={toc:d},p="wrapper";function m(e){let{components:t,...n}=e;return(0,i.kt)(p,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Sometimes you want to create handlers that serve a very small need and that are not\nnecessarily re-usable. In such cases, you probably will need to hook only into one of\nthe different phases (",(0,i.kt)("inlineCode",{parentName:"p"},"before"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"onError"),")."),(0,i.kt)("p",null,"In these cases you can use ",(0,i.kt)("strong",{parentName:"p"},"inline middlewares")," which are shortcut functions to hook\nlogic into Middy's control flow."),(0,i.kt)("p",null,"Let's see how inline middlewares work with a simple example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy((event, context) => {\n // do stuff\n })\n .before(async (request) => {\n // do something in the before phase\n })\n .after(async (request) => {\n // do something in the after phase\n })\n .onError(async (request) => {\n // do something in the on error phase\n })\n")),(0,i.kt)("p",null,"As you can see above, a middy instance also exposes the ",(0,i.kt)("inlineCode",{parentName:"p"},"before"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"onError"),"\nmethods to allow you to quickly hook in simple inline middlewares."))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/d0953a14.1625530c.js b/assets/js/d0953a14.8629ffe0.js similarity index 99% rename from assets/js/d0953a14.1625530c.js rename to assets/js/d0953a14.8629ffe0.js index 851d84e82..f8e5ab2f8 100644 --- a/assets/js/d0953a14.1625530c.js +++ b/assets/js/d0953a14.8629ffe0.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4740],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},c=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),u=d(n),c=r,f=u["".concat(s,".").concat(c)]||u[c]||m[c]||l;return n?a.createElement(f,i(i({ref:t},p),{},{components:n})):a.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=c;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[u]="string"==typeof e?e:r,i[1]=o;for(var d=2;d{n.d(t,{Z:()=>i});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var a=n(7462),r=n(7294),l=n(6010),i=n(2466),o=n(6550),s=n(1980),d=n(7392),p=n(12);function u(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??u(n);return function(e){const t=(0,d.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function c(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=m(e),[i,o]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!c({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,d]=f({queryString:n,groupId:a}),[u,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,p.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),v=(()=>{const e=s??u;return c({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{v&&o(v)}),[v]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!c({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),h(e)}),[d,h,l]),tabValues:l}}var v=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:n,selectedValue:o,selectValue:s,tabValues:d}=e;const p=[],{blockElementScrollPositionUntilNextRender:u}=(0,i.o5)(),m=e=>{const t=e.currentTarget,n=p.indexOf(t),a=d[n].value;a!==o&&(u(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const n=p.indexOf(e.currentTarget)+1;t=p[n]??p[0];break}case"ArrowLeft":{const n=p.indexOf(e.currentTarget)-1;t=p[n]??p[p.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},d.map((e=>{let{value:t,label:n,attributes:i}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>p.push(e),onKeyDown:c,onClick:m},i,{className:(0,l.Z)("tabs__item",y.tabItem,i?.className,{"tabs__item--active":o===t})}),n??t)})))}function b(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function k(e){const t=h(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},r.createElement(g,(0,a.Z)({},e,t)),r.createElement(b,(0,a.Z)({},e,t)))}function N(e){const t=(0,v.Z)();return r.createElement(k,(0,a.Z)({key:String(t)},e))}},3144:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>d,toc:()=>u});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),i=n(5162);const o={title:"validator"},s=void 0,d={unversionedId:"middlewares/validator",id:"middlewares/validator",title:"validator",description:"This middleware automatically validates incoming events and outgoing responses against custom",source:"@site/docs/middlewares/validator.md",sourceDirName:"middlewares",slug:"/middlewares/validator",permalink:"/docs/middlewares/validator",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/validator.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"validator"},sidebar:"tutorialSidebar",previous:{title:"sts",permalink:"/docs/middlewares/sts"},next:{title:"warmup",permalink:"/docs/middlewares/warmup"}},p={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"transpileSchema",id:"transpileschema",level:2},{value:"transpileLocale",id:"transpilelocale",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Pre-transpiling example (recommended)",id:"pre-transpiling-example-recommended",level:2},{value:"Transpile during cold-start",id:"transpile-during-cold-start",level:2},{value:"Transpile during cold-start with default messages",id:"transpile-during-cold-start-with-default-messages",level:2}],m={toc:u},c="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(c,(0,a.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This middleware automatically validates incoming events and outgoing responses against custom\nschemas defined with the ",(0,r.kt)("a",{parentName:"p",href:"http://json-schema.org/"},"JSON schema syntax"),"."),(0,r.kt)("p",null,"Want to use another validator? Try one of the community validators:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-ajv"},"ajv")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-sparks-joi"},"middy-sparks-joi"))),(0,r.kt)("p",null,"If an incoming event fails validation a ",(0,r.kt)("inlineCode",{parentName:"p"},"BadRequest")," error is raised.\nIf an outgoing response fails validation a ",(0,r.kt)("inlineCode",{parentName:"p"},"InternalServerError")," error is\nraised."),(0,r.kt)("p",null,"This middleware can be used in combination with\n",(0,r.kt)("a",{parentName:"p",href:"#httperrorhandler"},(0,r.kt)("inlineCode",{parentName:"a"},"httpErrorHandler"))," to automatically return the right\nresponse to the user."),(0,r.kt)("p",null,"It can also be used in combination with ",(0,r.kt)("a",{parentName:"p",href:"#httpContentNegotiation"},(0,r.kt)("inlineCode",{parentName:"a"},"http-content-negotiation"))," to load localized translations for the error messages (based on the currently requested language). This feature uses internally ",(0,r.kt)("a",{parentName:"p",href:"http://npm.im/ajv-ftl-i18n"},(0,r.kt)("inlineCode",{parentName:"a"},"ajv-ftl-i18n"))," module, so reference to this module for options and more advanced use cases. By default the language used will be English (",(0,r.kt)("inlineCode",{parentName:"p"},"en"),"), but you can redefine the default language by passing it in the ",(0,r.kt)("inlineCode",{parentName:"p"},"ajvOptions")," options with the key ",(0,r.kt)("inlineCode",{parentName:"p"},"defaultLanguage")," and specifying as value one of the ",(0,r.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/ajv-i18n#supported-locales"},"supported locales"),"."),(0,r.kt)("p",null,"Also, this middleware accepts an object with plugins to be applied to customize the internal ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv")," instance."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/validator\nnpm install --save-dev ajv-cmd # Optional: for pre-transpiling\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/validator\nyarn add --dev ajv-cmd # Optional: for pre-transpiling\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/validator\npnpm add --save-dev ajv-cmd # Optional: for pre-transpiling\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"eventSchema")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): The compiled ajv validator that will be used\nto validate the input (",(0,r.kt)("inlineCode",{parentName:"li"},"request.event"),") of the Lambda handler."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"contextSchema")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): The compiled ajv validator that will be used\nto validate the input (",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),") of the Lambda handler. Has additional support for ",(0,r.kt)("inlineCode",{parentName:"li"},"typeof")," keyword to allow validation of ",(0,r.kt)("inlineCode",{parentName:"li"},'"typeof":"function"'),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"responseSchema")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): The compiled ajv validator that will be used\nto validate the output (",(0,r.kt)("inlineCode",{parentName:"li"},"request.response"),") of the Lambda handler."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"i18nEnabled")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),"): Option to disable i18n default package."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"defaultLanguage")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"en"),"): When language not found, what language to fallback to."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"languages")," (object) (default: ",(0,r.kt)("inlineCode",{parentName:"li"},"{}"),"): Localization overrides")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"At least one of ",(0,r.kt)("inlineCode",{parentName:"li"},"eventSchema")," or ",(0,r.kt)("inlineCode",{parentName:"li"},"responseSchema")," is required."),(0,r.kt)("li",{parentName:"ul"},"If you'd like to have the error details as part of the response, it will need to be handled separately. You can access them from ",(0,r.kt)("inlineCode",{parentName:"li"},"request.error.cause"),", the original response can be found at ",(0,r.kt)("inlineCode",{parentName:"li"},"request.error.response"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"Important")," Transpiling schemas & locales on the fly will cause a 50-150ms performance hit during cold start for simple JSON Schemas. Precompiling is highly recommended.")),(0,r.kt)("h2",{id:"transpileschema"},"transpileSchema"),(0,r.kt)("p",null,"Transpile JSON-Schema in to JavaScript. Default ajv plugins used: ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-i18n"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-formats"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-formats-draft2019"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-keywords"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-errors"),"."),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"schema")," (object) (required): JSON-Schema object"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ajvOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to ",(0,r.kt)("a",{parentName:"li",href:"https://ajv.js.org/docs/api.html#options"},"ajv"),"\nclass constructor. Defaults are ",(0,r.kt)("inlineCode",{parentName:"li"},"{ strict: true, coerceTypes: 'array', allErrors: true, useDefaults: 'empty', messages: true }"),".")),(0,r.kt)("h2",{id:"transpilelocale"},"transpileLocale"),(0,r.kt)("p",null,"Transpile Fluent (.ftl) localization file into ajv compatible format. Allows the overriding of the default messages and adds support for multi-language ",(0,r.kt)("inlineCode",{parentName:"p"},"errrorMessages"),"."),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ftl")," (string) (required): Contents of an ftl file to be transpiled.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("p",null,"Example for event validation:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nconst schema = {\n type: 'object',\n required: ['body', 'foo'],\n properties: {\n // this will pass validation\n body: {\n type: 'string'\n },\n // this won't as it won't be in the event\n foo: {\n type: 'string'\n }\n }\n}\n\nhandler.use(\n validator({\n eventSchema: transpileSchema(schema)\n })\n)\n\n// invokes the handler, note that property foo is missing\nconst event = {\n body: JSON.stringify({ something: 'somethingelse' })\n}\nhandler(event, {}, (err, res) => {\n t.is(err.message, 'Event object failed validation')\n})\n")),(0,r.kt)("p",null,"Example for response validation:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nconst responseSchema = transpileSchema({\n type: 'object',\n required: ['body', 'statusCode'],\n properties: {\n body: {\n type: 'object'\n },\n statusCode: {\n type: 'number'\n }\n }\n})\n\nhandler.use(validator({ responseSchema }))\n\nhandler({}, {}, (err, response) => {\n t.not(err, null)\n t.is(err.message, 'Response object failed validation')\n expect(response).not.toBe(null)\n // it doesn't destroy the response so it can be used by other middlewares\n})\n")),(0,r.kt)("p",null,"Example for body validation:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpJsonBodyParser from '@middy/http-json-body-parser'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nconst schema = {\n type: 'object',\n required: ['body'],\n properties: {\n body: {\n type: 'object',\n required: ['name', 'email'],\n properties: {\n name: { type: 'string' },\n email: { type: 'string', format: 'email' }\n // schema options https://ajv.js.org/json-schema.html#json-data-type\n }\n }\n }\n}\n\n// to validate the body we need to parse it first\nhandler.use(httpJsonBodyParser()).use(\n validator({\n eventSchema: transpileSchema(schema)\n })\n)\n")),(0,r.kt)("h2",{id:"pre-transpiling-example-recommended"},"Pre-transpiling example (recommended)"),(0,r.kt)("p",null,"Run a build script to before running tests & deployment."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"#!/usr/bin/env bash\n\n# This is an example, should be customize to meet ones needs\n# Powered by `ajv-cmd`\n# $ ajv --help\n\nbundle () {\n ajv validate ${1} --valid \\\n --strict true --coerce-types array --all-errors true --use-defaults empty\n ajv transpile ${1} \\\n --strict true --coerce-types array --all-errors true --use-defaults empty \\\n -o ${1%.json}.js\n}\n\nfor file in handlers/*/schema.*.json; do\n bundle $file\ndone\n\nlocale () {\n LOCALE=$(basename ${1%.ftl})\n ajv ftl ${1} --locale ${LOCALE} -o ${1%.ftl}.js\n}\n\nfor file in handlers/*/*.ftl; do\n locale $file\ndone\n")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport eventSchema from './schema.event.js'\nimport en from './en.js'\nimport fr from './fr.js'\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema,\n languages: { en, fr }\n })\n )\n .handler((event, context) => {\n return {}\n })\n")),(0,r.kt)("h2",{id:"transpile-during-cold-start"},"Transpile during cold-start"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import { readFile } from 'node:fs/promises'\nimport middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema, transpileLocale } from '@middy/validator/transpile'\nimport eventSchema from './schema.event.json'\n\nconst en = transpileLocale(await readFile('./en.ftl'))\nconst fr = transpileLocale(await readFile('./fr.ftl'))\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema: transpileSchema(eventSchema),\n languages: { en, fr }\n })\n )\n .handler((event, context) => {\n return {}\n })\n")),(0,r.kt)("h2",{id:"transpile-during-cold-start-with-default-messages"},"Transpile during cold-start with default messages"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import { readFile } from 'node:fs/promises'\nimport middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema, transpileLocale } from '@middy/validator/transpile'\nimport { en, fr } from 'ajv-ftl-i18n' // `ajv-i18n` can also be used\nimport eventSchema from './schema.event.json'\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema: transpileSchema(eventSchema),\n languages: { en, fr }\n })\n )\n .handler((event, context) => {\n return {}\n })\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4740],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},c=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),u=d(n),c=r,f=u["".concat(s,".").concat(c)]||u[c]||m[c]||l;return n?a.createElement(f,i(i({ref:t},p),{},{components:n})):a.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=c;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[u]="string"==typeof e?e:r,i[1]=o;for(var d=2;d{n.d(t,{Z:()=>i});var a=n(7294),r=n(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>N});var a=n(7462),r=n(7294),l=n(6010),i=n(2466),o=n(6550),s=n(1980),d=n(7392),p=n(12);function u(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??u(n);return function(e){const t=(0,d.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function c(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,s._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=m(e),[i,o]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!c({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,d]=f({queryString:n,groupId:a}),[u,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,p.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),v=(()=>{const e=s??u;return c({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{v&&o(v)}),[v]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!c({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),h(e)}),[d,h,l]),tabValues:l}}var v=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:n,selectedValue:o,selectValue:s,tabValues:d}=e;const p=[],{blockElementScrollPositionUntilNextRender:u}=(0,i.o5)(),m=e=>{const t=e.currentTarget,n=p.indexOf(t),a=d[n].value;a!==o&&(u(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":{const n=p.indexOf(e.currentTarget)+1;t=p[n]??p[0];break}case"ArrowLeft":{const n=p.indexOf(e.currentTarget)-1;t=p[n]??p[p.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},d.map((e=>{let{value:t,label:n,attributes:i}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>p.push(e),onKeyDown:c,onClick:m},i,{className:(0,l.Z)("tabs__item",y.tabItem,i?.className,{"tabs__item--active":o===t})}),n??t)})))}function b(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function k(e){const t=h(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},r.createElement(g,(0,a.Z)({},e,t)),r.createElement(b,(0,a.Z)({},e,t)))}function N(e){const t=(0,v.Z)();return r.createElement(k,(0,a.Z)({key:String(t)},e))}},3144:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>d,toc:()=>u});var a=n(7462),r=(n(7294),n(3905)),l=n(4866),i=n(5162);const o={title:"validator"},s=void 0,d={unversionedId:"middlewares/validator",id:"middlewares/validator",title:"validator",description:"This middleware automatically validates incoming events and outgoing responses against custom",source:"@site/docs/middlewares/validator.md",sourceDirName:"middlewares",slug:"/middlewares/validator",permalink:"/docs/middlewares/validator",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/validator.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"validator"},sidebar:"tutorialSidebar",previous:{title:"sts",permalink:"/docs/middlewares/sts"},next:{title:"warmup",permalink:"/docs/middlewares/warmup"}},p={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"transpileSchema",id:"transpileschema",level:2},{value:"transpileLocale",id:"transpilelocale",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Pre-transpiling example (recommended)",id:"pre-transpiling-example-recommended",level:2},{value:"Transpile during cold-start",id:"transpile-during-cold-start",level:2},{value:"Transpile during cold-start with default messages",id:"transpile-during-cold-start-with-default-messages",level:2}],m={toc:u},c="wrapper";function f(e){let{components:t,...n}=e;return(0,r.kt)(c,(0,a.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This middleware automatically validates incoming events and outgoing responses against custom\nschemas defined with the ",(0,r.kt)("a",{parentName:"p",href:"http://json-schema.org/"},"JSON schema syntax"),"."),(0,r.kt)("p",null,"Want to use another validator? Try one of the community validators:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-ajv"},"ajv")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-sparks-joi"},"middy-sparks-joi"))),(0,r.kt)("p",null,"If an incoming event fails validation a ",(0,r.kt)("inlineCode",{parentName:"p"},"BadRequest")," error is raised.\nIf an outgoing response fails validation a ",(0,r.kt)("inlineCode",{parentName:"p"},"InternalServerError")," error is\nraised."),(0,r.kt)("p",null,"This middleware can be used in combination with\n",(0,r.kt)("a",{parentName:"p",href:"#httperrorhandler"},(0,r.kt)("inlineCode",{parentName:"a"},"httpErrorHandler"))," to automatically return the right\nresponse to the user."),(0,r.kt)("p",null,"It can also be used in combination with ",(0,r.kt)("a",{parentName:"p",href:"#httpContentNegotiation"},(0,r.kt)("inlineCode",{parentName:"a"},"http-content-negotiation"))," to load localized translations for the error messages (based on the currently requested language). This feature uses internally ",(0,r.kt)("a",{parentName:"p",href:"http://npm.im/ajv-ftl-i18n"},(0,r.kt)("inlineCode",{parentName:"a"},"ajv-ftl-i18n"))," module, so reference to this module for options and more advanced use cases. By default the language used will be English (",(0,r.kt)("inlineCode",{parentName:"p"},"en"),"), but you can redefine the default language by passing it in the ",(0,r.kt)("inlineCode",{parentName:"p"},"ajvOptions")," options with the key ",(0,r.kt)("inlineCode",{parentName:"p"},"defaultLanguage")," and specifying as value one of the ",(0,r.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/ajv-i18n#supported-locales"},"supported locales"),"."),(0,r.kt)("p",null,"Also, this middleware accepts an object with plugins to be applied to customize the internal ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv")," instance."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/validator\nnpm install --save-dev ajv-cmd # Optional: for pre-transpiling\n"))),(0,r.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/validator\nyarn add --dev ajv-cmd # Optional: for pre-transpiling\n"))),(0,r.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/validator\npnpm add --save-dev ajv-cmd # Optional: for pre-transpiling\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"eventSchema")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): The compiled ajv validator that will be used\nto validate the input (",(0,r.kt)("inlineCode",{parentName:"li"},"request.event"),") of the Lambda handler."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"contextSchema")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): The compiled ajv validator that will be used\nto validate the input (",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),") of the Lambda handler. Has additional support for ",(0,r.kt)("inlineCode",{parentName:"li"},"typeof")," keyword to allow validation of ",(0,r.kt)("inlineCode",{parentName:"li"},'"typeof":"function"'),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"responseSchema")," (function) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): The compiled ajv validator that will be used\nto validate the output (",(0,r.kt)("inlineCode",{parentName:"li"},"request.response"),") of the Lambda handler."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"i18nEnabled")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"true"),"): Option to disable i18n default package."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"defaultLanguage")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"en"),"): When language not found, what language to fallback to."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"languages")," (object) (default: ",(0,r.kt)("inlineCode",{parentName:"li"},"{}"),"): Localization overrides")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"At least one of ",(0,r.kt)("inlineCode",{parentName:"li"},"eventSchema")," or ",(0,r.kt)("inlineCode",{parentName:"li"},"responseSchema")," is required."),(0,r.kt)("li",{parentName:"ul"},"If you'd like to have the error details as part of the response, it will need to be handled separately. You can access them from ",(0,r.kt)("inlineCode",{parentName:"li"},"request.error.cause"),", the original response can be found at ",(0,r.kt)("inlineCode",{parentName:"li"},"request.error.response"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"Important")," Transpiling schemas & locales on the fly will cause a 50-150ms performance hit during cold start for simple JSON Schemas. Precompiling is highly recommended.")),(0,r.kt)("h2",{id:"transpileschema"},"transpileSchema"),(0,r.kt)("p",null,"Transpile JSON-Schema in to JavaScript. Default ajv plugins used: ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-i18n"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-formats"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-formats-draft2019"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-keywords"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"ajv-errors"),"."),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"schema")," (object) (required): JSON-Schema object"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ajvOptions")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"undefined"),"): Options to pass to ",(0,r.kt)("a",{parentName:"li",href:"https://ajv.js.org/docs/api.html#options"},"ajv"),"\nclass constructor. Defaults are ",(0,r.kt)("inlineCode",{parentName:"li"},"{ strict: true, coerceTypes: 'array', allErrors: true, useDefaults: 'empty', messages: true }"),".")),(0,r.kt)("h2",{id:"transpilelocale"},"transpileLocale"),(0,r.kt)("p",null,"Transpile Fluent (.ftl) localization file into ajv compatible format. Allows the overriding of the default messages and adds support for multi-language ",(0,r.kt)("inlineCode",{parentName:"p"},"errrorMessages"),"."),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ftl")," (string) (required): Contents of an ftl file to be transpiled.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("p",null,"Example for event validation:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nconst schema = {\n type: 'object',\n required: ['body', 'foo'],\n properties: {\n // this will pass validation\n body: {\n type: 'string'\n },\n // this won't as it won't be in the event\n foo: {\n type: 'string'\n }\n }\n}\n\nhandler.use(\n validator({\n eventSchema: transpileSchema(schema)\n })\n)\n\n// invokes the handler, note that property foo is missing\nconst event = {\n body: JSON.stringify({ something: 'somethingelse' })\n}\nhandler(event, {}, (err, res) => {\n t.is(err.message, 'Event object failed validation')\n})\n")),(0,r.kt)("p",null,"Example for response validation:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nconst responseSchema = transpileSchema({\n type: 'object',\n required: ['body', 'statusCode'],\n properties: {\n body: {\n type: 'object'\n },\n statusCode: {\n type: 'number'\n }\n }\n})\n\nhandler.use(validator({ responseSchema }))\n\nhandler({}, {}, (err, response) => {\n t.not(err, null)\n t.is(err.message, 'Response object failed validation')\n expect(response).not.toBe(null)\n // it doesn't destroy the response so it can be used by other middlewares\n})\n")),(0,r.kt)("p",null,"Example for body validation:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpJsonBodyParser from '@middy/http-json-body-parser'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nconst schema = {\n type: 'object',\n required: ['body'],\n properties: {\n body: {\n type: 'object',\n required: ['name', 'email'],\n properties: {\n name: { type: 'string' },\n email: { type: 'string', format: 'email' }\n // schema options https://ajv.js.org/json-schema.html#json-data-type\n }\n }\n }\n}\n\n// to validate the body we need to parse it first\nhandler.use(httpJsonBodyParser()).use(\n validator({\n eventSchema: transpileSchema(schema)\n })\n)\n")),(0,r.kt)("h2",{id:"pre-transpiling-example-recommended"},"Pre-transpiling example (recommended)"),(0,r.kt)("p",null,"Run a build script to before running tests & deployment."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"#!/usr/bin/env bash\n\n# This is an example, should be customize to meet ones needs\n# Powered by `ajv-cmd`\n# $ ajv --help\n\nbundle () {\n ajv validate ${1} --valid \\\n --strict true --coerce-types array --all-errors true --use-defaults empty\n ajv transpile ${1} \\\n --strict true --coerce-types array --all-errors true --use-defaults empty \\\n -o ${1%.json}.js\n}\n\nfor file in handlers/*/schema.*.json; do\n bundle $file\ndone\n\nlocale () {\n LOCALE=$(basename ${1%.ftl})\n ajv ftl ${1} --locale ${LOCALE} -o ${1%.ftl}.js\n}\n\nfor file in handlers/*/*.ftl; do\n locale $file\ndone\n")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport eventSchema from './schema.event.js'\nimport en from './en.js'\nimport fr from './fr.js'\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema,\n languages: { en, fr }\n })\n )\n .handler((event, context) => {\n return {}\n })\n")),(0,r.kt)("h2",{id:"transpile-during-cold-start"},"Transpile during cold-start"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import { readFile } from 'node:fs/promises'\nimport middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema, transpileLocale } from '@middy/validator/transpile'\nimport eventSchema from './schema.event.json'\n\nconst en = transpileLocale(await readFile('./en.ftl'))\nconst fr = transpileLocale(await readFile('./fr.ftl'))\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema: transpileSchema(eventSchema),\n languages: { en, fr }\n })\n )\n .handler((event, context) => {\n return {}\n })\n")),(0,r.kt)("h2",{id:"transpile-during-cold-start-with-default-messages"},"Transpile during cold-start with default messages"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import { readFile } from 'node:fs/promises'\nimport middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema, transpileLocale } from '@middy/validator/transpile'\nimport { en, fr } from 'ajv-ftl-i18n' // `ajv-i18n` can also be used\nimport eventSchema from './schema.event.json'\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema: transpileSchema(eventSchema),\n languages: { en, fr }\n })\n )\n .handler((event, context) => {\n return {}\n })\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/d80baa5c.b223a48e.js b/assets/js/d80baa5c.57db7023.js similarity index 98% rename from assets/js/d80baa5c.b223a48e.js rename to assets/js/d80baa5c.57db7023.js index 7f0351420..a30f65591 100644 --- a/assets/js/d80baa5c.b223a48e.js +++ b/assets/js/d80baa5c.57db7023.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9647],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),u=c(n),m=a,f=u["".concat(l,".").concat(m)]||u[m]||p[m]||o;return n?r.createElement(f,i(i({ref:t},d),{},{components:n})):r.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[u]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"Internal Storage",position:4},i=void 0,s={unversionedId:"writing-middlewares/internal-storage",id:"writing-middlewares/internal-storage",title:"Internal Storage",description:"The handler also contains an internal object that can be used to store values securely between middlewares that",source:"@site/docs/writing-middlewares/04-internal-storage.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/internal-storage",permalink:"/docs/writing-middlewares/internal-storage",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/04-internal-storage.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:4,frontMatter:{title:"Internal Storage",position:4},sidebar:"tutorialSidebar",previous:{title:"Inline Middlewares",permalink:"/docs/writing-middlewares/inline-middlewares"},next:{title:"Handle Timeouts",permalink:"/docs/writing-middlewares/timeouts"}},l={},c=[],d={toc:c},u="wrapper";function p(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"The handler also contains an ",(0,a.kt)("inlineCode",{parentName:"p"},"internal")," object that can be used to store values securely between middlewares that\nexpires when the event ends. To compliment this there is also a cache where middleware can store request promises.\nDuring ",(0,a.kt)("inlineCode",{parentName:"p"},"before")," these promises can be stored into ",(0,a.kt)("inlineCode",{parentName:"p"},"internal")," then resolved only when needed. This pattern is useful to\ntake advantage of the async nature of node especially when you have multiple middleware that require reaching out the\nexternal APIs."),(0,a.kt)("p",null,"Here is a middleware boilerplate using this pattern:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import { canPrefetch, getInternal, processCache } from '@middy/util'\n\nconst defaults = {\n fetchData: {}, // { internalKey: params }\n disablePrefetch: false,\n cacheKey: 'custom',\n cacheExpiry: -1,\n setToContext: false\n}\n\nconst customMiddleware = (opts = {}) => {\n const options = { ...defaults, ...opts }\n\n const fetch = () => {\n const values = {}\n // Start your custom fetch\n for (const internalKey of Object.keys(options.fetchData)) {\n values[internalKey] = fetch('...', options.fetchData[internalKey]).then(\n (res) => res.text()\n )\n }\n // End your custom fetch\n return values\n }\n\n if (canPrefetch(options)) {\n processCache(options, fetch)\n }\n\n const customMiddlewareBefore = async (request) => {\n const { value } = processCache(options, fetch, request)\n\n Object.assign(request.internal, value)\n if (options.setToContext) {\n const data = await getInternal(Object.keys(options.fetchData), request)\n Object.assign(request.context, data)\n }\n }\n\n return {\n before: customMiddlewareBefore\n }\n}\n\nexport default customMiddleware\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9647],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},u="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),u=c(n),m=a,f=u["".concat(l,".").concat(m)]||u[m]||p[m]||o;return n?r.createElement(f,i(i({ref:t},d),{},{components:n})):r.createElement(f,i({ref:t},d))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[u]="string"==typeof e?e:a,i[1]=s;for(var c=2;c{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const o={title:"Internal Storage",position:4},i=void 0,s={unversionedId:"writing-middlewares/internal-storage",id:"writing-middlewares/internal-storage",title:"Internal Storage",description:"The handler also contains an internal object that can be used to store values securely between middlewares that",source:"@site/docs/writing-middlewares/04-internal-storage.md",sourceDirName:"writing-middlewares",slug:"/writing-middlewares/internal-storage",permalink:"/docs/writing-middlewares/internal-storage",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/04-internal-storage.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:4,frontMatter:{title:"Internal Storage",position:4},sidebar:"tutorialSidebar",previous:{title:"Inline Middlewares",permalink:"/docs/writing-middlewares/inline-middlewares"},next:{title:"Handle Timeouts",permalink:"/docs/writing-middlewares/timeouts"}},l={},c=[],d={toc:c},u="wrapper";function p(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"The handler also contains an ",(0,a.kt)("inlineCode",{parentName:"p"},"internal")," object that can be used to store values securely between middlewares that\nexpires when the event ends. To compliment this there is also a cache where middleware can store request promises.\nDuring ",(0,a.kt)("inlineCode",{parentName:"p"},"before")," these promises can be stored into ",(0,a.kt)("inlineCode",{parentName:"p"},"internal")," then resolved only when needed. This pattern is useful to\ntake advantage of the async nature of node especially when you have multiple middleware that require reaching out the\nexternal APIs."),(0,a.kt)("p",null,"Here is a middleware boilerplate using this pattern:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import { canPrefetch, getInternal, processCache } from '@middy/util'\n\nconst defaults = {\n fetchData: {}, // { internalKey: params }\n disablePrefetch: false,\n cacheKey: 'custom',\n cacheExpiry: -1,\n setToContext: false\n}\n\nconst customMiddleware = (opts = {}) => {\n const options = { ...defaults, ...opts }\n\n const fetch = () => {\n const values = {}\n // Start your custom fetch\n for (const internalKey of Object.keys(options.fetchData)) {\n values[internalKey] = fetch('...', options.fetchData[internalKey]).then(\n (res) => res.text()\n )\n }\n // End your custom fetch\n return values\n }\n\n if (canPrefetch(options)) {\n processCache(options, fetch)\n }\n\n const customMiddlewareBefore = async (request) => {\n const { value } = processCache(options, fetch, request)\n\n Object.assign(request.internal, value)\n if (options.setToContext) {\n const data = await getInternal(Object.keys(options.fetchData), request)\n Object.assign(request.context, data)\n }\n }\n\n return {\n before: customMiddlewareBefore\n }\n}\n\nexport default customMiddleware\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/da0b5c8a.375e2780.js b/assets/js/da0b5c8a.774386b5.js similarity index 98% rename from assets/js/da0b5c8a.375e2780.js rename to assets/js/da0b5c8a.774386b5.js index 66648fe63..d43642a93 100644 --- a/assets/js/da0b5c8a.375e2780.js +++ b/assets/js/da0b5c8a.774386b5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7796],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function l(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var u=r.createContext({}),s=function(e){var t=r.useContext(u),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},c=function(e){var t=s(e.components);return r.createElement(u.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,u=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),p=s(n),m=a,f=p["".concat(u,".").concat(m)]||p[m]||d[m]||o;return n?r.createElement(f,l(l({ref:t},c),{},{components:n})):r.createElement(f,l({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,l=new Array(o);l[0]=m;var i={};for(var u in t)hasOwnProperty.call(t,u)&&(i[u]=t[u]);i.originalType=e,i[p]="string"==typeof e?e:a,l[1]=i;for(var s=2;s{n.d(t,{Z:()=>l});var r=n(7294),a=n(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:n,className:l}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(o.tabItem,l),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>k});var r=n(7462),a=n(7294),o=n(6010),l=n(2466),i=n(6550),u=n(1980),s=n(7392),c=n(12);function p(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function d(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??p(n);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u._X)(o),(0,a.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=d(e),[l,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[u,s]=f({queryString:n,groupId:r}),[p,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),y=(()=>{const e=u??p;return m({value:e,tabValues:o})?e:null})();(0,a.useLayoutEffect)((()=>{y&&i(y)}),[y]);return{selectedValue:l,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),s(e),b(e)}),[s,b,o]),tabValues:o}}var y=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function h(e){let{className:t,block:n,selectedValue:i,selectValue:u,tabValues:s}=e;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,l.o5)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),r=s[n].value;r!==i&&(p(t),u(r))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":n},t)},s.map((e=>{let{value:t,label:n,attributes:l}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:d},l,{className:(0,o.Z)("tabs__item",v.tabItem,l?.className,{"tabs__item--active":i===t})}),n??t)})))}function g(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function w(e){const t=b(e);return a.createElement("div",{className:(0,o.Z)("tabs-container",v.tabList)},a.createElement(h,(0,r.Z)({},e,t)),a.createElement(g,(0,r.Z)({},e,t)))}function k(e){const t=(0,y.Z)();return a.createElement(w,(0,r.Z)({key:String(t)},e))}},7837:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>f,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var r=n(7462),a=(n(7294),n(3905)),o=n(4866),l=n(5162);const i={title:"do-not-wait-for-empty-event-loop"},u=void 0,s={unversionedId:"middlewares/do-not-wait-for-empty-event-loop",id:"middlewares/do-not-wait-for-empty-event-loop",title:"do-not-wait-for-empty-event-loop",description:"This middleware sets context.callbackWaitsForEmptyEventLoop property to false.",source:"@site/docs/middlewares/do-not-wait-for-empty-event-loop.md",sourceDirName:"middlewares",slug:"/middlewares/do-not-wait-for-empty-event-loop",permalink:"/docs/middlewares/do-not-wait-for-empty-event-loop",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/do-not-wait-for-empty-event-loop.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"do-not-wait-for-empty-event-loop"},sidebar:"tutorialSidebar",previous:{title:"cloudwatch-metrics",permalink:"/docs/middlewares/cloudwatch-metrics"},next:{title:"dynamodb",permalink:"/docs/middlewares/dynamodb"}},c={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:p},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware sets ",(0,a.kt)("inlineCode",{parentName:"p"},"context.callbackWaitsForEmptyEventLoop")," property to ",(0,a.kt)("inlineCode",{parentName:"p"},"false"),".\nThis will prevent Lambda from timing out because of open database connections, etc."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/do-not-wait-for-empty-event-loop\n"))),(0,a.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/do-not-wait-for-empty-event-loop\n"))),(0,a.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/do-not-wait-for-empty-event-loop\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("p",null,"By default the middleware sets the ",(0,a.kt)("inlineCode",{parentName:"p"},"callbackWaitsForEmptyEventLoop")," property to ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," only in the ",(0,a.kt)("inlineCode",{parentName:"p"},"before")," phase,\nmeaning you can override it in handler to ",(0,a.kt)("inlineCode",{parentName:"p"},"true")," if needed. You can set it in all steps with the options:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"runOnBefore")," (defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"true"),") - sets property before running your handler"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"runOnAfter")," (defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"runOnError")," (defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport doNotWaitForEmptyEventLoop from '@middy/do-not-wait-for-empty-event-loop'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler.use(doNotWaitForEmptyEventLoop({runOnError: true}))\n\n// When Lambda runs the handler it gets context with\n// callbackWaitsForEmptyEventLoop property set to false\n\nhandler(event, context, (_, response) => {\n t.is(context.callbackWaitsForEmptyEventLoop,false)\n})\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7796],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function l(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var u=r.createContext({}),s=function(e){var t=r.useContext(u),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},c=function(e){var t=s(e.components);return r.createElement(u.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,u=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),p=s(n),m=a,f=p["".concat(u,".").concat(m)]||p[m]||d[m]||o;return n?r.createElement(f,l(l({ref:t},c),{},{components:n})):r.createElement(f,l({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,l=new Array(o);l[0]=m;var i={};for(var u in t)hasOwnProperty.call(t,u)&&(i[u]=t[u]);i.originalType=e,i[p]="string"==typeof e?e:a,l[1]=i;for(var s=2;s{n.d(t,{Z:()=>l});var r=n(7294),a=n(6010);const o={tabItem:"tabItem_Ymn6"};function l(e){let{children:t,hidden:n,className:l}=e;return r.createElement("div",{role:"tabpanel",className:(0,a.Z)(o.tabItem,l),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>k});var r=n(7462),a=n(7294),o=n(6010),l=n(2466),i=n(6550),u=n(1980),s=n(7392),c=n(12);function p(e){return function(e){return a.Children.map(e,(e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}function d(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??p(n);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.k6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u._X)(o),(0,a.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=d(e),[l,i]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[u,s]=f({queryString:n,groupId:r}),[p,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),y=(()=>{const e=u??p;return m({value:e,tabValues:o})?e:null})();(0,a.useLayoutEffect)((()=>{y&&i(y)}),[y]);return{selectedValue:l,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),s(e),b(e)}),[s,b,o]),tabValues:o}}var y=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function h(e){let{className:t,block:n,selectedValue:i,selectValue:u,tabValues:s}=e;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,l.o5)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),r=s[n].value;r!==i&&(p(t),u(r))},m=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return a.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":n},t)},s.map((e=>{let{value:t,label:n,attributes:l}=e;return a.createElement("li",(0,r.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:d},l,{className:(0,o.Z)("tabs__item",v.tabItem,l?.className,{"tabs__item--active":i===t})}),n??t)})))}function g(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return a.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r}))))}function w(e){const t=b(e);return a.createElement("div",{className:(0,o.Z)("tabs-container",v.tabList)},a.createElement(h,(0,r.Z)({},e,t)),a.createElement(g,(0,r.Z)({},e,t)))}function k(e){const t=(0,y.Z)();return a.createElement(w,(0,r.Z)({key:String(t)},e))}},7837:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>f,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var r=n(7462),a=(n(7294),n(3905)),o=n(4866),l=n(5162);const i={title:"do-not-wait-for-empty-event-loop"},u=void 0,s={unversionedId:"middlewares/do-not-wait-for-empty-event-loop",id:"middlewares/do-not-wait-for-empty-event-loop",title:"do-not-wait-for-empty-event-loop",description:"This middleware sets context.callbackWaitsForEmptyEventLoop property to false.",source:"@site/docs/middlewares/do-not-wait-for-empty-event-loop.md",sourceDirName:"middlewares",slug:"/middlewares/do-not-wait-for-empty-event-loop",permalink:"/docs/middlewares/do-not-wait-for-empty-event-loop",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/do-not-wait-for-empty-event-loop.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"do-not-wait-for-empty-event-loop"},sidebar:"tutorialSidebar",previous:{title:"cloudwatch-metrics",permalink:"/docs/middlewares/cloudwatch-metrics"},next:{title:"dynamodb",permalink:"/docs/middlewares/dynamodb"}},c={},p=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],d={toc:p},m="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This middleware sets ",(0,a.kt)("inlineCode",{parentName:"p"},"context.callbackWaitsForEmptyEventLoop")," property to ",(0,a.kt)("inlineCode",{parentName:"p"},"false"),".\nThis will prevent Lambda from timing out because of open database connections, etc."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)(o.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,a.kt)(l.Z,{value:"npm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/do-not-wait-for-empty-event-loop\n"))),(0,a.kt)(l.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/do-not-wait-for-empty-event-loop\n"))),(0,a.kt)(l.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/do-not-wait-for-empty-event-loop\n")))),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("p",null,"By default the middleware sets the ",(0,a.kt)("inlineCode",{parentName:"p"},"callbackWaitsForEmptyEventLoop")," property to ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," only in the ",(0,a.kt)("inlineCode",{parentName:"p"},"before")," phase,\nmeaning you can override it in handler to ",(0,a.kt)("inlineCode",{parentName:"p"},"true")," if needed. You can set it in all steps with the options:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"runOnBefore")," (defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"true"),") - sets property before running your handler"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"runOnAfter")," (defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"runOnError")," (defaults to ",(0,a.kt)("inlineCode",{parentName:"li"},"false"),")")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport doNotWaitForEmptyEventLoop from '@middy/do-not-wait-for-empty-event-loop'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler.use(doNotWaitForEmptyEventLoop({runOnError: true}))\n\n// When Lambda runs the handler it gets context with\n// callbackWaitsForEmptyEventLoop property set to false\n\nhandler(event, context, (_, response) => {\n t.is(context.callbackWaitsForEmptyEventLoop,false)\n})\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/dbc9373d.6d2ce6d8.js b/assets/js/dbc9373d.118163fc.js similarity index 98% rename from assets/js/dbc9373d.6d2ce6d8.js rename to assets/js/dbc9373d.118163fc.js index 167bb7070..554be9a0f 100644 --- a/assets/js/dbc9373d.6d2ce6d8.js +++ b/assets/js/dbc9373d.118163fc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9116],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function i(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),u=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},c=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,s=e.parentName,c=o(e,["components","mdxType","originalType","parentName"]),d=u(r),m=n,f=d["".concat(s,".").concat(m)]||d[m]||p[m]||l;return r?a.createElement(f,i(i({ref:t},c),{},{components:r})):a.createElement(f,i({ref:t},c))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,i=new Array(l);i[0]=m;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[d]="string"==typeof e?e:n,i[1]=o;for(var u=2;u{r.d(t,{Z:()=>i});var a=r(7294),n=r(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:r,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,i),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var a=r(7462),n=r(7294),l=r(6010),i=r(2466),o=r(6550),s=r(1980),u=r(7392),c=r(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??d(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const a=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,l=p(e),[i,o]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,u]=f({queryString:r,groupId:a}),[d,h]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,c.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),b=(()=>{const e=s??d;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{b&&o(b)}),[b]);return{selectedValue:i,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),h(e)}),[u,h,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:o,selectValue:s,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),p=e=>{const t=e.currentTarget,r=c.indexOf(t),a=u[r].value;a!==o&&(d(t),s(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=c.indexOf(e.currentTarget)+1;t=c[r]??c[0];break}case"ArrowLeft":{const r=c.indexOf(e.currentTarget)-1;t=c[r]??c[c.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:i}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",y.tabItem,i?.className,{"tabs__item--active":o===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:a}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function k(e){const t=h(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,a.Z)({},e,t)),n.createElement(g,(0,a.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return n.createElement(k,(0,a.Z)({key:String(t)},e))}},8406:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var a=r(7462),n=(r(7294),r(3905)),l=r(4866),i=r(5162);const o={title:"http-security-headers"},s=void 0,u={unversionedId:"middlewares/http-security-headers",id:"middlewares/http-security-headers",title:"http-security-headers",description:"Applies best practice security headers to responses. It's a simplified port of HelmetJS. See HelmetJS documentation for more details.",source:"@site/docs/middlewares/http-security-headers.md",sourceDirName:"middlewares",slug:"/middlewares/http-security-headers",permalink:"/docs/middlewares/http-security-headers",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-security-headers.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-security-headers"},sidebar:"tutorialSidebar",previous:{title:"http-response-serializer",permalink:"/docs/middlewares/http-response-serializer"},next:{title:"http-urlencode-body-parser",permalink:"/docs/middlewares/http-urlencode-body-parser"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...r}=e;return(0,n.kt)(m,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Applies best practice security headers to responses. It's a simplified port of HelmetJS. See ",(0,n.kt)("a",{parentName:"p",href:"https://helmetjs.github.io/"},"HelmetJS")," documentation for more details."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-security-headers\n"))),(0,n.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-security-headers\n"))),(0,n.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-security-headers\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"dnsPrefetchControl")," controls browser DNS prefetching"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"expectCt")," for handling Certificate Transparency (Future Feature)"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"frameguard")," to prevent clickjacking"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"hidePoweredBy")," to remove the Server/X-Powered-By header"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"hsts")," for HTTP Strict Transport Security"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"ieNoOpen")," sets X-Download-Options for IE8+"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"noSniff")," to keep clients from sniffing the MIME type"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"referrerPolicy")," to hide the Referer header"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"xssFilter")," adds some small XSS protections")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpSecurityHeaders from '@middy/http-security-headers'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler\n .use(httpSecurityHeaders())\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9116],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function i(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),u=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},c=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,s=e.parentName,c=o(e,["components","mdxType","originalType","parentName"]),d=u(r),m=n,f=d["".concat(s,".").concat(m)]||d[m]||p[m]||l;return r?a.createElement(f,i(i({ref:t},c),{},{components:r})):a.createElement(f,i({ref:t},c))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,i=new Array(l);i[0]=m;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[d]="string"==typeof e?e:n,i[1]=o;for(var u=2;u{r.d(t,{Z:()=>i});var a=r(7294),n=r(6010);const l={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:r,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,i),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var a=r(7462),n=r(7294),l=r(6010),i=r(2466),o=r(6550),s=r(1980),u=r(7392),c=r(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??d(r);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const a=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,s._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,l=p(e),[i,o]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[s,u]=f({queryString:r,groupId:a}),[d,h]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,c.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),b=(()=>{const e=s??d;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{b&&o(b)}),[b]);return{selectedValue:i,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),h(e)}),[u,h,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:o,selectValue:s,tabValues:u}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.o5)(),p=e=>{const t=e.currentTarget,r=c.indexOf(t),a=u[r].value;a!==o&&(d(t),s(a))},m=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const r=c.indexOf(e.currentTarget)+1;t=c[r]??c[0];break}case"ArrowLeft":{const r=c.indexOf(e.currentTarget)-1;t=c[r]??c[c.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},u.map((e=>{let{value:t,label:r,attributes:i}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>c.push(e),onKeyDown:m,onClick:p},i,{className:(0,l.Z)("tabs__item",y.tabItem,i?.className,{"tabs__item--active":o===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:a}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function k(e){const t=h(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,a.Z)({},e,t)),n.createElement(g,(0,a.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return n.createElement(k,(0,a.Z)({key:String(t)},e))}},8406:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var a=r(7462),n=(r(7294),r(3905)),l=r(4866),i=r(5162);const o={title:"http-security-headers"},s=void 0,u={unversionedId:"middlewares/http-security-headers",id:"middlewares/http-security-headers",title:"http-security-headers",description:"Applies best practice security headers to responses. It's a simplified port of HelmetJS. See HelmetJS documentation for more details.",source:"@site/docs/middlewares/http-security-headers.md",sourceDirName:"middlewares",slug:"/middlewares/http-security-headers",permalink:"/docs/middlewares/http-security-headers",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-security-headers.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-security-headers"},sidebar:"tutorialSidebar",previous:{title:"http-response-serializer",permalink:"/docs/middlewares/http-response-serializer"},next:{title:"http-urlencode-body-parser",permalink:"/docs/middlewares/http-urlencode-body-parser"}},c={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],p={toc:d},m="wrapper";function f(e){let{components:t,...r}=e;return(0,n.kt)(m,(0,a.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Applies best practice security headers to responses. It's a simplified port of HelmetJS. See ",(0,n.kt)("a",{parentName:"p",href:"https://helmetjs.github.io/"},"HelmetJS")," documentation for more details."),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(i.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-security-headers\n"))),(0,n.kt)(i.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-security-headers\n"))),(0,n.kt)(i.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-security-headers\n")))),(0,n.kt)("h2",{id:"options"},"Options"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"dnsPrefetchControl")," controls browser DNS prefetching"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"expectCt")," for handling Certificate Transparency (Future Feature)"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"frameguard")," to prevent clickjacking"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"hidePoweredBy")," to remove the Server/X-Powered-By header"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"hsts")," for HTTP Strict Transport Security"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"ieNoOpen")," sets X-Download-Options for IE8+"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"noSniff")," to keep clients from sniffing the MIME type"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"referrerPolicy")," to hide the Referer header"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("inlineCode",{parentName:"li"},"xssFilter")," adds some small XSS protections")),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpSecurityHeaders from '@middy/http-security-headers'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nhandler\n .use(httpSecurityHeaders())\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/e0fb88b0.6f5b2c7d.js b/assets/js/e0fb88b0.061c349c.js similarity index 99% rename from assets/js/e0fb88b0.6f5b2c7d.js rename to assets/js/e0fb88b0.061c349c.js index c72431473..3b307dd48 100644 --- a/assets/js/e0fb88b0.6f5b2c7d.js +++ b/assets/js/e0fb88b0.061c349c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4288],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>w});var r=a(7294);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function n(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t=0||(i[a]=e[a]);return i}(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(i[a]=e[a])}return i}var l=r.createContext({}),d=function(e){var t=r.useContext(l),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},m=function(e){var t=d(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var a=e.components,i=e.mdxType,n=e.originalType,l=e.parentName,m=s(e,["components","mdxType","originalType","parentName"]),p=d(a),u=i,w=p["".concat(l,".").concat(u)]||p[u]||c[u]||n;return a?r.createElement(w,o(o({ref:t},m),{},{components:a})):r.createElement(w,o({ref:t},m))}));function w(e,t){var a=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var n=a.length,o=new Array(n);o[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:i,o[1]=s;for(var d=2;d{a.r(t),a.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>c,frontMatter:()=>n,metadata:()=>s,toc:()=>d});var r=a(7462),i=(a(7294),a(3905));const n={title:"Third-party middlewares",sidebar_position:100},o=void 0,s={unversionedId:"middlewares/third-party",id:"middlewares/third-party",title:"Third-party middlewares",description:"The following middlewares are created and maintained outside this project. We cannot guarantee for its functionality.",source:"@site/docs/middlewares/third-party.md",sourceDirName:"middlewares",slug:"/middlewares/third-party",permalink:"/docs/middlewares/third-party",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/third-party.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:100,frontMatter:{title:"Third-party middlewares",sidebar_position:100},sidebar:"tutorialSidebar",previous:{title:"Official middlewares",permalink:"/docs/middlewares/intro"},next:{title:"appconfig",permalink:"/docs/middlewares/appconfig"}},l={},d=[{value:"Version 2.x - 4.x",id:"version-2x---4x",level:2},{value:"Version 2.x - 3.x",id:"version-2x---3x",level:2},{value:"Version 1.x",id:"version-1x",level:2}],m={toc:d},p="wrapper";function c(e){let{components:t,...a}=e;return(0,i.kt)(p,(0,r.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"The following middlewares are created and maintained outside this project. We cannot guarantee for its functionality.\nIf your middleware is missing, feel free to ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/pulls"},"open a Pull Request"),"."),(0,i.kt)("h2",{id:"version-2x---4x"},"Version 2.x - 4.x"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/getndazn/dazn-lambda-powertools"},"dazn-lambda-powertools"),": A collection of middlewares, AWS clients and helper libraries that make working with lambda easier."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-ajv"},"middy-ajv"),": AJV validator optimized for performance"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/serkan-ozal/middy-console-logger"},"middy-console-logger"),": Middleware for filtering logs printed over console logging methods. If the level of the console logging method is equal or bigger than configured level, the log is printed, Otherwise, it is ignored."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/serkan-ozal/middy-event-loop-tracer"},"middy-event-loop-tracer"),": Middleware for dumping active tasks with their stacktraces in the event queue just before AWS Lambda function timeouts. So you can understand what was going on in the function when timeout happens."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-idempotent"},"middy-idempotent"),": idempotency middleware for middy"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/serkan-ozal/middy-invocation"},"middy-invocation"),": Middleware for accessing current AWS Lambda invocation event and context from anywhere without need to passing event and context as arguments through your code.- ",(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-lesslog"},"middy-lesslog"),": Middleware for ",(0,i.kt)("inlineCode",{parentName:"li"},"lesslog"),", a teeny-tiny and severless-ready logging utility"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-jsonapi"},"middy-jsonapi"),": JSONAPI middleware for middy"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-lesslog"},"middy-lesslog"),": Middleware for ",(0,i.kt)("inlineCode",{parentName:"li"},"lesslog"),", a teeny-tiny and severless-ready logging utility"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/serkan-ozal/middy-profiler"},"middy-profiler"),": Middleware for profiling CPU on AWS Lambda during invocation and shows what methods/modules consume what percent of CPU time"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-rds"},"middy-rds"),": Creates RDS connection using ",(0,i.kt)("inlineCode",{parentName:"li"},"knex")," or ",(0,i.kt)("inlineCode",{parentName:"li"},"pg")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-recaptcha"},"middy-recaptcha"),": reCAPTCHA validation middleware"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-sparks-joi"},"middy-sparks-joi"),": Joi validator")),(0,i.kt)("h2",{id:"version-2x---3x"},"Version 2.x - 3.x"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("p",{parentName:"li"},(0,i.kt)("a",{parentName:"p",href:"https://github.com/awslabs/aws-lambda-powertools-typescript"},"aws-lambda-powertools-typescript"),": A suite of utilities for AWS Lambda Functions that makes structured logging, creating custom metrics asynchronously and tracing with AWS X-Ray easier"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/#capturing-lambda-context-info"},"logger"),": Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/#middy-middleware"},"metrics"),": Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/"},"parameters"),": The Parameters utility provides high-level functions to retrieve one or multiple parameter values from AWS Systems Manager Parameter Store, AWS Secrets Manager, AWS AppConfig, Amazon DynamoDB, or your own parameter store."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/#lambda-handler"},"tracer"),": Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions")))),(0,i.kt)("h2",{id:"version-1x"},"Version 1.x"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-redis"},"middy-redis"),": Redis connection middleware"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-extractor"},"middy-extractor"),": Extracts data from events using expressions"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@keboola/middy-error-logger"},"@keboola/middy-error-logger"),": middleware that catches thrown exceptions and rejected promises and logs them comprehensibly to the console"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@keboola/middy-event-validator"},"@keboola/middy-event-validator"),": Joi powered event validation middleware"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-reroute"},"middy-reroute"),": provides complex redirect, rewrite and proxying capabilities by simply placing a rules file into your S3 bucket"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middytohof"},"middytohof"),": Convert Middy middleware plugins to higher-order functions returning lambda handlers"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/wrap-ware"},"wrap-ware"),": A middleware wrapper which works with promises / async"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-middleware-warmup"},"middy-middleware-warmup"),": A middy plugin to help keep your Lambdas warm during Winter"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@sharecover-co/middy-aws-xray-tracing"},"@sharecover-co/middy-aws-xray-tracing"),": AWS X-Ray Tracing Middleware"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@sharecover-co/middy-http-response-serializer"},"@sharecover-co/middy-http-response-serializer"),": This middleware serializes the response to JSON and wraps it in a 200 HTTP response"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@seedrs/middyjs-middleware"},"@seedrs/middyjs-middleware"),": Collection of useful middlewares"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-autoproxyresponse"},"middy-autoproxyresponse"),": A middleware that lets you return simple JavaScript objects from Lambda function handlers and converts them into LAMBDA_PROXY responses"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-middleware-jwt-auth"},"jwt-auth"),": JSON web token authorization middleware based on ",(0,i.kt)("inlineCode",{parentName:"li"},"express-jwt")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-mongoose-connector"},"middy-mongoose-connector"),": MongoDB connection middleware for ",(0,i.kt)("a",{parentName:"li",href:"https://mongoosejs.com/"},"mongoose.js")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@ematipico/middy-request-response"},"@ematipico/middy-request-response"),": a middleware that creates a pair of request/response objects"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@marcosantonocito/middy-cognito-permission"},"@marcosantonocito/middy-cognito-permission"),": Authorization and roles permission management for the Middy framework that works with Amazon Cognito"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-env"},"middy-env"),": Fetch, validate and type cast environment variables"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/Eomm/sqs-json-body-parser"},"sqs-json-body-parser"),": Parse the SQS body to JSON"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-lesslog/v/legacy"},"middy-lesslog"),": Middleware for ",(0,i.kt)("inlineCode",{parentName:"li"},"lesslog"),", a teeny-tiny and severless-ready logging utility")))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4288],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>w});var r=a(7294);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function n(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t=0||(i[a]=e[a]);return i}(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(i[a]=e[a])}return i}var l=r.createContext({}),d=function(e){var t=r.useContext(l),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},m=function(e){var t=d(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var a=e.components,i=e.mdxType,n=e.originalType,l=e.parentName,m=s(e,["components","mdxType","originalType","parentName"]),p=d(a),u=i,w=p["".concat(l,".").concat(u)]||p[u]||c[u]||n;return a?r.createElement(w,o(o({ref:t},m),{},{components:a})):r.createElement(w,o({ref:t},m))}));function w(e,t){var a=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var n=a.length,o=new Array(n);o[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:i,o[1]=s;for(var d=2;d{a.r(t),a.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>c,frontMatter:()=>n,metadata:()=>s,toc:()=>d});var r=a(7462),i=(a(7294),a(3905));const n={title:"Third-party middlewares",sidebar_position:100},o=void 0,s={unversionedId:"middlewares/third-party",id:"middlewares/third-party",title:"Third-party middlewares",description:"The following middlewares are created and maintained outside this project. We cannot guarantee for its functionality.",source:"@site/docs/middlewares/third-party.md",sourceDirName:"middlewares",slug:"/middlewares/third-party",permalink:"/docs/middlewares/third-party",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/third-party.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:100,frontMatter:{title:"Third-party middlewares",sidebar_position:100},sidebar:"tutorialSidebar",previous:{title:"Official middlewares",permalink:"/docs/middlewares/intro"},next:{title:"appconfig",permalink:"/docs/middlewares/appconfig"}},l={},d=[{value:"Version 2.x - 4.x",id:"version-2x---4x",level:2},{value:"Version 2.x - 3.x",id:"version-2x---3x",level:2},{value:"Version 1.x",id:"version-1x",level:2}],m={toc:d},p="wrapper";function c(e){let{components:t,...a}=e;return(0,i.kt)(p,(0,r.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"The following middlewares are created and maintained outside this project. We cannot guarantee for its functionality.\nIf your middleware is missing, feel free to ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/middyjs/middy/pulls"},"open a Pull Request"),"."),(0,i.kt)("h2",{id:"version-2x---4x"},"Version 2.x - 4.x"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/getndazn/dazn-lambda-powertools"},"dazn-lambda-powertools"),": A collection of middlewares, AWS clients and helper libraries that make working with lambda easier."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-ajv"},"middy-ajv"),": AJV validator optimized for performance"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/serkan-ozal/middy-console-logger"},"middy-console-logger"),": Middleware for filtering logs printed over console logging methods. If the level of the console logging method is equal or bigger than configured level, the log is printed, Otherwise, it is ignored."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/serkan-ozal/middy-event-loop-tracer"},"middy-event-loop-tracer"),": Middleware for dumping active tasks with their stacktraces in the event queue just before AWS Lambda function timeouts. So you can understand what was going on in the function when timeout happens."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-idempotent"},"middy-idempotent"),": idempotency middleware for middy"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/serkan-ozal/middy-invocation"},"middy-invocation"),": Middleware for accessing current AWS Lambda invocation event and context from anywhere without need to passing event and context as arguments through your code.- ",(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-lesslog"},"middy-lesslog"),": Middleware for ",(0,i.kt)("inlineCode",{parentName:"li"},"lesslog"),", a teeny-tiny and severless-ready logging utility"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-jsonapi"},"middy-jsonapi"),": JSONAPI middleware for middy"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-lesslog"},"middy-lesslog"),": Middleware for ",(0,i.kt)("inlineCode",{parentName:"li"},"lesslog"),", a teeny-tiny and severless-ready logging utility"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/serkan-ozal/middy-profiler"},"middy-profiler"),": Middleware for profiling CPU on AWS Lambda during invocation and shows what methods/modules consume what percent of CPU time"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-rds"},"middy-rds"),": Creates RDS connection using ",(0,i.kt)("inlineCode",{parentName:"li"},"knex")," or ",(0,i.kt)("inlineCode",{parentName:"li"},"pg")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-recaptcha"},"middy-recaptcha"),": reCAPTCHA validation middleware"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-sparks-joi"},"middy-sparks-joi"),": Joi validator")),(0,i.kt)("h2",{id:"version-2x---3x"},"Version 2.x - 3.x"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("p",{parentName:"li"},(0,i.kt)("a",{parentName:"p",href:"https://github.com/awslabs/aws-lambda-powertools-typescript"},"aws-lambda-powertools-typescript"),": A suite of utilities for AWS Lambda Functions that makes structured logging, creating custom metrics asynchronously and tracing with AWS X-Ray easier"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/#capturing-lambda-context-info"},"logger"),": Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/#middy-middleware"},"metrics"),": Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/"},"parameters"),": The Parameters utility provides high-level functions to retrieve one or multiple parameter values from AWS Systems Manager Parameter Store, AWS Secrets Manager, AWS AppConfig, Amazon DynamoDB, or your own parameter store."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/#lambda-handler"},"tracer"),": Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions")))),(0,i.kt)("h2",{id:"version-1x"},"Version 1.x"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-redis"},"middy-redis"),": Redis connection middleware"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-extractor"},"middy-extractor"),": Extracts data from events using expressions"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@keboola/middy-error-logger"},"@keboola/middy-error-logger"),": middleware that catches thrown exceptions and rejected promises and logs them comprehensibly to the console"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@keboola/middy-event-validator"},"@keboola/middy-event-validator"),": Joi powered event validation middleware"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-reroute"},"middy-reroute"),": provides complex redirect, rewrite and proxying capabilities by simply placing a rules file into your S3 bucket"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middytohof"},"middytohof"),": Convert Middy middleware plugins to higher-order functions returning lambda handlers"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/wrap-ware"},"wrap-ware"),": A middleware wrapper which works with promises / async"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-middleware-warmup"},"middy-middleware-warmup"),": A middy plugin to help keep your Lambdas warm during Winter"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@sharecover-co/middy-aws-xray-tracing"},"@sharecover-co/middy-aws-xray-tracing"),": AWS X-Ray Tracing Middleware"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@sharecover-co/middy-http-response-serializer"},"@sharecover-co/middy-http-response-serializer"),": This middleware serializes the response to JSON and wraps it in a 200 HTTP response"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@seedrs/middyjs-middleware"},"@seedrs/middyjs-middleware"),": Collection of useful middlewares"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-autoproxyresponse"},"middy-autoproxyresponse"),": A middleware that lets you return simple JavaScript objects from Lambda function handlers and converts them into LAMBDA_PROXY responses"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-middleware-jwt-auth"},"jwt-auth"),": JSON web token authorization middleware based on ",(0,i.kt)("inlineCode",{parentName:"li"},"express-jwt")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-mongoose-connector"},"middy-mongoose-connector"),": MongoDB connection middleware for ",(0,i.kt)("a",{parentName:"li",href:"https://mongoosejs.com/"},"mongoose.js")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@ematipico/middy-request-response"},"@ematipico/middy-request-response"),": a middleware that creates a pair of request/response objects"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/@marcosantonocito/middy-cognito-permission"},"@marcosantonocito/middy-cognito-permission"),": Authorization and roles permission management for the Middy framework that works with Amazon Cognito"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-env"},"middy-env"),": Fetch, validate and type cast environment variables"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://github.com/Eomm/sqs-json-body-parser"},"sqs-json-body-parser"),": Parse the SQS body to JSON"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"https://www.npmjs.com/package/middy-lesslog/v/legacy"},"middy-lesslog"),": Middleware for ",(0,i.kt)("inlineCode",{parentName:"li"},"lesslog"),", a teeny-tiny and severless-ready logging utility")))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/e1c77d88.2323bc8c.js b/assets/js/e1c77d88.786bbaa0.js similarity index 96% rename from assets/js/e1c77d88.2323bc8c.js rename to assets/js/e1c77d88.786bbaa0.js index 78f0abf1f..933648886 100644 --- a/assets/js/e1c77d88.2323bc8c.js +++ b/assets/js/e1c77d88.786bbaa0.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6388],{3905:(e,r,t)=>{t.d(r,{Zo:()=>c,kt:()=>f});var n=t(7294);function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function a(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var s=n.createContext({}),p=function(e){var r=n.useContext(s),t=r;return e&&(t="function"==typeof e?e(r):i(i({},r),e)),t},c=function(e){var r=p(e.components);return n.createElement(s.Provider,{value:r},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var r=e.children;return n.createElement(n.Fragment,{},r)}},u=n.forwardRef((function(e,r){var t=e.components,o=e.mdxType,a=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),d=p(t),u=o,f=d["".concat(s,".").concat(u)]||d[u]||m[u]||a;return t?n.createElement(f,i(i({ref:r},c),{},{components:t})):n.createElement(f,i({ref:r},c))}));function f(e,r){var t=arguments,o=r&&r.mdxType;if("string"==typeof e||o){var a=t.length,i=new Array(a);i[0]=u;var l={};for(var s in r)hasOwnProperty.call(r,s)&&(l[s]=r[s]);l.originalType=e,l[d]="string"==typeof e?e:o,i[1]=l;for(var p=2;p{t.r(r),t.d(r,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>l,toc:()=>p});var n=t(7462),o=(t(7294),t(3905));const a={title:"Apollo Server"},i=void 0,l={unversionedId:"integrations/apollo-server",id:"integrations/apollo-server",title:"Apollo Server",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/apollo-server.md",sourceDirName:"integrations",slug:"/integrations/apollo-server",permalink:"/docs/integrations/apollo-server",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/apollo-server.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Apollo Server"},sidebar:"tutorialSidebar",previous:{title:"AWS Relational Database Service (RDS)",permalink:"/docs/integrations/RDS"},next:{title:"Powertools for AWS Lambda",permalink:"/docs/integrations/lambda-powertools"}},s={},p=[],c={toc:p},d="wrapper";function m(e){let{components:r,...t}=e;return(0,o.kt)(d,(0,n.Z)({},c,t,{components:r,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { ApolloServer, gql } from 'apollo-server-lambda'\nimport { buildFederatedSchema } from '@apollo/federation'\nimport { resolvers } from './graphql/resolvers.js'\nimport { graphqlFileToStr } from './graphql/schema.js'\n\nconst graphQL = new ApolloServer({\n schema: buildFederatedSchema({\n typeDefs: gql(graphqlFileToStr),\n resolvers\n })\n})\n\n// Do not use: `@middy/http-json-body-parser` it is already handled within apollo\nexport const handler = middy(graphQL.createHandler())\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6388],{3905:(e,r,t)=>{t.d(r,{Zo:()=>c,kt:()=>f});var n=t(7294);function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function a(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var s=n.createContext({}),p=function(e){var r=n.useContext(s),t=r;return e&&(t="function"==typeof e?e(r):i(i({},r),e)),t},c=function(e){var r=p(e.components);return n.createElement(s.Provider,{value:r},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var r=e.children;return n.createElement(n.Fragment,{},r)}},u=n.forwardRef((function(e,r){var t=e.components,o=e.mdxType,a=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),d=p(t),u=o,f=d["".concat(s,".").concat(u)]||d[u]||m[u]||a;return t?n.createElement(f,i(i({ref:r},c),{},{components:t})):n.createElement(f,i({ref:r},c))}));function f(e,r){var t=arguments,o=r&&r.mdxType;if("string"==typeof e||o){var a=t.length,i=new Array(a);i[0]=u;var l={};for(var s in r)hasOwnProperty.call(r,s)&&(l[s]=r[s]);l.originalType=e,l[d]="string"==typeof e?e:o,i[1]=l;for(var p=2;p{t.r(r),t.d(r,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>l,toc:()=>p});var n=t(7462),o=(t(7294),t(3905));const a={title:"Apollo Server"},i=void 0,l={unversionedId:"integrations/apollo-server",id:"integrations/apollo-server",title:"Apollo Server",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/integrations/apollo-server.md",sourceDirName:"integrations",slug:"/integrations/apollo-server",permalink:"/docs/integrations/apollo-server",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/apollo-server.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Apollo Server"},sidebar:"tutorialSidebar",previous:{title:"AWS Relational Database Service (RDS)",permalink:"/docs/integrations/RDS"},next:{title:"Powertools for AWS Lambda",permalink:"/docs/integrations/lambda-powertools"}},s={},p=[],c={toc:p},d="wrapper";function m(e){let{components:r,...t}=e;return(0,o.kt)(d,(0,n.Z)({},c,t,{components:r,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { ApolloServer, gql } from 'apollo-server-lambda'\nimport { buildFederatedSchema } from '@apollo/federation'\nimport { resolvers } from './graphql/resolvers.js'\nimport { graphqlFileToStr } from './graphql/schema.js'\n\nconst graphQL = new ApolloServer({\n schema: buildFederatedSchema({\n typeDefs: gql(graphqlFileToStr),\n resolvers\n })\n})\n\n// Do not use: `@middy/http-json-body-parser` it is already handled within apollo\nexport const handler = middy(graphQL.createHandler())\n")))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/ea2a30f2.292cba21.js b/assets/js/ea2a30f2.6c3579c2.js similarity index 97% rename from assets/js/ea2a30f2.292cba21.js rename to assets/js/ea2a30f2.6c3579c2.js index 9e9e72bc7..cd0fa65b2 100644 --- a/assets/js/ea2a30f2.292cba21.js +++ b/assets/js/ea2a30f2.6c3579c2.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[527],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var l=r.createContext({}),p=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},c=function(e){var t=p(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,o=e.originalType,l=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),d=p(n),m=i,f=d["".concat(l,".").concat(m)]||d[m]||u[m]||o;return n?r.createElement(f,a(a({ref:t},c),{},{components:n})):r.createElement(f,a({ref:t},c))}));function f(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=n.length,a=new Array(o);a[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:i,a[1]=s;for(var p=2;p{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>a,default:()=>u,frontMatter:()=>o,metadata:()=>s,toc:()=>p});var r=n(7462),i=(n(7294),n(3905));const o={title:"Testing",position:5},a=void 0,s={unversionedId:"intro/testing",id:"intro/testing",title:"Testing",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/intro/06-testing.md",sourceDirName:"intro",slug:"/intro/testing",permalink:"/docs/intro/testing",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-testing.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:6,frontMatter:{title:"Testing",position:5},sidebar:"tutorialSidebar",previous:{title:"Streamify Response",permalink:"/docs/intro/streamify-response"},next:{title:"Use with TypeScript",permalink:"/docs/intro/typescript"}},l={},p=[],c={toc:p},d="wrapper";function u(e){let{components:t,...n}=e;return(0,i.kt)(d,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,i.kt)("p",null,"As of Middy v3, by default it will trigger an Abort signal shortly before a lambda times out to allow your handler to safely stop up and middleware to clean before the lambda terminates.\nWhen writing tests for lambda handlers wrapped with middy you'll need to account for this. There are a few approaches:"),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},"Set ",(0,i.kt)("inlineCode",{parentName:"li"},"middy(handler, { timeoutEarlyInMillis: 0 })")," to alternatively disable the creation of the AbortController."),(0,i.kt)("li",{parentName:"ol"},"Set ",(0,i.kt)("inlineCode",{parentName:"li"},"middy(handler, { timeoutEarlyResponse: () => {} })")," to disable the timeout error from being thrown using a no-op."),(0,i.kt)("li",{parentName:"ol"},"Set ",(0,i.kt)("inlineCode",{parentName:"li"},"context.getRemainingTimeInMillis = falsy")," to disable the creation of the AbortController.")),(0,i.kt)("p",null,"When using Middy ",(0,i.kt)("inlineCode",{parentName:"p"},"cache")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"cacheExpiry")," in unit tests for functions in your code, it is important to conditionally disable them for test cases by setting both Middy ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," fields as follows:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"{\n cache: false,\n cacheExpiry: 0,\n ...\n}\n")),(0,i.kt)("p",null,"Failing to do so may make the tests end with unfinished worker processes. Although they may still succeed, this can cause issues and timeout errors, namely in CI/CD environments."),(0,i.kt)("p",null,"An example of a message generated by Jest unit tests and which signals the need for this is as follows:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[527],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var l=r.createContext({}),p=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},c=function(e){var t=p(e.components);return r.createElement(l.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,o=e.originalType,l=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),d=p(n),m=i,f=d["".concat(l,".").concat(m)]||d[m]||u[m]||o;return n?r.createElement(f,a(a({ref:t},c),{},{components:n})):r.createElement(f,a({ref:t},c))}));function f(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=n.length,a=new Array(o);a[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:i,a[1]=s;for(var p=2;p{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>a,default:()=>u,frontMatter:()=>o,metadata:()=>s,toc:()=>p});var r=n(7462),i=(n(7294),n(3905));const o={title:"Testing",position:5},a=void 0,s={unversionedId:"intro/testing",id:"intro/testing",title:"Testing",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/intro/06-testing.md",sourceDirName:"intro",slug:"/intro/testing",permalink:"/docs/intro/testing",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-testing.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:6,frontMatter:{title:"Testing",position:5},sidebar:"tutorialSidebar",previous:{title:"Streamify Response",permalink:"/docs/intro/streamify-response"},next:{title:"Use with TypeScript",permalink:"/docs/intro/typescript"}},l={},p=[],c={toc:p},d="wrapper";function u(e){let{components:t,...n}=e;return(0,i.kt)(d,(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,i.kt)("p",null,"As of Middy v3, by default it will trigger an Abort signal shortly before a lambda times out to allow your handler to safely stop up and middleware to clean before the lambda terminates.\nWhen writing tests for lambda handlers wrapped with middy you'll need to account for this. There are a few approaches:"),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},"Set ",(0,i.kt)("inlineCode",{parentName:"li"},"middy(handler, { timeoutEarlyInMillis: 0 })")," to alternatively disable the creation of the AbortController."),(0,i.kt)("li",{parentName:"ol"},"Set ",(0,i.kt)("inlineCode",{parentName:"li"},"middy(handler, { timeoutEarlyResponse: () => {} })")," to disable the timeout error from being thrown using a no-op."),(0,i.kt)("li",{parentName:"ol"},"Set ",(0,i.kt)("inlineCode",{parentName:"li"},"context.getRemainingTimeInMillis = falsy")," to disable the creation of the AbortController.")),(0,i.kt)("p",null,"When using Middy ",(0,i.kt)("inlineCode",{parentName:"p"},"cache")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"cacheExpiry")," in unit tests for functions in your code, it is important to conditionally disable them for test cases by setting both Middy ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," fields as follows:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"{\n cache: false,\n cacheExpiry: 0,\n ...\n}\n")),(0,i.kt)("p",null,"Failing to do so may make the tests end with unfinished worker processes. Although they may still succeed, this can cause issues and timeout errors, namely in CI/CD environments."),(0,i.kt)("p",null,"An example of a message generated by Jest unit tests and which signals the need for this is as follows:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/ec96ff11.074f2a6a.js b/assets/js/ec96ff11.d9381704.js similarity index 96% rename from assets/js/ec96ff11.074f2a6a.js rename to assets/js/ec96ff11.d9381704.js index 3c3651a2b..5216c68d6 100644 --- a/assets/js/ec96ff11.074f2a6a.js +++ b/assets/js/ec96ff11.d9381704.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7276],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var s=n.createContext({}),l=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},p=function(e){var t=l(e.components);return n.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,o=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),u=l(r),f=i,m=u["".concat(s,".").concat(f)]||u[f]||d[f]||o;return r?n.createElement(m,a(a({ref:t},p),{},{components:r})):n.createElement(m,a({ref:t},p))}));function m(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=r.length,a=new Array(o);a[0]=f;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[u]="string"==typeof e?e:i,a[1]=c;for(var l=2;l{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>d,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var n=r(7462),i=(r(7294),r(3905));const o={title:"Utilities"},a=void 0,c={unversionedId:"intro/utilities",id:"intro/utilities",title:"Utilities",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/intro/08-utilities.md",sourceDirName:"intro",slug:"/intro/utilities",permalink:"/docs/intro/utilities",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-utilities.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:8,frontMatter:{title:"Utilities"},sidebar:"tutorialSidebar",previous:{title:"Influence",permalink:"/docs/intro/influence"},next:{title:"Release Cycle",permalink:"/docs/intro/release-cycle"}},s={},l=[],p={toc:l},u="wrapper";function d(e){let{components:t,...r}=e;return(0,i.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7276],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>m});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var s=n.createContext({}),l=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},p=function(e){var t=l(e.components);return n.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,o=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),u=l(r),f=i,m=u["".concat(s,".").concat(f)]||u[f]||d[f]||o;return r?n.createElement(m,a(a({ref:t},p),{},{components:r})):n.createElement(m,a({ref:t},p))}));function m(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=r.length,a=new Array(o);a[0]=f;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[u]="string"==typeof e?e:i,a[1]=c;for(var l=2;l{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>d,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var n=r(7462),i=(r(7294),r(3905));const o={title:"Utilities"},a=void 0,c={unversionedId:"intro/utilities",id:"intro/utilities",title:"Utilities",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/intro/08-utilities.md",sourceDirName:"intro",slug:"/intro/utilities",permalink:"/docs/intro/utilities",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-utilities.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:8,frontMatter:{title:"Utilities"},sidebar:"tutorialSidebar",previous:{title:"Influence",permalink:"/docs/intro/influence"},next:{title:"Release Cycle",permalink:"/docs/intro/release-cycle"}},s={},l=[],p={toc:l},u="wrapper";function d(e){let{components:t,...r}=e;return(0,i.kt)(u,(0,n.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/ecbeea21.49c4574d.js b/assets/js/ecbeea21.650067f9.js similarity index 98% rename from assets/js/ecbeea21.49c4574d.js rename to assets/js/ecbeea21.650067f9.js index 2a94cf353..8b29677fc 100644 --- a/assets/js/ecbeea21.49c4574d.js +++ b/assets/js/ecbeea21.650067f9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9310],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>h});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var d=r.createContext({}),l=function(e){var t=r.useContext(d),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(d.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,i=e.originalType,d=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=l(n),u=a,h=m["".concat(d,".").concat(u)]||m[u]||c[u]||i;return n?r.createElement(h,o(o({ref:t},p),{},{components:n})):r.createElement(h,o({ref:t},p))}));function h(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=n.length,o=new Array(i);o[0]=u;var s={};for(var d in t)hasOwnProperty.call(t,d)&&(s[d]=t[d]);s.originalType=e,s[m]="string"==typeof e?e:a,o[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const i={sidebar_position:1,title:"Introduction",slug:"/"},o=void 0,s={unversionedId:"intro/intro",id:"intro/intro",title:"Introduction",description:"What is middy",source:"@site/docs/intro/01-intro.md",sourceDirName:"intro",slug:"/",permalink:"/docs/",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:1,frontMatter:{sidebar_position:1,title:"Introduction",slug:"/"},sidebar:"tutorialSidebar",previous:{title:"Intro to Middy",permalink:"/docs/category/intro-to-middy"},next:{title:"Getting started",permalink:"/docs/intro/getting-started"}},d={},l=[{value:"What is middy",id:"what-is-middy",level:2},{value:"A quick example",id:"a-quick-example",level:2},{value:"Why?",id:"why",level:2}],p={toc:l},m="wrapper";function c(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h2",{id:"what-is-middy"},"What is middy"),(0,a.kt)("p",null,"Middy is a very simple ",(0,a.kt)("strong",{parentName:"p"},"middleware engine")," that allows you to simplify your ",(0,a.kt)("strong",{parentName:"p"},"AWS Lambda")," code when using ",(0,a.kt)("strong",{parentName:"p"},"Node.js"),"."),(0,a.kt)("p",null,"If you have used web frameworks like Express, then you will be familiar with the concepts adopted in Middy and you will be able to get started very quickly."),(0,a.kt)("p",null,"A middleware engine allows you to focus on the strict business logic of your Lambda and then attach additional common elements like authentication, authorization, validation, serialization, etc. in a modular and reusable way by decorating the main business logic."),(0,a.kt)("h2",{id:"a-quick-example"},"A quick example"),(0,a.kt)("p",null,"Code is better than 10,000 words, so let's jump into an example."),(0,a.kt)("p",null,"Let's assume you are building a JSON API to process a payment:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript",metastring:'title="handler.js"',title:'"handler.js"'},"// import core\nimport middy from '@middy/core' // esm Node v14+\n//const middy = require('@middy/core') // commonjs Node v12+\n\n// import some middlewares\nimport jsonBodyParser from '@middy/http-json-body-parser'\nimport httpErrorHandler from '@middy/http-error-handler'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\n// This is your common handler, in no way different than what you are used to doing every day in AWS Lambda\nconst lambdaHandler = async (event, context) => {\n // we don't need to deserialize the body ourself as a middleware will be used to do that\n const { creditCardNumber, expiryMonth, expiryYear, cvc, nameOnCard, amount } =\n event.body\n\n // do stuff with this data\n // ...\n\n const response = { result: 'success', message: 'payment processed correctly' }\n return { statusCode: 200, body: JSON.stringify(response) }\n}\n\n// Notice that in the handler you only added base business logic (no deserialization,\n// validation or error handler), we will add the rest with middlewares\n\nconst schema = {\n type: 'object',\n properties: {\n body: {\n type: 'object',\n properties: {\n creditCardNumber: {\n type: 'string',\n minLength: 12,\n maxLength: 19,\n pattern: '\\\\d+'\n },\n expiryMonth: { type: 'integer', minimum: 1, maximum: 12 },\n expiryYear: { type: 'integer', minimum: 2017, maximum: 2027 },\n cvc: { type: 'string', minLength: 3, maxLength: 4, pattern: '\\\\d+' },\n nameOnCard: { type: 'string' },\n amount: { type: 'number' }\n },\n required: ['creditCardNumber'] // Insert here all required event properties\n }\n }\n}\n\n// Let's \"middyfy\" our handler, then we will be able to attach middlewares to it\nconst handler = middy()\n .use(jsonBodyParser()) // parses the request body when it's a JSON and converts it to an object\n .use(validator({ eventSchema: transpileSchema(schema) })) // validates the input\n .use(httpErrorHandler()) // handles common http errors and returns proper responses\n .handler(lambdaHandler)\n")),(0,a.kt)("h2",{id:"why"},"Why?"),(0,a.kt)("p",null,"One of the main strengths of serverless and AWS Lambda is that, from a developer\nperspective, your focus is mostly shifted toward implementing business logic."),(0,a.kt)("p",null,"Anyway, when you are writing a handler, you still have to deal with some common technical concerns\noutside business logic, like input parsing and validation, output serialization,\nerror handling, etc."),(0,a.kt)("p",null,"Very often, all this necessary code ends up polluting the pure business logic code in\nyour handlers, making the code harder to read and to maintain."),(0,a.kt)("p",null,"In other contexts, like generic web frameworks (",(0,a.kt)("a",{parentName:"p",href:"http://fastify.io"},"fastify"),", ",(0,a.kt)("a",{parentName:"p",href:"https://hapijs.com/"},"hapi"),", ",(0,a.kt)("a",{parentName:"p",href:"http://expressjs.com/"},"express"),", etc.), this\nproblem has been solved using the ",(0,a.kt)("a",{parentName:"p",href:"https://www.packtpub.com/mapt/book/web_development/9781783287314/4/ch04lvl1sec33/middleware"},"middleware pattern"),"."),(0,a.kt)("p",null,"This pattern allows developers to isolate these common technical concerns into\n",(0,a.kt)("em",{parentName:"p"},'"steps"')," that ",(0,a.kt)("em",{parentName:"p"},"decorate")," the main business logic code.\nMiddleware functions are generally written as independent modules and then plugged into\nthe application in a configuration step, thus not polluting the main business logic\ncode that remains clean, readable, and easy to maintain."),(0,a.kt)("p",null,"Since we couldn't find a similar approach for AWS Lambda handlers, we decided\nto create middy, our own middleware framework for serverless in AWS land."))}c.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9310],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>h});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var d=r.createContext({}),l=function(e){var t=r.useContext(d),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(d.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,i=e.originalType,d=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=l(n),u=a,h=m["".concat(d,".").concat(u)]||m[u]||c[u]||i;return n?r.createElement(h,o(o({ref:t},p),{},{components:n})):r.createElement(h,o({ref:t},p))}));function h(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=n.length,o=new Array(i);o[0]=u;var s={};for(var d in t)hasOwnProperty.call(t,d)&&(s[d]=t[d]);s.originalType=e,s[m]="string"==typeof e?e:a,o[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const i={sidebar_position:1,title:"Introduction",slug:"/"},o=void 0,s={unversionedId:"intro/intro",id:"intro/intro",title:"Introduction",description:"What is middy",source:"@site/docs/intro/01-intro.md",sourceDirName:"intro",slug:"/",permalink:"/docs/",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/01-intro.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:1,frontMatter:{sidebar_position:1,title:"Introduction",slug:"/"},sidebar:"tutorialSidebar",previous:{title:"Intro to Middy",permalink:"/docs/category/intro-to-middy"},next:{title:"Getting started",permalink:"/docs/intro/getting-started"}},d={},l=[{value:"What is middy",id:"what-is-middy",level:2},{value:"A quick example",id:"a-quick-example",level:2},{value:"Why?",id:"why",level:2}],p={toc:l},m="wrapper";function c(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h2",{id:"what-is-middy"},"What is middy"),(0,a.kt)("p",null,"Middy is a very simple ",(0,a.kt)("strong",{parentName:"p"},"middleware engine")," that allows you to simplify your ",(0,a.kt)("strong",{parentName:"p"},"AWS Lambda")," code when using ",(0,a.kt)("strong",{parentName:"p"},"Node.js"),"."),(0,a.kt)("p",null,"If you have used web frameworks like Express, then you will be familiar with the concepts adopted in Middy and you will be able to get started very quickly."),(0,a.kt)("p",null,"A middleware engine allows you to focus on the strict business logic of your Lambda and then attach additional common elements like authentication, authorization, validation, serialization, etc. in a modular and reusable way by decorating the main business logic."),(0,a.kt)("h2",{id:"a-quick-example"},"A quick example"),(0,a.kt)("p",null,"Code is better than 10,000 words, so let's jump into an example."),(0,a.kt)("p",null,"Let's assume you are building a JSON API to process a payment:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript",metastring:'title="handler.js"',title:'"handler.js"'},"// import core\nimport middy from '@middy/core' // esm Node v14+\n//const middy = require('@middy/core') // commonjs Node v12+\n\n// import some middlewares\nimport jsonBodyParser from '@middy/http-json-body-parser'\nimport httpErrorHandler from '@middy/http-error-handler'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\n// This is your common handler, in no way different than what you are used to doing every day in AWS Lambda\nconst lambdaHandler = async (event, context) => {\n // we don't need to deserialize the body ourself as a middleware will be used to do that\n const { creditCardNumber, expiryMonth, expiryYear, cvc, nameOnCard, amount } =\n event.body\n\n // do stuff with this data\n // ...\n\n const response = { result: 'success', message: 'payment processed correctly' }\n return { statusCode: 200, body: JSON.stringify(response) }\n}\n\n// Notice that in the handler you only added base business logic (no deserialization,\n// validation or error handler), we will add the rest with middlewares\n\nconst schema = {\n type: 'object',\n properties: {\n body: {\n type: 'object',\n properties: {\n creditCardNumber: {\n type: 'string',\n minLength: 12,\n maxLength: 19,\n pattern: '\\\\d+'\n },\n expiryMonth: { type: 'integer', minimum: 1, maximum: 12 },\n expiryYear: { type: 'integer', minimum: 2017, maximum: 2027 },\n cvc: { type: 'string', minLength: 3, maxLength: 4, pattern: '\\\\d+' },\n nameOnCard: { type: 'string' },\n amount: { type: 'number' }\n },\n required: ['creditCardNumber'] // Insert here all required event properties\n }\n }\n}\n\n// Let's \"middyfy\" our handler, then we will be able to attach middlewares to it\nconst handler = middy()\n .use(jsonBodyParser()) // parses the request body when it's a JSON and converts it to an object\n .use(validator({ eventSchema: transpileSchema(schema) })) // validates the input\n .use(httpErrorHandler()) // handles common http errors and returns proper responses\n .handler(lambdaHandler)\n")),(0,a.kt)("h2",{id:"why"},"Why?"),(0,a.kt)("p",null,"One of the main strengths of serverless and AWS Lambda is that, from a developer\nperspective, your focus is mostly shifted toward implementing business logic."),(0,a.kt)("p",null,"Anyway, when you are writing a handler, you still have to deal with some common technical concerns\noutside business logic, like input parsing and validation, output serialization,\nerror handling, etc."),(0,a.kt)("p",null,"Very often, all this necessary code ends up polluting the pure business logic code in\nyour handlers, making the code harder to read and to maintain."),(0,a.kt)("p",null,"In other contexts, like generic web frameworks (",(0,a.kt)("a",{parentName:"p",href:"http://fastify.io"},"fastify"),", ",(0,a.kt)("a",{parentName:"p",href:"https://hapijs.com/"},"hapi"),", ",(0,a.kt)("a",{parentName:"p",href:"http://expressjs.com/"},"express"),", etc.), this\nproblem has been solved using the ",(0,a.kt)("a",{parentName:"p",href:"https://www.packtpub.com/mapt/book/web_development/9781783287314/4/ch04lvl1sec33/middleware"},"middleware pattern"),"."),(0,a.kt)("p",null,"This pattern allows developers to isolate these common technical concerns into\n",(0,a.kt)("em",{parentName:"p"},'"steps"')," that ",(0,a.kt)("em",{parentName:"p"},"decorate")," the main business logic code.\nMiddleware functions are generally written as independent modules and then plugged into\nthe application in a configuration step, thus not polluting the main business logic\ncode that remains clean, readable, and easy to maintain."),(0,a.kt)("p",null,"Since we couldn't find a similar approach for AWS Lambda handlers, we decided\nto create middy, our own middleware framework for serverless in AWS land."))}c.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/f0136a98.284dc04a.js b/assets/js/f0136a98.b38b3258.js similarity index 99% rename from assets/js/f0136a98.284dc04a.js rename to assets/js/f0136a98.b38b3258.js index 17fda4157..202c56472 100644 --- a/assets/js/f0136a98.284dc04a.js +++ b/assets/js/f0136a98.b38b3258.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1575],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var u=a.createContext({}),s=function(e){var t=a.useContext(u),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},p=function(e){var t=s(e.components);return a.createElement(u.Provider,{value:t},e.children)},d="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,u=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),d=s(r),m=n,f=d["".concat(u,".").concat(m)]||d[m]||c[m]||l;return r?a.createElement(f,o(o({ref:t},p),{},{components:r})):a.createElement(f,o({ref:t},p))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,o=new Array(l);o[0]=m;var i={};for(var u in t)hasOwnProperty.call(t,u)&&(i[u]=t[u]);i.originalType=e,i[d]="string"==typeof e?e:n,o[1]=i;for(var s=2;s{r.d(t,{Z:()=>o});var a=r(7294),n=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var a=r(7462),n=r(7294),l=r(6010),o=r(2466),i=r(6550),u=r(1980),s=r(7392),p=r(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function c(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??d(r);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const a=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,u._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,l=c(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[u,s]=f({queryString:r,groupId:a}),[d,h]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,p.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),b=(()=>{const e=u??d;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),s(e),h(e)}),[s,h,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:i,selectValue:u,tabValues:s}=e;const p=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.o5)(),c=e=>{const t=e.currentTarget,r=p.indexOf(t),a=s[r].value;a!==i&&(d(t),u(a))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const r=p.indexOf(e.currentTarget)+1;t=p[r]??p[0];break}case"ArrowLeft":{const r=p.indexOf(e.currentTarget)-1;t=p[r]??p[p.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},s.map((e=>{let{value:t,label:r,attributes:o}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:c},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":i===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:a}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function k(e){const t=h(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,a.Z)({},e,t)),n.createElement(g,(0,a.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return n.createElement(k,(0,a.Z)({key:String(t)},e))}},1144:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>u,default:()=>f,frontMatter:()=>i,metadata:()=>s,toc:()=>d});var a=r(7462),n=(r(7294),r(3905)),l=r(4866),o=r(5162);const i={title:"http-event-normalizer"},u=void 0,s={unversionedId:"middlewares/http-event-normalizer",id:"middlewares/http-event-normalizer",title:"http-event-normalizer",description:"If you need to access the query string or path parameters in an API Gateway event you",source:"@site/docs/middlewares/http-event-normalizer.md",sourceDirName:"middlewares",slug:"/middlewares/http-event-normalizer",permalink:"/docs/middlewares/http-event-normalizer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-event-normalizer.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"http-event-normalizer"},sidebar:"tutorialSidebar",previous:{title:"http-error-handler",permalink:"/docs/middlewares/http-error-handler"},next:{title:"http-header-normalizer",permalink:"/docs/middlewares/http-header-normalizer"}},p={},d=[{value:"Install",id:"install",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:d},m="wrapper";function f(e){let{components:t,...r}=e;return(0,n.kt)(m,(0,a.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"If you need to access the query string or path parameters in an API Gateway event you\ncan do so by reading the attributes in ",(0,n.kt)("inlineCode",{parentName:"p"},"event.queryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"p"},"event.multiValueQueryStringParameters")," and\n",(0,n.kt)("inlineCode",{parentName:"p"},"event.pathParameters"),", for example: ",(0,n.kt)("inlineCode",{parentName:"p"},"event.pathParameters.userId"),". Unfortunately\nif there are no parameters for these parameter holders, the relevant key ",(0,n.kt)("inlineCode",{parentName:"p"},"queryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"p"},"multiValueQueryStringParameters")," or ",(0,n.kt)("inlineCode",{parentName:"p"},"pathParameters")," won't be available in the object, causing an expression like ",(0,n.kt)("inlineCode",{parentName:"p"},"event.pathParameters.userId"),"\nto fail with the error: ",(0,n.kt)("inlineCode",{parentName:"p"},"TypeError: Cannot read property 'userId' of undefined"),"."),(0,n.kt)("p",null,"A simple solution would be to add an ",(0,n.kt)("inlineCode",{parentName:"p"},"if")," statement to verify if the ",(0,n.kt)("inlineCode",{parentName:"p"},"pathParameters")," (or ",(0,n.kt)("inlineCode",{parentName:"p"},"queryStringParameters"),"/",(0,n.kt)("inlineCode",{parentName:"p"},"multiValueQueryStringParameters"),")\nexists before accessing one of its parameters, but this approach is very verbose and error prone."),(0,n.kt)("p",null,"This middleware normalizes the API Gateway, ALB, Function URLs, and VPC Lattice events, making sure that an object for ",(0,n.kt)("inlineCode",{parentName:"p"},"queryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"p"},"multiValueQueryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"p"},"pathParameters"),", and ",(0,n.kt)("inlineCode",{parentName:"p"},"isBase64Encoded")," is always available (resulting in empty objects when no parameter is available), this way you don't have to worry about adding extra ",(0,n.kt)("inlineCode",{parentName:"p"},"if")," statements before trying to read a property and calling ",(0,n.kt)("inlineCode",{parentName:"p"},"event.pathParameters.userId")," will result in ",(0,n.kt)("inlineCode",{parentName:"p"},"undefined")," when no path parameter is available, but not in an error."),(0,n.kt)("blockquote",null,(0,n.kt)("p",{parentName:"blockquote"},"Important note : API Gateway HTTP API format 2.0 doesn't have ",(0,n.kt)("inlineCode",{parentName:"p"},"multiValueQueryStringParameters")," fields. Duplicate query strings are combined with commas and included in the ",(0,n.kt)("inlineCode",{parentName:"p"},"queryStringParameters")," field.")),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-event-normalizer\n"))),(0,n.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-event-normalizer\n"))),(0,n.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-event-normalizer\n")))),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpEventNormalizer from '@middy/http-event-normalizer'\n\nconst handler = middy((event, context) => {\n console.log(`Hello user ${event.pathParameters.userId}`)\n // might produce `Hello user undefined`, but not an error\n\n return {}\n})\n\nhandler.use(httpEventNormalizer())\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1575],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>f});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function o(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var u=a.createContext({}),s=function(e){var t=a.useContext(u),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},p=function(e){var t=s(e.components);return a.createElement(u.Provider,{value:t},e.children)},d="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,u=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),d=s(r),m=n,f=d["".concat(u,".").concat(m)]||d[m]||c[m]||l;return r?a.createElement(f,o(o({ref:t},p),{},{components:r})):a.createElement(f,o({ref:t},p))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,o=new Array(l);o[0]=m;var i={};for(var u in t)hasOwnProperty.call(t,u)&&(i[u]=t[u]);i.originalType=e,i[d]="string"==typeof e?e:n,o[1]=i;for(var s=2;s{r.d(t,{Z:()=>o});var a=r(7294),n=r(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:r,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,n.Z)(l.tabItem,o),hidden:r},t)}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var a=r(7462),n=r(7294),l=r(6010),o=r(2466),i=r(6550),u=r(1980),s=r(7392),p=r(12);function d(e){return function(e){return n.Children.map(e,(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:r,attributes:a,default:n}}=e;return{value:t,label:r,attributes:a,default:n}}))}function c(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??d(r);return function(e){const t=(0,s.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const a=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,u._X)(l),(0,n.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,l=c(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=r.find((e=>e.default))??r[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[u,s]=f({queryString:r,groupId:a}),[d,h]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,p.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),b=(()=>{const e=u??d;return m({value:e,tabValues:l})?e:null})();(0,n.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),s(e),h(e)}),[s,h,l]),tabValues:l}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function v(e){let{className:t,block:r,selectedValue:i,selectValue:u,tabValues:s}=e;const p=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.o5)(),c=e=>{const t=e.currentTarget,r=p.indexOf(t),a=s[r].value;a!==i&&(d(t),u(a))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const r=p.indexOf(e.currentTarget)+1;t=p[r]??p[0];break}case"ArrowLeft":{const r=p.indexOf(e.currentTarget)-1;t=p[r]??p[p.length-1];break}}t?.focus()};return n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":r},t)},s.map((e=>{let{value:t,label:r,attributes:o}=e;return n.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>p.push(e),onKeyDown:m,onClick:c},o,{className:(0,l.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":i===t})}),r??t)})))}function g(e){let{lazy:t,children:r,selectedValue:a}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return n.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function k(e){const t=h(e);return n.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},n.createElement(v,(0,a.Z)({},e,t)),n.createElement(g,(0,a.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return n.createElement(k,(0,a.Z)({key:String(t)},e))}},1144:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>u,default:()=>f,frontMatter:()=>i,metadata:()=>s,toc:()=>d});var a=r(7462),n=(r(7294),r(3905)),l=r(4866),o=r(5162);const i={title:"http-event-normalizer"},u=void 0,s={unversionedId:"middlewares/http-event-normalizer",id:"middlewares/http-event-normalizer",title:"http-event-normalizer",description:"If you need to access the query string or path parameters in an API Gateway event you",source:"@site/docs/middlewares/http-event-normalizer.md",sourceDirName:"middlewares",slug:"/middlewares/http-event-normalizer",permalink:"/docs/middlewares/http-event-normalizer",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-event-normalizer.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"http-event-normalizer"},sidebar:"tutorialSidebar",previous:{title:"http-error-handler",permalink:"/docs/middlewares/http-error-handler"},next:{title:"http-header-normalizer",permalink:"/docs/middlewares/http-header-normalizer"}},p={},d=[{value:"Install",id:"install",level:2},{value:"Sample usage",id:"sample-usage",level:2}],c={toc:d},m="wrapper";function f(e){let{components:t,...r}=e;return(0,n.kt)(m,(0,a.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"If you need to access the query string or path parameters in an API Gateway event you\ncan do so by reading the attributes in ",(0,n.kt)("inlineCode",{parentName:"p"},"event.queryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"p"},"event.multiValueQueryStringParameters")," and\n",(0,n.kt)("inlineCode",{parentName:"p"},"event.pathParameters"),", for example: ",(0,n.kt)("inlineCode",{parentName:"p"},"event.pathParameters.userId"),". Unfortunately\nif there are no parameters for these parameter holders, the relevant key ",(0,n.kt)("inlineCode",{parentName:"p"},"queryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"p"},"multiValueQueryStringParameters")," or ",(0,n.kt)("inlineCode",{parentName:"p"},"pathParameters")," won't be available in the object, causing an expression like ",(0,n.kt)("inlineCode",{parentName:"p"},"event.pathParameters.userId"),"\nto fail with the error: ",(0,n.kt)("inlineCode",{parentName:"p"},"TypeError: Cannot read property 'userId' of undefined"),"."),(0,n.kt)("p",null,"A simple solution would be to add an ",(0,n.kt)("inlineCode",{parentName:"p"},"if")," statement to verify if the ",(0,n.kt)("inlineCode",{parentName:"p"},"pathParameters")," (or ",(0,n.kt)("inlineCode",{parentName:"p"},"queryStringParameters"),"/",(0,n.kt)("inlineCode",{parentName:"p"},"multiValueQueryStringParameters"),")\nexists before accessing one of its parameters, but this approach is very verbose and error prone."),(0,n.kt)("p",null,"This middleware normalizes the API Gateway, ALB, Function URLs, and VPC Lattice events, making sure that an object for ",(0,n.kt)("inlineCode",{parentName:"p"},"queryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"p"},"multiValueQueryStringParameters"),", ",(0,n.kt)("inlineCode",{parentName:"p"},"pathParameters"),", and ",(0,n.kt)("inlineCode",{parentName:"p"},"isBase64Encoded")," is always available (resulting in empty objects when no parameter is available), this way you don't have to worry about adding extra ",(0,n.kt)("inlineCode",{parentName:"p"},"if")," statements before trying to read a property and calling ",(0,n.kt)("inlineCode",{parentName:"p"},"event.pathParameters.userId")," will result in ",(0,n.kt)("inlineCode",{parentName:"p"},"undefined")," when no path parameter is available, but not in an error."),(0,n.kt)("blockquote",null,(0,n.kt)("p",{parentName:"blockquote"},"Important note : API Gateway HTTP API format 2.0 doesn't have ",(0,n.kt)("inlineCode",{parentName:"p"},"multiValueQueryStringParameters")," fields. Duplicate query strings are combined with commas and included in the ",(0,n.kt)("inlineCode",{parentName:"p"},"queryStringParameters")," field.")),(0,n.kt)("h2",{id:"install"},"Install"),(0,n.kt)("p",null,"To install this middleware you can use NPM:"),(0,n.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,n.kt)(o.Z,{value:"npm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/http-event-normalizer\n"))),(0,n.kt)(o.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/http-event-normalizer\n"))),(0,n.kt)(o.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/http-event-normalizer\n")))),(0,n.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport httpEventNormalizer from '@middy/http-event-normalizer'\n\nconst handler = middy((event, context) => {\n console.log(`Hello user ${event.pathParameters.userId}`)\n // might produce `Hello user undefined`, but not an error\n\n return {}\n})\n\nhandler.use(httpEventNormalizer())\n")))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/f0886e87.cbb1e214.js b/assets/js/f0886e87.7733fb97.js similarity index 99% rename from assets/js/f0886e87.cbb1e214.js rename to assets/js/f0886e87.7733fb97.js index 8e55fff80..e57024e6e 100644 --- a/assets/js/f0886e87.cbb1e214.js +++ b/assets/js/f0886e87.7733fb97.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3955],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),s=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},l=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},c=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,l=d(e,["components","mdxType","originalType","parentName"]),m=s(r),c=a,f=m["".concat(p,".").concat(c)]||m[c]||u[c]||o;return r?n.createElement(f,i(i({ref:t},l),{},{components:r})):n.createElement(f,i({ref:t},l))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=c;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var s=2;s{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>d,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"Function URL"},i=void 0,d={unversionedId:"events/function-url",id:"events/function-url",title:"Function URL",description:"Same as API Gateway (HTTP), but with support for response streams.",source:"@site/docs/events/function-url.md",sourceDirName:"events",slug:"/events/function-url",permalink:"/docs/events/function-url",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/function-url.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Function URL"},sidebar:"tutorialSidebar",previous:{title:"EventBridge",permalink:"/docs/events/event-bridge"},next:{title:"IoT Events",permalink:"/docs/events/iot-events"}},p={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],l={toc:s},m="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Same as API Gateway (HTTP), but with support for response streams."),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html"},"Using AWS Lambda with Amazon API Gateway")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html"},"Working with HTTP APIs"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer'\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n },\n streamifyResponse: true\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n default: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .use(httpErrorHandlerMiddleware())\n .handler((event, context, { signal }) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3955],{3905:(e,t,r)=>{r.d(t,{Zo:()=>l,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),s=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},l=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},c=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,l=d(e,["components","mdxType","originalType","parentName"]),m=s(r),c=a,f=m["".concat(p,".").concat(c)]||m[c]||u[c]||o;return r?n.createElement(f,i(i({ref:t},l),{},{components:r})):n.createElement(f,i({ref:t},l))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=c;var d={};for(var p in t)hasOwnProperty.call(t,p)&&(d[p]=t[p]);d.originalType=e,d[m]="string"==typeof e?e:a,i[1]=d;for(var s=2;s{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>d,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"Function URL"},i=void 0,d={unversionedId:"events/function-url",id:"events/function-url",title:"Function URL",description:"Same as API Gateway (HTTP), but with support for response streams.",source:"@site/docs/events/function-url.md",sourceDirName:"events",slug:"/events/function-url",permalink:"/docs/events/function-url",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/function-url.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Function URL"},sidebar:"tutorialSidebar",previous:{title:"EventBridge",permalink:"/docs/events/event-bridge"},next:{title:"IoT Events",permalink:"/docs/events/iot-events"}},p={},s=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],l={toc:s},m="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Same as API Gateway (HTTP), but with support for response streams."),(0,a.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html"},"Using AWS Lambda with Amazon API Gateway")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html"},"Working with HTTP APIs"))),(0,a.kt)("h2",{id:"example"},"Example"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport errorLoggerMiddleware from '@middy/error-logger'\nimport inputOutputLoggerMiddleware from '@middy/input-output-logger'\nimport httpContentNegotiationMiddleware from '@middy/http-content-negotiation'\nimport httpContentEncodingMiddleware from '@middy/http-content-encoding'\nimport httpCorsMiddleware from '@middy/http-cors'\nimport httpErrorHandlerMiddleware from '@middy/http-error-handler'\nimport httpEventNormalizerMiddleware from '@middy/http-event-normalizer'\nimport httpHeaderNormalizerMiddleware from '@middy/http-header-normalizer'\nimport httpJsonBodyParserMiddleware from '@middy/http-json-body-parser'\nimport httpMultipartBodyParserMiddleware from '@middy/http-multipart-body-parser'\nimport httpPartialResponseMiddleware from '@middy/http-partial-response'\nimport httpResponseSerializerMiddleware from '@middy/http-response-serializer'\nimport httpSecurityHeadersMiddleware from '@middy/http-security-headers'\nimport httpUrlencodeBodyParserMiddleware from '@middy/http-urlencode-body-parser'\nimport httpUrlencodePathParametersParserMiddleware from '@middy/http-urlencode-path-parser'\nimport validatorMiddleware from 'validator'\nimport warmupMiddleware from 'warmup'\n\nimport eventSchema from './eventSchema.json' assert { type: 'json' }\nimport responseSchema from './responseSchema.json' assert { type: 'json' }\n\nexport const handler = middy({\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n },\n streamifyResponse: true\n})\n .use(warmupMiddleware())\n .use(httpEventNormalizerMiddleware())\n .use(httpHeaderNormalizerMiddleware())\n .use(\n httpContentNegotiationMiddleware({\n availableLanguages: ['en-CA', 'fr-CA'],\n availableMediaTypes: ['application/json']\n })\n )\n .use(httpUrlencodePathParametersParserMiddleware())\n // Start oneOf\n .use(httpUrlencodeBodyParserMiddleware())\n .use(httpJsonBodyParserMiddleware())\n .use(httpMultipartBodyParserMiddleware())\n // End oneOf\n .use(httpSecurityHeadersMiddleware())\n .use(httpCorsMiddleware())\n .use(httpContentEncodingMiddleware())\n .use(\n httpResponseSerializerMiddleware({\n serializers: [\n {\n regex: /^application\\/json$/,\n serializer: ({ body }) => JSON.stringify(body)\n }\n ],\n default: 'application/json'\n })\n )\n .use(httpPartialResponseMiddleware())\n .use(validatorMiddleware({ eventSchema, responseSchema }))\n .use(httpErrorHandlerMiddleware())\n .handler((event, context, { signal }) => {\n // ...\n })\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/f20815ad.ec7a9c98.js b/assets/js/f20815ad.9d6c3d8c.js similarity index 96% rename from assets/js/f20815ad.ec7a9c98.js rename to assets/js/f20815ad.9d6c3d8c.js index dfed835c3..ad9101f2e 100644 --- a/assets/js/f20815ad.ec7a9c98.js +++ b/assets/js/f20815ad.9d6c3d8c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4760],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),u=l(n),m=o,f=u["".concat(s,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[u]="string"==typeof e?e:o,i[1]=c;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>c,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const a={title:"Connect"},i=void 0,c={unversionedId:"events/connect",id:"events/connect",title:"Connect",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/connect.md",sourceDirName:"events",slug:"/events/connect",permalink:"/docs/events/connect",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/connect.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"Connect"},sidebar:"tutorialSidebar",previous:{title:"Config",permalink:"/docs/events/config"},next:{title:"DocumentDB",permalink:"/docs/events/documentdb"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-connect.html"},"Using Lambda with Amazon Connect"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4760],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),u=l(n),m=o,f=u["".concat(s,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[u]="string"==typeof e?e:o,i[1]=c;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>c,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const a={title:"Connect"},i=void 0,c={unversionedId:"events/connect",id:"events/connect",title:"Connect",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/connect.md",sourceDirName:"events",slug:"/events/connect",permalink:"/docs/events/connect",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/connect.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"Connect"},sidebar:"tutorialSidebar",previous:{title:"Config",permalink:"/docs/events/config"},next:{title:"DocumentDB",permalink:"/docs/events/documentdb"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-connect.html"},"Using Lambda with Amazon Connect"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/f33bafb6.8904e1e2.js b/assets/js/f33bafb6.2bf10b2d.js similarity index 98% rename from assets/js/f33bafb6.8904e1e2.js rename to assets/js/f33bafb6.2bf10b2d.js index 7e68567cd..91a935543 100644 --- a/assets/js/f33bafb6.8904e1e2.js +++ b/assets/js/f33bafb6.2bf10b2d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8185],{3905:(e,t,r)=>{r.d(t,{Zo:()=>u,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function l(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var d=n.createContext({}),s=function(e){var t=n.useContext(d),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},u=function(e){var t=s(e.components);return n.createElement(d.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,d=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),c=s(r),m=a,f=c["".concat(d,".").concat(m)]||c[m]||p[m]||o;return r?n.createElement(f,l(l({ref:t},u),{},{components:r})):n.createElement(f,l({ref:t},u))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,l=new Array(o);l[0]=m;var i={};for(var d in t)hasOwnProperty.call(t,d)&&(i[d]=t[d]);i.originalType=e,i[c]="string"==typeof e?e:a,l[1]=i;for(var s=2;s{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"ws-router"},l=void 0,i={unversionedId:"routers/ws-router",id:"routers/ws-router",title:"ws-router",description:"This handler can route to requests to one of a nested handler based on routeKey of an WebSocket event from API Gateway (WebSocket).",source:"@site/docs/routers/ws-router.md",sourceDirName:"routers",slug:"/routers/ws-router",permalink:"/docs/routers/ws-router",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/routers/ws-router.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"ws-router"},sidebar:"tutorialSidebar",previous:{title:"http-router",permalink:"/docs/routers/http-router"},next:{title:"Upgrade",permalink:"/docs/category/upgrade"}},d={},s=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],u={toc:s},c="wrapper";function p(e){let{components:t,...r}=e;return(0,a.kt)(c,(0,n.Z)({},u,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This handler can route to requests to one of a nested handler based on ",(0,a.kt)("inlineCode",{parentName:"p"},"routeKey")," of an WebSocket event from API Gateway (WebSocket)."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/ws-router\n")),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"routes")," (array","[{routeKey, handler}]",") (required): Array of route objects.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"routeKey")," (string) (required): AWS formatted route key. ie ",(0,a.kt)("inlineCode",{parentName:"li"},"$connect"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"$disconnect"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"$default")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"handler")," (function) (required): Any ",(0,a.kt)("inlineCode",{parentName:"li"},"handler(event, context, {signal})")," function")))),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"Errors should be handled as part of the router middleware stack ",(0,a.kt)("strong",{parentName:"li"},"or")," the lambdaHandler middleware stack. Handled errors in the later will trigger the ",(0,a.kt)("inlineCode",{parentName:"li"},"after")," middleware stack of the former."),(0,a.kt)("li",{parentName:"ul"},"Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsRouterHandler from '@middy/ws-router'\nimport wsResponseMiddleware from '@middy/ws-response'\nimport validatorMiddleware from '@middy/validator'\n\nconst connectHandler = middy()\n .use(validatorMiddleware({eventSchema: {...} }))\n .handler((event, context) => {\n return 'connected'\n })\n\nconst disconnectHandler = middy()\n .use(validatorMiddleware({eventSchema: {...} }))\n .handler((event, context) => {\n return 'disconnected'\n })\n\nexport const handler = middy()\n .use(wsResponseMiddleware())\n .handler(wsRouterHandler([\n {\n routeKey: '$connect',\n handler: connectHandler\n },\n {\n routeKey: '$disconnect',\n handler: disconnectHandler\n }\n ]))\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8185],{3905:(e,t,r)=>{r.d(t,{Zo:()=>u,kt:()=>f});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function l(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var d=n.createContext({}),s=function(e){var t=n.useContext(d),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},u=function(e){var t=s(e.components);return n.createElement(d.Provider,{value:t},e.children)},c="mdxType",p={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,d=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),c=s(r),m=a,f=c["".concat(d,".").concat(m)]||c[m]||p[m]||o;return r?n.createElement(f,l(l({ref:t},u),{},{components:r})):n.createElement(f,l({ref:t},u))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,l=new Array(o);l[0]=m;var i={};for(var d in t)hasOwnProperty.call(t,d)&&(i[d]=t[d]);i.originalType=e,i[c]="string"==typeof e?e:a,l[1]=i;for(var s=2;s{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"ws-router"},l=void 0,i={unversionedId:"routers/ws-router",id:"routers/ws-router",title:"ws-router",description:"This handler can route to requests to one of a nested handler based on routeKey of an WebSocket event from API Gateway (WebSocket).",source:"@site/docs/routers/ws-router.md",sourceDirName:"routers",slug:"/routers/ws-router",permalink:"/docs/routers/ws-router",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/routers/ws-router.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"ws-router"},sidebar:"tutorialSidebar",previous:{title:"http-router",permalink:"/docs/routers/http-router"},next:{title:"Upgrade",permalink:"/docs/category/upgrade"}},d={},s=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}],u={toc:s},c="wrapper";function p(e){let{components:t,...r}=e;return(0,a.kt)(c,(0,n.Z)({},u,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"This handler can route to requests to one of a nested handler based on ",(0,a.kt)("inlineCode",{parentName:"p"},"routeKey")," of an WebSocket event from API Gateway (WebSocket)."),(0,a.kt)("h2",{id:"install"},"Install"),(0,a.kt)("p",null,"To install this middleware you can use NPM:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/ws-router\n")),(0,a.kt)("h2",{id:"options"},"Options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"routes")," (array","[{routeKey, handler}]",") (required): Array of route objects.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"routeKey")," (string) (required): AWS formatted route key. ie ",(0,a.kt)("inlineCode",{parentName:"li"},"$connect"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"$disconnect"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"$default")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"handler")," (function) (required): Any ",(0,a.kt)("inlineCode",{parentName:"li"},"handler(event, context, {signal})")," function")))),(0,a.kt)("p",null,"NOTES:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"Errors should be handled as part of the router middleware stack ",(0,a.kt)("strong",{parentName:"li"},"or")," the lambdaHandler middleware stack. Handled errors in the later will trigger the ",(0,a.kt)("inlineCode",{parentName:"li"},"after")," middleware stack of the former."),(0,a.kt)("li",{parentName:"ul"},"Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack.")),(0,a.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport wsRouterHandler from '@middy/ws-router'\nimport wsResponseMiddleware from '@middy/ws-response'\nimport validatorMiddleware from '@middy/validator'\n\nconst connectHandler = middy()\n .use(validatorMiddleware({eventSchema: {...} }))\n .handler((event, context) => {\n return 'connected'\n })\n\nconst disconnectHandler = middy()\n .use(validatorMiddleware({eventSchema: {...} }))\n .handler((event, context) => {\n return 'disconnected'\n })\n\nexport const handler = middy()\n .use(wsResponseMiddleware())\n .handler(wsRouterHandler([\n {\n routeKey: '$connect',\n handler: connectHandler\n },\n {\n routeKey: '$disconnect',\n handler: disconnectHandler\n }\n ]))\n")))}p.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/f795adf5.c1935a2a.js b/assets/js/f795adf5.8051875b.js similarity index 98% rename from assets/js/f795adf5.c1935a2a.js rename to assets/js/f795adf5.8051875b.js index 9b02a8c25..c67b29052 100644 --- a/assets/js/f795adf5.c1935a2a.js +++ b/assets/js/f795adf5.8051875b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8841],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var l=n.createContext({}),s=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},d=function(e){var t=s(e.components);return n.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,d=c(e,["components","mdxType","originalType","parentName"]),p=s(r),m=a,y=p["".concat(l,".").concat(m)]||p[m]||u[m]||o;return r?n.createElement(y,i(i({ref:t},d),{},{components:r})):n.createElement(y,i({ref:t},d))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[p]="string"==typeof e?e:a,i[1]=c;for(var s=2;s{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"Early return",position:4},i=void 0,c={unversionedId:"intro/early-interrupt",id:"intro/early-interrupt",title:"Early return",description:"Some middlewares might need to stop the whole execution flow and return a response immediately.",source:"@site/docs/intro/04-early-interrupt.md",sourceDirName:"intro",slug:"/intro/early-interrupt",permalink:"/docs/intro/early-interrupt",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/04-early-interrupt.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:4,frontMatter:{title:"Early return",position:4},sidebar:"tutorialSidebar",previous:{title:"How it works",permalink:"/docs/intro/how-it-works"},next:{title:"Handling Errors",permalink:"/docs/intro/handling-errors"}},l={},s=[],d={toc:s},p="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(p,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Some middlewares might need to stop the whole execution flow and return a response immediately."),(0,a.kt)("p",null,"If you want to do this you can invoke ",(0,a.kt)("inlineCode",{parentName:"p"},"return response")," in your middleware."),(0,a.kt)("p",null,(0,a.kt)("strong",{parentName:"p"},"Note"),": this will totally stop the execution of successive middlewares in any phase (",(0,a.kt)("inlineCode",{parentName:"p"},"before"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"after"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"onError"),") and returns\nan early response (or an error) directly at the Lambda level. If your middlewares do a specific task on every request\nlike output serialization, error handling or clean, these won't be invoked in this case. They will have to be handled before the return."),(0,a.kt)("p",null,"In this example, we can use this capability for building a sample caching middleware:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"// some function that calculates the cache id based on the current event\nconst calculateCacheId = (event) => {\n /* ... */\n}\nconst storage = {}\n\n// middleware\nconst cacheMiddleware = (options) => {\n let cacheKey\n\n const cacheMiddlewareBefore = async (request) => {\n cacheKey = options.calculateCacheId(request.event)\n if (options.storage.hasOwnProperty(cacheKey)) {\n // exits early and returns the value from the cache if it's already there\n return options.storage[cacheKey]\n }\n }\n\n const cacheMiddlewareAfter = async (request) => {\n // stores the calculated response in the cache\n options.storage[cacheKey] = request.response\n }\n\n return {\n before: cacheMiddlewareBefore,\n after: cacheMiddlewareAfter\n }\n}\n\n// sample usage\nconst handler = middy((event, context) => {\n /* ... */\n}).use(\n cacheMiddleware({\n calculateCacheId,\n storage\n })\n)\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8841],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>y});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var l=n.createContext({}),s=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},d=function(e){var t=s(e.components);return n.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,d=c(e,["components","mdxType","originalType","parentName"]),p=s(r),m=a,y=p["".concat(l,".").concat(m)]||p[m]||u[m]||o;return r?n.createElement(y,i(i({ref:t},d),{},{components:r})):n.createElement(y,i({ref:t},d))}));function y(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[p]="string"==typeof e?e:a,i[1]=c;for(var s=2;s{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>s});var n=r(7462),a=(r(7294),r(3905));const o={title:"Early return",position:4},i=void 0,c={unversionedId:"intro/early-interrupt",id:"intro/early-interrupt",title:"Early return",description:"Some middlewares might need to stop the whole execution flow and return a response immediately.",source:"@site/docs/intro/04-early-interrupt.md",sourceDirName:"intro",slug:"/intro/early-interrupt",permalink:"/docs/intro/early-interrupt",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/04-early-interrupt.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:4,frontMatter:{title:"Early return",position:4},sidebar:"tutorialSidebar",previous:{title:"How it works",permalink:"/docs/intro/how-it-works"},next:{title:"Handling Errors",permalink:"/docs/intro/handling-errors"}},l={},s=[],d={toc:s},p="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(p,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Some middlewares might need to stop the whole execution flow and return a response immediately."),(0,a.kt)("p",null,"If you want to do this you can invoke ",(0,a.kt)("inlineCode",{parentName:"p"},"return response")," in your middleware."),(0,a.kt)("p",null,(0,a.kt)("strong",{parentName:"p"},"Note"),": this will totally stop the execution of successive middlewares in any phase (",(0,a.kt)("inlineCode",{parentName:"p"},"before"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"after"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"onError"),") and returns\nan early response (or an error) directly at the Lambda level. If your middlewares do a specific task on every request\nlike output serialization, error handling or clean, these won't be invoked in this case. They will have to be handled before the return."),(0,a.kt)("p",null,"In this example, we can use this capability for building a sample caching middleware:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},"// some function that calculates the cache id based on the current event\nconst calculateCacheId = (event) => {\n /* ... */\n}\nconst storage = {}\n\n// middleware\nconst cacheMiddleware = (options) => {\n let cacheKey\n\n const cacheMiddlewareBefore = async (request) => {\n cacheKey = options.calculateCacheId(request.event)\n if (options.storage.hasOwnProperty(cacheKey)) {\n // exits early and returns the value from the cache if it's already there\n return options.storage[cacheKey]\n }\n }\n\n const cacheMiddlewareAfter = async (request) => {\n // stores the calculated response in the cache\n options.storage[cacheKey] = request.response\n }\n\n return {\n before: cacheMiddlewareBefore,\n after: cacheMiddlewareAfter\n }\n}\n\n// sample usage\nconst handler = middy((event, context) => {\n /* ... */\n}).use(\n cacheMiddleware({\n calculateCacheId,\n storage\n })\n)\n")))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/f9850e34.0b113ed3.js b/assets/js/f9850e34.f77c26f5.js similarity index 97% rename from assets/js/f9850e34.0b113ed3.js rename to assets/js/f9850e34.f77c26f5.js index 3ecc44ae7..931641ce8 100644 --- a/assets/js/f9850e34.0b113ed3.js +++ b/assets/js/f9850e34.f77c26f5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6177],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>h});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var d=n.createContext({}),s=function(e){var t=n.useContext(d),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},p=function(e){var t=s(e.components);return n.createElement(d.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,a=e.originalType,d=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),c=s(r),u=i,h=c["".concat(d,".").concat(u)]||c[u]||m[u]||a;return r?n.createElement(h,o(o({ref:t},p),{},{components:r})):n.createElement(h,o({ref:t},p))}));function h(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=r.length,o=new Array(a);o[0]=u;var l={};for(var d in t)hasOwnProperty.call(t,d)&&(l[d]=t[d]);l.originalType=e,l[c]="string"==typeof e?e:i,o[1]=l;for(var s=2;s{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var n=r(7462),i=(r(7294),r(3905));const a={title:"How it works",position:3},o=void 0,l={unversionedId:"intro/how-it-works",id:"intro/how-it-works",title:"How it works",description:"Middy implements the classic onion-like middleware pattern, with some peculiar details.",source:"@site/docs/intro/03-how-it-works.md",sourceDirName:"intro",slug:"/intro/how-it-works",permalink:"/docs/intro/how-it-works",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/03-how-it-works.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",sidebarPosition:3,frontMatter:{title:"How it works",position:3},sidebar:"tutorialSidebar",previous:{title:"Getting started",permalink:"/docs/intro/getting-started"},next:{title:"Early return",permalink:"/docs/intro/early-interrupt"}},d={},s=[{value:"Execution order",id:"execution-order",level:2}],p={toc:s},c="wrapper";function m(e){let{components:t,...a}=e;return(0,i.kt)(c,(0,n.Z)({},p,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Middy implements the classic ",(0,i.kt)("em",{parentName:"p"},"onion-like")," middleware pattern, with some peculiar details."),(0,i.kt)("p",null,(0,i.kt)("img",{alt:"Middy middleware engine diagram",src:r(2321).Z,width:"664",height:"547"})),(0,i.kt)("p",null,"When you attach a new middleware this will wrap the business logic contained in the handler\nin two separate steps."),(0,i.kt)("p",null,"When another middleware is attached this will wrap the handler again and it will be wrapped by\nall the previously added middlewares in order, creating multiple layers for interacting with\nthe ",(0,i.kt)("em",{parentName:"p"},"request")," (event) and the ",(0,i.kt)("em",{parentName:"p"},"response"),"."),(0,i.kt)("p",null,"This way the ",(0,i.kt)("em",{parentName:"p"},"request-response cycle")," flows through all the middlewares, the\nhandler and all the middlewares again, giving the opportunity within every step to\nmodify or enrich the current request, context, or the response."),(0,i.kt)("h2",{id:"execution-order"},"Execution order"),(0,i.kt)("p",null,"Middlewares have two phases: ",(0,i.kt)("inlineCode",{parentName:"p"},"before")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"after"),"."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"before")," phase, happens ",(0,i.kt)("em",{parentName:"p"},"before")," the handler is executed. In this code the\nresponse is not created yet, so you will have access only to the request."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," phase, happens ",(0,i.kt)("em",{parentName:"p"},"after")," the handler is executed. In this code you will\nhave access to both the request and the response."),(0,i.kt)("p",null,"If you have three middlewares attached (as in the image above), this is the expected\norder of execution:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware1")," (before)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware2")," (before)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware3")," (before)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"handler")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware3")," (after)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware2")," (after)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware1")," (after)")),(0,i.kt)("p",null,"Notice that in the ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," phase, middlewares are executed in inverted order,\nthis way the first handler attached is the one with the highest priority as it will\nbe the first able to change the request and last able to modify the response before\nit gets sent to the user."))}m.isMDXComponent=!0},2321:(e,t,r)=>{r.d(t,{Z:()=>n});const n=r.p+"assets/images/middy-middleware-engine-eb7bdaefff782d4d36cce8f149f7fa85.png"}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6177],{3905:(e,t,r)=>{r.d(t,{Zo:()=>p,kt:()=>h});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var d=n.createContext({}),s=function(e){var t=n.useContext(d),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},p=function(e){var t=s(e.components);return n.createElement(d.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,a=e.originalType,d=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),c=s(r),u=i,h=c["".concat(d,".").concat(u)]||c[u]||m[u]||a;return r?n.createElement(h,o(o({ref:t},p),{},{components:r})):n.createElement(h,o({ref:t},p))}));function h(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=r.length,o=new Array(a);o[0]=u;var l={};for(var d in t)hasOwnProperty.call(t,d)&&(l[d]=t[d]);l.originalType=e,l[c]="string"==typeof e?e:i,o[1]=l;for(var s=2;s{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var n=r(7462),i=(r(7294),r(3905));const a={title:"How it works",position:3},o=void 0,l={unversionedId:"intro/how-it-works",id:"intro/how-it-works",title:"How it works",description:"Middy implements the classic onion-like middleware pattern, with some peculiar details.",source:"@site/docs/intro/03-how-it-works.md",sourceDirName:"intro",slug:"/intro/how-it-works",permalink:"/docs/intro/how-it-works",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/03-how-it-works.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",sidebarPosition:3,frontMatter:{title:"How it works",position:3},sidebar:"tutorialSidebar",previous:{title:"Getting started",permalink:"/docs/intro/getting-started"},next:{title:"Early return",permalink:"/docs/intro/early-interrupt"}},d={},s=[{value:"Execution order",id:"execution-order",level:2}],p={toc:s},c="wrapper";function m(e){let{components:t,...a}=e;return(0,i.kt)(c,(0,n.Z)({},p,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Middy implements the classic ",(0,i.kt)("em",{parentName:"p"},"onion-like")," middleware pattern, with some peculiar details."),(0,i.kt)("p",null,(0,i.kt)("img",{alt:"Middy middleware engine diagram",src:r(2321).Z,width:"664",height:"547"})),(0,i.kt)("p",null,"When you attach a new middleware this will wrap the business logic contained in the handler\nin two separate steps."),(0,i.kt)("p",null,"When another middleware is attached this will wrap the handler again and it will be wrapped by\nall the previously added middlewares in order, creating multiple layers for interacting with\nthe ",(0,i.kt)("em",{parentName:"p"},"request")," (event) and the ",(0,i.kt)("em",{parentName:"p"},"response"),"."),(0,i.kt)("p",null,"This way the ",(0,i.kt)("em",{parentName:"p"},"request-response cycle")," flows through all the middlewares, the\nhandler and all the middlewares again, giving the opportunity within every step to\nmodify or enrich the current request, context, or the response."),(0,i.kt)("h2",{id:"execution-order"},"Execution order"),(0,i.kt)("p",null,"Middlewares have two phases: ",(0,i.kt)("inlineCode",{parentName:"p"},"before")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"after"),"."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"before")," phase, happens ",(0,i.kt)("em",{parentName:"p"},"before")," the handler is executed. In this code the\nresponse is not created yet, so you will have access only to the request."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," phase, happens ",(0,i.kt)("em",{parentName:"p"},"after")," the handler is executed. In this code you will\nhave access to both the request and the response."),(0,i.kt)("p",null,"If you have three middlewares attached (as in the image above), this is the expected\norder of execution:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware1")," (before)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware2")," (before)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware3")," (before)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"handler")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware3")," (after)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware2")," (after)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"middleware1")," (after)")),(0,i.kt)("p",null,"Notice that in the ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," phase, middlewares are executed in inverted order,\nthis way the first handler attached is the one with the highest priority as it will\nbe the first able to change the request and last able to modify the response before\nit gets sent to the user."))}m.isMDXComponent=!0},2321:(e,t,r)=>{r.d(t,{Z:()=>n});const n=r.p+"assets/images/middy-middleware-engine-eb7bdaefff782d4d36cce8f149f7fa85.png"}}]); \ No newline at end of file diff --git a/assets/js/faf674c6.96f65ccf.js b/assets/js/faf674c6.9ab1856d.js similarity index 96% rename from assets/js/faf674c6.96f65ccf.js rename to assets/js/faf674c6.9ab1856d.js index af948ac7f..1e529ad63 100644 --- a/assets/js/faf674c6.96f65ccf.js +++ b/assets/js/faf674c6.9ab1856d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4962],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const a={title:"IoT Events"},i=void 0,s={unversionedId:"events/iot-events",id:"events/iot-events",title:"IoT Events",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/iot-events.md",sourceDirName:"events",slug:"/events/iot-events",permalink:"/docs/events/iot-events",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/iot-events.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"IoT Events"},sidebar:"tutorialSidebar",previous:{title:"Function URL",permalink:"/docs/events/function-url"},next:{title:"Internet of things (IoT)",permalink:"/docs/events/iot"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-iotevents.html"},"Using AWS Lambda with AWS IoT Events"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4962],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},p=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,a=e.originalType,c=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=l(n),m=o,f=u["".concat(c,".").concat(m)]||u[m]||d[m]||a;return n?r.createElement(f,i(i({ref:t},p),{},{components:n})):r.createElement(f,i({ref:t},p))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=n.length,i=new Array(a);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:o,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var r=n(7462),o=(n(7294),n(3905));const a={title:"IoT Events"},i=void 0,s={unversionedId:"events/iot-events",id:"events/iot-events",title:"IoT Events",description:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.",source:"@site/docs/events/iot-events.md",sourceDirName:"events",slug:"/events/iot-events",permalink:"/docs/events/iot-events",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/iot-events.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"IoT Events"},sidebar:"tutorialSidebar",previous:{title:"Function URL",permalink:"/docs/events/function-url"},next:{title:"Internet of things (IoT)",permalink:"/docs/events/iot"}},c={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}],p={toc:l},u="wrapper";function d(e){let{components:t,...n}=e;return(0,o.kt)(u,(0,r.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"caution"},(0,o.kt)("p",{parentName:"admonition"},"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub.")),(0,o.kt)("h2",{id:"aws-documentation"},"AWS Documentation"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/lambda/latest/dg/services-iotevents.html"},"Using AWS Lambda with AWS IoT Events"))),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/ff488875.c097ec36.js b/assets/js/ff488875.8ebfa897.js similarity index 99% rename from assets/js/ff488875.c097ec36.js rename to assets/js/ff488875.8ebfa897.js index 0ec62f433..185362f21 100644 --- a/assets/js/ff488875.c097ec36.js +++ b/assets/js/ff488875.8ebfa897.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1531],{3905:(e,t,a)=>{a.d(t,{Zo:()=>d,kt:()=>f});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function s(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var o=n.createContext({}),u=function(e){var t=n.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):s(s({},t),e)),a},d=function(e){var t=u(e.components);return n.createElement(o.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},p=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),m=u(a),p=r,f=m["".concat(o,".").concat(p)]||m[p]||c[p]||l;return a?n.createElement(f,s(s({ref:t},d),{},{components:a})):n.createElement(f,s({ref:t},d))}));function f(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=a.length,s=new Array(l);s[0]=p;var i={};for(var o in t)hasOwnProperty.call(t,o)&&(i[o]=t[o]);i.originalType=e,i[m]="string"==typeof e?e:r,s[1]=i;for(var u=2;u{a.d(t,{Z:()=>s});var n=a(7294),r=a(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:a,className:s}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,s),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var n=a(7462),r=a(7294),l=a(6010),s=a(2466),i=a(6550),o=a(1980),u=a(7392),d=a(12);function m(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function c(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??m(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function p(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const n=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function h(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,l=c(e),[s,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:a,groupId:n}),[m,h]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),b=(()=>{const e=o??m;return p({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),h(e)}),[u,h,l]),tabValues:l}}var b=a(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:a,selectedValue:i,selectValue:o,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:m}=(0,s.o5)(),c=e=>{const t=e.currentTarget,a=d.indexOf(t),n=u[a].value;n!==i&&(m(t),o(n))},p=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=d.indexOf(e.currentTarget)+1;t=d[a]??d[0];break}case"ArrowLeft":{const a=d.indexOf(e.currentTarget)-1;t=d[a]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:s}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:p,onClick:c},s,{className:(0,l.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":i===t})}),a??t)})))}function g(e){let{lazy:t,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function v(e){const t=h(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},r.createElement(k,(0,n.Z)({},e,t)),r.createElement(g,(0,n.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return r.createElement(v,(0,n.Z)({key:String(t)},e))}},4785:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>m});var n=a(7462),r=(a(7294),a(3905)),l=a(4866),s=a(5162);const i={title:"ssm"},o=void 0,u={unversionedId:"middlewares/ssm",id:"middlewares/ssm",title:"ssm",description:"This middleware fetches parameters from AWS Systems Manager Parameter Store.",source:"@site/docs/middlewares/ssm.md",sourceDirName:"middlewares",slug:"/middlewares/ssm",permalink:"/docs/middlewares/ssm",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ssm.md",tags:[],version:"current",lastUpdatedAt:1697596175,formattedLastUpdatedAt:"Oct 18, 2023",frontMatter:{title:"ssm"},sidebar:"tutorialSidebar",previous:{title:"sqs-partial-batch-failure",permalink:"/docs/middlewares/sqs-partial-batch-failure"},next:{title:"sts",permalink:"/docs/middlewares/sts"}},d={},m=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],c={toc:m},p="wrapper";function f(e){let{components:t,...a}=e;return(0,r.kt)(p,(0,n.Z)({},c,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This middleware fetches parameters from ",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html"},"AWS Systems Manager Parameter Store"),"."),(0,r.kt)("p",null,"Parameters to fetch can be defined by path and by name (not mutually exclusive). See AWS docs ",(0,r.kt)("a",{parentName:"p",href:"https://aws.amazon.com/blogs/mt/organize-parameters-by-hierarchy-tags-or-amazon-cloudwatch-events-with-amazon-ec2-systems-manager-parameter-store/"},"here"),"."),(0,r.kt)("p",null,"Parameters can be assigned to the function handler's ",(0,r.kt)("inlineCode",{parentName:"p"},"context")," object by setting the ",(0,r.kt)("inlineCode",{parentName:"p"},"setToContext")," flag to ",(0,r.kt)("inlineCode",{parentName:"p"},"true"),". By default all parameters are added with uppercase names."),(0,r.kt)("p",null,"The Middleware makes a single API request to fetch all the parameters defined by name, but must make an additional request per specified path. This is because the AWS SDK currently doesn't expose a method to retrieve parameters from multiple paths."),(0,r.kt)("p",null,"For each parameter defined by name, you also provide the name under which its value should be added to ",(0,r.kt)("inlineCode",{parentName:"p"},"context"),". For each path, you instead provide a prefix, and by default the value import each parameter returned from that path will be added to ",(0,r.kt)("inlineCode",{parentName:"p"},"context")," with a name equal to what's left of the parameter's full name ",(0,r.kt)("em",{parentName:"p"},"after")," the defined path, with the prefix prepended. If the prefix is an empty string, nothing is prepended. You can override this behaviour by providing your own mapping function with the ",(0,r.kt)("inlineCode",{parentName:"p"},"getParamNameFromPath")," config option."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/ssm\nnpm install --save-dev @aws-sdk/client-ssm\n"))),(0,r.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/ssm\nyarn add --dev @aws-sdk/client-ssm\n"))),(0,r.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/ssm\npnpm add --save-dev @aws-sdk/client-ssm\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"SSMClient"),"): SSMClient class constructor (i.e. that has been instrumented with AWS X-Ray). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-ssm"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to SSMClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (optional): Internal key where role tokens are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (optional): Enable AWS X-Ray by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameter ",(0,r.kt)("inlineCode",{parentName:"li"},"Names"),"/",(0,r.kt)("inlineCode",{parentName:"li"},"Path"),". ",(0,r.kt)("inlineCode",{parentName:"li"},"SecureString")," are automatically decrypted."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"ssm"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store role tokens to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"ssm:GetParameters")," and/or ",(0,r.kt)("inlineCode",{parentName:"li"},"ssm:GetParametersByPath")," depending on what you're requesting, along with ",(0,r.kt)("inlineCode",{parentName:"li"},"kms:Decrypt"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"SSM")," has ",(0,r.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/general/latest/gr/ssm.html"},"throughput limitations"),". Switching to Advanced Parameter type or increasing ",(0,r.kt)("inlineCode",{parentName:"li"},"maxRetries")," and ",(0,r.kt)("inlineCode",{parentName:"li"},"retryDelayOptions.base")," in ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," may be required.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport ssm from '@middy/ssm'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nlet globalDefaults = {}\nhandler\n .use(\n ssm({\n fetchData: {\n accessToken: '/dev/service_name/access_token', // single value\n dbParams: '/dev/service_name/database/', // object of values, key for each path\n defaults: '/dev/defaults'\n },\n setToContext: true\n })\n )\n .before((request) => {\n globalDefaults = request.context.defaults.global\n })\n")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport ssm from '@middy/ssm'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nlet globalDefaults = {}\nhandler\n .use(\n ssm({\n fetchData: {\n defaults: '/dev/defaults'\n },\n cacheKey: 'ssm-defaults'\n })\n )\n .use(\n ssm({\n fetchData: {\n accessToken: '/dev/service_name/access_token', // single value\n dbParams: '/dev/service_name/database/' // object of values, key for each path\n },\n cacheExpiry: 15 * 60 * 1000,\n cacheKey: 'ssm-secrets'\n })\n )\n // ... other middleware that fetch\n .before(async (request) => {\n const data = await getInternal(\n ['accessToken', 'dbParams', 'defaults'],\n request\n )\n Object.assign(request.context, data)\n })\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-ssm")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1531],{3905:(e,t,a)=>{a.d(t,{Zo:()=>d,kt:()=>f});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function s(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var o=n.createContext({}),u=function(e){var t=n.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):s(s({},t),e)),a},d=function(e){var t=u(e.components);return n.createElement(o.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},p=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),m=u(a),p=r,f=m["".concat(o,".").concat(p)]||m[p]||c[p]||l;return a?n.createElement(f,s(s({ref:t},d),{},{components:a})):n.createElement(f,s({ref:t},d))}));function f(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=a.length,s=new Array(l);s[0]=p;var i={};for(var o in t)hasOwnProperty.call(t,o)&&(i[o]=t[o]);i.originalType=e,i[m]="string"==typeof e?e:r,s[1]=i;for(var u=2;u{a.d(t,{Z:()=>s});var n=a(7294),r=a(6010);const l={tabItem:"tabItem_Ymn6"};function s(e){let{children:t,hidden:a,className:s}=e;return n.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,s),hidden:a},t)}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var n=a(7462),r=a(7294),l=a(6010),s=a(2466),i=a(6550),o=a(1980),u=a(7392),d=a(12);function m(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:r}}=e;return{value:t,label:a,attributes:n,default:r}}))}function c(e){const{values:t,children:a}=e;return(0,r.useMemo)((()=>{const e=t??m(a);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,a])}function p(e){let{value:t,tabValues:a}=e;return a.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:a}=e;const n=(0,i.k6)(),l=function(e){let{queryString:t=!1,groupId:a}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:t,groupId:a});return[(0,o._X)(l),(0,r.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(n.location.search);t.set(l,e),n.replace({...n.location,search:t.toString()})}),[l,n])]}function h(e){const{defaultValue:t,queryString:a=!1,groupId:n}=e,l=c(e),[s,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${a.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:l}))),[o,u]=f({queryString:a,groupId:n}),[m,h]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[n,l]=(0,d.Nk)(a);return[n,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),b=(()=>{const e=o??m;return p({value:e,tabValues:l})?e:null})();(0,r.useLayoutEffect)((()=>{b&&i(b)}),[b]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),h(e)}),[u,h,l]),tabValues:l}}var b=a(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function k(e){let{className:t,block:a,selectedValue:i,selectValue:o,tabValues:u}=e;const d=[],{blockElementScrollPositionUntilNextRender:m}=(0,s.o5)(),c=e=>{const t=e.currentTarget,a=d.indexOf(t),n=u[a].value;n!==i&&(m(t),o(n))},p=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=d.indexOf(e.currentTarget)+1;t=d[a]??d[0];break}case"ArrowLeft":{const a=d.indexOf(e.currentTarget)-1;t=d[a]??d[d.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":a},t)},u.map((e=>{let{value:t,label:a,attributes:s}=e;return r.createElement("li",(0,n.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:e=>d.push(e),onKeyDown:p,onClick:c},s,{className:(0,l.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":i===t})}),a??t)})))}function g(e){let{lazy:t,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function v(e){const t=h(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",y.tabList)},r.createElement(k,(0,n.Z)({},e,t)),r.createElement(g,(0,n.Z)({},e,t)))}function w(e){const t=(0,b.Z)();return r.createElement(v,(0,n.Z)({key:String(t)},e))}},4785:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>f,frontMatter:()=>i,metadata:()=>u,toc:()=>m});var n=a(7462),r=(a(7294),a(3905)),l=a(4866),s=a(5162);const i={title:"ssm"},o=void 0,u={unversionedId:"middlewares/ssm",id:"middlewares/ssm",title:"ssm",description:"This middleware fetches parameters from AWS Systems Manager Parameter Store.",source:"@site/docs/middlewares/ssm.md",sourceDirName:"middlewares",slug:"/middlewares/ssm",permalink:"/docs/middlewares/ssm",draft:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ssm.md",tags:[],version:"current",lastUpdatedAt:1697945563,formattedLastUpdatedAt:"Oct 22, 2023",frontMatter:{title:"ssm"},sidebar:"tutorialSidebar",previous:{title:"sqs-partial-batch-failure",permalink:"/docs/middlewares/sqs-partial-batch-failure"},next:{title:"sts",permalink:"/docs/middlewares/sts"}},d={},m=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2},{value:"Bundling",id:"bundling",level:2}],c={toc:m},p="wrapper";function f(e){let{components:t,...a}=e;return(0,r.kt)(p,(0,n.Z)({},c,a,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This middleware fetches parameters from ",(0,r.kt)("a",{parentName:"p",href:"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html"},"AWS Systems Manager Parameter Store"),"."),(0,r.kt)("p",null,"Parameters to fetch can be defined by path and by name (not mutually exclusive). See AWS docs ",(0,r.kt)("a",{parentName:"p",href:"https://aws.amazon.com/blogs/mt/organize-parameters-by-hierarchy-tags-or-amazon-cloudwatch-events-with-amazon-ec2-systems-manager-parameter-store/"},"here"),"."),(0,r.kt)("p",null,"Parameters can be assigned to the function handler's ",(0,r.kt)("inlineCode",{parentName:"p"},"context")," object by setting the ",(0,r.kt)("inlineCode",{parentName:"p"},"setToContext")," flag to ",(0,r.kt)("inlineCode",{parentName:"p"},"true"),". By default all parameters are added with uppercase names."),(0,r.kt)("p",null,"The Middleware makes a single API request to fetch all the parameters defined by name, but must make an additional request per specified path. This is because the AWS SDK currently doesn't expose a method to retrieve parameters from multiple paths."),(0,r.kt)("p",null,"For each parameter defined by name, you also provide the name under which its value should be added to ",(0,r.kt)("inlineCode",{parentName:"p"},"context"),". For each path, you instead provide a prefix, and by default the value import each parameter returned from that path will be added to ",(0,r.kt)("inlineCode",{parentName:"p"},"context")," with a name equal to what's left of the parameter's full name ",(0,r.kt)("em",{parentName:"p"},"after")," the defined path, with the prefix prepended. If the prefix is an empty string, nothing is prepended. You can override this behaviour by providing your own mapping function with the ",(0,r.kt)("inlineCode",{parentName:"p"},"getParamNameFromPath")," config option."),(0,r.kt)("h2",{id:"install"},"Install"),(0,r.kt)("p",null,"To install this middleware you can use NPM:"),(0,r.kt)(l.Z,{groupId:"npm2yarn",mdxType:"Tabs"},(0,r.kt)(s.Z,{value:"npm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"npm install --save @middy/ssm\nnpm install --save-dev @aws-sdk/client-ssm\n"))),(0,r.kt)(s.Z,{value:"yarn",label:"Yarn",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"yarn add @middy/ssm\nyarn add --dev @aws-sdk/client-ssm\n"))),(0,r.kt)(s.Z,{value:"pnpm",label:"pnpm",mdxType:"TabItem"},(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"pnpm add @middy/ssm\npnpm add --save-dev @aws-sdk/client-ssm\n")))),(0,r.kt)("h2",{id:"options"},"Options"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"AwsClient")," (object) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"SSMClient"),"): SSMClient class constructor (i.e. that has been instrumented with AWS X-Ray). Must be from ",(0,r.kt)("inlineCode",{parentName:"li"},"@aws-sdk/client-ssm"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," (object) (optional): Options to pass to SSMClient class constructor."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," (string) (optional): Internal key where role tokens are stored. See ",(0,r.kt)("a",{parentName:"li",href:"/docs/middlewares/sts"},"@middy/sts")," on to set this."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"awsClientCapture")," (function) (optional): Enable AWS X-Ray by passing ",(0,r.kt)("inlineCode",{parentName:"li"},"captureAWSv3Client")," from ",(0,r.kt)("inlineCode",{parentName:"li"},"aws-xray-sdk")," in."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"fetchData")," (object) (required): Mapping of internal key name to API request parameter ",(0,r.kt)("inlineCode",{parentName:"li"},"Names"),"/",(0,r.kt)("inlineCode",{parentName:"li"},"Path"),". ",(0,r.kt)("inlineCode",{parentName:"li"},"SecureString")," are automatically decrypted."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"disablePrefetch")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): On cold start requests will trigger early if they can. Setting ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientAssumeRole")," disables prefetch."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheKey")," (string) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"ssm"),"): Cache key for the fetched data responses. Must be unique across all middleware."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"cacheExpiry")," (number) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),"): How long fetch data responses should be cached for. ",(0,r.kt)("inlineCode",{parentName:"li"},"-1"),": cache forever, ",(0,r.kt)("inlineCode",{parentName:"li"},"0"),": never cache, ",(0,r.kt)("inlineCode",{parentName:"li"},"n"),": cache for n ms."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"setToContext")," (boolean) (default ",(0,r.kt)("inlineCode",{parentName:"li"},"false"),"): Store role tokens to ",(0,r.kt)("inlineCode",{parentName:"li"},"request.context"),".")),(0,r.kt)("p",null,"NOTES:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Lambda is required to have IAM permission for ",(0,r.kt)("inlineCode",{parentName:"li"},"ssm:GetParameters")," and/or ",(0,r.kt)("inlineCode",{parentName:"li"},"ssm:GetParametersByPath")," depending on what you're requesting, along with ",(0,r.kt)("inlineCode",{parentName:"li"},"kms:Decrypt"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"SSM")," has ",(0,r.kt)("a",{parentName:"li",href:"https://docs.aws.amazon.com/general/latest/gr/ssm.html"},"throughput limitations"),". Switching to Advanced Parameter type or increasing ",(0,r.kt)("inlineCode",{parentName:"li"},"maxRetries")," and ",(0,r.kt)("inlineCode",{parentName:"li"},"retryDelayOptions.base")," in ",(0,r.kt)("inlineCode",{parentName:"li"},"awsClientOptions")," may be required.")),(0,r.kt)("h2",{id:"sample-usage"},"Sample usage"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport ssm from '@middy/ssm'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nlet globalDefaults = {}\nhandler\n .use(\n ssm({\n fetchData: {\n accessToken: '/dev/service_name/access_token', // single value\n dbParams: '/dev/service_name/database/', // object of values, key for each path\n defaults: '/dev/defaults'\n },\n setToContext: true\n })\n )\n .before((request) => {\n globalDefaults = request.context.defaults.global\n })\n")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-javascript"},"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport ssm from '@middy/ssm'\n\nconst handler = middy((event, context) => {\n return {}\n})\n\nlet globalDefaults = {}\nhandler\n .use(\n ssm({\n fetchData: {\n defaults: '/dev/defaults'\n },\n cacheKey: 'ssm-defaults'\n })\n )\n .use(\n ssm({\n fetchData: {\n accessToken: '/dev/service_name/access_token', // single value\n dbParams: '/dev/service_name/database/' // object of values, key for each path\n },\n cacheExpiry: 15 * 60 * 1000,\n cacheKey: 'ssm-secrets'\n })\n )\n // ... other middleware that fetch\n .before(async (request) => {\n const data = await getInternal(\n ['accessToken', 'dbParams', 'defaults'],\n request\n )\n Object.assign(request.context, data)\n })\n")),(0,r.kt)("h2",{id:"bundling"},"Bundling"),(0,r.kt)("p",null,"To exclude ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk")," add ",(0,r.kt)("inlineCode",{parentName:"p"},"@aws-sdk/client-ssm")," to the exclude list."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/main.ae96d8f4.js b/assets/js/main.2c8d4a2c.js similarity index 99% rename from assets/js/main.ae96d8f4.js rename to assets/js/main.2c8d4a2c.js index e829889e2..2c6c9e26c 100644 --- a/assets/js/main.ae96d8f4.js +++ b/assets/js/main.2c8d4a2c.js @@ -1,2 +1,2 @@ -/*! For license information please see main.ae96d8f4.js.LICENSE.txt */ -(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[179],{723:(e,t,n)=>{"use strict";n.d(t,{Z:()=>f});var r=n(7294),a=n(7462),o=n(8356),i=n.n(o),l=n(6887);const s={"00787874":[()=>n.e(8086).then(n.t.bind(n,9577,19)),"~docs/default/category-docs-tutorialsidebar-category-middy-intro-32a.json",9577],"01c9695c":[()=>Promise.all([n.e(532),n.e(3295)]).then(n.bind(n,4284)),"@site/docs/middlewares/http-json-body-parser.md",4284],"028754be":[()=>n.e(6238).then(n.bind(n,6105)),"@site/docs/events/sqs.md",6105],"0480b142":[()=>n.e(836).then(n.bind(n,3584)),"@site/docs/faq.md",3584],"08eadb91":[()=>n.e(1428).then(n.bind(n,8118)),"@site/docs/writing-middlewares/01-intro.md",8118],"08f83687":[()=>n.e(5409).then(n.bind(n,8710)),"@site/docs/events/code-commit.md",8710],"0976e874":[()=>Promise.all([n.e(532),n.e(4267)]).then(n.bind(n,6252)),"@site/docs/middlewares/error-logger.md",6252],"0ce61a91":[()=>n.e(6540).then(n.bind(n,9398)),"@site/docs/best-practices/05-bundling.md",9398],"0d245e6a":[()=>n.e(8481).then(n.bind(n,5505)),"@site/docs/events/kinesis-firehose.md",5505],"0e90e864":[()=>Promise.all([n.e(532),n.e(1469)]).then(n.bind(n,5891)),"@site/docs/middlewares/secrets-manager.md",5891],"1124057e":[()=>Promise.all([n.e(532),n.e(2308)]).then(n.bind(n,4724)),"@site/docs/middlewares/dynamodb.md",4724],"14eb3368":[()=>Promise.all([n.e(532),n.e(9817)]).then(n.bind(n,4228)),"@theme/DocCategoryGeneratedIndexPage",4228],"171930c3":[()=>n.e(2786).then(n.bind(n,5933)),"@site/docs/integrations/RDS.md",5933],17896441:[()=>Promise.all([n.e(532),n.e(614),n.e(817),n.e(7918)]).then(n.bind(n,230)),"@theme/DocItem",230],"18dc5a76":[()=>n.e(7566).then(n.bind(n,8134)),"@site/docs/events/api-gateway-http.md",8134],"19606b2d":[()=>Promise.all([n.e(532),n.e(1544)]).then(n.bind(n,236)),"@site/docs/middlewares/event-normalizer.md",236],"1be78505":[()=>Promise.all([n.e(532),n.e(9514)]).then(n.bind(n,9963)),"@theme/DocPage",9963],"1c88510b":[()=>Promise.all([n.e(532),n.e(7858)]).then(n.bind(n,1113)),"@site/docs/middlewares/s3-object-response.md",1113],"1e42f3f3":[()=>n.e(8102).then(n.bind(n,8714)),"@site/docs/middlewares/ws-json-body-parser.md",8714],"1ea8ecd6":[()=>n.e(5341).then(n.bind(n,6157)),"@site/docs/events/iot.md",6157],"1f391b9e":[()=>Promise.all([n.e(532),n.e(614),n.e(817),n.e(3085)]).then(n.bind(n,4247)),"@theme/MDXPage",4247],"211396ae":[()=>n.e(3616).then(n.bind(n,6862)),"@site/docs/events/cloud-watch-logs.md",6862],"24a252b9":[()=>Promise.all([n.e(532),n.e(1098)]).then(n.bind(n,5796)),"@site/docs/middlewares/input-output-logger.md",5796],"28b74e92":[()=>n.e(3839).then(n.bind(n,352)),"@site/docs/events/cloud-trail.md",352],"2b234cfe":[()=>n.e(9158).then(n.bind(n,3959)),"@site/docs/events/secrets-manager.md",3959],"2e6cdb22":[()=>Promise.all([n.e(532),n.e(5774)]).then(n.bind(n,4087)),"@site/docs/middlewares/ws-response.md",4087],"2f4f2e7a":[()=>n.e(5222).then(n.bind(n,5088)),"@site/docs/events/alexa.md",5088],"340d0816":[()=>n.e(8729).then(n.bind(n,997)),"@site/docs/events/mq.md",997],"34ad80cb":[()=>n.e(4662).then(n.bind(n,4131)),"@site/docs/events/cloud-front.md",4131],"34ebece8":[()=>n.e(5853).then(n.bind(n,8088)),"@site/docs/events/workmail.md",8088],"3673b941":[()=>Promise.all([n.e(532),n.e(2344)]).then(n.bind(n,3230)),"@site/docs/middlewares/rds-signer.md",3230],"393be207":[()=>n.e(7414).then(n.bind(n,3123)),"@site/src/pages/markdown-page.md",3123],"3a74057e":[()=>n.e(517).then(n.bind(n,2952)),"@site/docs/integrations/pino.md",2952],"3db93d31":[()=>Promise.all([n.e(532),n.e(3631)]).then(n.bind(n,7427)),"@site/docs/middlewares/http-multipart-body-parser.md",7427],"3e0add53":[()=>n.e(4844).then(n.t.bind(n,3769,19)),"/home/runner/work/middy/middy/website/.docusaurus/docusaurus-plugin-content-docs/default/plugin-route-context-module-100.json",3769],"3ea7551b":[()=>n.e(9868).then(n.t.bind(n,9207,19)),"~docs/default/category-docs-tutorialsidebar-category-best-practices-14d.json",9207],"3f569cdf":[()=>Promise.all([n.e(532),n.e(3775)]).then(n.bind(n,504)),"@site/docs/middlewares/warmup.md",504],"4149078a":[()=>n.e(4183).then(n.bind(n,7794)),"@site/docs/upgrade/2-3.md",7794],"41b3f383":[()=>Promise.all([n.e(532),n.e(479)]).then(n.bind(n,6241)),"@site/docs/middlewares/service-discovery.md",6241],"436b299f":[()=>Promise.all([n.e(532),n.e(5077)]).then(n.bind(n,3687)),"@site/docs/middlewares/http-error-handler.md",3687],"44063d41":[()=>n.e(5709).then(n.t.bind(n,1290,19)),"~docs/default/category-docs-tutorialsidebar-category-upgrade-a5e.json",1290],"447662a1":[()=>n.e(1768).then(n.bind(n,9705)),"@site/docs/writing-middlewares/02-configurable-middlewares.md",9705],"4924cac4":[()=>Promise.all([n.e(532),n.e(5270)]).then(n.bind(n,8760)),"@site/docs/middlewares/http-cors.md",8760],"49fe1afb":[()=>n.e(9076).then(n.bind(n,1093)),"@site/docs/writing-middlewares/07-with-typescript.md",1093],"4f2dd8bc":[()=>n.e(8792).then(n.t.bind(n,1720,19)),"~docs/default/category-docs-tutorialsidebar-category-integrations-b7d.json",1720],"4f3a9363":[()=>n.e(8852).then(n.bind(n,5571)),"@site/docs/events/documentdb.md",5571],"5018e04c":[()=>n.e(9862).then(n.bind(n,377)),"@site/docs/intro/06-typescript.md",377],"52912c74":[()=>n.e(7452).then(n.bind(n,578)),"@site/docs/events/event-bridge.md",578],"53f1e98a":[()=>n.e(2469).then(n.bind(n,4572)),"@site/docs/events/s3.md",4572],"54ed1cf2":[()=>n.e(6827).then(n.bind(n,2492)),"@site/docs/best-practices/07-profiling.md",2492],"54fc444e":[()=>n.e(1790).then(n.bind(n,3817)),"@site/docs/best-practices/02-connection-reuse.md",3817],"56ed1c64":[()=>n.e(4097).then(n.bind(n,8393)),"@site/docs/events/01-intro.md",8393],"58ba397f":[()=>Promise.all([n.e(532),n.e(1497)]).then(n.bind(n,3278)),"@site/docs/middlewares/http-urlencode-path-parser.md",3278],"590578cb":[()=>n.e(3181).then(n.bind(n,4393)),"@site/docs/intro/08-history.md",4393],"59ac4306":[()=>Promise.all([n.e(532),n.e(3151)]).then(n.bind(n,6381)),"@site/docs/middlewares/http-urlencode-body-parser.md",6381],"5a01598e":[()=>n.e(4297).then(n.bind(n,3699)),"@site/docs/upgrade/3-4.md",3699],"5afe45f2":[()=>Promise.all([n.e(532),n.e(5938)]).then(n.bind(n,6179)),"@site/docs/intro/02-getting-started.md",6179],"5e80d65e":[()=>n.e(1436).then(n.bind(n,7164)),"@site/docs/intro/07-hooks.md",7164],"5e9f5e1a":[()=>Promise.resolve().then(n.bind(n,6809)),"@generated/docusaurus.config",6809],"632f0854":[()=>n.e(9997).then(n.bind(n,698)),"@site/docs/writing-middlewares/05-timeouts.md",698],"646b055a":[()=>n.e(5686).then(n.bind(n,5010)),"@site/docs/events/s3-batch.md",5010],"654635c7":[()=>Promise.all([n.e(532),n.e(1338)]).then(n.bind(n,3423)),"@site/docs/routers/http-router.md",3423],"65ce35be":[()=>n.e(8002).then(n.bind(n,8056)),"@site/docs/events/kafka-self-managed.md",8056],"667584a0":[()=>n.e(2600).then(n.bind(n,1023)),"@site/docs/events/sns.md",1023],"68318e94":[()=>n.e(811).then(n.bind(n,1910)),"@site/docs/events/api-gateway-authorizer.md",1910],"687b60fb":[()=>n.e(7783).then(n.bind(n,2391)),"@site/docs/upgrade/0-1.md",2391],"6a1376e9":[()=>Promise.all([n.e(532),n.e(8644)]).then(n.bind(n,7886)),"@site/docs/middlewares/sqs-partial-batch-failure.md",7886],"6c4d050a":[()=>Promise.all([n.e(532),n.e(5512)]).then(n.bind(n,3058)),"@site/docs/middlewares/http-header-normalizer.md",3058],70761510:[()=>n.e(5024).then(n.bind(n,491)),"@site/docs/best-practices/06-small-node-modules.md",491],"7076eee1":[()=>n.e(481).then(n.bind(n,5846)),"@site/docs/events/application-load-balancer.md",5846],"71d5009c":[()=>n.e(2193).then(n.bind(n,9987)),"@site/docs/events/config.md",9987],73083085:[()=>n.e(8365).then(n.bind(n,4465)),"@site/docs/events/api-gateway-rest.md",4465],"7745d517":[()=>Promise.all([n.e(532),n.e(1702)]).then(n.bind(n,2426)),"@site/docs/middlewares/appconfig.md",2426],79674995:[()=>n.e(8200).then(n.bind(n,1189)),"@site/docs/events/cloud-formation.md",1189],"796ad5a5":[()=>n.e(6172).then(n.bind(n,4619)),"@site/docs/events/appsync.md",4619],"7cb784f6":[()=>n.e(711).then(n.bind(n,7124)),"@site/docs/upgrade/1-2.md",7124],"810a87d2":[()=>n.e(8455).then(n.t.bind(n,2472,19)),"~docs/default/category-docs-tutorialsidebar-category-writing-middlewares-c2b.json",2472],"871ff594":[()=>n.e(7359).then(n.t.bind(n,5745,19)),"/home/runner/work/middy/middy/website/.docusaurus/docusaurus-plugin-content-pages/default/plugin-route-context-module-100.json",5745],"89ce8835":[()=>n.e(1955).then(n.bind(n,8086)),"@site/docs/events/cognito.md",8086],"935f2afb":[()=>n.e(53).then(n.t.bind(n,1109,19)),"~docs/default/version-current-metadata-prop-751.json",1109],"949815f5":[()=>n.e(8394).then(n.bind(n,1057)),"@site/docs/events/kafka-managed-streaming.md",1057],"958c573d":[()=>n.e(8786).then(n.bind(n,6551)),"@site/docs/events/s3-object.md",6551],"9d43f09c":[()=>n.e(8591).then(n.bind(n,3380)),"@site/docs/events/ec2.md",3380],"9d560f77":[()=>n.e(310).then(n.bind(n,7904)),"@site/docs/events/dynamodb.md",7904],a0697f1b:[()=>n.e(5258).then(n.bind(n,5549)),"@site/docs/events/vpc-lattice.md",5549],a07e9812:[()=>n.e(2511).then(n.bind(n,7963)),"@site/docs/events/rds.md",7963],a17e0e42:[()=>Promise.all([n.e(532),n.e(2201)]).then(n.bind(n,6951)),"@site/docs/middlewares/s3.md",6951],a2b2d33a:[()=>n.e(8974).then(n.bind(n,4794)),"@site/docs/writing-middlewares/06-more-examples.md",4794],a3787fd8:[()=>n.e(9576).then(n.bind(n,6710)),"@site/docs/intro/08-influence.md",6710],a7630442:[()=>n.e(9502).then(n.bind(n,1822)),"@site/docs/intro/11-sponsoring.md",1822],a7c9f8b5:[()=>n.e(5898).then(n.bind(n,6881)),"@site/docs/events/ses.md",6881],a8e9225e:[()=>Promise.all([n.e(532),n.e(9319)]).then(n.bind(n,1468)),"@site/docs/middlewares/http-content-negotiation.md",1468],acb7d57c:[()=>n.e(1819).then(n.bind(n,3019)),"@site/docs/best-practices/01-intro.md",3019],ace0032f:[()=>n.e(2521).then(n.bind(n,1173)),"@site/docs/integrations/serverless-stack.md",1173],ad1e712e:[()=>n.e(9235).then(n.bind(n,6592)),"@site/docs/middlewares/00-intro.md",6592],aecdbf7e:[()=>Promise.all([n.e(532),n.e(1073)]).then(n.bind(n,7676)),"@site/docs/middlewares/cloudwatch-metrics.md",7676],afa23cb9:[()=>n.e(6161).then(n.t.bind(n,2982,19)),"~docs/default/category-docs-tutorialsidebar-category-middlewares-a97.json",2982],b3edb814:[()=>Promise.all([n.e(532),n.e(3786)]).then(n.bind(n,6995)),"@site/docs/middlewares/sts.md",6995],b5163cd3:[()=>n.e(4751).then(n.bind(n,5024)),"@site/docs/integrations/01-intro.md",5024],b5584809:[()=>n.e(2803).then(n.bind(n,4316)),"@site/docs/integrations/serverless-framework.md",4316],b5aee65c:[()=>n.e(4510).then(n.bind(n,4543)),"@site/docs/intro/09-release-cycle.md",4543],b6105e9b:[()=>n.e(8471).then(n.bind(n,304)),"@site/docs/events/code-pipeline.md",304],b6b85ed9:[()=>Promise.all([n.e(532),n.e(6476)]).then(n.bind(n,3976)),"@site/docs/middlewares/http-content-encoding.md",3976],b83c886a:[()=>n.e(8931).then(n.bind(n,1235)),"@site/docs/intro/10-contributing.md",1235],b9c75af0:[()=>n.e(4504).then(n.bind(n,8525)),"@site/docs/events/kinesis-streams.md",8525],bff6c11b:[()=>n.e(4785).then(n.bind(n,7123)),"@site/docs/events/api-gateway-ws.md",7123],c0ad98a5:[()=>Promise.all([n.e(532),n.e(2932)]).then(n.bind(n,5535)),"@site/docs/middlewares/http-partial-response.md",5535],c1378803:[()=>Promise.all([n.e(532),n.e(7450)]).then(n.bind(n,9310)),"@site/docs/integrations/lambda-powertools.md",9310],c21432a2:[()=>n.e(1570).then(n.bind(n,8112)),"@site/docs/intro/06-streamify-response.md",8112],c2371ba7:[()=>Promise.all([n.e(532),n.e(7724)]).then(n.bind(n,6933)),"@site/docs/middlewares/http-response-serializer.md",6933],c4f5d8e4:[()=>Promise.all([n.e(532),n.e(614),n.e(4195)]).then(n.bind(n,4537)),"@site/src/pages/index.js",4537],c4fefc0c:[()=>n.e(7812).then(n.bind(n,9945)),"@site/docs/best-practices/03-internal-context.md",9945],cb00b214:[()=>n.e(1721).then(n.t.bind(n,736,19)),"~docs/default/category-docs-tutorialsidebar-category-aws-event-examples-51d.json",736],cc16eb0f:[()=>n.e(5893).then(n.bind(n,3313)),"@site/docs/events/lex.md",3313],cd47eedf:[()=>n.e(4388).then(n.bind(n,8609)),"@site/docs/intro/05-handling-errors.md",8609],ce7003dc:[()=>n.e(9071).then(n.bind(n,6949)),"@site/docs/writing-middlewares/03-inline-middlewares.md",6949],d0953a14:[()=>Promise.all([n.e(532),n.e(4740)]).then(n.bind(n,3144)),"@site/docs/middlewares/validator.md",3144],d80baa5c:[()=>n.e(9647).then(n.bind(n,7906)),"@site/docs/writing-middlewares/04-internal-storage.md",7906],da0b5c8a:[()=>Promise.all([n.e(532),n.e(7796)]).then(n.bind(n,7837)),"@site/docs/middlewares/do-not-wait-for-empty-event-loop.md",7837],dbc9373d:[()=>Promise.all([n.e(532),n.e(9116)]).then(n.bind(n,8406)),"@site/docs/middlewares/http-security-headers.md",8406],e0fb88b0:[()=>n.e(4288).then(n.bind(n,2627)),"@site/docs/middlewares/third-party.md",2627],e1c77d88:[()=>n.e(6388).then(n.bind(n,3009)),"@site/docs/integrations/apollo-server.md",3009],e326eb4c:[()=>n.e(7677).then(n.t.bind(n,8203,19)),"~docs/default/category-docs-tutorialsidebar-category-routers-ed1.json",8203],ea2a30f2:[()=>n.e(527).then(n.bind(n,5186)),"@site/docs/intro/06-testing.md",5186],ec96ff11:[()=>n.e(7276).then(n.bind(n,8849)),"@site/docs/intro/08-utilities.md",8849],ecbeea21:[()=>n.e(9310).then(n.bind(n,5262)),"@site/docs/intro/01-intro.md",5262],f0136a98:[()=>Promise.all([n.e(532),n.e(1575)]).then(n.bind(n,1144)),"@site/docs/middlewares/http-event-normalizer.md",1144],f0886e87:[()=>n.e(3955).then(n.bind(n,8569)),"@site/docs/events/function-url.md",8569],f20815ad:[()=>n.e(4760).then(n.bind(n,3750)),"@site/docs/events/connect.md",3750],f33bafb6:[()=>n.e(8185).then(n.bind(n,265)),"@site/docs/routers/ws-router.md",265],f795adf5:[()=>n.e(8841).then(n.bind(n,9677)),"@site/docs/intro/04-early-interrupt.md",9677],f9850e34:[()=>n.e(6177).then(n.bind(n,1977)),"@site/docs/intro/03-how-it-works.md",1977],faf674c6:[()=>n.e(4962).then(n.bind(n,4011)),"@site/docs/events/iot-events.md",4011],ff488875:[()=>Promise.all([n.e(532),n.e(1531)]).then(n.bind(n,4785)),"@site/docs/middlewares/ssm.md",4785]};function c(e){let{error:t,retry:n,pastDelay:a}=e;return t?r.createElement("div",{style:{textAlign:"center",color:"#fff",backgroundColor:"#fa383e",borderColor:"#fa383e",borderStyle:"solid",borderRadius:"0.25rem",borderWidth:"1px",boxSizing:"border-box",display:"block",padding:"1rem",flex:"0 0 50%",marginLeft:"25%",marginRight:"25%",marginTop:"5rem",maxWidth:"50%",width:"100%"}},r.createElement("p",null,String(t)),r.createElement("div",null,r.createElement("button",{type:"button",onClick:n},"Retry"))):a?r.createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"}},r.createElement("svg",{id:"loader",style:{width:128,height:110,position:"absolute",top:"calc(100vh - 64%)"},viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",stroke:"#61dafb"},r.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(1 1)",strokeWidth:"2"},r.createElement("circle",{cx:"22",cy:"22",r:"6",strokeOpacity:"0"},r.createElement("animate",{attributeName:"r",begin:"1.5s",dur:"3s",values:"6;22",calcMode:"linear",repeatCount:"indefinite"}),r.createElement("animate",{attributeName:"stroke-opacity",begin:"1.5s",dur:"3s",values:"1;0",calcMode:"linear",repeatCount:"indefinite"}),r.createElement("animate",{attributeName:"stroke-width",begin:"1.5s",dur:"3s",values:"2;0",calcMode:"linear",repeatCount:"indefinite"})),r.createElement("circle",{cx:"22",cy:"22",r:"6",strokeOpacity:"0"},r.createElement("animate",{attributeName:"r",begin:"3s",dur:"3s",values:"6;22",calcMode:"linear",repeatCount:"indefinite"}),r.createElement("animate",{attributeName:"stroke-opacity",begin:"3s",dur:"3s",values:"1;0",calcMode:"linear",repeatCount:"indefinite"}),r.createElement("animate",{attributeName:"stroke-width",begin:"3s",dur:"3s",values:"2;0",calcMode:"linear",repeatCount:"indefinite"})),r.createElement("circle",{cx:"22",cy:"22",r:"8"},r.createElement("animate",{attributeName:"r",begin:"0s",dur:"1.5s",values:"6;1;2;3;4;5;6",calcMode:"linear",repeatCount:"indefinite"}))))):null}var u=n(9670),d=n(226);function p(e,t){if("*"===e)return i()({loading:c,loader:()=>n.e(4204).then(n.bind(n,4204)),modules:["@theme/NotFound"],webpack:()=>[4204],render(e,t){const n=e.default;return r.createElement(d.z,{value:{plugin:{name:"native",id:"default"}}},r.createElement(n,t))}});const o=l[`${e}-${t}`],p={},f=[],m=[],h=(0,u.Z)(o);return Object.entries(h).forEach((e=>{let[t,n]=e;const r=s[n];r&&(p[t]=r[0],f.push(r[1]),m.push(r[2]))})),i().Map({loading:c,loader:p,modules:f,webpack:()=>m,render(t,n){const i=JSON.parse(JSON.stringify(o));Object.entries(t).forEach((t=>{let[n,r]=t;const a=r.default;if(!a)throw new Error(`The page component at ${e} doesn't have a default export. This makes it impossible to render anything. Consider default-exporting a React component.`);"object"!=typeof a&&"function"!=typeof a||Object.keys(r).filter((e=>"default"!==e)).forEach((e=>{a[e]=r[e]}));let o=i;const l=n.split(".");l.slice(0,-1).forEach((e=>{o=o[e]})),o[l[l.length-1]]=a}));const l=i.__comp;delete i.__comp;const s=i.__context;return delete i.__context,r.createElement(d.z,{value:s},r.createElement(l,(0,a.Z)({},i,n)))}})}const f=[{path:"/markdown-page",component:p("/markdown-page","08c"),exact:!0},{path:"/docs",component:p("/docs","7a8"),routes:[{path:"/docs/",component:p("/docs/","a61"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/bundling",component:p("/docs/best-practices/bundling","ec3"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/connection-reuse",component:p("/docs/best-practices/connection-reuse","e9a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/internal-context",component:p("/docs/best-practices/internal-context","fb7"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/intro",component:p("/docs/best-practices/intro","816"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/profiling",component:p("/docs/best-practices/profiling","6cf"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/small-node-modules",component:p("/docs/best-practices/small-node-modules","385"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/aws-event-examples",component:p("/docs/category/aws-event-examples","116"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/best-practices",component:p("/docs/category/best-practices","320"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/integrations",component:p("/docs/category/integrations","3d4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/intro-to-middy",component:p("/docs/category/intro-to-middy","a3d"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/middlewares",component:p("/docs/category/middlewares","65f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/routers",component:p("/docs/category/routers","8cd"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/upgrade",component:p("/docs/category/upgrade","558"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/writing-middlewares",component:p("/docs/category/writing-middlewares","c76"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/alexa",component:p("/docs/events/alexa","561"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/api-gateway-authorizer",component:p("/docs/events/api-gateway-authorizer","b1d"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/api-gateway-http",component:p("/docs/events/api-gateway-http","dc8"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/api-gateway-rest",component:p("/docs/events/api-gateway-rest","1d4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/api-gateway-ws",component:p("/docs/events/api-gateway-ws","ddb"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/application-load-balancer",component:p("/docs/events/application-load-balancer","344"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/appsync",component:p("/docs/events/appsync","c0f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cloud-formation",component:p("/docs/events/cloud-formation","134"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cloud-front",component:p("/docs/events/cloud-front","2e5"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cloud-trail",component:p("/docs/events/cloud-trail","ec9"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cloud-watch-logs",component:p("/docs/events/cloud-watch-logs","21e"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/code-commit",component:p("/docs/events/code-commit","676"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/code-pipeline",component:p("/docs/events/code-pipeline","785"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cognito",component:p("/docs/events/cognito","207"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/config",component:p("/docs/events/config","bfe"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/connect",component:p("/docs/events/connect","f4d"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/documentdb",component:p("/docs/events/documentdb","7a2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/dynamodb",component:p("/docs/events/dynamodb","53a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/ec2",component:p("/docs/events/ec2","94f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/event-bridge",component:p("/docs/events/event-bridge","3bf"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/function-url",component:p("/docs/events/function-url","b85"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/intro",component:p("/docs/events/intro","e69"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/iot",component:p("/docs/events/iot","cea"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/iot-events",component:p("/docs/events/iot-events","6c2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/kafka-managed-streaming",component:p("/docs/events/kafka-managed-streaming","bbd"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/kafka-self-managed",component:p("/docs/events/kafka-self-managed","d9e"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/kinesis-firehose",component:p("/docs/events/kinesis-firehose","253"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/kinesis-streams",component:p("/docs/events/kinesis-streams","9aa"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/lex",component:p("/docs/events/lex","af4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/mq",component:p("/docs/events/mq","5eb"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/rds",component:p("/docs/events/rds","3c4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/s3",component:p("/docs/events/s3","05f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/s3-batch",component:p("/docs/events/s3-batch","e3b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/s3-object",component:p("/docs/events/s3-object","d5a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/secrets-manager",component:p("/docs/events/secrets-manager","ea6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/ses",component:p("/docs/events/ses","22b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/sns",component:p("/docs/events/sns","af6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/sqs",component:p("/docs/events/sqs","2ce"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/vpc-lattice",component:p("/docs/events/vpc-lattice","ec4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/workmail",component:p("/docs/events/workmail","541"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/faq",component:p("/docs/faq","e79"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/apollo-server",component:p("/docs/integrations/apollo-server","d7d"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/intro",component:p("/docs/integrations/intro","0d2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/lambda-powertools",component:p("/docs/integrations/lambda-powertools","57c"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/pino",component:p("/docs/integrations/pino","2b6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/RDS",component:p("/docs/integrations/RDS","c6b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/serverless-framework",component:p("/docs/integrations/serverless-framework","95a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/serverless-stack",component:p("/docs/integrations/serverless-stack","206"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/contributing",component:p("/docs/intro/contributing","e03"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/early-interrupt",component:p("/docs/intro/early-interrupt","5ac"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/getting-started",component:p("/docs/intro/getting-started","224"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/handling-errors",component:p("/docs/intro/handling-errors","9da"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/history",component:p("/docs/intro/history","b44"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/hooks",component:p("/docs/intro/hooks","bb3"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/how-it-works",component:p("/docs/intro/how-it-works","965"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/influence",component:p("/docs/intro/influence","6be"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/release-cycle",component:p("/docs/intro/release-cycle","f31"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/sponsoring",component:p("/docs/intro/sponsoring","578"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/streamify-response",component:p("/docs/intro/streamify-response","9ee"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/testing",component:p("/docs/intro/testing","064"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/typescript",component:p("/docs/intro/typescript","3e8"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/utilities",component:p("/docs/intro/utilities","b1f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/appconfig",component:p("/docs/middlewares/appconfig","ca4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/cloudwatch-metrics",component:p("/docs/middlewares/cloudwatch-metrics","8bc"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/do-not-wait-for-empty-event-loop",component:p("/docs/middlewares/do-not-wait-for-empty-event-loop","579"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/dynamodb",component:p("/docs/middlewares/dynamodb","8d2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/error-logger",component:p("/docs/middlewares/error-logger","388"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/event-normalizer",component:p("/docs/middlewares/event-normalizer","6b6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-content-encoding",component:p("/docs/middlewares/http-content-encoding","404"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-content-negotiation",component:p("/docs/middlewares/http-content-negotiation","b8b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-cors",component:p("/docs/middlewares/http-cors","d5f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-error-handler",component:p("/docs/middlewares/http-error-handler","044"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-event-normalizer",component:p("/docs/middlewares/http-event-normalizer","442"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-header-normalizer",component:p("/docs/middlewares/http-header-normalizer","614"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-json-body-parser",component:p("/docs/middlewares/http-json-body-parser","6df"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-multipart-body-parser",component:p("/docs/middlewares/http-multipart-body-parser","022"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-partial-response",component:p("/docs/middlewares/http-partial-response","35c"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-response-serializer",component:p("/docs/middlewares/http-response-serializer","041"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-security-headers",component:p("/docs/middlewares/http-security-headers","410"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-urlencode-body-parser",component:p("/docs/middlewares/http-urlencode-body-parser","041"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-urlencode-path-parser",component:p("/docs/middlewares/http-urlencode-path-parser","678"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/input-output-logger",component:p("/docs/middlewares/input-output-logger","40b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/intro",component:p("/docs/middlewares/intro","e79"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/rds-signer",component:p("/docs/middlewares/rds-signer","a53"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/s3",component:p("/docs/middlewares/s3","b3a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/s3-object-response",component:p("/docs/middlewares/s3-object-response","5ed"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/secrets-manager",component:p("/docs/middlewares/secrets-manager","381"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/service-discovery",component:p("/docs/middlewares/service-discovery","d35"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/sqs-partial-batch-failure",component:p("/docs/middlewares/sqs-partial-batch-failure","4f2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/ssm",component:p("/docs/middlewares/ssm","42b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/sts",component:p("/docs/middlewares/sts","522"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/third-party",component:p("/docs/middlewares/third-party","588"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/validator",component:p("/docs/middlewares/validator","37c"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/warmup",component:p("/docs/middlewares/warmup","d75"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/ws-json-body-parser",component:p("/docs/middlewares/ws-json-body-parser","8b5"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/ws-response",component:p("/docs/middlewares/ws-response","702"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/routers/http-router",component:p("/docs/routers/http-router","9b1"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/routers/ws-router",component:p("/docs/routers/ws-router","354"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/0-1",component:p("/docs/upgrade/0-1","95b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/1-2",component:p("/docs/upgrade/1-2","667"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/2-3",component:p("/docs/upgrade/2-3","b3c"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/3-4",component:p("/docs/upgrade/3-4","809"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/configurable-middlewares",component:p("/docs/writing-middlewares/configurable-middlewares","4e7"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/inline-middlewares",component:p("/docs/writing-middlewares/inline-middlewares","d97"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/internal-storage",component:p("/docs/writing-middlewares/internal-storage","cc1"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/intro",component:p("/docs/writing-middlewares/intro","b44"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/more-examples",component:p("/docs/writing-middlewares/more-examples","fa2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/timeouts",component:p("/docs/writing-middlewares/timeouts","1a6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/with-typescript",component:p("/docs/writing-middlewares/with-typescript","863"),exact:!0,sidebar:"tutorialSidebar"}]},{path:"/",component:p("/","645"),exact:!0},{path:"*",component:p("*")}]},8934:(e,t,n)=>{"use strict";n.d(t,{_:()=>a,t:()=>o});var r=n(7294);const a=r.createContext(!1);function o(e){let{children:t}=e;const[n,o]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{o(!0)}),[]),r.createElement(a.Provider,{value:n},t)}},7221:(e,t,n)=>{"use strict";var r=n(7294),a=n(3935),o=n(3727),i=n(405),l=n(412);const s=[n(2497),n(3310),n(8320),n(2295)];var c=n(723),u=n(6550),d=n(8790);function p(e){let{children:t}=e;return r.createElement(r.Fragment,null,t)}var f=n(7462),m=n(5742),h=n(2263),g=n(4996),b=n(6668),v=n(1944),y=n(4711),w=n(9727),k=n(3320),S=n(8780),E=n(197);function x(){const{i18n:{defaultLocale:e,localeConfigs:t}}=(0,h.Z)(),n=(0,y.l)();return r.createElement(m.Z,null,Object.entries(t).map((e=>{let[t,{htmlLang:a}]=e;return r.createElement("link",{key:t,rel:"alternate",href:n.createUrl({locale:t,fullyQualified:!0}),hrefLang:a})})),r.createElement("link",{rel:"alternate",href:n.createUrl({locale:e,fullyQualified:!0}),hrefLang:"x-default"}))}function _(e){let{permalink:t}=e;const{siteConfig:{url:n}}=(0,h.Z)(),a=function(){const{siteConfig:{url:e,baseUrl:t,trailingSlash:n}}=(0,h.Z)(),{pathname:r}=(0,u.TH)();return e+(0,S.applyTrailingSlash)((0,g.Z)(r),{trailingSlash:n,baseUrl:t})}(),o=t?`${n}${t}`:a;return r.createElement(m.Z,null,r.createElement("meta",{property:"og:url",content:o}),r.createElement("link",{rel:"canonical",href:o}))}function C(){const{i18n:{currentLocale:e}}=(0,h.Z)(),{metadata:t,image:n}=(0,b.L)();return r.createElement(r.Fragment,null,r.createElement(m.Z,null,r.createElement("meta",{name:"twitter:card",content:"summary_large_image"}),r.createElement("body",{className:w.h})),n&&r.createElement(v.d,{image:n}),r.createElement(_,null),r.createElement(x,null),r.createElement(E.Z,{tag:k.HX,locale:e}),r.createElement(m.Z,null,t.map(((e,t)=>r.createElement("meta",(0,f.Z)({key:t},e))))))}const T=new Map;function A(e){if(T.has(e.pathname))return{...e,pathname:T.get(e.pathname)};if((0,d.f)(c.Z,e.pathname).some((e=>{let{route:t}=e;return!0===t.exact})))return T.set(e.pathname,e.pathname),e;const t=e.pathname.trim().replace(/(?:\/index)?\.html$/,"")||"/";return T.set(e.pathname,t),{...e,pathname:t}}var L=n(8934),P=n(8940);function R(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r{const r=t.default?.[e]??t[e];return r?.(...n)}));return()=>a.forEach((e=>e?.()))}const N=function(e){let{children:t,location:n,previousLocation:a}=e;return(0,r.useLayoutEffect)((()=>{a!==n&&(!function(e){let{location:t,previousLocation:n}=e;if(!n)return;const r=t.pathname===n.pathname,a=t.hash===n.hash,o=t.search===n.search;if(r&&a&&!o)return;const{hash:i}=t;if(i){const e=decodeURIComponent(i.substring(1)),t=document.getElementById(e);t?.scrollIntoView()}else window.scrollTo(0,0)}({location:n,previousLocation:a}),R("onRouteDidUpdate",{previousLocation:a,location:n}))}),[a,n]),t};function O(e){const t=Array.from(new Set([e,decodeURI(e)])).map((e=>(0,d.f)(c.Z,e))).flat();return Promise.all(t.map((e=>e.route.component.preload?.())))}class I extends r.Component{previousLocation;routeUpdateCleanupCb;constructor(e){super(e),this.previousLocation=null,this.routeUpdateCleanupCb=l.Z.canUseDOM?R("onRouteUpdate",{previousLocation:null,location:this.props.location}):()=>{},this.state={nextRouteHasLoaded:!0}}shouldComponentUpdate(e,t){if(e.location===this.props.location)return t.nextRouteHasLoaded;const n=e.location;return this.previousLocation=this.props.location,this.setState({nextRouteHasLoaded:!1}),this.routeUpdateCleanupCb=R("onRouteUpdate",{previousLocation:this.previousLocation,location:n}),O(n.pathname).then((()=>{this.routeUpdateCleanupCb(),this.setState({nextRouteHasLoaded:!0})})).catch((e=>{console.warn(e),window.location.reload()})),!1}render(){const{children:e,location:t}=this.props;return r.createElement(N,{previousLocation:this.previousLocation,location:t},r.createElement(u.AW,{location:t,render:()=>e}))}}const D=I,M="__docusaurus-base-url-issue-banner-container",F="__docusaurus-base-url-issue-banner",j="__docusaurus-base-url-issue-banner-suggestion-container",B="__DOCUSAURUS_INSERT_BASEURL_BANNER";function z(e){return`\nwindow['${B}'] = true;\n\ndocument.addEventListener('DOMContentLoaded', maybeInsertBanner);\n\nfunction maybeInsertBanner() {\n var shouldInsert = window['${B}'];\n shouldInsert && insertBanner();\n}\n\nfunction insertBanner() {\n var bannerContainer = document.getElementById('${M}');\n if (!bannerContainer) {\n return;\n }\n var bannerHtml = ${JSON.stringify(function(e){return`\n
\n

Your Docusaurus site did not load properly.

\n

A very common reason is a wrong site baseUrl configuration.

\n

Current configured baseUrl = ${e} ${"/"===e?" (default value)":""}

\n

We suggest trying baseUrl =

\n
\n`}(e)).replace(/{window[B]=!1}),[]),r.createElement(r.Fragment,null,!l.Z.canUseDOM&&r.createElement(m.Z,null,r.createElement("script",null,z(e))),r.createElement("div",{id:M}))}function $(){const{siteConfig:{baseUrl:e,baseUrlIssueBanner:t}}=(0,h.Z)(),{pathname:n}=(0,u.TH)();return t&&n===e?r.createElement(U,null):null}function q(){const{siteConfig:{favicon:e,title:t,noIndex:n},i18n:{currentLocale:a,localeConfigs:o}}=(0,h.Z)(),i=(0,g.Z)(e),{htmlLang:l,direction:s}=o[a];return r.createElement(m.Z,null,r.createElement("html",{lang:l,dir:s}),r.createElement("title",null,t),r.createElement("meta",{property:"og:title",content:t}),r.createElement("meta",{name:"viewport",content:"width=device-width, initial-scale=1.0"}),n&&r.createElement("meta",{name:"robots",content:"noindex, nofollow"}),e&&r.createElement("link",{rel:"icon",href:i}))}var G=n(4763),H=n(2389);function Z(){const e=(0,H.Z)();return r.createElement(m.Z,null,r.createElement("html",{"data-has-hydrated":e}))}function V(){const e=(0,d.H)(c.Z),t=(0,u.TH)();return r.createElement(G.Z,null,r.createElement(P.M,null,r.createElement(L.t,null,r.createElement(p,null,r.createElement(q,null),r.createElement(C,null),r.createElement($,null),r.createElement(D,{location:A(t)},e)),r.createElement(Z,null))))}var W=n(6887);const Y=function(e){try{return document.createElement("link").relList.supports(e)}catch{return!1}}("prefetch")?function(e){return new Promise(((t,n)=>{if("undefined"==typeof document)return void n();const r=document.createElement("link");r.setAttribute("rel","prefetch"),r.setAttribute("href",e),r.onload=()=>t(),r.onerror=()=>n();const a=document.getElementsByTagName("head")[0]??document.getElementsByName("script")[0]?.parentNode;a?.appendChild(r)}))}:function(e){return new Promise(((t,n)=>{const r=new XMLHttpRequest;r.open("GET",e,!0),r.withCredentials=!0,r.onload=()=>{200===r.status?t():n()},r.send(null)}))};var K=n(9670);const X=new Set,Q=new Set,J=()=>navigator.connection?.effectiveType.includes("2g")||navigator.connection?.saveData,ee={prefetch(e){if(!(e=>!J()&&!Q.has(e)&&!X.has(e))(e))return!1;X.add(e);const t=(0,d.f)(c.Z,e).flatMap((e=>{return t=e.route.path,Object.entries(W).filter((e=>{let[n]=e;return n.replace(/-[^-]+$/,"")===t})).flatMap((e=>{let[,t]=e;return Object.values((0,K.Z)(t))}));var t}));return Promise.all(t.map((e=>{const t=n.gca(e);return t&&!t.includes("undefined")?Y(t).catch((()=>{})):Promise.resolve()})))},preload:e=>!!(e=>!J()&&!Q.has(e))(e)&&(Q.add(e),O(e))},te=Object.freeze(ee);if(l.Z.canUseDOM){window.docusaurus=te;const e=a.hydrate;O(window.location.pathname).then((()=>{e(r.createElement(i.B6,null,r.createElement(o.VK,null,r.createElement(V,null))),document.getElementById("__docusaurus"))}))}},8940:(e,t,n)=>{"use strict";n.d(t,{_:()=>u,M:()=>d});var r=n(7294),a=n(6809);const o=JSON.parse('{"docusaurus-lunr-search":{"default":{"fileNames":{"searchDoc":"search-doc-1697596251182.json","lunrIndex":"lunr-index-1697596251182.json"}}},"docusaurus-plugin-content-docs":{"default":{"path":"/docs","versions":[{"name":"current","label":"Next","isLast":true,"path":"/docs","mainDocId":"intro/intro","docs":[{"id":"best-practices/bundling","path":"/docs/best-practices/bundling","sidebar":"tutorialSidebar"},{"id":"best-practices/connection-reuse","path":"/docs/best-practices/connection-reuse","sidebar":"tutorialSidebar"},{"id":"best-practices/internal-context","path":"/docs/best-practices/internal-context","sidebar":"tutorialSidebar"},{"id":"best-practices/intro","path":"/docs/best-practices/intro","sidebar":"tutorialSidebar"},{"id":"best-practices/profiling","path":"/docs/best-practices/profiling","sidebar":"tutorialSidebar"},{"id":"best-practices/small-node-modules","path":"/docs/best-practices/small-node-modules","sidebar":"tutorialSidebar"},{"id":"events/alexa","path":"/docs/events/alexa","sidebar":"tutorialSidebar"},{"id":"events/api-gateway-authorizer","path":"/docs/events/api-gateway-authorizer","sidebar":"tutorialSidebar"},{"id":"events/api-gateway-http","path":"/docs/events/api-gateway-http","sidebar":"tutorialSidebar"},{"id":"events/api-gateway-rest","path":"/docs/events/api-gateway-rest","sidebar":"tutorialSidebar"},{"id":"events/api-gateway-ws","path":"/docs/events/api-gateway-ws","sidebar":"tutorialSidebar"},{"id":"events/application-load-balancer","path":"/docs/events/application-load-balancer","sidebar":"tutorialSidebar"},{"id":"events/appsync","path":"/docs/events/appsync","sidebar":"tutorialSidebar"},{"id":"events/cloud-formation","path":"/docs/events/cloud-formation","sidebar":"tutorialSidebar"},{"id":"events/cloud-front","path":"/docs/events/cloud-front","sidebar":"tutorialSidebar"},{"id":"events/cloud-trail","path":"/docs/events/cloud-trail","sidebar":"tutorialSidebar"},{"id":"events/cloud-watch-logs","path":"/docs/events/cloud-watch-logs","sidebar":"tutorialSidebar"},{"id":"events/code-commit","path":"/docs/events/code-commit","sidebar":"tutorialSidebar"},{"id":"events/code-pipeline","path":"/docs/events/code-pipeline","sidebar":"tutorialSidebar"},{"id":"events/cognito","path":"/docs/events/cognito","sidebar":"tutorialSidebar"},{"id":"events/config","path":"/docs/events/config","sidebar":"tutorialSidebar"},{"id":"events/connect","path":"/docs/events/connect","sidebar":"tutorialSidebar"},{"id":"events/documentdb","path":"/docs/events/documentdb","sidebar":"tutorialSidebar"},{"id":"events/dynamodb","path":"/docs/events/dynamodb","sidebar":"tutorialSidebar"},{"id":"events/ec2","path":"/docs/events/ec2","sidebar":"tutorialSidebar"},{"id":"events/event-bridge","path":"/docs/events/event-bridge","sidebar":"tutorialSidebar"},{"id":"events/function-url","path":"/docs/events/function-url","sidebar":"tutorialSidebar"},{"id":"events/intro","path":"/docs/events/intro","sidebar":"tutorialSidebar"},{"id":"events/iot","path":"/docs/events/iot","sidebar":"tutorialSidebar"},{"id":"events/iot-events","path":"/docs/events/iot-events","sidebar":"tutorialSidebar"},{"id":"events/kafka-managed-streaming","path":"/docs/events/kafka-managed-streaming","sidebar":"tutorialSidebar"},{"id":"events/kafka-self-managed","path":"/docs/events/kafka-self-managed","sidebar":"tutorialSidebar"},{"id":"events/kinesis-firehose","path":"/docs/events/kinesis-firehose","sidebar":"tutorialSidebar"},{"id":"events/kinesis-streams","path":"/docs/events/kinesis-streams","sidebar":"tutorialSidebar"},{"id":"events/lex","path":"/docs/events/lex","sidebar":"tutorialSidebar"},{"id":"events/mq","path":"/docs/events/mq","sidebar":"tutorialSidebar"},{"id":"events/rds","path":"/docs/events/rds","sidebar":"tutorialSidebar"},{"id":"events/s3","path":"/docs/events/s3","sidebar":"tutorialSidebar"},{"id":"events/s3-batch","path":"/docs/events/s3-batch","sidebar":"tutorialSidebar"},{"id":"events/s3-object","path":"/docs/events/s3-object","sidebar":"tutorialSidebar"},{"id":"events/secrets-manager","path":"/docs/events/secrets-manager","sidebar":"tutorialSidebar"},{"id":"events/ses","path":"/docs/events/ses","sidebar":"tutorialSidebar"},{"id":"events/sns","path":"/docs/events/sns","sidebar":"tutorialSidebar"},{"id":"events/sqs","path":"/docs/events/sqs","sidebar":"tutorialSidebar"},{"id":"events/vpc-lattice","path":"/docs/events/vpc-lattice","sidebar":"tutorialSidebar"},{"id":"events/workmail","path":"/docs/events/workmail","sidebar":"tutorialSidebar"},{"id":"faq","path":"/docs/faq","sidebar":"tutorialSidebar"},{"id":"integrations/apollo-server","path":"/docs/integrations/apollo-server","sidebar":"tutorialSidebar"},{"id":"integrations/intro","path":"/docs/integrations/intro","sidebar":"tutorialSidebar"},{"id":"integrations/lambda-powertools","path":"/docs/integrations/lambda-powertools","sidebar":"tutorialSidebar"},{"id":"integrations/pino","path":"/docs/integrations/pino","sidebar":"tutorialSidebar"},{"id":"integrations/RDS","path":"/docs/integrations/RDS","sidebar":"tutorialSidebar"},{"id":"integrations/serverless-framework","path":"/docs/integrations/serverless-framework","sidebar":"tutorialSidebar"},{"id":"integrations/serverless-stack","path":"/docs/integrations/serverless-stack","sidebar":"tutorialSidebar"},{"id":"intro/contributing","path":"/docs/intro/contributing","sidebar":"tutorialSidebar"},{"id":"intro/early-interrupt","path":"/docs/intro/early-interrupt","sidebar":"tutorialSidebar"},{"id":"intro/getting-started","path":"/docs/intro/getting-started","sidebar":"tutorialSidebar"},{"id":"intro/handling-errors","path":"/docs/intro/handling-errors","sidebar":"tutorialSidebar"},{"id":"intro/history","path":"/docs/intro/history","sidebar":"tutorialSidebar"},{"id":"intro/hooks","path":"/docs/intro/hooks","sidebar":"tutorialSidebar"},{"id":"intro/how-it-works","path":"/docs/intro/how-it-works","sidebar":"tutorialSidebar"},{"id":"intro/influence","path":"/docs/intro/influence","sidebar":"tutorialSidebar"},{"id":"intro/intro","path":"/docs/","sidebar":"tutorialSidebar"},{"id":"intro/release-cycle","path":"/docs/intro/release-cycle","sidebar":"tutorialSidebar"},{"id":"intro/sponsoring","path":"/docs/intro/sponsoring","sidebar":"tutorialSidebar"},{"id":"intro/streamify-response","path":"/docs/intro/streamify-response","sidebar":"tutorialSidebar"},{"id":"intro/testing","path":"/docs/intro/testing","sidebar":"tutorialSidebar"},{"id":"intro/typescript","path":"/docs/intro/typescript","sidebar":"tutorialSidebar"},{"id":"intro/utilities","path":"/docs/intro/utilities","sidebar":"tutorialSidebar"},{"id":"middlewares/appconfig","path":"/docs/middlewares/appconfig","sidebar":"tutorialSidebar"},{"id":"middlewares/cloudwatch-metrics","path":"/docs/middlewares/cloudwatch-metrics","sidebar":"tutorialSidebar"},{"id":"middlewares/do-not-wait-for-empty-event-loop","path":"/docs/middlewares/do-not-wait-for-empty-event-loop","sidebar":"tutorialSidebar"},{"id":"middlewares/dynamodb","path":"/docs/middlewares/dynamodb","sidebar":"tutorialSidebar"},{"id":"middlewares/error-logger","path":"/docs/middlewares/error-logger","sidebar":"tutorialSidebar"},{"id":"middlewares/event-normalizer","path":"/docs/middlewares/event-normalizer","sidebar":"tutorialSidebar"},{"id":"middlewares/http-content-encoding","path":"/docs/middlewares/http-content-encoding","sidebar":"tutorialSidebar"},{"id":"middlewares/http-content-negotiation","path":"/docs/middlewares/http-content-negotiation","sidebar":"tutorialSidebar"},{"id":"middlewares/http-cors","path":"/docs/middlewares/http-cors","sidebar":"tutorialSidebar"},{"id":"middlewares/http-error-handler","path":"/docs/middlewares/http-error-handler","sidebar":"tutorialSidebar"},{"id":"middlewares/http-event-normalizer","path":"/docs/middlewares/http-event-normalizer","sidebar":"tutorialSidebar"},{"id":"middlewares/http-header-normalizer","path":"/docs/middlewares/http-header-normalizer","sidebar":"tutorialSidebar"},{"id":"middlewares/http-json-body-parser","path":"/docs/middlewares/http-json-body-parser","sidebar":"tutorialSidebar"},{"id":"middlewares/http-multipart-body-parser","path":"/docs/middlewares/http-multipart-body-parser","sidebar":"tutorialSidebar"},{"id":"middlewares/http-partial-response","path":"/docs/middlewares/http-partial-response","sidebar":"tutorialSidebar"},{"id":"middlewares/http-response-serializer","path":"/docs/middlewares/http-response-serializer","sidebar":"tutorialSidebar"},{"id":"middlewares/http-security-headers","path":"/docs/middlewares/http-security-headers","sidebar":"tutorialSidebar"},{"id":"middlewares/http-urlencode-body-parser","path":"/docs/middlewares/http-urlencode-body-parser","sidebar":"tutorialSidebar"},{"id":"middlewares/http-urlencode-path-parser","path":"/docs/middlewares/http-urlencode-path-parser","sidebar":"tutorialSidebar"},{"id":"middlewares/input-output-logger","path":"/docs/middlewares/input-output-logger","sidebar":"tutorialSidebar"},{"id":"middlewares/intro","path":"/docs/middlewares/intro","sidebar":"tutorialSidebar"},{"id":"middlewares/rds-signer","path":"/docs/middlewares/rds-signer","sidebar":"tutorialSidebar"},{"id":"middlewares/s3","path":"/docs/middlewares/s3","sidebar":"tutorialSidebar"},{"id":"middlewares/s3-object-response","path":"/docs/middlewares/s3-object-response","sidebar":"tutorialSidebar"},{"id":"middlewares/secrets-manager","path":"/docs/middlewares/secrets-manager","sidebar":"tutorialSidebar"},{"id":"middlewares/service-discovery","path":"/docs/middlewares/service-discovery","sidebar":"tutorialSidebar"},{"id":"middlewares/sqs-partial-batch-failure","path":"/docs/middlewares/sqs-partial-batch-failure","sidebar":"tutorialSidebar"},{"id":"middlewares/ssm","path":"/docs/middlewares/ssm","sidebar":"tutorialSidebar"},{"id":"middlewares/sts","path":"/docs/middlewares/sts","sidebar":"tutorialSidebar"},{"id":"middlewares/third-party","path":"/docs/middlewares/third-party","sidebar":"tutorialSidebar"},{"id":"middlewares/validator","path":"/docs/middlewares/validator","sidebar":"tutorialSidebar"},{"id":"middlewares/warmup","path":"/docs/middlewares/warmup","sidebar":"tutorialSidebar"},{"id":"middlewares/ws-json-body-parser","path":"/docs/middlewares/ws-json-body-parser","sidebar":"tutorialSidebar"},{"id":"middlewares/ws-response","path":"/docs/middlewares/ws-response","sidebar":"tutorialSidebar"},{"id":"routers/http-router","path":"/docs/routers/http-router","sidebar":"tutorialSidebar"},{"id":"routers/ws-router","path":"/docs/routers/ws-router","sidebar":"tutorialSidebar"},{"id":"upgrade/0-1","path":"/docs/upgrade/0-1","sidebar":"tutorialSidebar"},{"id":"upgrade/1-2","path":"/docs/upgrade/1-2","sidebar":"tutorialSidebar"},{"id":"upgrade/2-3","path":"/docs/upgrade/2-3","sidebar":"tutorialSidebar"},{"id":"upgrade/3-4","path":"/docs/upgrade/3-4","sidebar":"tutorialSidebar"},{"id":"writing-middlewares/configurable-middlewares","path":"/docs/writing-middlewares/configurable-middlewares","sidebar":"tutorialSidebar"},{"id":"writing-middlewares/inline-middlewares","path":"/docs/writing-middlewares/inline-middlewares","sidebar":"tutorialSidebar"},{"id":"writing-middlewares/internal-storage","path":"/docs/writing-middlewares/internal-storage","sidebar":"tutorialSidebar"},{"id":"writing-middlewares/intro","path":"/docs/writing-middlewares/intro","sidebar":"tutorialSidebar"},{"id":"writing-middlewares/more-examples","path":"/docs/writing-middlewares/more-examples","sidebar":"tutorialSidebar"},{"id":"writing-middlewares/timeouts","path":"/docs/writing-middlewares/timeouts","sidebar":"tutorialSidebar"},{"id":"writing-middlewares/with-typescript","path":"/docs/writing-middlewares/with-typescript","sidebar":"tutorialSidebar"},{"id":"/category/intro-to-middy","path":"/docs/category/intro-to-middy","sidebar":"tutorialSidebar"},{"id":"/category/middlewares","path":"/docs/category/middlewares","sidebar":"tutorialSidebar"},{"id":"/category/writing-middlewares","path":"/docs/category/writing-middlewares","sidebar":"tutorialSidebar"},{"id":"/category/routers","path":"/docs/category/routers","sidebar":"tutorialSidebar"},{"id":"/category/upgrade","path":"/docs/category/upgrade","sidebar":"tutorialSidebar"},{"id":"/category/aws-event-examples","path":"/docs/category/aws-event-examples","sidebar":"tutorialSidebar"},{"id":"/category/integrations","path":"/docs/category/integrations","sidebar":"tutorialSidebar"},{"id":"/category/best-practices","path":"/docs/category/best-practices","sidebar":"tutorialSidebar"}],"draftIds":[],"sidebars":{"tutorialSidebar":{"link":{"path":"/docs/category/intro-to-middy","label":"Intro to Middy"}}}}],"breadcrumbs":true}}}'),i=JSON.parse('{"defaultLocale":"en","locales":["en"],"path":"i18n","currentLocale":"en","localeConfigs":{"en":{"label":"English","direction":"ltr","htmlLang":"en","calendar":"gregory","path":"en"}}}');var l=n(7529);const s=JSON.parse('{"docusaurusVersion":"2.4.3","siteVersion":"0.0.0","pluginVersions":{"docusaurus-plugin-content-docs":{"type":"package","name":"@docusaurus/plugin-content-docs","version":"2.4.3"},"docusaurus-plugin-content-blog":{"type":"package","name":"@docusaurus/plugin-content-blog","version":"2.4.3"},"docusaurus-plugin-content-pages":{"type":"package","name":"@docusaurus/plugin-content-pages","version":"2.4.3"},"docusaurus-plugin-sitemap":{"type":"package","name":"@docusaurus/plugin-sitemap","version":"2.4.3"},"docusaurus-theme-classic":{"type":"package","name":"@docusaurus/theme-classic","version":"2.4.3"},"docusaurus-lunr-search":{"type":"package","name":"docusaurus-lunr-search","version":"2.4.2"}}}'),c={siteConfig:a.default,siteMetadata:s,globalData:o,i18n:i,codeTranslations:l},u=r.createContext(c);function d(e){let{children:t}=e;return r.createElement(u.Provider,{value:c},t)}},4763:(e,t,n)=>{"use strict";n.d(t,{Z:()=>p});var r=n(7294),a=n(412),o=n(5742),i=n(8780),l=n(4173);function s(e){let{error:t,tryAgain:n}=e;return r.createElement("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"flex-start",minHeight:"100vh",width:"100%",maxWidth:"80ch",fontSize:"20px",margin:"0 auto",padding:"1rem"}},r.createElement("h1",{style:{fontSize:"3rem"}},"This page crashed"),r.createElement("button",{type:"button",onClick:n,style:{margin:"1rem 0",fontSize:"2rem",cursor:"pointer",borderRadius:20,padding:"1rem"}},"Try again"),r.createElement(c,{error:t}))}function c(e){let{error:t}=e;const n=(0,i.getErrorCausalChain)(t).map((e=>e.message)).join("\n\nCause:\n");return r.createElement("p",{style:{whiteSpace:"pre-wrap"}},n)}function u(e){let{error:t,tryAgain:n}=e;return r.createElement(p,{fallback:()=>r.createElement(s,{error:t,tryAgain:n})},r.createElement(o.Z,null,r.createElement("title",null,"Page Error")),r.createElement(l.Z,null,r.createElement(s,{error:t,tryAgain:n})))}const d=e=>r.createElement(u,e);class p extends r.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){a.Z.canUseDOM&&this.setState({error:e})}render(){const{children:e}=this.props,{error:t}=this.state;if(t){const e={error:t,tryAgain:()=>this.setState({error:null})};return(this.props.fallback??d)(e)}return e??null}}},412:(e,t,n)=>{"use strict";n.d(t,{Z:()=>a});const r="undefined"!=typeof window&&"document"in window&&"createElement"in window.document,a={canUseDOM:r,canUseEventListeners:r&&("addEventListener"in window||"attachEvent"in window),canUseIntersectionObserver:r&&"IntersectionObserver"in window,canUseViewport:r&&"screen"in window}},5742:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294),a=n(405);function o(e){return r.createElement(a.ql,e)}},9960:(e,t,n)=>{"use strict";n.d(t,{Z:()=>f});var r=n(7462),a=n(7294),o=n(3727),i=n(8780),l=n(2263),s=n(3919),c=n(412);const u=a.createContext({collectLink:()=>{}});var d=n(4996);function p(e,t){let{isNavLink:n,to:p,href:f,activeClassName:m,isActive:h,"data-noBrokenLinkCheck":g,autoAddBaseUrl:b=!0,...v}=e;const{siteConfig:{trailingSlash:y,baseUrl:w}}=(0,l.Z)(),{withBaseUrl:k}=(0,d.C)(),S=(0,a.useContext)(u),E=(0,a.useRef)(null);(0,a.useImperativeHandle)(t,(()=>E.current));const x=p||f;const _=(0,s.Z)(x),C=x?.replace("pathname://","");let T=void 0!==C?(A=C,b&&(e=>e.startsWith("/"))(A)?k(A):A):void 0;var A;T&&_&&(T=(0,i.applyTrailingSlash)(T,{trailingSlash:y,baseUrl:w}));const L=(0,a.useRef)(!1),P=n?o.OL:o.rU,R=c.Z.canUseIntersectionObserver,N=(0,a.useRef)(),O=()=>{L.current||null==T||(window.docusaurus.preload(T),L.current=!0)};(0,a.useEffect)((()=>(!R&&_&&null!=T&&window.docusaurus.prefetch(T),()=>{R&&N.current&&N.current.disconnect()})),[N,T,R,_]);const I=T?.startsWith("#")??!1,D=!T||!_||I;return D||g||S.collectLink(T),D?a.createElement("a",(0,r.Z)({ref:E,href:T},x&&!_&&{target:"_blank",rel:"noopener noreferrer"},v)):a.createElement(P,(0,r.Z)({},v,{onMouseEnter:O,onTouchStart:O,innerRef:e=>{E.current=e,R&&e&&_&&(N.current=new window.IntersectionObserver((t=>{t.forEach((t=>{e===t.target&&(t.isIntersecting||t.intersectionRatio>0)&&(N.current.unobserve(e),N.current.disconnect(),null!=T&&window.docusaurus.prefetch(T))}))})),N.current.observe(e))},to:T},n&&{isActive:h,activeClassName:m}))}const f=a.forwardRef(p)},5999:(e,t,n)=>{"use strict";n.d(t,{Z:()=>s,I:()=>l});var r=n(7294);function a(e,t){const n=e.split(/(\{\w+\})/).map(((e,n)=>{if(n%2==1){const n=t?.[e.slice(1,-1)];if(void 0!==n)return n}return e}));return n.some((e=>(0,r.isValidElement)(e)))?n.map(((e,t)=>(0,r.isValidElement)(e)?r.cloneElement(e,{key:t}):e)).filter((e=>""!==e)):n.join("")}var o=n(7529);function i(e){let{id:t,message:n}=e;if(void 0===t&&void 0===n)throw new Error("Docusaurus translation declarations must have at least a translation id or a default translation message");return o[t??n]??n??t}function l(e,t){let{message:n,id:r}=e;return a(i({message:n,id:r}),t)}function s(e){let{children:t,id:n,values:o}=e;if(t&&"string"!=typeof t)throw console.warn("Illegal children",t),new Error("The Docusaurus component only accept simple string values");const l=i({message:t,id:n});return r.createElement(r.Fragment,null,a(l,o))}},9935:(e,t,n)=>{"use strict";n.d(t,{m:()=>r});const r="default"},3919:(e,t,n)=>{"use strict";function r(e){return/^(?:\w*:|\/\/)/.test(e)}function a(e){return void 0!==e&&!r(e)}n.d(t,{Z:()=>a,b:()=>r})},4996:(e,t,n)=>{"use strict";n.d(t,{C:()=>i,Z:()=>l});var r=n(7294),a=n(2263),o=n(3919);function i(){const{siteConfig:{baseUrl:e,url:t}}=(0,a.Z)(),n=(0,r.useCallback)(((n,r)=>function(e,t,n,r){let{forcePrependBaseUrl:a=!1,absolute:i=!1}=void 0===r?{}:r;if(!n||n.startsWith("#")||(0,o.b)(n))return n;if(a)return t+n.replace(/^\//,"");if(n===t.replace(/\/$/,""))return t;const l=n.startsWith(t)?n:t+n.replace(/^\//,"");return i?e+l:l}(t,e,n,r)),[t,e]);return{withBaseUrl:n}}function l(e,t){void 0===t&&(t={});const{withBaseUrl:n}=i();return n(e,t)}},2263:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294),a=n(8940);function o(){return(0,r.useContext)(a._)}},8084:(e,t,n)=>{"use strict";n.d(t,{OD:()=>o,eZ:()=>i});var r=n(2263),a=n(9935);function o(e,t){void 0===t&&(t={});const n=function(){const{globalData:e}=(0,r.Z)();return e}()[e];if(!n&&t.failfast)throw new Error(`Docusaurus plugin global data not found for "${e}" plugin.`);return n}function i(e,t,n){void 0===t&&(t=a.m),void 0===n&&(n={});const r=o(e),i=r?.[t];if(!i&&n.failfast)throw new Error(`Docusaurus plugin global data not found for "${e}" plugin with id "${t}".`);return i}},2389:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294),a=n(8934);function o(){return(0,r.useContext)(a._)}},9670:(e,t,n)=>{"use strict";n.d(t,{Z:()=>a});const r=e=>"object"==typeof e&&!!e&&Object.keys(e).length>0;function a(e){const t={};return function e(n,a){Object.entries(n).forEach((n=>{let[o,i]=n;const l=a?`${a}.${o}`:o;r(i)?e(i,l):t[l]=i}))}(e),t}},226:(e,t,n)=>{"use strict";n.d(t,{_:()=>a,z:()=>o});var r=n(7294);const a=r.createContext(null);function o(e){let{children:t,value:n}=e;const o=r.useContext(a),i=(0,r.useMemo)((()=>function(e){let{parent:t,value:n}=e;if(!t){if(!n)throw new Error("Unexpected: no Docusaurus route context found");if(!("plugin"in n))throw new Error("Unexpected: Docusaurus topmost route context has no `plugin` attribute");return n}const r={...t.data,...n?.data};return{plugin:t.plugin,data:r}}({parent:o,value:n})),[o,n]);return r.createElement(a.Provider,{value:i},t)}},4104:(e,t,n)=>{"use strict";n.d(t,{Iw:()=>f,gA:()=>u,_r:()=>s,Jo:()=>m,zh:()=>c,yW:()=>p,gB:()=>d});var r=n(6550),a=n(8084);const o=e=>e.versions.find((e=>e.isLast));function i(e,t){const n=function(e,t){const n=o(e);return[...e.versions.filter((e=>e!==n)),n].find((e=>!!(0,r.LX)(t,{path:e.path,exact:!1,strict:!1})))}(e,t),a=n?.docs.find((e=>!!(0,r.LX)(t,{path:e.path,exact:!0,strict:!1})));return{activeVersion:n,activeDoc:a,alternateDocVersions:a?function(t){const n={};return e.versions.forEach((e=>{e.docs.forEach((r=>{r.id===t&&(n[e.name]=r)}))})),n}(a.id):{}}}const l={},s=()=>(0,a.OD)("docusaurus-plugin-content-docs")??l,c=e=>(0,a.eZ)("docusaurus-plugin-content-docs",e,{failfast:!0});function u(e){void 0===e&&(e={});const t=s(),{pathname:n}=(0,r.TH)();return function(e,t,n){void 0===n&&(n={});const a=Object.entries(e).sort(((e,t)=>t[1].path.localeCompare(e[1].path))).find((e=>{let[,n]=e;return!!(0,r.LX)(t,{path:n.path,exact:!1,strict:!1})})),o=a?{pluginId:a[0],pluginData:a[1]}:void 0;if(!o&&n.failfast)throw new Error(`Can't find active docs plugin for "${t}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(e).map((e=>e.path)).join(", ")}`);return o}(t,n,e)}function d(e){return c(e).versions}function p(e){const t=c(e);return o(t)}function f(e){const t=c(e),{pathname:n}=(0,r.TH)();return i(t,n)}function m(e){const t=c(e),{pathname:n}=(0,r.TH)();return function(e,t){const n=o(e);return{latestDocSuggestion:i(e,t).alternateDocVersions[n.name],latestVersionSuggestion:n}}(t,n)}},8320:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>o});var r=n(4865),a=n.n(r);a().configure({showSpinner:!1});const o={onRouteUpdate(e){let{location:t,previousLocation:n}=e;if(n&&t.pathname!==n.pathname){const e=window.setTimeout((()=>{a().start()}),200);return()=>window.clearTimeout(e)}},onRouteDidUpdate(){a().done()}}},3310:(e,t,n)=>{"use strict";n.r(t);var r=n(7410),a=n(6809);!function(e){const{themeConfig:{prism:t}}=a.default,{additionalLanguages:r}=t;globalThis.Prism=e,r.forEach((e=>{n(6726)(`./prism-${e}`)})),delete globalThis.Prism}(r.Z)},9471:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294);const a={iconExternalLink:"iconExternalLink_nPIU"};function o(e){let{width:t=13.5,height:n=13.5}=e;return r.createElement("svg",{width:t,height:n,"aria-hidden":"true",viewBox:"0 0 24 24",className:a.iconExternalLink},r.createElement("path",{fill:"currentColor",d:"M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"}))}},4173:(e,t,n)=>{"use strict";n.d(t,{Z:()=>pt});var r=n(7294),a=n(6010),o=n(4763),i=n(1944),l=n(7462),s=n(6550),c=n(5999),u=n(5936);const d="__docusaurus_skipToContent_fallback";function p(e){e.setAttribute("tabindex","-1"),e.focus(),e.removeAttribute("tabindex")}function f(){const e=(0,r.useRef)(null),{action:t}=(0,s.k6)(),n=(0,r.useCallback)((e=>{e.preventDefault();const t=document.querySelector("main:first-of-type")??document.getElementById(d);t&&p(t)}),[]);return(0,u.S)((n=>{let{location:r}=n;e.current&&!r.hash&&"PUSH"===t&&p(e.current)})),{containerRef:e,onClick:n}}const m=(0,c.I)({id:"theme.common.skipToMainContent",description:"The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation",message:"Skip to main content"});function h(e){const t=e.children??m,{containerRef:n,onClick:a}=f();return r.createElement("div",{ref:n,role:"region","aria-label":m},r.createElement("a",(0,l.Z)({},e,{href:`#${d}`,onClick:a}),t))}var g=n(5281),b=n(9727);const v={skipToContent:"skipToContent_fXgn"};function y(){return r.createElement(h,{className:v.skipToContent})}var w=n(6668),k=n(9689);function S(e){let{width:t=21,height:n=21,color:a="currentColor",strokeWidth:o=1.2,className:i,...s}=e;return r.createElement("svg",(0,l.Z)({viewBox:"0 0 15 15",width:t,height:n},s),r.createElement("g",{stroke:a,strokeWidth:o},r.createElement("path",{d:"M.75.75l13.5 13.5M14.25.75L.75 14.25"})))}const E={closeButton:"closeButton_CVFx"};function x(e){return r.createElement("button",(0,l.Z)({type:"button","aria-label":(0,c.I)({id:"theme.AnnouncementBar.closeButtonAriaLabel",message:"Close",description:"The ARIA label for close button of announcement bar"})},e,{className:(0,a.Z)("clean-btn close",E.closeButton,e.className)}),r.createElement(S,{width:14,height:14,strokeWidth:3.1}))}const _={content:"content_knG7"};function C(e){const{announcementBar:t}=(0,w.L)(),{content:n}=t;return r.createElement("div",(0,l.Z)({},e,{className:(0,a.Z)(_.content,e.className),dangerouslySetInnerHTML:{__html:n}}))}const T={announcementBar:"announcementBar_mb4j",announcementBarPlaceholder:"announcementBarPlaceholder_vyr4",announcementBarClose:"announcementBarClose_gvF7",announcementBarContent:"announcementBarContent_xLdY"};function A(){const{announcementBar:e}=(0,w.L)(),{isActive:t,close:n}=(0,k.nT)();if(!t)return null;const{backgroundColor:a,textColor:o,isCloseable:i}=e;return r.createElement("div",{className:T.announcementBar,style:{backgroundColor:a,color:o},role:"banner"},i&&r.createElement("div",{className:T.announcementBarPlaceholder}),r.createElement(C,{className:T.announcementBarContent}),i&&r.createElement(x,{onClick:n,className:T.announcementBarClose}))}var L=n(3163),P=n(2466);var R=n(902),N=n(3102);const O=r.createContext(null);function I(e){let{children:t}=e;const n=function(){const e=(0,L.e)(),t=(0,N.HY)(),[n,a]=(0,r.useState)(!1),o=null!==t.component,i=(0,R.D9)(o);return(0,r.useEffect)((()=>{o&&!i&&a(!0)}),[o,i]),(0,r.useEffect)((()=>{o?e.shown||a(!0):a(!1)}),[e.shown,o]),(0,r.useMemo)((()=>[n,a]),[n])}();return r.createElement(O.Provider,{value:n},t)}function D(e){if(e.component){const t=e.component;return r.createElement(t,e.props)}}function M(){const e=(0,r.useContext)(O);if(!e)throw new R.i6("NavbarSecondaryMenuDisplayProvider");const[t,n]=e,a=(0,r.useCallback)((()=>n(!1)),[n]),o=(0,N.HY)();return(0,r.useMemo)((()=>({shown:t,hide:a,content:D(o)})),[a,o,t])}function F(e){let{header:t,primaryMenu:n,secondaryMenu:o}=e;const{shown:i}=M();return r.createElement("div",{className:"navbar-sidebar"},t,r.createElement("div",{className:(0,a.Z)("navbar-sidebar__items",{"navbar-sidebar__items--show-secondary":i})},r.createElement("div",{className:"navbar-sidebar__item menu"},n),r.createElement("div",{className:"navbar-sidebar__item menu"},o)))}var j=n(2949),B=n(2389);function z(e){return r.createElement("svg",(0,l.Z)({viewBox:"0 0 24 24",width:24,height:24},e),r.createElement("path",{fill:"currentColor",d:"M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"}))}function U(e){return r.createElement("svg",(0,l.Z)({viewBox:"0 0 24 24",width:24,height:24},e),r.createElement("path",{fill:"currentColor",d:"M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"}))}const $={toggle:"toggle_vylO",toggleButton:"toggleButton_gllP",darkToggleIcon:"darkToggleIcon_wfgR",lightToggleIcon:"lightToggleIcon_pyhR",toggleButtonDisabled:"toggleButtonDisabled_aARS"};function q(e){let{className:t,buttonClassName:n,value:o,onChange:i}=e;const l=(0,B.Z)(),s=(0,c.I)({message:"Switch between dark and light mode (currently {mode})",id:"theme.colorToggle.ariaLabel",description:"The ARIA label for the navbar color mode toggle"},{mode:"dark"===o?(0,c.I)({message:"dark mode",id:"theme.colorToggle.ariaLabel.mode.dark",description:"The name for the dark color mode"}):(0,c.I)({message:"light mode",id:"theme.colorToggle.ariaLabel.mode.light",description:"The name for the light color mode"})});return r.createElement("div",{className:(0,a.Z)($.toggle,t)},r.createElement("button",{className:(0,a.Z)("clean-btn",$.toggleButton,!l&&$.toggleButtonDisabled,n),type:"button",onClick:()=>i("dark"===o?"light":"dark"),disabled:!l,title:s,"aria-label":s,"aria-live":"polite"},r.createElement(z,{className:(0,a.Z)($.toggleIcon,$.lightToggleIcon)}),r.createElement(U,{className:(0,a.Z)($.toggleIcon,$.darkToggleIcon)})))}const G=r.memo(q),H={darkNavbarColorModeToggle:"darkNavbarColorModeToggle_X3D1"};function Z(e){let{className:t}=e;const n=(0,w.L)().navbar.style,a=(0,w.L)().colorMode.disableSwitch,{colorMode:o,setColorMode:i}=(0,j.I)();return a?null:r.createElement(G,{className:t,buttonClassName:"dark"===n?H.darkNavbarColorModeToggle:void 0,value:o,onChange:i})}var V=n(1327);function W(){return r.createElement(V.Z,{className:"navbar__brand",imageClassName:"navbar__logo",titleClassName:"navbar__title text--truncate"})}function Y(){const e=(0,L.e)();return r.createElement("button",{type:"button","aria-label":(0,c.I)({id:"theme.docs.sidebar.closeSidebarButtonAriaLabel",message:"Close navigation bar",description:"The ARIA label for close button of mobile sidebar"}),className:"clean-btn navbar-sidebar__close",onClick:()=>e.toggle()},r.createElement(S,{color:"var(--ifm-color-emphasis-600)"}))}function K(){return r.createElement("div",{className:"navbar-sidebar__brand"},r.createElement(W,null),r.createElement(Z,{className:"margin-right--md"}),r.createElement(Y,null))}var X=n(9960),Q=n(4996),J=n(3919);function ee(e,t){return void 0!==e&&void 0!==t&&new RegExp(e,"gi").test(t)}var te=n(9471);function ne(e){let{activeBasePath:t,activeBaseRegex:n,to:a,href:o,label:i,html:s,isDropdownLink:c,prependBaseUrlToHref:u,...d}=e;const p=(0,Q.Z)(a),f=(0,Q.Z)(t),m=(0,Q.Z)(o,{forcePrependBaseUrl:!0}),h=i&&o&&!(0,J.Z)(o),g=s?{dangerouslySetInnerHTML:{__html:s}}:{children:r.createElement(r.Fragment,null,i,h&&r.createElement(te.Z,c&&{width:12,height:12}))};return o?r.createElement(X.Z,(0,l.Z)({href:u?m:o},d,g)):r.createElement(X.Z,(0,l.Z)({to:p,isNavLink:!0},(t||n)&&{isActive:(e,t)=>n?ee(n,t.pathname):t.pathname.startsWith(f)},d,g))}function re(e){let{className:t,isDropdownItem:n=!1,...o}=e;const i=r.createElement(ne,(0,l.Z)({className:(0,a.Z)(n?"dropdown__link":"navbar__item navbar__link",t),isDropdownLink:n},o));return n?r.createElement("li",null,i):i}function ae(e){let{className:t,isDropdownItem:n,...o}=e;return r.createElement("li",{className:"menu__list-item"},r.createElement(ne,(0,l.Z)({className:(0,a.Z)("menu__link",t)},o)))}function oe(e){let{mobile:t=!1,position:n,...a}=e;const o=t?ae:re;return r.createElement(o,(0,l.Z)({},a,{activeClassName:a.activeClassName??(t?"menu__link--active":"navbar__link--active")}))}var ie=n(6043),le=n(8596),se=n(2263);function ce(e,t){return e.some((e=>function(e,t){return!!(0,le.Mg)(e.to,t)||!!ee(e.activeBaseRegex,t)||!(!e.activeBasePath||!t.startsWith(e.activeBasePath))}(e,t)))}function ue(e){let{items:t,position:n,className:o,onClick:i,...s}=e;const c=(0,r.useRef)(null),[u,d]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("focusin",e),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("focusin",e)}}),[c]),r.createElement("div",{ref:c,className:(0,a.Z)("navbar__item","dropdown","dropdown--hoverable",{"dropdown--right":"right"===n,"dropdown--show":u})},r.createElement(ne,(0,l.Z)({"aria-haspopup":"true","aria-expanded":u,role:"button",href:s.to?void 0:"#",className:(0,a.Z)("navbar__link",o)},s,{onClick:s.to?void 0:e=>e.preventDefault(),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),d(!u))}}),s.children??s.label),r.createElement("ul",{className:"dropdown__menu"},t.map(((e,t)=>r.createElement(_e,(0,l.Z)({isDropdownItem:!0,activeClassName:"dropdown__link--active"},e,{key:t}))))))}function de(e){let{items:t,className:n,position:o,onClick:i,...c}=e;const u=function(){const{siteConfig:{baseUrl:e}}=(0,se.Z)(),{pathname:t}=(0,s.TH)();return t.replace(e,"/")}(),d=ce(t,u),{collapsed:p,toggleCollapsed:f,setCollapsed:m}=(0,ie.u)({initialState:()=>!d});return(0,r.useEffect)((()=>{d&&m(!d)}),[u,d,m]),r.createElement("li",{className:(0,a.Z)("menu__list-item",{"menu__list-item--collapsed":p})},r.createElement(ne,(0,l.Z)({role:"button",className:(0,a.Z)("menu__link menu__link--sublist menu__link--sublist-caret",n)},c,{onClick:e=>{e.preventDefault(),f()}}),c.children??c.label),r.createElement(ie.z,{lazy:!0,as:"ul",className:"menu__list",collapsed:p},t.map(((e,t)=>r.createElement(_e,(0,l.Z)({mobile:!0,isDropdownItem:!0,onClick:i,activeClassName:"menu__link--active"},e,{key:t}))))))}function pe(e){let{mobile:t=!1,...n}=e;const a=t?de:ue;return r.createElement(a,n)}var fe=n(4711);function me(e){let{width:t=20,height:n=20,...a}=e;return r.createElement("svg",(0,l.Z)({viewBox:"0 0 24 24",width:t,height:n,"aria-hidden":!0},a),r.createElement("path",{fill:"currentColor",d:"M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"}))}const he="iconLanguage_nlXk";var ge=n(8084);const be=e=>{const t=(0,r.useRef)(!1),o=(0,r.useRef)(null),[i,l]=(0,r.useState)(!1),c=(0,s.k6)(),{siteConfig:u={}}=(0,se.Z)(),d=(0,B.Z)(),{baseUrl:p}=u,f=(0,ge.eZ)("docusaurus-lunr-search"),m=()=>{t.current||(Promise.all([fetch(`${p}${f.fileNames.searchDoc}`).then((e=>e.json())),fetch(`${p}${f.fileNames.lunrIndex}`).then((e=>e.json())),Promise.all([n.e(4611),n.e(5684)]).then(n.bind(n,4734)),Promise.all([n.e(532),n.e(2572)]).then(n.bind(n,2572))]).then((e=>{let[t,n,{default:r}]=e;0!==t.length&&(((e,t,n)=>{new n({searchDocs:e,searchIndex:t,baseUrl:p,inputSelector:"#search_input_react",handleSelected:(e,t,n)=>{const r=n.url||"/";document.createElement("a").href=r,c.push(r)}})})(t,n,r),l(!0))})),t.current=!0)},h=(0,r.useCallback)((t=>{o.current.contains(t.target)||o.current.focus(),e.handleSearchBarToggle&&e.handleSearchBarToggle(!e.isSearchBarExpanded)}),[e.isSearchBarExpanded]);return d&&m(),r.createElement("div",{className:"navbar__search",key:"search-box"},r.createElement("span",{"aria-label":"expand searchbar",role:"button",className:(0,a.Z)("search-icon",{"search-icon-hidden":e.isSearchBarExpanded}),onClick:h,onKeyDown:h,tabIndex:0}),r.createElement("input",{id:"search_input_react",type:"search",placeholder:i?"Search":"Loading...","aria-label":"Search",className:(0,a.Z)("navbar__search-input",{"search-bar-expanded":e.isSearchBarExpanded},{"search-bar":!e.isSearchBarExpanded}),onClick:m,onMouseOver:m,onFocus:h,onBlur:h,ref:o,disabled:!i}))},ve={searchBox:"searchBox_ZlJk"};function ye(e){let{children:t,className:n}=e;return r.createElement("div",{className:(0,a.Z)(n,ve.searchBox)},t)}var we=n(4104),ke=n(3438);var Se=n(373);const Ee=e=>e.docs.find((t=>t.id===e.mainDocId));const xe={default:oe,localeDropdown:function(e){let{mobile:t,dropdownItemsBefore:n,dropdownItemsAfter:a,...o}=e;const{i18n:{currentLocale:i,locales:u,localeConfigs:d}}=(0,se.Z)(),p=(0,fe.l)(),{search:f,hash:m}=(0,s.TH)(),h=[...n,...u.map((e=>{const n=`${`pathname://${p.createUrl({locale:e,fullyQualified:!1})}`}${f}${m}`;return{label:d[e].label,lang:d[e].htmlLang,to:n,target:"_self",autoAddBaseUrl:!1,className:e===i?t?"menu__link--active":"dropdown__link--active":""}})),...a],g=t?(0,c.I)({message:"Languages",id:"theme.navbar.mobileLanguageDropdown.label",description:"The label for the mobile language switcher dropdown"}):d[i].label;return r.createElement(pe,(0,l.Z)({},o,{mobile:t,label:r.createElement(r.Fragment,null,r.createElement(me,{className:he}),g),items:h}))},search:function(e){let{mobile:t,className:n}=e;return t?null:r.createElement(ye,{className:n},r.createElement(be,null))},dropdown:pe,html:function(e){let{value:t,className:n,mobile:o=!1,isDropdownItem:i=!1}=e;const l=i?"li":"div";return r.createElement(l,{className:(0,a.Z)({navbar__item:!o&&!i,"menu__list-item":o},n),dangerouslySetInnerHTML:{__html:t}})},doc:function(e){let{docId:t,label:n,docsPluginId:a,...o}=e;const{activeDoc:i}=(0,we.Iw)(a),s=(0,ke.vY)(t,a);return null===s?null:r.createElement(oe,(0,l.Z)({exact:!0},o,{isActive:()=>i?.path===s.path||!!i?.sidebar&&i.sidebar===s.sidebar,label:n??s.id,to:s.path}))},docSidebar:function(e){let{sidebarId:t,label:n,docsPluginId:a,...o}=e;const{activeDoc:i}=(0,we.Iw)(a),s=(0,ke.oz)(t,a).link;if(!s)throw new Error(`DocSidebarNavbarItem: Sidebar with ID "${t}" doesn't have anything to be linked to.`);return r.createElement(oe,(0,l.Z)({exact:!0},o,{isActive:()=>i?.sidebar===t,label:n??s.label,to:s.path}))},docsVersion:function(e){let{label:t,to:n,docsPluginId:a,...o}=e;const i=(0,ke.lO)(a)[0],s=t??i.label,c=n??(e=>e.docs.find((t=>t.id===e.mainDocId)))(i).path;return r.createElement(oe,(0,l.Z)({},o,{label:s,to:c}))},docsVersionDropdown:function(e){let{mobile:t,docsPluginId:n,dropdownActiveClassDisabled:a,dropdownItemsBefore:o,dropdownItemsAfter:i,...u}=e;const{search:d,hash:p}=(0,s.TH)(),f=(0,we.Iw)(n),m=(0,we.gB)(n),{savePreferredVersionName:h}=(0,Se.J)(n),g=[...o,...m.map((e=>{const t=f.alternateDocVersions[e.name]??Ee(e);return{label:e.label,to:`${t.path}${d}${p}`,isActive:()=>e===f.activeVersion,onClick:()=>h(e.name)}})),...i],b=(0,ke.lO)(n)[0],v=t&&g.length>1?(0,c.I)({id:"theme.navbar.mobileVersionsDropdown.label",message:"Versions",description:"The label for the navbar versions dropdown on mobile view"}):b.label,y=t&&g.length>1?void 0:Ee(b).path;return g.length<=1?r.createElement(oe,(0,l.Z)({},u,{mobile:t,label:v,to:y,isActive:a?()=>!1:void 0})):r.createElement(pe,(0,l.Z)({},u,{mobile:t,label:v,to:y,items:g,isActive:a?()=>!1:void 0}))}};function _e(e){let{type:t,...n}=e;const a=function(e,t){return e&&"default"!==e?e:"items"in t?"dropdown":"default"}(t,n),o=xe[a];if(!o)throw new Error(`No NavbarItem component found for type "${t}".`);return r.createElement(o,n)}function Ce(){const e=(0,L.e)(),t=(0,w.L)().navbar.items;return r.createElement("ul",{className:"menu__list"},t.map(((t,n)=>r.createElement(_e,(0,l.Z)({mobile:!0},t,{onClick:()=>e.toggle(),key:n})))))}function Te(e){return r.createElement("button",(0,l.Z)({},e,{type:"button",className:"clean-btn navbar-sidebar__back"}),r.createElement(c.Z,{id:"theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel",description:"The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)"},"\u2190 Back to main menu"))}function Ae(){const e=0===(0,w.L)().navbar.items.length,t=M();return r.createElement(r.Fragment,null,!e&&r.createElement(Te,{onClick:()=>t.hide()}),t.content)}function Le(){const e=(0,L.e)();var t;return void 0===(t=e.shown)&&(t=!0),(0,r.useEffect)((()=>(document.body.style.overflow=t?"hidden":"visible",()=>{document.body.style.overflow="visible"})),[t]),e.shouldRender?r.createElement(F,{header:r.createElement(K,null),primaryMenu:r.createElement(Ce,null),secondaryMenu:r.createElement(Ae,null)}):null}const Pe={navbarHideable:"navbarHideable_m1mJ",navbarHidden:"navbarHidden_jGov"};function Re(e){return r.createElement("div",(0,l.Z)({role:"presentation"},e,{className:(0,a.Z)("navbar-sidebar__backdrop",e.className)}))}function Ne(e){let{children:t}=e;const{navbar:{hideOnScroll:n,style:o}}=(0,w.L)(),i=(0,L.e)(),{navbarRef:l,isNavbarVisible:s}=function(e){const[t,n]=(0,r.useState)(e),a=(0,r.useRef)(!1),o=(0,r.useRef)(0),i=(0,r.useCallback)((e=>{null!==e&&(o.current=e.getBoundingClientRect().height)}),[]);return(0,P.RF)(((t,r)=>{let{scrollY:i}=t;if(!e)return;if(i=l?n(!1):i+c{if(!e)return;const r=t.location.hash;if(r?document.getElementById(r.substring(1)):void 0)return a.current=!0,void n(!1);n(!0)})),{navbarRef:i,isNavbarVisible:t}}(n);return r.createElement("nav",{ref:l,"aria-label":(0,c.I)({id:"theme.NavBar.navAriaLabel",message:"Main",description:"The ARIA label for the main navigation"}),className:(0,a.Z)("navbar","navbar--fixed-top",n&&[Pe.navbarHideable,!s&&Pe.navbarHidden],{"navbar--dark":"dark"===o,"navbar--primary":"primary"===o,"navbar-sidebar--show":i.shown})},t,r.createElement(Re,{onClick:i.toggle}),r.createElement(Le,null))}var Oe=n(8780);const Ie={errorBoundaryError:"errorBoundaryError_a6uf"};function De(e){return r.createElement("button",(0,l.Z)({type:"button"},e),r.createElement(c.Z,{id:"theme.ErrorPageContent.tryAgain",description:"The label of the button to try again rendering when the React error boundary captures an error"},"Try again"))}function Me(e){let{error:t}=e;const n=(0,Oe.getErrorCausalChain)(t).map((e=>e.message)).join("\n\nCause:\n");return r.createElement("p",{className:Ie.errorBoundaryError},n)}class Fe extends r.Component{componentDidCatch(e,t){throw this.props.onError(e,t)}render(){return this.props.children}}const je="right";function Be(e){let{width:t=30,height:n=30,className:a,...o}=e;return r.createElement("svg",(0,l.Z)({className:a,width:t,height:n,viewBox:"0 0 30 30","aria-hidden":"true"},o),r.createElement("path",{stroke:"currentColor",strokeLinecap:"round",strokeMiterlimit:"10",strokeWidth:"2",d:"M4 7h22M4 15h22M4 23h22"}))}function ze(){const{toggle:e,shown:t}=(0,L.e)();return r.createElement("button",{onClick:e,"aria-label":(0,c.I)({id:"theme.docs.sidebar.toggleSidebarButtonAriaLabel",message:"Toggle navigation bar",description:"The ARIA label for hamburger menu button of mobile navigation"}),"aria-expanded":t,className:"navbar__toggle clean-btn",type:"button"},r.createElement(Be,null))}const Ue={colorModeToggle:"colorModeToggle_DEke"};function $e(e){let{items:t}=e;return r.createElement(r.Fragment,null,t.map(((e,t)=>r.createElement(Fe,{key:t,onError:t=>new Error(`A theme navbar item failed to render.\nPlease double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config:\n${JSON.stringify(e,null,2)}`,{cause:t})},r.createElement(_e,e)))))}function qe(e){let{left:t,right:n}=e;return r.createElement("div",{className:"navbar__inner"},r.createElement("div",{className:"navbar__items"},t),r.createElement("div",{className:"navbar__items navbar__items--right"},n))}function Ge(){const e=(0,L.e)(),t=(0,w.L)().navbar.items,[n,a]=function(e){function t(e){return"left"===(e.position??je)}return[e.filter(t),e.filter((e=>!t(e)))]}(t),o=t.find((e=>"search"===e.type));return r.createElement(qe,{left:r.createElement(r.Fragment,null,!e.disabled&&r.createElement(ze,null),r.createElement(W,null),r.createElement($e,{items:n})),right:r.createElement(r.Fragment,null,r.createElement($e,{items:a}),r.createElement(Z,{className:Ue.colorModeToggle}),!o&&r.createElement(ye,null,r.createElement(be,null)))})}function He(){return r.createElement(Ne,null,r.createElement(Ge,null))}function Ze(e){let{item:t}=e;const{to:n,href:a,label:o,prependBaseUrlToHref:i,...s}=t,c=(0,Q.Z)(n),u=(0,Q.Z)(a,{forcePrependBaseUrl:!0});return r.createElement(X.Z,(0,l.Z)({className:"footer__link-item"},a?{href:i?u:a}:{to:c},s),o,a&&!(0,J.Z)(a)&&r.createElement(te.Z,null))}function Ve(e){let{item:t}=e;return t.html?r.createElement("li",{className:"footer__item",dangerouslySetInnerHTML:{__html:t.html}}):r.createElement("li",{key:t.href??t.to,className:"footer__item"},r.createElement(Ze,{item:t}))}function We(e){let{column:t}=e;return r.createElement("div",{className:"col footer__col"},r.createElement("div",{className:"footer__title"},t.title),r.createElement("ul",{className:"footer__items clean-list"},t.items.map(((e,t)=>r.createElement(Ve,{key:t,item:e})))))}function Ye(e){let{columns:t}=e;return r.createElement("div",{className:"row footer__links"},t.map(((e,t)=>r.createElement(We,{key:t,column:e}))))}function Ke(){return r.createElement("span",{className:"footer__link-separator"},"\xb7")}function Xe(e){let{item:t}=e;return t.html?r.createElement("span",{className:"footer__link-item",dangerouslySetInnerHTML:{__html:t.html}}):r.createElement(Ze,{item:t})}function Qe(e){let{links:t}=e;return r.createElement("div",{className:"footer__links text--center"},r.createElement("div",{className:"footer__links"},t.map(((e,n)=>r.createElement(r.Fragment,{key:n},r.createElement(Xe,{item:e}),t.length!==n+1&&r.createElement(Ke,null))))))}function Je(e){let{links:t}=e;return function(e){return"title"in e[0]}(t)?r.createElement(Ye,{columns:t}):r.createElement(Qe,{links:t})}var et=n(941);const tt={footerLogoLink:"footerLogoLink_BH7S"};function nt(e){let{logo:t}=e;const{withBaseUrl:n}=(0,Q.C)(),o={light:n(t.src),dark:n(t.srcDark??t.src)};return r.createElement(et.Z,{className:(0,a.Z)("footer__logo",t.className),alt:t.alt,sources:o,width:t.width,height:t.height,style:t.style})}function rt(e){let{logo:t}=e;return t.href?r.createElement(X.Z,{href:t.href,className:tt.footerLogoLink,target:t.target},r.createElement(nt,{logo:t})):r.createElement(nt,{logo:t})}function at(e){let{copyright:t}=e;return r.createElement("div",{className:"footer__copyright",dangerouslySetInnerHTML:{__html:t}})}function ot(e){let{style:t,links:n,logo:o,copyright:i}=e;return r.createElement("footer",{className:(0,a.Z)("footer",{"footer--dark":"dark"===t})},r.createElement("div",{className:"container container-fluid"},n,(o||i)&&r.createElement("div",{className:"footer__bottom text--center"},o&&r.createElement("div",{className:"margin-bottom--sm"},o),i)))}function it(){const{footer:e}=(0,w.L)();if(!e)return null;const{copyright:t,links:n,logo:a,style:o}=e;return r.createElement(ot,{style:o,links:n&&n.length>0&&r.createElement(Je,{links:n}),logo:a&&r.createElement(rt,{logo:a}),copyright:t&&r.createElement(at,{copyright:t})})}const lt=r.memo(it),st=(0,R.Qc)([j.S,k.pl,P.OC,Se.L5,i.VC,function(e){let{children:t}=e;return r.createElement(N.n2,null,r.createElement(L.M,null,r.createElement(I,null,t)))}]);function ct(e){let{children:t}=e;return r.createElement(st,null,t)}function ut(e){let{error:t,tryAgain:n}=e;return r.createElement("main",{className:"container margin-vert--xl"},r.createElement("div",{className:"row"},r.createElement("div",{className:"col col--6 col--offset-3"},r.createElement("h1",{className:"hero__title"},r.createElement(c.Z,{id:"theme.ErrorPageContent.title",description:"The title of the fallback page when the page crashed"},"This page crashed.")),r.createElement("div",{className:"margin-vert--lg"},r.createElement(De,{onClick:n,className:"button button--primary shadow--lw"})),r.createElement("hr",null),r.createElement("div",{className:"margin-vert--md"},r.createElement(Me,{error:t})))))}const dt={mainWrapper:"mainWrapper_z2l0"};function pt(e){const{children:t,noFooter:n,wrapperClassName:l,title:s,description:c}=e;return(0,b.t)(),r.createElement(ct,null,r.createElement(i.d,{title:s,description:c}),r.createElement(y,null),r.createElement(A,null),r.createElement(He,null),r.createElement("div",{id:d,className:(0,a.Z)(g.k.wrapper.main,dt.mainWrapper,l)},r.createElement(o.Z,{fallback:e=>r.createElement(ut,e)},t)),!n&&r.createElement(lt,null))}},1327:(e,t,n)=>{"use strict";n.d(t,{Z:()=>d});var r=n(7462),a=n(7294),o=n(9960),i=n(4996),l=n(2263),s=n(6668),c=n(941);function u(e){let{logo:t,alt:n,imageClassName:r}=e;const o={light:(0,i.Z)(t.src),dark:(0,i.Z)(t.srcDark||t.src)},l=a.createElement(c.Z,{className:t.className,sources:o,height:t.height,width:t.width,alt:n,style:t.style});return r?a.createElement("div",{className:r},l):l}function d(e){const{siteConfig:{title:t}}=(0,l.Z)(),{navbar:{title:n,logo:c}}=(0,s.L)(),{imageClassName:d,titleClassName:p,...f}=e,m=(0,i.Z)(c?.href||"/"),h=n?"":t,g=c?.alt??h;return a.createElement(o.Z,(0,r.Z)({to:m},f,c?.target&&{target:c.target}),c&&a.createElement(u,{logo:c,alt:g,imageClassName:d}),null!=n&&a.createElement("b",{className:p},n))}},197:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294),a=n(5742);function o(e){let{locale:t,version:n,tag:o}=e;const i=t;return r.createElement(a.Z,null,t&&r.createElement("meta",{name:"docusaurus_locale",content:t}),n&&r.createElement("meta",{name:"docusaurus_version",content:n}),o&&r.createElement("meta",{name:"docusaurus_tag",content:o}),i&&r.createElement("meta",{name:"docsearch:language",content:i}),n&&r.createElement("meta",{name:"docsearch:version",content:n}),o&&r.createElement("meta",{name:"docsearch:docusaurus_tag",content:o}))}},941:(e,t,n)=>{"use strict";n.d(t,{Z:()=>c});var r=n(7462),a=n(7294),o=n(6010),i=n(2389),l=n(2949);const s={themedImage:"themedImage_ToTc","themedImage--light":"themedImage--light_HNdA","themedImage--dark":"themedImage--dark_i4oU"};function c(e){const t=(0,i.Z)(),{colorMode:n}=(0,l.I)(),{sources:c,className:u,alt:d,...p}=e,f=t?"dark"===n?["dark"]:["light"]:["light","dark"];return a.createElement(a.Fragment,null,f.map((e=>a.createElement("img",(0,r.Z)({key:e,src:c[e],alt:d,className:(0,o.Z)(s.themedImage,s[`themedImage--${e}`],u)},p)))))}},6043:(e,t,n)=>{"use strict";n.d(t,{u:()=>s,z:()=>g});var r=n(7462),a=n(7294),o=n(412),i=n(1442);const l="ease-in-out";function s(e){let{initialState:t}=e;const[n,r]=(0,a.useState)(t??!1),o=(0,a.useCallback)((()=>{r((e=>!e))}),[]);return{collapsed:n,setCollapsed:r,toggleCollapsed:o}}const c={display:"none",overflow:"hidden",height:"0px"},u={display:"block",overflow:"visible",height:"auto"};function d(e,t){const n=t?c:u;e.style.display=n.display,e.style.overflow=n.overflow,e.style.height=n.height}function p(e){let{collapsibleRef:t,collapsed:n,animation:r}=e;const o=(0,a.useRef)(!1);(0,a.useEffect)((()=>{const e=t.current;function a(){const t=e.scrollHeight,n=r?.duration??function(e){if((0,i.n)())return 1;const t=e/36;return Math.round(10*(4+15*t**.25+t/5))}(t);return{transition:`height ${n}ms ${r?.easing??l}`,height:`${t}px`}}function s(){const t=a();e.style.transition=t.transition,e.style.height=t.height}if(!o.current)return d(e,n),void(o.current=!0);return e.style.willChange="height",function(){const t=requestAnimationFrame((()=>{n?(s(),requestAnimationFrame((()=>{e.style.height=c.height,e.style.overflow=c.overflow}))):(e.style.display="block",requestAnimationFrame((()=>{s()})))}));return()=>cancelAnimationFrame(t)}()}),[t,n,r])}function f(e){if(!o.Z.canUseDOM)return e?c:u}function m(e){let{as:t="div",collapsed:n,children:r,animation:o,onCollapseTransitionEnd:i,className:l,disableSSRStyle:s}=e;const c=(0,a.useRef)(null);return p({collapsibleRef:c,collapsed:n,animation:o}),a.createElement(t,{ref:c,style:s?void 0:f(n),onTransitionEnd:e=>{"height"===e.propertyName&&(d(c.current,n),i?.(n))},className:l},r)}function h(e){let{collapsed:t,...n}=e;const[o,i]=(0,a.useState)(!t),[l,s]=(0,a.useState)(t);return(0,a.useLayoutEffect)((()=>{t||i(!0)}),[t]),(0,a.useLayoutEffect)((()=>{o&&s(t)}),[o,t]),o?a.createElement(m,(0,r.Z)({},n,{collapsed:l})):null}function g(e){let{lazy:t,...n}=e;const r=t?h:m;return a.createElement(r,n)}},9689:(e,t,n)=>{"use strict";n.d(t,{nT:()=>m,pl:()=>f});var r=n(7294),a=n(2389),o=n(12),i=n(902),l=n(6668);const s=(0,o.WA)("docusaurus.announcement.dismiss"),c=(0,o.WA)("docusaurus.announcement.id"),u=()=>"true"===s.get(),d=e=>s.set(String(e)),p=r.createContext(null);function f(e){let{children:t}=e;const n=function(){const{announcementBar:e}=(0,l.L)(),t=(0,a.Z)(),[n,o]=(0,r.useState)((()=>!!t&&u()));(0,r.useEffect)((()=>{o(u())}),[]);const i=(0,r.useCallback)((()=>{d(!0),o(!0)}),[]);return(0,r.useEffect)((()=>{if(!e)return;const{id:t}=e;let n=c.get();"annoucement-bar"===n&&(n="announcement-bar");const r=t!==n;c.set(t),r&&d(!1),!r&&u()||o(!1)}),[e]),(0,r.useMemo)((()=>({isActive:!!e&&!n,close:i})),[e,n,i])}();return r.createElement(p.Provider,{value:n},t)}function m(){const e=(0,r.useContext)(p);if(!e)throw new i.i6("AnnouncementBarProvider");return e}},2949:(e,t,n)=>{"use strict";n.d(t,{I:()=>g,S:()=>h});var r=n(7294),a=n(412),o=n(902),i=n(12),l=n(6668);const s=r.createContext(void 0),c="theme",u=(0,i.WA)(c),d={light:"light",dark:"dark"},p=e=>e===d.dark?d.dark:d.light,f=e=>a.Z.canUseDOM?p(document.documentElement.getAttribute("data-theme")):p(e),m=e=>{u.set(p(e))};function h(e){let{children:t}=e;const n=function(){const{colorMode:{defaultMode:e,disableSwitch:t,respectPrefersColorScheme:n}}=(0,l.L)(),[a,o]=(0,r.useState)(f(e));(0,r.useEffect)((()=>{t&&u.del()}),[t]);const i=(0,r.useCallback)((function(t,r){void 0===r&&(r={});const{persist:a=!0}=r;t?(o(t),a&&m(t)):(o(n?window.matchMedia("(prefers-color-scheme: dark)").matches?d.dark:d.light:e),u.del())}),[n,e]);(0,r.useEffect)((()=>{document.documentElement.setAttribute("data-theme",p(a))}),[a]),(0,r.useEffect)((()=>{if(t)return;const e=e=>{if(e.key!==c)return;const t=u.get();null!==t&&i(p(t))};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,i]);const s=(0,r.useRef)(!1);return(0,r.useEffect)((()=>{if(t&&!n)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>{window.matchMedia("print").matches||s.current?s.current=window.matchMedia("print").matches:i(null)};return e.addListener(r),()=>e.removeListener(r)}),[i,t,n]),(0,r.useMemo)((()=>({colorMode:a,setColorMode:i,get isDarkTheme(){return a===d.dark},setLightTheme(){i(d.light)},setDarkTheme(){i(d.dark)}})),[a,i])}();return r.createElement(s.Provider,{value:n},t)}function g(){const e=(0,r.useContext)(s);if(null==e)throw new o.i6("ColorModeProvider","Please see https://docusaurus.io/docs/api/themes/configuration#use-color-mode.");return e}},373:(e,t,n)=>{"use strict";n.d(t,{J:()=>v,L5:()=>g});var r=n(7294),a=n(4104),o=n(9935),i=n(6668),l=n(3438),s=n(902),c=n(12);const u=e=>`docs-preferred-version-${e}`,d={save:(e,t,n)=>{(0,c.WA)(u(e),{persistence:t}).set(n)},read:(e,t)=>(0,c.WA)(u(e),{persistence:t}).get(),clear:(e,t)=>{(0,c.WA)(u(e),{persistence:t}).del()}},p=e=>Object.fromEntries(e.map((e=>[e,{preferredVersionName:null}])));const f=r.createContext(null);function m(){const e=(0,a._r)(),t=(0,i.L)().docs.versionPersistence,n=(0,r.useMemo)((()=>Object.keys(e)),[e]),[o,l]=(0,r.useState)((()=>p(n)));(0,r.useEffect)((()=>{l(function(e){let{pluginIds:t,versionPersistence:n,allDocsData:r}=e;function a(e){const t=d.read(e,n);return r[e].versions.some((e=>e.name===t))?{preferredVersionName:t}:(d.clear(e,n),{preferredVersionName:null})}return Object.fromEntries(t.map((e=>[e,a(e)])))}({allDocsData:e,versionPersistence:t,pluginIds:n}))}),[e,t,n]);return[o,(0,r.useMemo)((()=>({savePreferredVersion:function(e,n){d.save(e,t,n),l((t=>({...t,[e]:{preferredVersionName:n}})))}})),[t])]}function h(e){let{children:t}=e;const n=m();return r.createElement(f.Provider,{value:n},t)}function g(e){let{children:t}=e;return l.cE?r.createElement(h,null,t):r.createElement(r.Fragment,null,t)}function b(){const e=(0,r.useContext)(f);if(!e)throw new s.i6("DocsPreferredVersionContextProvider");return e}function v(e){void 0===e&&(e=o.m);const t=(0,a.zh)(e),[n,i]=b(),{preferredVersionName:l}=n[e];return{preferredVersion:t.versions.find((e=>e.name===l))??null,savePreferredVersionName:(0,r.useCallback)((t=>{i.savePreferredVersion(e,t)}),[i,e])}}},1116:(e,t,n)=>{"use strict";n.d(t,{V:()=>s,b:()=>l});var r=n(7294),a=n(902);const o=Symbol("EmptyContext"),i=r.createContext(o);function l(e){let{children:t,name:n,items:a}=e;const o=(0,r.useMemo)((()=>n&&a?{name:n,items:a}:null),[n,a]);return r.createElement(i.Provider,{value:o},t)}function s(){const e=(0,r.useContext)(i);if(e===o)throw new a.i6("DocsSidebarProvider");return e}},4477:(e,t,n)=>{"use strict";n.d(t,{E:()=>l,q:()=>i});var r=n(7294),a=n(902);const o=r.createContext(null);function i(e){let{children:t,version:n}=e;return r.createElement(o.Provider,{value:n},t)}function l(){const e=(0,r.useContext)(o);if(null===e)throw new a.i6("DocsVersionProvider");return e}},3163:(e,t,n)=>{"use strict";n.d(t,{M:()=>d,e:()=>p});var r=n(7294),a=n(3102),o=n(7524),i=n(1980),l=n(6668),s=n(902);const c=r.createContext(void 0);function u(){const e=function(){const e=(0,a.HY)(),{items:t}=(0,l.L)().navbar;return 0===t.length&&!e.component}(),t=(0,o.i)(),n=!e&&"mobile"===t,[s,c]=(0,r.useState)(!1);(0,i.Rb)((()=>{if(s)return c(!1),!1}));const u=(0,r.useCallback)((()=>{c((e=>!e))}),[]);return(0,r.useEffect)((()=>{"desktop"===t&&c(!1)}),[t]),(0,r.useMemo)((()=>({disabled:e,shouldRender:n,toggle:u,shown:s})),[e,n,u,s])}function d(e){let{children:t}=e;const n=u();return r.createElement(c.Provider,{value:n},t)}function p(){const e=r.useContext(c);if(void 0===e)throw new s.i6("NavbarMobileSidebarProvider");return e}},3102:(e,t,n)=>{"use strict";n.d(t,{HY:()=>l,Zo:()=>s,n2:()=>i});var r=n(7294),a=n(902);const o=r.createContext(null);function i(e){let{children:t}=e;const n=(0,r.useState)({component:null,props:null});return r.createElement(o.Provider,{value:n},t)}function l(){const e=(0,r.useContext)(o);if(!e)throw new a.i6("NavbarSecondaryMenuContentProvider");return e[0]}function s(e){let{component:t,props:n}=e;const i=(0,r.useContext)(o);if(!i)throw new a.i6("NavbarSecondaryMenuContentProvider");const[,l]=i,s=(0,a.Ql)(n);return(0,r.useEffect)((()=>{l({component:t,props:s})}),[l,t,s]),(0,r.useEffect)((()=>()=>l({component:null,props:null})),[l]),null}},9727:(e,t,n)=>{"use strict";n.d(t,{h:()=>a,t:()=>o});var r=n(7294);const a="navigation-with-keyboard";function o(){(0,r.useEffect)((()=>{function e(e){"keydown"===e.type&&"Tab"===e.key&&document.body.classList.add(a),"mousedown"===e.type&&document.body.classList.remove(a)}return document.addEventListener("keydown",e),document.addEventListener("mousedown",e),()=>{document.body.classList.remove(a),document.removeEventListener("keydown",e),document.removeEventListener("mousedown",e)}}),[])}},7524:(e,t,n)=>{"use strict";n.d(t,{i:()=>c});var r=n(7294),a=n(412);const o={desktop:"desktop",mobile:"mobile",ssr:"ssr"},i=996;function l(){return a.Z.canUseDOM?window.innerWidth>i?o.desktop:o.mobile:o.ssr}const s=!1;function c(){const[e,t]=(0,r.useState)((()=>s?"ssr":l()));return(0,r.useEffect)((()=>{function e(){t(l())}const n=s?window.setTimeout(e,1e3):void 0;return window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e),clearTimeout(n)}}),[]),e}},5281:(e,t,n)=>{"use strict";n.d(t,{k:()=>r});const r={page:{blogListPage:"blog-list-page",blogPostPage:"blog-post-page",blogTagsListPage:"blog-tags-list-page",blogTagPostListPage:"blog-tags-post-list-page",docsDocPage:"docs-doc-page",docsTagsListPage:"docs-tags-list-page",docsTagDocListPage:"docs-tags-doc-list-page",mdxPage:"mdx-page"},wrapper:{main:"main-wrapper",blogPages:"blog-wrapper",docsPages:"docs-wrapper",mdxPages:"mdx-wrapper"},common:{editThisPage:"theme-edit-this-page",lastUpdated:"theme-last-updated",backToTopButton:"theme-back-to-top-button",codeBlock:"theme-code-block",admonition:"theme-admonition",admonitionType:e=>`theme-admonition-${e}`},layout:{},docs:{docVersionBanner:"theme-doc-version-banner",docVersionBadge:"theme-doc-version-badge",docBreadcrumbs:"theme-doc-breadcrumbs",docMarkdown:"theme-doc-markdown",docTocMobile:"theme-doc-toc-mobile",docTocDesktop:"theme-doc-toc-desktop",docFooter:"theme-doc-footer",docFooterTagsRow:"theme-doc-footer-tags-row",docFooterEditMetaRow:"theme-doc-footer-edit-meta-row",docSidebarContainer:"theme-doc-sidebar-container",docSidebarMenu:"theme-doc-sidebar-menu",docSidebarItemCategory:"theme-doc-sidebar-item-category",docSidebarItemLink:"theme-doc-sidebar-item-link",docSidebarItemCategoryLevel:e=>`theme-doc-sidebar-item-category-level-${e}`,docSidebarItemLinkLevel:e=>`theme-doc-sidebar-item-link-level-${e}`},blog:{}}},1442:(e,t,n)=>{"use strict";function r(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}n.d(t,{n:()=>r})},3438:(e,t,n)=>{"use strict";n.d(t,{MN:()=>_,Wl:()=>m,_F:()=>v,cE:()=>p,hI:()=>x,jA:()=>h,lO:()=>k,oz:()=>S,s1:()=>w,vY:()=>E,xz:()=>f});var r=n(7294),a=n(6550),o=n(8790),i=n(4104),l=n(373),s=n(4477),c=n(1116),u=n(7392),d=n(8596);const p=!!i._r;function f(e){const t=(0,s.E)();if(!e)return;const n=t.docs[e];if(!n)throw new Error(`no version doc found by id=${e}`);return n}function m(e){if(e.href)return e.href;for(const t of e.items){if("link"===t.type)return t.href;if("category"===t.type){const e=m(t);if(e)return e}}}function h(){const{pathname:e}=(0,a.TH)(),t=(0,c.V)();if(!t)throw new Error("Unexpected: cant find current sidebar in context");const n=y({sidebarItems:t.items,pathname:e,onlyCategories:!0}).slice(-1)[0];if(!n)throw new Error(`${e} is not associated with a category. useCurrentSidebarCategory() should only be used on category index pages.`);return n}const g=(e,t)=>void 0!==e&&(0,d.Mg)(e,t),b=(e,t)=>e.some((e=>v(e,t)));function v(e,t){return"link"===e.type?g(e.href,t):"category"===e.type&&(g(e.href,t)||b(e.items,t))}function y(e){let{sidebarItems:t,pathname:n,onlyCategories:r=!1}=e;const a=[];return function e(t){for(const o of t)if("category"===o.type&&((0,d.Mg)(o.href,n)||e(o.items))||"link"===o.type&&(0,d.Mg)(o.href,n)){return r&&"category"!==o.type||a.unshift(o),!0}return!1}(t),a}function w(){const e=(0,c.V)(),{pathname:t}=(0,a.TH)(),n=(0,i.gA)()?.pluginData.breadcrumbs;return!1!==n&&e?y({sidebarItems:e.items,pathname:t}):null}function k(e){const{activeVersion:t}=(0,i.Iw)(e),{preferredVersion:n}=(0,l.J)(e),a=(0,i.yW)(e);return(0,r.useMemo)((()=>(0,u.j)([t,n,a].filter(Boolean))),[t,n,a])}function S(e,t){const n=k(t);return(0,r.useMemo)((()=>{const t=n.flatMap((e=>e.sidebars?Object.entries(e.sidebars):[])),r=t.find((t=>t[0]===e));if(!r)throw new Error(`Can't find any sidebar with id "${e}" in version${n.length>1?"s":""} ${n.map((e=>e.name)).join(", ")}".\nAvailable sidebar ids are:\n- ${t.map((e=>e[0])).join("\n- ")}`);return r[1]}),[e,n])}function E(e,t){const n=k(t);return(0,r.useMemo)((()=>{const t=n.flatMap((e=>e.docs)),r=t.find((t=>t.id===e));if(!r){if(n.flatMap((e=>e.draftIds)).includes(e))return null;throw new Error(`Couldn't find any doc with id "${e}" in version${n.length>1?"s":""} "${n.map((e=>e.name)).join(", ")}".\nAvailable doc ids are:\n- ${(0,u.j)(t.map((e=>e.id))).join("\n- ")}`)}return r}),[e,n])}function x(e){let{route:t,versionMetadata:n}=e;const r=(0,a.TH)(),i=t.routes,l=i.find((e=>(0,a.LX)(r.pathname,e)));if(!l)return null;const s=l.sidebar,c=s?n.docsSidebars[s]:void 0;return{docElement:(0,o.H)(i),sidebarName:s,sidebarItems:c}}function _(e){return e.filter((e=>"category"!==e.type||!!m(e)))}},1980:(e,t,n)=>{"use strict";n.d(t,{Rb:()=>l,_X:()=>s});var r=n(7294),a=n(6550),o=n(1688),i=n(902);function l(e){!function(e){const t=(0,a.k6)(),n=(0,i.zX)(e);(0,r.useEffect)((()=>t.block(((e,t)=>n(e,t)))),[t,n])}(((t,n)=>{if("POP"===n)return e(t,n)}))}function s(e){return function(e){const t=(0,a.k6)();return(0,o.useSyncExternalStore)(t.listen,(()=>e(t)),(()=>e(t)))}((t=>null===e?null:new URLSearchParams(t.location.search).get(e)))}},7392:(e,t,n)=>{"use strict";function r(e,t){return void 0===t&&(t=(e,t)=>e===t),e.filter(((n,r)=>e.findIndex((e=>t(e,n)))!==r))}function a(e){return Array.from(new Set(e))}n.d(t,{j:()=>a,l:()=>r})},1944:(e,t,n)=>{"use strict";n.d(t,{FG:()=>p,d:()=>u,VC:()=>f});var r=n(7294),a=n(6010),o=n(5742),i=n(226);function l(){const e=r.useContext(i._);if(!e)throw new Error("Unexpected: no Docusaurus route context found");return e}var s=n(4996),c=n(2263);function u(e){let{title:t,description:n,keywords:a,image:i,children:l}=e;const u=function(e){const{siteConfig:t}=(0,c.Z)(),{title:n,titleDelimiter:r}=t;return e?.trim().length?`${e.trim()} ${r} ${n}`:n}(t),{withBaseUrl:d}=(0,s.C)(),p=i?d(i,{absolute:!0}):void 0;return r.createElement(o.Z,null,t&&r.createElement("title",null,u),t&&r.createElement("meta",{property:"og:title",content:u}),n&&r.createElement("meta",{name:"description",content:n}),n&&r.createElement("meta",{property:"og:description",content:n}),a&&r.createElement("meta",{name:"keywords",content:Array.isArray(a)?a.join(","):a}),p&&r.createElement("meta",{property:"og:image",content:p}),p&&r.createElement("meta",{name:"twitter:image",content:p}),l)}const d=r.createContext(void 0);function p(e){let{className:t,children:n}=e;const i=r.useContext(d),l=(0,a.Z)(i,t);return r.createElement(d.Provider,{value:l},r.createElement(o.Z,null,r.createElement("html",{className:l})),n)}function f(e){let{children:t}=e;const n=l(),o=`plugin-${n.plugin.name.replace(/docusaurus-(?:plugin|theme)-(?:content-)?/gi,"")}`;const i=`plugin-id-${n.plugin.id}`;return r.createElement(p,{className:(0,a.Z)(o,i)},t)}},902:(e,t,n)=>{"use strict";n.d(t,{D9:()=>i,Qc:()=>c,Ql:()=>s,i6:()=>l,zX:()=>o});var r=n(7294);const a=n(412).Z.canUseDOM?r.useLayoutEffect:r.useEffect;function o(e){const t=(0,r.useRef)(e);return a((()=>{t.current=e}),[e]),(0,r.useCallback)((function(){return t.current(...arguments)}),[])}function i(e){const t=(0,r.useRef)();return a((()=>{t.current=e})),t.current}class l extends Error{constructor(e,t){super(),this.name="ReactContextError",this.message=`Hook ${this.stack?.split("\n")[1]?.match(/at (?:\w+\.)?(?\w+)/)?.groups.name??""} is called outside the <${e}>. ${t??""}`}}function s(e){const t=Object.entries(e);return t.sort(((e,t)=>e[0].localeCompare(t[0]))),(0,r.useMemo)((()=>e),t.flat())}function c(e){return t=>{let{children:n}=t;return r.createElement(r.Fragment,null,e.reduceRight(((e,t)=>r.createElement(t,null,e)),n))}}},8596:(e,t,n)=>{"use strict";n.d(t,{Mg:()=>i,Ns:()=>l});var r=n(7294),a=n(723),o=n(2263);function i(e,t){const n=e=>(!e||e.endsWith("/")?e:`${e}/`)?.toLowerCase();return n(e)===n(t)}function l(){const{baseUrl:e}=(0,o.Z)().siteConfig;return(0,r.useMemo)((()=>function(e){let{baseUrl:t,routes:n}=e;function r(e){return e.path===t&&!0===e.exact}function a(e){return e.path===t&&!e.exact}return function e(t){if(0===t.length)return;return t.find(r)||e(t.filter(a).flatMap((e=>e.routes??[])))}(n)}({routes:a.Z,baseUrl:e})),[e])}},2466:(e,t,n)=>{"use strict";n.d(t,{Ct:()=>f,OC:()=>s,RF:()=>d,o5:()=>p});var r=n(7294),a=n(412),o=n(2389),i=n(902);const l=r.createContext(void 0);function s(e){let{children:t}=e;const n=function(){const e=(0,r.useRef)(!0);return(0,r.useMemo)((()=>({scrollEventsEnabledRef:e,enableScrollEvents:()=>{e.current=!0},disableScrollEvents:()=>{e.current=!1}})),[])}();return r.createElement(l.Provider,{value:n},t)}function c(){const e=(0,r.useContext)(l);if(null==e)throw new i.i6("ScrollControllerProvider");return e}const u=()=>a.Z.canUseDOM?{scrollX:window.pageXOffset,scrollY:window.pageYOffset}:null;function d(e,t){void 0===t&&(t=[]);const{scrollEventsEnabledRef:n}=c(),a=(0,r.useRef)(u()),o=(0,i.zX)(e);(0,r.useEffect)((()=>{const e=()=>{if(!n.current)return;const e=u();o(e,a.current),a.current=e},t={passive:!0};return e(),window.addEventListener("scroll",e,t),()=>window.removeEventListener("scroll",e,t)}),[o,n,...t])}function p(){const e=c(),t=function(){const e=(0,r.useRef)({elem:null,top:0}),t=(0,r.useCallback)((t=>{e.current={elem:t,top:t.getBoundingClientRect().top}}),[]),n=(0,r.useCallback)((()=>{const{current:{elem:t,top:n}}=e;if(!t)return{restored:!1};const r=t.getBoundingClientRect().top-n;return r&&window.scrollBy({left:0,top:r}),e.current={elem:null,top:0},{restored:0!==r}}),[]);return(0,r.useMemo)((()=>({save:t,restore:n})),[n,t])}(),n=(0,r.useRef)(void 0),a=(0,r.useCallback)((r=>{t.save(r),e.disableScrollEvents(),n.current=()=>{const{restored:r}=t.restore();if(n.current=void 0,r){const t=()=>{e.enableScrollEvents(),window.removeEventListener("scroll",t)};window.addEventListener("scroll",t)}else e.enableScrollEvents()}}),[e,t]);return(0,r.useLayoutEffect)((()=>{queueMicrotask((()=>n.current?.()))})),{blockElementScrollPositionUntilNextRender:a}}function f(){const e=(0,r.useRef)(null),t=(0,o.Z)()&&"smooth"===getComputedStyle(document.documentElement).scrollBehavior;return{startScroll:n=>{e.current=t?function(e){return window.scrollTo({top:e,behavior:"smooth"}),()=>{}}(n):function(e){let t=null;const n=document.documentElement.scrollTop>e;return function r(){const a=document.documentElement.scrollTop;(n&&a>e||!n&&at&&cancelAnimationFrame(t)}(n)},cancelScroll:()=>e.current?.()}}},3320:(e,t,n)=>{"use strict";n.d(t,{HX:()=>r,os:()=>a});n(2263);const r="default";function a(e,t){return`docs-${e}-${t}`}},12:(e,t,n)=>{"use strict";n.d(t,{Nk:()=>d,WA:()=>u});var r=n(7294),a=n(1688);const o="localStorage";function i(e){let{key:t,oldValue:n,newValue:r,storage:a}=e;if(n===r)return;const o=document.createEvent("StorageEvent");o.initStorageEvent("storage",!1,!1,t,n,r,window.location.href,a),window.dispatchEvent(o)}function l(e){if(void 0===e&&(e=o),"undefined"==typeof window)throw new Error("Browser storage is not available on Node.js/Docusaurus SSR process.");if("none"===e)return null;try{return window[e]}catch(n){return t=n,s||(console.warn("Docusaurus browser storage is not available.\nPossible reasons: running Docusaurus in an iframe, in an incognito browser session, or using too strict browser privacy settings.",t),s=!0),null}var t}let s=!1;const c={get:()=>null,set:()=>{},del:()=>{},listen:()=>()=>{}};function u(e,t){if("undefined"==typeof window)return function(e){function t(){throw new Error(`Illegal storage API usage for storage key "${e}".\nDocusaurus storage APIs are not supposed to be called on the server-rendering process.\nPlease only call storage APIs in effects and event handlers.`)}return{get:t,set:t,del:t,listen:t}}(e);const n=l(t?.persistence);return null===n?c:{get:()=>{try{return n.getItem(e)}catch(t){return console.error(`Docusaurus storage error, can't get key=${e}`,t),null}},set:t=>{try{const r=n.getItem(e);n.setItem(e,t),i({key:e,oldValue:r,newValue:t,storage:n})}catch(r){console.error(`Docusaurus storage error, can't set ${e}=${t}`,r)}},del:()=>{try{const t=n.getItem(e);n.removeItem(e),i({key:e,oldValue:t,newValue:null,storage:n})}catch(t){console.error(`Docusaurus storage error, can't delete key=${e}`,t)}},listen:t=>{try{const r=r=>{r.storageArea===n&&r.key===e&&t(r)};return window.addEventListener("storage",r),()=>window.removeEventListener("storage",r)}catch(r){return console.error(`Docusaurus storage error, can't listen for changes of key=${e}`,r),()=>{}}}}}function d(e,t){const n=(0,r.useRef)((()=>null===e?c:u(e,t))).current(),o=(0,r.useCallback)((e=>"undefined"==typeof window?()=>{}:n.listen(e)),[n]);return[(0,a.useSyncExternalStore)(o,(()=>"undefined"==typeof window?null:n.get()),(()=>null)),n]}},4711:(e,t,n)=>{"use strict";n.d(t,{l:()=>i});var r=n(2263),a=n(6550),o=n(8780);function i(){const{siteConfig:{baseUrl:e,url:t,trailingSlash:n},i18n:{defaultLocale:i,currentLocale:l}}=(0,r.Z)(),{pathname:s}=(0,a.TH)(),c=(0,o.applyTrailingSlash)(s,{trailingSlash:n,baseUrl:e}),u=l===i?e:e.replace(`/${l}/`,"/"),d=c.replace(e,"");return{createUrl:function(e){let{locale:n,fullyQualified:r}=e;return`${r?t:""}${function(e){return e===i?`${u}`:`${u}${e}/`}(n)}${d}`}}}},5936:(e,t,n)=>{"use strict";n.d(t,{S:()=>i});var r=n(7294),a=n(6550),o=n(902);function i(e){const t=(0,a.TH)(),n=(0,o.D9)(t),i=(0,o.zX)(e);(0,r.useEffect)((()=>{n&&t!==n&&i({location:t,previousLocation:n})}),[i,t,n])}},6668:(e,t,n)=>{"use strict";n.d(t,{L:()=>a});var r=n(2263);function a(){return(0,r.Z)().siteConfig.themeConfig}},8802:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){const{trailingSlash:n,baseUrl:r}=t;if(e.startsWith("#"))return e;if(void 0===n)return e;const[a]=e.split(/[#?]/),o="/"===a||a===r?a:(i=a,n?function(e){return e.endsWith("/")?e:`${e}/`}(i):function(e){return e.endsWith("/")?e.slice(0,-1):e}(i));var i;return e.replace(a,o)}},4143:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getErrorCausalChain=void 0,t.getErrorCausalChain=function e(t){return t.cause?[t,...e(t.cause)]:[t]}},8780:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getErrorCausalChain=t.applyTrailingSlash=t.blogPostContainerID=void 0,t.blogPostContainerID="__blog-post-container";var a=n(8802);Object.defineProperty(t,"applyTrailingSlash",{enumerable:!0,get:function(){return r(a).default}});var o=n(4143);Object.defineProperty(t,"getErrorCausalChain",{enumerable:!0,get:function(){return o.getErrorCausalChain}})},6010:(e,t,n)=>{"use strict";function r(e){var t,n,a="";if("string"==typeof e||"number"==typeof e)a+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;ta});const a=function(){for(var e,t,n=0,a="";n{"use strict";n.d(t,{lX:()=>w,q_:()=>C,ob:()=>f,PP:()=>A,Ep:()=>p});var r=n(7462);function a(e){return"/"===e.charAt(0)}function o(e,t){for(var n=t,r=n+1,a=e.length;r=0;p--){var f=i[p];"."===f?o(i,p):".."===f?(o(i,p),d++):d&&(o(i,p),d--)}if(!c)for(;d--;d)i.unshift("..");!c||""===i[0]||i[0]&&a(i[0])||i.unshift("");var m=i.join("/");return n&&"/"!==m.substr(-1)&&(m+="/"),m};var l=n(8776);function s(e){return"/"===e.charAt(0)?e:"/"+e}function c(e){return"/"===e.charAt(0)?e.substr(1):e}function u(e,t){return function(e,t){return 0===e.toLowerCase().indexOf(t.toLowerCase())&&-1!=="/?#".indexOf(e.charAt(t.length))}(e,t)?e.substr(t.length):e}function d(e){return"/"===e.charAt(e.length-1)?e.slice(0,-1):e}function p(e){var t=e.pathname,n=e.search,r=e.hash,a=t||"/";return n&&"?"!==n&&(a+="?"===n.charAt(0)?n:"?"+n),r&&"#"!==r&&(a+="#"===r.charAt(0)?r:"#"+r),a}function f(e,t,n,a){var o;"string"==typeof e?(o=function(e){var t=e||"/",n="",r="",a=t.indexOf("#");-1!==a&&(r=t.substr(a),t=t.substr(0,a));var o=t.indexOf("?");return-1!==o&&(n=t.substr(o),t=t.substr(0,o)),{pathname:t,search:"?"===n?"":n,hash:"#"===r?"":r}}(e),o.state=t):(void 0===(o=(0,r.Z)({},e)).pathname&&(o.pathname=""),o.search?"?"!==o.search.charAt(0)&&(o.search="?"+o.search):o.search="",o.hash?"#"!==o.hash.charAt(0)&&(o.hash="#"+o.hash):o.hash="",void 0!==t&&void 0===o.state&&(o.state=t));try{o.pathname=decodeURI(o.pathname)}catch(l){throw l instanceof URIError?new URIError('Pathname "'+o.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):l}return n&&(o.key=n),a?o.pathname?"/"!==o.pathname.charAt(0)&&(o.pathname=i(o.pathname,a.pathname)):o.pathname=a.pathname:o.pathname||(o.pathname="/"),o}function m(){var e=null;var t=[];return{setPrompt:function(t){return e=t,function(){e===t&&(e=null)}},confirmTransitionTo:function(t,n,r,a){if(null!=e){var o="function"==typeof e?e(t,n):e;"string"==typeof o?"function"==typeof r?r(o,a):a(!0):a(!1!==o)}else a(!0)},appendListener:function(e){var n=!0;function r(){n&&e.apply(void 0,arguments)}return t.push(r),function(){n=!1,t=t.filter((function(e){return e!==r}))}},notifyListeners:function(){for(var e=arguments.length,n=new Array(e),r=0;rt?n.splice(t,n.length-t,a):n.push(a),d({action:r,location:a,index:t,entries:n})}}))},replace:function(e,t){var r="REPLACE",a=f(e,t,h(),w.location);u.confirmTransitionTo(a,r,n,(function(e){e&&(w.entries[w.index]=a,d({action:r,location:a}))}))},go:y,goBack:function(){y(-1)},goForward:function(){y(1)},canGo:function(e){var t=w.index+e;return t>=0&&t{"use strict";var r=n(9864),a={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},o={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},i={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},l={};function s(e){return r.isMemo(e)?i:l[e.$$typeof]||a}l[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},l[r.Memo]=i;var c=Object.defineProperty,u=Object.getOwnPropertyNames,d=Object.getOwnPropertySymbols,p=Object.getOwnPropertyDescriptor,f=Object.getPrototypeOf,m=Object.prototype;e.exports=function e(t,n,r){if("string"!=typeof n){if(m){var a=f(n);a&&a!==m&&e(t,a,r)}var i=u(n);d&&(i=i.concat(d(n)));for(var l=s(t),h=s(n),g=0;g{"use strict";e.exports=function(e,t,n,r,a,o,i,l){if(!e){var s;if(void 0===t)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,a,o,i,l],u=0;(s=new Error(t.replace(/%s/g,(function(){return c[u++]})))).name="Invariant Violation"}throw s.framesToPop=1,s}}},5826:e=>{e.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},2497:(e,t,n)=>{"use strict";n.r(t)},2295:(e,t,n)=>{"use strict";n.r(t)},4865:function(e,t,n){var r,a;r=function(){var e,t,n={version:"0.2.0"},r=n.settings={minimum:.08,easing:"ease",positionUsing:"",speed:200,trickle:!0,trickleRate:.02,trickleSpeed:800,showSpinner:!0,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",template:'
'};function a(e,t,n){return en?n:e}function o(e){return 100*(-1+e)}function i(e,t,n){var a;return(a="translate3d"===r.positionUsing?{transform:"translate3d("+o(e)+"%,0,0)"}:"translate"===r.positionUsing?{transform:"translate("+o(e)+"%,0)"}:{"margin-left":o(e)+"%"}).transition="all "+t+"ms "+n,a}n.configure=function(e){var t,n;for(t in e)void 0!==(n=e[t])&&e.hasOwnProperty(t)&&(r[t]=n);return this},n.status=null,n.set=function(e){var t=n.isStarted();e=a(e,r.minimum,1),n.status=1===e?null:e;var o=n.render(!t),c=o.querySelector(r.barSelector),u=r.speed,d=r.easing;return o.offsetWidth,l((function(t){""===r.positionUsing&&(r.positionUsing=n.getPositioningCSS()),s(c,i(e,u,d)),1===e?(s(o,{transition:"none",opacity:1}),o.offsetWidth,setTimeout((function(){s(o,{transition:"all "+u+"ms linear",opacity:0}),setTimeout((function(){n.remove(),t()}),u)}),u)):setTimeout(t,u)})),this},n.isStarted=function(){return"number"==typeof n.status},n.start=function(){n.status||n.set(0);var e=function(){setTimeout((function(){n.status&&(n.trickle(),e())}),r.trickleSpeed)};return r.trickle&&e(),this},n.done=function(e){return e||n.status?n.inc(.3+.5*Math.random()).set(1):this},n.inc=function(e){var t=n.status;return t?("number"!=typeof e&&(e=(1-t)*a(Math.random()*t,.1,.95)),t=a(t+e,0,.994),n.set(t)):n.start()},n.trickle=function(){return n.inc(Math.random()*r.trickleRate)},e=0,t=0,n.promise=function(r){return r&&"resolved"!==r.state()?(0===t&&n.start(),e++,t++,r.always((function(){0==--t?(e=0,n.done()):n.set((e-t)/e)})),this):this},n.render=function(e){if(n.isRendered())return document.getElementById("nprogress");u(document.documentElement,"nprogress-busy");var t=document.createElement("div");t.id="nprogress",t.innerHTML=r.template;var a,i=t.querySelector(r.barSelector),l=e?"-100":o(n.status||0),c=document.querySelector(r.parent);return s(i,{transition:"all 0 linear",transform:"translate3d("+l+"%,0,0)"}),r.showSpinner||(a=t.querySelector(r.spinnerSelector))&&f(a),c!=document.body&&u(c,"nprogress-custom-parent"),c.appendChild(t),t},n.remove=function(){d(document.documentElement,"nprogress-busy"),d(document.querySelector(r.parent),"nprogress-custom-parent");var e=document.getElementById("nprogress");e&&f(e)},n.isRendered=function(){return!!document.getElementById("nprogress")},n.getPositioningCSS=function(){var e=document.body.style,t="WebkitTransform"in e?"Webkit":"MozTransform"in e?"Moz":"msTransform"in e?"ms":"OTransform"in e?"O":"";return t+"Perspective"in e?"translate3d":t+"Transform"in e?"translate":"margin"};var l=function(){var e=[];function t(){var n=e.shift();n&&n(t)}return function(n){e.push(n),1==e.length&&t()}}(),s=function(){var e=["Webkit","O","Moz","ms"],t={};function n(e){return e.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,(function(e,t){return t.toUpperCase()}))}function r(t){var n=document.body.style;if(t in n)return t;for(var r,a=e.length,o=t.charAt(0).toUpperCase()+t.slice(1);a--;)if((r=e[a]+o)in n)return r;return t}function a(e){return e=n(e),t[e]||(t[e]=r(e))}function o(e,t,n){t=a(t),e.style[t]=n}return function(e,t){var n,r,a=arguments;if(2==a.length)for(n in t)void 0!==(r=t[n])&&t.hasOwnProperty(n)&&o(e,n,r);else o(e,a[1],a[2])}}();function c(e,t){return("string"==typeof e?e:p(e)).indexOf(" "+t+" ")>=0}function u(e,t){var n=p(e),r=n+t;c(n,t)||(e.className=r.substring(1))}function d(e,t){var n,r=p(e);c(e,t)&&(n=r.replace(" "+t+" "," "),e.className=n.substring(1,n.length-1))}function p(e){return(" "+(e.className||"")+" ").replace(/\s+/gi," ")}function f(e){e&&e.parentNode&&e.parentNode.removeChild(e)}return n},void 0===(a="function"==typeof r?r.call(t,n,t,e):r)||(e.exports=a)},7418:e=>{"use strict";var t=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(a){return!1}}()?Object.assign:function(e,a){for(var o,i,l=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(e),s=1;s{var r=n(5826);e.exports=f,e.exports.parse=o,e.exports.compile=function(e,t){return l(o(e,t),t)},e.exports.tokensToFunction=l,e.exports.tokensToRegExp=p;var a=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function o(e,t){for(var n,r=[],o=0,i=0,l="",u=t&&t.delimiter||"/";null!=(n=a.exec(e));){var d=n[0],p=n[1],f=n.index;if(l+=e.slice(i,f),i=f+d.length,p)l+=p[1];else{var m=e[i],h=n[2],g=n[3],b=n[4],v=n[5],y=n[6],w=n[7];l&&(r.push(l),l="");var k=null!=h&&null!=m&&m!==h,S="+"===y||"*"===y,E="?"===y||"*"===y,x=n[2]||u,_=b||v;r.push({name:g||o++,prefix:h||"",delimiter:x,optional:E,repeat:S,partial:k,asterisk:!!w,pattern:_?c(_):w?".*":"[^"+s(x)+"]+?"})}}return i{"use strict";n.d(t,{Z:()=>o});var r=function(){var e=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,t=0,n={},r={util:{encode:function e(t){return t instanceof a?new a(t.type,e(t.content),t.alias):Array.isArray(t)?t.map(e):t.replace(/&/g,"&").replace(/=d.reach);E+=S.value.length,S=S.next){var x=S.value;if(t.length>e.length)return;if(!(x instanceof a)){var _,C=1;if(v){if(!(_=o(k,E,e,b))||_.index>=e.length)break;var T=_.index,A=_.index+_[0].length,L=E;for(L+=S.value.length;T>=L;)L+=(S=S.next).value.length;if(E=L-=S.value.length,S.value instanceof a)continue;for(var P=S;P!==t.tail&&(Ld.reach&&(d.reach=I);var D=S.prev;if(N&&(D=s(t,D,N),E+=N.length),c(t,D,C),S=s(t,D,new a(p,g?r.tokenize(R,g):R,y,R)),O&&s(t,S,O),C>1){var M={cause:p+","+m,reach:I};i(e,t,n,S.prev,E,M),d&&M.reach>d.reach&&(d.reach=M.reach)}}}}}}function l(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0}function s(e,t,n){var r=t.next,a={value:n,prev:t,next:r};return t.next=a,r.prev=a,e.length++,a}function c(e,t,n){for(var r=t.next,a=0;a"+o.content+""},r}(),a=r;r.default=r,a.languages.markup={comment:{pattern://,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern://i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]},a.languages.markup.tag.inside["attr-value"].inside.entity=a.languages.markup.entity,a.languages.markup.doctype.inside["internal-subset"].inside=a.languages.markup,a.hooks.add("wrap",(function(e){"entity"===e.type&&(e.attributes.title=e.content.replace(/&/,"&"))})),Object.defineProperty(a.languages.markup.tag,"addInlined",{value:function(e,t){var n={};n["language-"+t]={pattern:/(^$)/i,lookbehind:!0,inside:a.languages[t]},n.cdata=/^$/i;var r={"included-cdata":{pattern://i,inside:n}};r["language-"+t]={pattern:/[\s\S]+/,inside:a.languages[t]};var o={};o[e]={pattern:RegExp(/(<__[^>]*>)(?:))*\]\]>|(?!)/.source.replace(/__/g,(function(){return e})),"i"),lookbehind:!0,greedy:!0,inside:r},a.languages.insertBefore("markup","cdata",o)}}),Object.defineProperty(a.languages.markup.tag,"addAttribute",{value:function(e,t){a.languages.markup.tag.inside["special-attr"].push({pattern:RegExp(/(^|["'\s])/.source+"(?:"+e+")"+/\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,"i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[t,"language-"+t],inside:a.languages[t]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}}),a.languages.html=a.languages.markup,a.languages.mathml=a.languages.markup,a.languages.svg=a.languages.markup,a.languages.xml=a.languages.extend("markup",{}),a.languages.ssml=a.languages.xml,a.languages.atom=a.languages.xml,a.languages.rss=a.languages.xml,function(e){var t="\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b",n={pattern:/(^(["']?)\w+\2)[ \t]+\S.*/,lookbehind:!0,alias:"punctuation",inside:null},r={bash:n,environment:{pattern:RegExp("\\$"+t),alias:"constant"},variable:[{pattern:/\$?\(\([\s\S]+?\)\)/,greedy:!0,inside:{variable:[{pattern:/(^\$\(\([\s\S]+)\)\)/,lookbehind:!0},/^\$\(\(/],number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,operator:/--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,greedy:!0,inside:{variable:/^\$\(|^`|\)$|`$/}},{pattern:/\$\{[^}]+\}/,greedy:!0,inside:{operator:/:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,punctuation:/[\[\]]/,environment:{pattern:RegExp("(\\{)"+t),lookbehind:!0,alias:"constant"}}},/\$(?:\w+|[#?*!@$])/],entity:/\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/};e.languages.bash={shebang:{pattern:/^#!\s*\/.*/,alias:"important"},comment:{pattern:/(^|[^"{\\$])#.*/,lookbehind:!0},"function-name":[{pattern:/(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,lookbehind:!0,alias:"function"},{pattern:/\b[\w-]+(?=\s*\(\s*\)\s*\{)/,alias:"function"}],"for-or-select":{pattern:/(\b(?:for|select)\s+)\w+(?=\s+in\s)/,alias:"variable",lookbehind:!0},"assign-left":{pattern:/(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,inside:{environment:{pattern:RegExp("(^|[\\s;|&]|[<>]\\()"+t),lookbehind:!0,alias:"constant"}},alias:"variable",lookbehind:!0},string:[{pattern:/((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,lookbehind:!0,greedy:!0,inside:r},{pattern:/((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,lookbehind:!0,greedy:!0,inside:{bash:n}},{pattern:/(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,lookbehind:!0,greedy:!0,inside:r},{pattern:/(^|[^$\\])'[^']*'/,lookbehind:!0,greedy:!0},{pattern:/\$'(?:[^'\\]|\\[\s\S])*'/,greedy:!0,inside:{entity:r.entity}}],environment:{pattern:RegExp("\\$?"+t),alias:"constant"},variable:r.variable,function:{pattern:/(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,lookbehind:!0},keyword:{pattern:/(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,lookbehind:!0},builtin:{pattern:/(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,lookbehind:!0,alias:"class-name"},boolean:{pattern:/(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,lookbehind:!0},"file-descriptor":{pattern:/\B&\d\b/,alias:"important"},operator:{pattern:/\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,inside:{"file-descriptor":{pattern:/^\d/,alias:"important"}}},punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,number:{pattern:/(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,lookbehind:!0}},n.inside=e.languages.bash;for(var a=["comment","function-name","for-or-select","assign-left","string","environment","function","keyword","builtin","boolean","file-descriptor","operator","punctuation","number"],o=r.variable[1].inside,i=0;i]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/},a.languages.c=a.languages.extend("clike",{comment:{pattern:/\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},string:{pattern:/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},"class-name":{pattern:/(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,lookbehind:!0},keyword:/\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,function:/\b[a-z_]\w*(?=\s*\()/i,number:/(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/}),a.languages.insertBefore("c","string",{char:{pattern:/'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,greedy:!0}}),a.languages.insertBefore("c","string",{macro:{pattern:/(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,greedy:!0,alias:"property",inside:{string:[{pattern:/^(#\s*include\s*)<[^>]+>/,lookbehind:!0},a.languages.c.string],char:a.languages.c.char,comment:a.languages.c.comment,"macro-name":[{pattern:/(^#\s*define\s+)\w+\b(?!\()/i,lookbehind:!0},{pattern:/(^#\s*define\s+)\w+\b(?=\()/i,lookbehind:!0,alias:"function"}],directive:{pattern:/^(#\s*)[a-z]+/,lookbehind:!0,alias:"keyword"},"directive-hash":/^#/,punctuation:/##|\\(?=[\r\n])/,expression:{pattern:/\S[\s\S]*/,inside:a.languages.c}}}}),a.languages.insertBefore("c","function",{constant:/\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/}),delete a.languages.c.boolean,function(e){var t=/\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,n=/\b(?!)\w+(?:\s*\.\s*\w+)*\b/.source.replace(//g,(function(){return t.source}));e.languages.cpp=e.languages.extend("c",{"class-name":[{pattern:RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!)\w+/.source.replace(//g,(function(){return t.source}))),lookbehind:!0},/\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/],keyword:t,number:{pattern:/(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,greedy:!0},operator:/>>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,boolean:/\b(?:false|true)\b/}),e.languages.insertBefore("cpp","string",{module:{pattern:RegExp(/(\b(?:import|module)\s+)/.source+"(?:"+/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source+"|"+/(?:\s*:\s*)?|:\s*/.source.replace(//g,(function(){return n}))+")"),lookbehind:!0,greedy:!0,inside:{string:/^[<"][\s\S]+/,operator:/:/,punctuation:/\./}},"raw-string":{pattern:/R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,alias:"string",greedy:!0}}),e.languages.insertBefore("cpp","keyword",{"generic-function":{pattern:/\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,inside:{function:/^\w+/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:e.languages.cpp}}}}),e.languages.insertBefore("cpp","operator",{"double-colon":{pattern:/::/,alias:"punctuation"}}),e.languages.insertBefore("cpp","class-name",{"base-clause":{pattern:/(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,lookbehind:!0,greedy:!0,inside:e.languages.extend("cpp",{})}}),e.languages.insertBefore("inside","double-colon",{"class-name":/\b[a-z_]\w*\b(?!\s*::)/i},e.languages.cpp["base-clause"])}(a),function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:"selector"},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp("\\burl\\((?:"+t.source+"|"+/(?:[^\\\r\n()"']|\\[\s\S])*/.source+")\\)","i"),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp("^"+t.source+"$"),alias:"url"}}},selector:{pattern:RegExp("(^|[{}\\s])[^{}\\s](?:[^{};\"'\\s]|\\s+(?![\\s{])|"+t.source+")*(?=\\s*\\{)"),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var n=e.languages.markup;n&&(n.tag.addInlined("style","css"),n.tag.addAttribute("style","css"))}(a),function(e){var t,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;e.languages.css.selector={pattern:e.languages.css.selector.pattern,lookbehind:!0,inside:t={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-\w]+/,id:/#[-\w]+/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)(?:(?!\s)[-*\w\xA0-\uFFFF])*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)(?:(?!\s)[-\w\xA0-\uFFFF])+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)(?:(?!\s)[-\w\xA0-\uFFFF])+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],combinator:/>|\+|~|\|\|/,punctuation:/[(),]/}},e.languages.css.atrule.inside["selector-function-argument"].inside=t,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*/i,lookbehind:!0}});var r={pattern:/(\b\d+)(?:%|[a-z]+(?![\w-]))/,lookbehind:!0},a={pattern:/(^|[^\w.-])-?(?:\d+(?:\.\d+)?|\.\d+)/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#[\da-f]{3,8}\b/i,alias:"color"},color:[{pattern:/(^|[^\w-])(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)(?![\w-])/i,lookbehind:!0},{pattern:/\b(?:hsl|rgb)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:hsl|rgb)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,inside:{unit:r,number:a,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:r,number:a})}(a),a.languages.javascript=a.languages.extend("clike",{"class-name":[a.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(/(^|[^\w$])/.source+"(?:"+/NaN|Infinity/.source+"|"+/0[bB][01]+(?:_[01]+)*n?/.source+"|"+/0[oO][0-7]+(?:_[0-7]+)*n?/.source+"|"+/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source+"|"+/\d+(?:_\d+)*n/.source+"|"+/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source+")"+/(?![\w$])/.source),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),a.languages.javascript["class-name"][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,a.languages.insertBefore("javascript","keyword",{regex:{pattern:/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:a.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:a.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:a.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:a.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:a.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),a.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:a.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:"property"}}),a.languages.insertBefore("javascript","operator",{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:"property"}}),a.languages.markup&&(a.languages.markup.tag.addInlined("script","javascript"),a.languages.markup.tag.addAttribute(/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,"javascript")),a.languages.js=a.languages.javascript,function(e){var t=/#(?!\{).+/,n={pattern:/#\{[^}]+\}/,alias:"variable"};e.languages.coffeescript=e.languages.extend("javascript",{comment:t,string:[{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,inside:{interpolation:n}}],keyword:/\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,"class-member":{pattern:/@(?!\d)\w+/,alias:"variable"}}),e.languages.insertBefore("coffeescript","comment",{"multiline-comment":{pattern:/###[\s\S]+?###/,alias:"comment"},"block-regex":{pattern:/\/{3}[\s\S]*?\/{3}/,alias:"regex",inside:{comment:t,interpolation:n}}}),e.languages.insertBefore("coffeescript","string",{"inline-javascript":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,inside:{delimiter:{pattern:/^`|`$/,alias:"punctuation"},script:{pattern:/[\s\S]+/,alias:"language-javascript",inside:e.languages.javascript}}},"multiline-string":[{pattern:/'''[\s\S]*?'''/,greedy:!0,alias:"string"},{pattern:/"""[\s\S]*?"""/,greedy:!0,alias:"string",inside:{interpolation:n}}]}),e.languages.insertBefore("coffeescript","keyword",{property:/(?!\d)\w+(?=\s*:(?!:))/}),delete e.languages.coffeescript["template-string"],e.languages.coffee=e.languages.coffeescript}(a),function(e){var t=/[*&][^\s[\]{},]+/,n=/!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/,r="(?:"+n.source+"(?:[ \t]+"+t.source+")?|"+t.source+"(?:[ \t]+"+n.source+")?)",a=/(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-])(?:[ \t]*(?:(?![#:])|:))*/.source.replace(//g,(function(){return/[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source})),o=/"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;function i(e,t){t=(t||"").replace(/m/g,"")+"m";var n=/([:\-,[{]\s*(?:\s<>[ \t]+)?)(?:<>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source.replace(/<>/g,(function(){return r})).replace(/<>/g,(function(){return e}));return RegExp(n,t)}e.languages.yaml={scalar:{pattern:RegExp(/([\-:]\s*(?:\s<>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source.replace(/<>/g,(function(){return r}))),lookbehind:!0,alias:"string"},comment:/#.*/,key:{pattern:RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<>[ \t]+)?)<>(?=\s*:\s)/.source.replace(/<>/g,(function(){return r})).replace(/<>/g,(function(){return"(?:"+a+"|"+o+")"}))),lookbehind:!0,greedy:!0,alias:"atrule"},directive:{pattern:/(^[ \t]*)%.+/m,lookbehind:!0,alias:"important"},datetime:{pattern:i(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?))?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),lookbehind:!0,alias:"number"},boolean:{pattern:i(/false|true/.source,"i"),lookbehind:!0,alias:"important"},null:{pattern:i(/null|~/.source,"i"),lookbehind:!0,alias:"important"},string:{pattern:i(o),lookbehind:!0,greedy:!0},number:{pattern:i(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source,"i"),lookbehind:!0},tag:n,important:t,punctuation:/---|[:[\]{}\-,|>?]|\.\.\./},e.languages.yml=e.languages.yaml}(a),function(e){var t=/(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;function n(e){return e=e.replace(//g,(function(){return t})),RegExp(/((?:^|[^\\])(?:\\{2})*)/.source+"(?:"+e+")")}var r=/(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source,a=/\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g,(function(){return r})),o=/\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;e.languages.markdown=e.languages.extend("markup",{}),e.languages.insertBefore("markdown","prolog",{"front-matter-block":{pattern:/(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"front-matter":{pattern:/\S+(?:\s+\S+)*/,alias:["yaml","language-yaml"],inside:e.languages.yaml}}},blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:"punctuation"},table:{pattern:RegExp("^"+a+o+"(?:"+a+")*","m"),inside:{"table-data-rows":{pattern:RegExp("^("+a+o+")(?:"+a+")*$"),lookbehind:!0,inside:{"table-data":{pattern:RegExp(r),inside:e.languages.markdown},punctuation:/\|/}},"table-line":{pattern:RegExp("^("+a+")"+o+"$"),lookbehind:!0,inside:{punctuation:/\||:?-{3,}:?/}},"table-header-row":{pattern:RegExp("^"+a+"$"),inside:{"table-header":{pattern:RegExp(r),alias:"important",inside:e.languages.markdown},punctuation:/\|/}}}},code:[{pattern:/((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,lookbehind:!0,alias:"keyword"},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:"url"},bold:{pattern:n(/\b__(?:(?!_)|_(?:(?!_))+_)+__\b|\*\*(?:(?!\*)|\*(?:(?!\*))+\*)+\*\*/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[\s\S]+(?=..$)/,lookbehind:!0,inside:{}},punctuation:/\*\*|__/}},italic:{pattern:n(/\b_(?:(?!_)|__(?:(?!_))+__)+_\b|\*(?:(?!\*)|\*\*(?:(?!\*))+\*\*)+\*/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^.)[\s\S]+(?=.$)/,lookbehind:!0,inside:{}},punctuation:/[*_]/}},strike:{pattern:n(/(~~?)(?:(?!~))+\2/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^~~?)[\s\S]+(?=\1$)/,lookbehind:!0,inside:{}},punctuation:/~~?/}},"code-snippet":{pattern:/(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,lookbehind:!0,greedy:!0,alias:["code","keyword"]},url:{pattern:n(/!?\[(?:(?!\]))+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\]))+\])/.source),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ \t]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,lookbehind:!0}}}}),["url","bold","italic","strike"].forEach((function(t){["url","bold","italic","strike","code-snippet"].forEach((function(n){t!==n&&(e.languages.markdown[t].inside.content.inside[n]=e.languages.markdown[n])}))})),e.hooks.add("after-tokenize",(function(e){"markdown"!==e.language&&"md"!==e.language||function e(t){if(t&&"string"!=typeof t)for(var n=0,r=t.length;n",quot:'"'},s=String.fromCodePoint||String.fromCharCode;e.languages.md=e.languages.markdown}(a),a.languages.graphql={comment:/#.*/,description:{pattern:/(?:"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*")(?=\s*[a-z_])/i,greedy:!0,alias:"string",inside:{"language-markdown":{pattern:/(^"(?:"")?)(?!\1)[\s\S]+(?=\1$)/,lookbehind:!0,inside:a.languages.markdown}}},string:{pattern:/"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*"/,greedy:!0},number:/(?:\B-|\b)\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,boolean:/\b(?:false|true)\b/,variable:/\$[a-z_]\w*/i,directive:{pattern:/@[a-z_]\w*/i,alias:"function"},"attr-name":{pattern:/\b[a-z_]\w*(?=\s*(?:\((?:[^()"]|"(?:\\.|[^\\"\r\n])*")*\))?:)/i,greedy:!0},"atom-input":{pattern:/\b[A-Z]\w*Input\b/,alias:"class-name"},scalar:/\b(?:Boolean|Float|ID|Int|String)\b/,constant:/\b[A-Z][A-Z_\d]*\b/,"class-name":{pattern:/(\b(?:enum|implements|interface|on|scalar|type|union)\s+|&\s*|:\s*|\[)[A-Z_]\w*/,lookbehind:!0},fragment:{pattern:/(\bfragment\s+|\.{3}\s*(?!on\b))[a-zA-Z_]\w*/,lookbehind:!0,alias:"function"},"definition-mutation":{pattern:/(\bmutation\s+)[a-zA-Z_]\w*/,lookbehind:!0,alias:"function"},"definition-query":{pattern:/(\bquery\s+)[a-zA-Z_]\w*/,lookbehind:!0,alias:"function"},keyword:/\b(?:directive|enum|extend|fragment|implements|input|interface|mutation|on|query|repeatable|scalar|schema|subscription|type|union)\b/,operator:/[!=|&]|\.{3}/,"property-query":/\w+(?=\s*\()/,object:/\w+(?=\s*\{)/,punctuation:/[!(){}\[\]:=,]/,property:/\w+/},a.hooks.add("after-tokenize",(function(e){if("graphql"===e.language)for(var t=e.tokens.filter((function(e){return"string"!=typeof e&&"comment"!==e.type&&"scalar"!==e.type})),n=0;n0)){var l=p(/^\{$/,/^\}$/);if(-1===l)continue;for(var s=n;s=0&&f(c,"variable-input")}}}}function u(e){return t[n+e]}function d(e,t){t=t||0;for(var n=0;n?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,punctuation:/[;[\]()`,.]/},function(e){var t=e.languages.javascript["template-string"],n=t.pattern.source,r=t.inside.interpolation,a=r.inside["interpolation-punctuation"],o=r.pattern.source;function i(t,r){if(e.languages[t])return{pattern:RegExp("((?:"+r+")\\s*)"+n),lookbehind:!0,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},"embedded-code":{pattern:/[\s\S]+/,alias:t}}}}function l(e,t){return"___"+t.toUpperCase()+"_"+e+"___"}function s(t,n,r){var a={code:t,grammar:n,language:r};return e.hooks.run("before-tokenize",a),a.tokens=e.tokenize(a.code,a.grammar),e.hooks.run("after-tokenize",a),a.tokens}function c(t){var n={};n["interpolation-punctuation"]=a;var o=e.tokenize(t,n);if(3===o.length){var i=[1,1];i.push.apply(i,s(o[1],e.languages.javascript,"javascript")),o.splice.apply(o,i)}return new e.Token("interpolation",o,r.alias,t)}function u(t,n,r){var a=e.tokenize(t,{interpolation:{pattern:RegExp(o),lookbehind:!0}}),i=0,u={},d=s(a.map((function(e){if("string"==typeof e)return e;for(var n,a=e.content;-1!==t.indexOf(n=l(i++,r)););return u[n]=a,n})).join(""),n,r),p=Object.keys(u);return i=0,function e(t){for(var n=0;n=p.length)return;var r=t[n];if("string"==typeof r||"string"==typeof r.content){var a=p[i],o="string"==typeof r?r:r.content,l=o.indexOf(a);if(-1!==l){++i;var s=o.substring(0,l),d=c(u[a]),f=o.substring(l+a.length),m=[];if(s&&m.push(s),m.push(d),f){var h=[f];e(h),m.push.apply(m,h)}"string"==typeof r?(t.splice.apply(t,[n,1].concat(m)),n+=m.length-1):r.content=m}}else{var g=r.content;Array.isArray(g)?e(g):e([g])}}}(d),new e.Token(r,d,"language-"+r,t)}e.languages.javascript["template-string"]=[i("css",/\b(?:styled(?:\([^)]*\))?(?:\s*\.\s*\w+(?:\([^)]*\))*)*|css(?:\s*\.\s*(?:global|resolve))?|createGlobalStyle|keyframes)/.source),i("html",/\bhtml|\.\s*(?:inner|outer)HTML\s*\+?=/.source),i("svg",/\bsvg/.source),i("markdown",/\b(?:markdown|md)/.source),i("graphql",/\b(?:gql|graphql(?:\s*\.\s*experimental)?)/.source),i("sql",/\bsql/.source),t].filter(Boolean);var d={javascript:!0,js:!0,typescript:!0,ts:!0,jsx:!0,tsx:!0};function p(e){return"string"==typeof e?e:Array.isArray(e)?e.map(p).join(""):p(e.content)}e.hooks.add("after-tokenize",(function(t){t.language in d&&function t(n){for(var r=0,a=n.length;r]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),e.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete e.languages.typescript.parameter,delete e.languages.typescript["literal-property"];var t=e.languages.extend("typescript",{});delete t["class-name"],e.languages.typescript["class-name"].inside=t,e.languages.insertBefore("typescript","function",{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:"operator"},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:t}}}}),e.languages.ts=e.languages.typescript}(a),function(e){function t(e,t){return RegExp(e.replace(//g,(function(){return/(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/.source})),t)}e.languages.insertBefore("javascript","function-variable",{"method-variable":{pattern:RegExp("(\\.\\s*)"+e.languages.javascript["function-variable"].pattern.source),lookbehind:!0,alias:["function-variable","method","function","property-access"]}}),e.languages.insertBefore("javascript","function",{method:{pattern:RegExp("(\\.\\s*)"+e.languages.javascript.function.source),lookbehind:!0,alias:["function","property-access"]}}),e.languages.insertBefore("javascript","constant",{"known-class-name":[{pattern:/\b(?:(?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)?Array|ArrayBuffer|BigInt|Boolean|DataView|Date|Error|Function|Intl|JSON|(?:Weak)?(?:Map|Set)|Math|Number|Object|Promise|Proxy|Reflect|RegExp|String|Symbol|WebAssembly)\b/,alias:"class-name"},{pattern:/\b(?:[A-Z]\w*)Error\b/,alias:"class-name"}]}),e.languages.insertBefore("javascript","keyword",{imports:{pattern:t(/(\bimport\b\s*)(?:(?:\s*,\s*(?:\*\s*as\s+|\{[^{}]*\}))?|\*\s*as\s+|\{[^{}]*\})(?=\s*\bfrom\b)/.source),lookbehind:!0,inside:e.languages.javascript},exports:{pattern:t(/(\bexport\b\s*)(?:\*(?:\s*as\s+)?(?=\s*\bfrom\b)|\{[^{}]*\})/.source),lookbehind:!0,inside:e.languages.javascript}}),e.languages.javascript.keyword.unshift({pattern:/\b(?:as|default|export|from|import)\b/,alias:"module"},{pattern:/\b(?:await|break|catch|continue|do|else|finally|for|if|return|switch|throw|try|while|yield)\b/,alias:"control-flow"},{pattern:/\bnull\b/,alias:["null","nil"]},{pattern:/\bundefined\b/,alias:"nil"}),e.languages.insertBefore("javascript","operator",{spread:{pattern:/\.{3}/,alias:"operator"},arrow:{pattern:/=>/,alias:"operator"}}),e.languages.insertBefore("javascript","punctuation",{"property-access":{pattern:t(/(\.\s*)#?/.source),lookbehind:!0},"maybe-class-name":{pattern:/(^|[^$\w\xA0-\uFFFF])[A-Z][$\w\xA0-\uFFFF]+/,lookbehind:!0},dom:{pattern:/\b(?:document|(?:local|session)Storage|location|navigator|performance|window)\b/,alias:"variable"},console:{pattern:/\bconsole(?=\s*\.)/,alias:"class-name"}});for(var n=["function","function-variable","method","method-variable","property-access"],r=0;r*\.{3}(?:[^{}]|)*\})/.source;function o(e,t){return e=e.replace(//g,(function(){return n})).replace(//g,(function(){return r})).replace(//g,(function(){return a})),RegExp(e,t)}a=o(a).source,e.languages.jsx=e.languages.extend("markup",t),e.languages.jsx.tag.pattern=o(/<\/?(?:[\w.:-]+(?:+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|))?|))**\/?)?>/.source),e.languages.jsx.tag.inside.tag.pattern=/^<\/?[^\s>\/]*/,e.languages.jsx.tag.inside["attr-value"].pattern=/=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/,e.languages.jsx.tag.inside.tag.inside["class-name"]=/^[A-Z]\w*(?:\.[A-Z]\w*)*$/,e.languages.jsx.tag.inside.comment=t.comment,e.languages.insertBefore("inside","attr-name",{spread:{pattern:o(//.source),inside:e.languages.jsx}},e.languages.jsx.tag),e.languages.insertBefore("inside","special-attr",{script:{pattern:o(/=/.source),alias:"language-javascript",inside:{"script-punctuation":{pattern:/^=(?=\{)/,alias:"punctuation"},rest:e.languages.jsx}}},e.languages.jsx.tag);var i=function(e){return e?"string"==typeof e?e:"string"==typeof e.content?e.content:e.content.map(i).join(""):""},l=function(t){for(var n=[],r=0;r0&&n[n.length-1].tagName===i(a.content[0].content[1])&&n.pop():"/>"===a.content[a.content.length-1].content||n.push({tagName:i(a.content[0].content[1]),openedBraces:0}):n.length>0&&"punctuation"===a.type&&"{"===a.content?n[n.length-1].openedBraces++:n.length>0&&n[n.length-1].openedBraces>0&&"punctuation"===a.type&&"}"===a.content?n[n.length-1].openedBraces--:o=!0),(o||"string"==typeof a)&&n.length>0&&0===n[n.length-1].openedBraces){var s=i(a);r0&&("string"==typeof t[r-1]||"plain-text"===t[r-1].type)&&(s=i(t[r-1])+s,t.splice(r-1,1),r--),t[r]=new e.Token("plain-text",s,null,s)}a.content&&"string"!=typeof a.content&&l(a.content)}};e.hooks.add("after-tokenize",(function(e){"jsx"!==e.language&&"tsx"!==e.language||l(e.tokens)}))}(a),function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach((function(n){var r=t[n],a=[];/^\w+$/.test(n)||a.push(/\w+/.exec(n)[0]),"diff"===n&&a.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:a,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}})),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(a),a.languages.git={comment:/^#.*/m,deleted:/^[-\u2013].*/m,inserted:/^\+.*/m,string:/("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,command:{pattern:/^.*\$ git .*$/m,inside:{parameter:/\s--?\w+/}},coord:/^@@.*@@$/m,"commit-sha1":/^commit \w{40}$/m},a.languages.go=a.languages.extend("clike",{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,boolean:/\b(?:_|false|iota|nil|true)\b/,number:[/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i],operator:/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,builtin:/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/}),a.languages.insertBefore("go","string",{char:{pattern:/'(?:\\.|[^'\\\r\n]){0,10}'/,greedy:!0}}),delete a.languages.go["class-name"],function(e){function t(e,t){return"___"+e.toUpperCase()+t+"___"}Object.defineProperties(e.languages["markup-templating"]={},{buildPlaceholders:{value:function(n,r,a,o){if(n.language===r){var i=n.tokenStack=[];n.code=n.code.replace(a,(function(e){if("function"==typeof o&&!o(e))return e;for(var a,l=i.length;-1!==n.code.indexOf(a=t(r,l));)++l;return i[l]=e,a})),n.grammar=e.languages.markup}}},tokenizePlaceholders:{value:function(n,r){if(n.language===r&&n.tokenStack){n.grammar=e.languages[r];var a=0,o=Object.keys(n.tokenStack);!function i(l){for(var s=0;s=o.length);s++){var c=l[s];if("string"==typeof c||c.content&&"string"==typeof c.content){var u=o[a],d=n.tokenStack[u],p="string"==typeof c?c:c.content,f=t(r,u),m=p.indexOf(f);if(m>-1){++a;var h=p.substring(0,m),g=new e.Token(r,e.tokenize(d,n.grammar),"language-"+r,d),b=p.substring(m+f.length),v=[];h&&v.push.apply(v,i([h])),v.push(g),b&&v.push.apply(v,i([b])),"string"==typeof c?l.splice.apply(l,[s,1].concat(v)):c.content=v}}else c.content&&i(c.content)}return l}(n.tokens)}}}})}(a),function(e){e.languages.handlebars={comment:/\{\{![\s\S]*?\}\}/,delimiter:{pattern:/^\{\{\{?|\}\}\}?$/,alias:"punctuation"},string:/(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][+-]?\d+)?/,boolean:/\b(?:false|true)\b/,block:{pattern:/^(\s*(?:~\s*)?)[#\/]\S+?(?=\s*(?:~\s*)?$|\s)/,lookbehind:!0,alias:"keyword"},brackets:{pattern:/\[[^\]]+\]/,inside:{punctuation:/\[|\]/,variable:/[\s\S]+/}},punctuation:/[!"#%&':()*+,.\/;<=>@\[\\\]^`{|}~]/,variable:/[^!"#%&'()*+,\/;<=>@\[\\\]^`{|}~\s]+/},e.hooks.add("before-tokenize",(function(t){e.languages["markup-templating"].buildPlaceholders(t,"handlebars",/\{\{\{[\s\S]+?\}\}\}|\{\{[\s\S]+?\}\}/g)})),e.hooks.add("after-tokenize",(function(t){e.languages["markup-templating"].tokenizePlaceholders(t,"handlebars")})),e.languages.hbs=e.languages.handlebars}(a),a.languages.json={property:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,lookbehind:!0,greedy:!0},comment:{pattern:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},number:/-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:"keyword"}},a.languages.webmanifest=a.languages.json,a.languages.less=a.languages.extend("css",{comment:[/\/\*[\s\S]*?\*\//,{pattern:/(^|[^\\])\/\/.*/,lookbehind:!0}],atrule:{pattern:/@[\w-](?:\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};\s]|\s+(?!\s))*?(?=\s*\{)/,inside:{punctuation:/[:()]/}},selector:{pattern:/(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};@\s]|\s+(?!\s))*?(?=\s*\{)/,inside:{variable:/@+[\w-]+/}},property:/(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/,operator:/[+\-*\/]/}),a.languages.insertBefore("less","property",{variable:[{pattern:/@[\w-]+\s*:/,inside:{punctuation:/:/}},/@@?[\w-]+/],"mixin-usage":{pattern:/([{;]\s*)[.#](?!\d)[\w-].*?(?=[(;])/,lookbehind:!0,alias:"function"}}),a.languages.makefile={comment:{pattern:/(^|[^\\])#(?:\\(?:\r\n|[\s\S])|[^\\\r\n])*/,lookbehind:!0},string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"builtin-target":{pattern:/\.[A-Z][^:#=\s]+(?=\s*:(?!=))/,alias:"builtin"},target:{pattern:/^(?:[^:=\s]|[ \t]+(?![\s:]))+(?=\s*:(?!=))/m,alias:"symbol",inside:{variable:/\$+(?:(?!\$)[^(){}:#=\s]+|(?=[({]))/}},variable:/\$+(?:(?!\$)[^(){}:#=\s]+|\([@*%<^+?][DF]\)|(?=[({]))/,keyword:/-include\b|\b(?:define|else|endef|endif|export|ifn?def|ifn?eq|include|override|private|sinclude|undefine|unexport|vpath)\b/,function:{pattern:/(\()(?:abspath|addsuffix|and|basename|call|dir|error|eval|file|filter(?:-out)?|findstring|firstword|flavor|foreach|guile|if|info|join|lastword|load|notdir|or|origin|patsubst|realpath|shell|sort|strip|subst|suffix|value|warning|wildcard|word(?:list|s)?)(?=[ \t])/,lookbehind:!0},operator:/(?:::|[?:+!])?=|[|@]/,punctuation:/[:;(){}]/},a.languages.objectivec=a.languages.extend("c",{string:{pattern:/@?"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},keyword:/\b(?:asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|in|inline|int|long|register|return|self|short|signed|sizeof|static|struct|super|switch|typedef|typeof|union|unsigned|void|volatile|while)\b|(?:@interface|@end|@implementation|@protocol|@class|@public|@protected|@private|@property|@try|@catch|@finally|@throw|@synthesize|@dynamic|@selector)\b/,operator:/-[->]?|\+\+?|!=?|<>?=?|==?|&&?|\|\|?|[~^%?*\/@]/}),delete a.languages.objectivec["class-name"],a.languages.objc=a.languages.objectivec,a.languages.ocaml={comment:{pattern:/\(\*[\s\S]*?\*\)/,greedy:!0},char:{pattern:/'(?:[^\\\r\n']|\\(?:.|[ox]?[0-9a-f]{1,3}))'/i,greedy:!0},string:[{pattern:/"(?:\\(?:[\s\S]|\r\n)|[^\\\r\n"])*"/,greedy:!0},{pattern:/\{([a-z_]*)\|[\s\S]*?\|\1\}/,greedy:!0}],number:[/\b(?:0b[01][01_]*|0o[0-7][0-7_]*)\b/i,/\b0x[a-f0-9][a-f0-9_]*(?:\.[a-f0-9_]*)?(?:p[+-]?\d[\d_]*)?(?!\w)/i,/\b\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?\d[\d_]*)?(?!\w)/i],directive:{pattern:/\B#\w+/,alias:"property"},label:{pattern:/\B~\w+/,alias:"property"},"type-variable":{pattern:/\B'\w+/,alias:"function"},variant:{pattern:/`\w+/,alias:"symbol"},keyword:/\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|nonrec|object|of|open|private|rec|sig|struct|then|to|try|type|val|value|virtual|when|where|while|with)\b/,boolean:/\b(?:false|true)\b/,"operator-like-punctuation":{pattern:/\[[<>|]|[>|]\]|\{<|>\}/,alias:"punctuation"},operator:/\.[.~]|:[=>]|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,punctuation:/;;|::|[(){}\[\].,:;#]|\b_\b/},a.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0,greedy:!0},"string-interpolation":{pattern:/(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,lookbehind:!0,inside:{"format-spec":{pattern:/(:)[^:(){}]+(?=\}$)/,lookbehind:!0},"conversion-option":{pattern:/![sra](?=[:}]$)/,alias:"punctuation"},rest:null}},string:/[\s\S]+/}},"triple-quoted-string":{pattern:/(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,greedy:!0,alias:"string"},string:{pattern:/(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,greedy:!0},function:{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)\w+/i,lookbehind:!0},decorator:{pattern:/(^[\t ]*)@\w+(?:\.\w+)*/m,lookbehind:!0,alias:["annotation","punctuation"],inside:{punctuation:/\./}},keyword:/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,builtin:/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,boolean:/\b(?:False|None|True)\b/,number:/\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,operator:/[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,punctuation:/[{}[\];(),.:]/},a.languages.python["string-interpolation"].inside.interpolation.inside.rest=a.languages.python,a.languages.py=a.languages.python,a.languages.reason=a.languages.extend("clike",{string:{pattern:/"(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/,greedy:!0},"class-name":/\b[A-Z]\w*/,keyword:/\b(?:and|as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|method|module|mutable|new|nonrec|object|of|open|or|private|rec|sig|struct|switch|then|to|try|type|val|virtual|when|while|with)\b/,operator:/\.{3}|:[:=]|\|>|->|=(?:==?|>)?|<=?|>=?|[|^?'#!~`]|[+\-*\/]\.?|\b(?:asr|land|lor|lsl|lsr|lxor|mod)\b/}),a.languages.insertBefore("reason","class-name",{char:{pattern:/'(?:\\x[\da-f]{2}|\\o[0-3][0-7][0-7]|\\\d{3}|\\.|[^'\\\r\n])'/,greedy:!0},constructor:/\b[A-Z]\w*\b(?!\s*\.)/,label:{pattern:/\b[a-z]\w*(?=::)/,alias:"symbol"}}),delete a.languages.reason.function,function(e){e.languages.sass=e.languages.extend("css",{comment:{pattern:/^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t].+)*/m,lookbehind:!0,greedy:!0}}),e.languages.insertBefore("sass","atrule",{"atrule-line":{pattern:/^(?:[ \t]*)[@+=].+/m,greedy:!0,inside:{atrule:/(?:@[\w-]+|[+=])/}}}),delete e.languages.sass.atrule;var t=/\$[-\w]+|#\{\$[-\w]+\}/,n=[/[+*\/%]|[=!]=|<=?|>=?|\b(?:and|not|or)\b/,{pattern:/(\s)-(?=\s)/,lookbehind:!0}];e.languages.insertBefore("sass","property",{"variable-line":{pattern:/^[ \t]*\$.+/m,greedy:!0,inside:{punctuation:/:/,variable:t,operator:n}},"property-line":{pattern:/^[ \t]*(?:[^:\s]+ *:.*|:[^:\s].*)/m,greedy:!0,inside:{property:[/[^:\s]+(?=\s*:)/,{pattern:/(:)[^:\s]+/,lookbehind:!0}],punctuation:/:/,variable:t,operator:n,important:e.languages.sass.important}}}),delete e.languages.sass.property,delete e.languages.sass.important,e.languages.insertBefore("sass","punctuation",{selector:{pattern:/^([ \t]*)\S(?:,[^,\r\n]+|[^,\r\n]*)(?:,[^,\r\n]+)*(?:,(?:\r?\n|\r)\1[ \t]+\S(?:,[^,\r\n]+|[^,\r\n]*)(?:,[^,\r\n]+)*)*/m,lookbehind:!0,greedy:!0}})}(a),a.languages.scss=a.languages.extend("css",{comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},atrule:{pattern:/@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,inside:{rule:/@[\w-]+/}},url:/(?:[-a-z]+-)?url(?=\()/i,selector:{pattern:/(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,inside:{parent:{pattern:/&/,alias:"important"},placeholder:/%[-\w]+/,variable:/\$[-\w]+|#\{\$[-\w]+\}/}},property:{pattern:/(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,inside:{variable:/\$[-\w]+|#\{\$[-\w]+\}/}}}),a.languages.insertBefore("scss","atrule",{keyword:[/@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,{pattern:/( )(?:from|through)(?= )/,lookbehind:!0}]}),a.languages.insertBefore("scss","important",{variable:/\$[-\w]+|#\{\$[-\w]+\}/}),a.languages.insertBefore("scss","function",{"module-modifier":{pattern:/\b(?:as|hide|show|with)\b/i,alias:"keyword"},placeholder:{pattern:/%[-\w]+/,alias:"selector"},statement:{pattern:/\B!(?:default|optional)\b/i,alias:"keyword"},boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:"keyword"},operator:{pattern:/(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,lookbehind:!0}}),a.languages.scss.atrule.inside.rest=a.languages.scss,function(e){var t={pattern:/(\b\d+)(?:%|[a-z]+)/,lookbehind:!0},n={pattern:/(^|[^\w.-])-?(?:\d+(?:\.\d+)?|\.\d+)/,lookbehind:!0},r={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},url:{pattern:/\burl\((["']?).*?\1\)/i,greedy:!0},string:{pattern:/("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,greedy:!0},interpolation:null,func:null,important:/\B!(?:important|optional)\b/i,keyword:{pattern:/(^|\s+)(?:(?:else|for|if|return|unless)(?=\s|$)|@[\w-]+)/,lookbehind:!0},hexcode:/#[\da-f]{3,6}/i,color:[/\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i,{pattern:/\b(?:hsl|rgb)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:hsl|rgb)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,inside:{unit:t,number:n,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:t,boolean:/\b(?:false|true)\b/,operator:[/~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.{2,3}|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/],number:n,punctuation:/[{}()\[\];:,]/};r.interpolation={pattern:/\{[^\r\n}:]+\}/,alias:"variable",inside:{delimiter:{pattern:/^\{|\}$/,alias:"punctuation"},rest:r}},r.func={pattern:/[\w-]+\([^)]*\).*/,inside:{function:/^[^(]+/,rest:r}},e.languages.stylus={"atrule-declaration":{pattern:/(^[ \t]*)@.+/m,lookbehind:!0,inside:{atrule:/^@[\w-]+/,rest:r}},"variable-declaration":{pattern:/(^[ \t]*)[\w$-]+\s*.?=[ \t]*(?:\{[^{}]*\}|\S.*|$)/m,lookbehind:!0,inside:{variable:/^\S+/,rest:r}},statement:{pattern:/(^[ \t]*)(?:else|for|if|return|unless)[ \t].+/m,lookbehind:!0,inside:{keyword:/^\S+/,rest:r}},"property-declaration":{pattern:/((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)(?!\s)[^{\r\n]*(?:;|[^{\r\n,]$(?!(?:\r?\n|\r)(?:\{|\2[ \t])))/m,lookbehind:!0,inside:{property:{pattern:/^[^\s:]+/,inside:{interpolation:r.interpolation}},rest:r}},selector:{pattern:/(^[ \t]*)(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\)|(?![\w-]))|\{[^}\r\n]+\})+)(?:(?:\r?\n|\r)(?:\1(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\)|(?![\w-]))|\{[^}\r\n]+\})+)))*(?:,$|\{|(?=(?:\r?\n|\r)(?:\{|\1[ \t])))/m,lookbehind:!0,inside:{interpolation:r.interpolation,comment:r.comment,punctuation:/[{},]/}},func:r.func,string:r.string,comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0,greedy:!0},interpolation:r.interpolation,punctuation:/[{}()\[\];:.]/}}(a),function(e){var t=e.util.clone(e.languages.typescript);e.languages.tsx=e.languages.extend("jsx",t),delete e.languages.tsx.parameter,delete e.languages.tsx["literal-property"];var n=e.languages.tsx.tag;n.pattern=RegExp(/(^|[^\w$]|(?=<\/))/.source+"(?:"+n.pattern.source+")",n.pattern.flags),n.lookbehind=!0}(a),a.languages.wasm={comment:[/\(;[\s\S]*?;\)/,{pattern:/;;.*/,greedy:!0}],string:{pattern:/"(?:\\[\s\S]|[^"\\])*"/,greedy:!0},keyword:[{pattern:/\b(?:align|offset)=/,inside:{operator:/=/}},{pattern:/\b(?:(?:f32|f64|i32|i64)(?:\.(?:abs|add|and|ceil|clz|const|convert_[su]\/i(?:32|64)|copysign|ctz|demote\/f64|div(?:_[su])?|eqz?|extend_[su]\/i32|floor|ge(?:_[su])?|gt(?:_[su])?|le(?:_[su])?|load(?:(?:8|16|32)_[su])?|lt(?:_[su])?|max|min|mul|neg?|nearest|or|popcnt|promote\/f32|reinterpret\/[fi](?:32|64)|rem_[su]|rot[lr]|shl|shr_[su]|sqrt|store(?:8|16|32)?|sub|trunc(?:_[su]\/f(?:32|64))?|wrap\/i64|xor))?|memory\.(?:grow|size))\b/,inside:{punctuation:/\./}},/\b(?:anyfunc|block|br(?:_if|_table)?|call(?:_indirect)?|data|drop|elem|else|end|export|func|get_(?:global|local)|global|if|import|local|loop|memory|module|mut|nop|offset|param|result|return|select|set_(?:global|local)|start|table|tee_local|then|type|unreachable)\b/],variable:/\$[\w!#$%&'*+\-./:<=>?@\\^`|~]+/,number:/[+-]?\b(?:\d(?:_?\d)*(?:\.\d(?:_?\d)*)?(?:[eE][+-]?\d(?:_?\d)*)?|0x[\da-fA-F](?:_?[\da-fA-F])*(?:\.[\da-fA-F](?:_?[\da-fA-D])*)?(?:[pP][+-]?\d(?:_?\d)*)?)\b|\binf\b|\bnan(?::0x[\da-fA-F](?:_?[\da-fA-D])*)?\b/,punctuation:/[()]/};const o=a},9901:e=>{e.exports&&(e.exports={core:{meta:{path:"components/prism-core.js",option:"mandatory"},core:"Core"},themes:{meta:{path:"themes/{id}.css",link:"index.html?theme={id}",exclusive:!0},prism:{title:"Default",option:"default"},"prism-dark":"Dark","prism-funky":"Funky","prism-okaidia":{title:"Okaidia",owner:"ocodia"},"prism-twilight":{title:"Twilight",owner:"remybach"},"prism-coy":{title:"Coy",owner:"tshedor"},"prism-solarizedlight":{title:"Solarized Light",owner:"hectormatos2011 "},"prism-tomorrow":{title:"Tomorrow Night",owner:"Rosey"}},languages:{meta:{path:"components/prism-{id}",noCSS:!0,examplesPath:"examples/prism-{id}",addCheckAll:!0},markup:{title:"Markup",alias:["html","xml","svg","mathml","ssml","atom","rss"],aliasTitles:{html:"HTML",xml:"XML",svg:"SVG",mathml:"MathML",ssml:"SSML",atom:"Atom",rss:"RSS"},option:"default"},css:{title:"CSS",option:"default",modify:"markup"},clike:{title:"C-like",option:"default"},javascript:{title:"JavaScript",require:"clike",modify:"markup",optional:"regex",alias:"js",option:"default"},abap:{title:"ABAP",owner:"dellagustin"},abnf:{title:"ABNF",owner:"RunDevelopment"},actionscript:{title:"ActionScript",require:"javascript",modify:"markup",owner:"Golmote"},ada:{title:"Ada",owner:"Lucretia"},agda:{title:"Agda",owner:"xy-ren"},al:{title:"AL",owner:"RunDevelopment"},antlr4:{title:"ANTLR4",alias:"g4",owner:"RunDevelopment"},apacheconf:{title:"Apache Configuration",owner:"GuiTeK"},apex:{title:"Apex",require:["clike","sql"],owner:"RunDevelopment"},apl:{title:"APL",owner:"ngn"},applescript:{title:"AppleScript",owner:"Golmote"},aql:{title:"AQL",owner:"RunDevelopment"},arduino:{title:"Arduino",require:"cpp",alias:"ino",owner:"dkern"},arff:{title:"ARFF",owner:"Golmote"},armasm:{title:"ARM Assembly",alias:"arm-asm",owner:"RunDevelopment"},arturo:{title:"Arturo",alias:"art",optional:["bash","css","javascript","markup","markdown","sql"],owner:"drkameleon"},asciidoc:{alias:"adoc",title:"AsciiDoc",owner:"Golmote"},aspnet:{title:"ASP.NET (C#)",require:["markup","csharp"],owner:"nauzilus"},asm6502:{title:"6502 Assembly",owner:"kzurawel"},asmatmel:{title:"Atmel AVR Assembly",owner:"cerkit"},autohotkey:{title:"AutoHotkey",owner:"aviaryan"},autoit:{title:"AutoIt",owner:"Golmote"},avisynth:{title:"AviSynth",alias:"avs",owner:"Zinfidel"},"avro-idl":{title:"Avro IDL",alias:"avdl",owner:"RunDevelopment"},awk:{title:"AWK",alias:"gawk",aliasTitles:{gawk:"GAWK"},owner:"RunDevelopment"},bash:{title:"Bash",alias:["sh","shell"],aliasTitles:{sh:"Shell",shell:"Shell"},owner:"zeitgeist87"},basic:{title:"BASIC",owner:"Golmote"},batch:{title:"Batch",owner:"Golmote"},bbcode:{title:"BBcode",alias:"shortcode",aliasTitles:{shortcode:"Shortcode"},owner:"RunDevelopment"},bbj:{title:"BBj",owner:"hyyan"},bicep:{title:"Bicep",owner:"johnnyreilly"},birb:{title:"Birb",require:"clike",owner:"Calamity210"},bison:{title:"Bison",require:"c",owner:"Golmote"},bnf:{title:"BNF",alias:"rbnf",aliasTitles:{rbnf:"RBNF"},owner:"RunDevelopment"},bqn:{title:"BQN",owner:"yewscion"},brainfuck:{title:"Brainfuck",owner:"Golmote"},brightscript:{title:"BrightScript",owner:"RunDevelopment"},bro:{title:"Bro",owner:"wayward710"},bsl:{title:"BSL (1C:Enterprise)",alias:"oscript",aliasTitles:{oscript:"OneScript"},owner:"Diversus23"},c:{title:"C",require:"clike",owner:"zeitgeist87"},csharp:{title:"C#",require:"clike",alias:["cs","dotnet"],owner:"mvalipour"},cpp:{title:"C++",require:"c",owner:"zeitgeist87"},cfscript:{title:"CFScript",require:"clike",alias:"cfc",owner:"mjclemente"},chaiscript:{title:"ChaiScript",require:["clike","cpp"],owner:"RunDevelopment"},cil:{title:"CIL",owner:"sbrl"},cilkc:{title:"Cilk/C",require:"c",alias:"cilk-c",owner:"OpenCilk"},cilkcpp:{title:"Cilk/C++",require:"cpp",alias:["cilk-cpp","cilk"],owner:"OpenCilk"},clojure:{title:"Clojure",owner:"troglotit"},cmake:{title:"CMake",owner:"mjrogozinski"},cobol:{title:"COBOL",owner:"RunDevelopment"},coffeescript:{title:"CoffeeScript",require:"javascript",alias:"coffee",owner:"R-osey"},concurnas:{title:"Concurnas",alias:"conc",owner:"jasontatton"},csp:{title:"Content-Security-Policy",owner:"ScottHelme"},cooklang:{title:"Cooklang",owner:"ahue"},coq:{title:"Coq",owner:"RunDevelopment"},crystal:{title:"Crystal",require:"ruby",owner:"MakeNowJust"},"css-extras":{title:"CSS Extras",require:"css",modify:"css",owner:"milesj"},csv:{title:"CSV",owner:"RunDevelopment"},cue:{title:"CUE",owner:"RunDevelopment"},cypher:{title:"Cypher",owner:"RunDevelopment"},d:{title:"D",require:"clike",owner:"Golmote"},dart:{title:"Dart",require:"clike",owner:"Golmote"},dataweave:{title:"DataWeave",owner:"machaval"},dax:{title:"DAX",owner:"peterbud"},dhall:{title:"Dhall",owner:"RunDevelopment"},diff:{title:"Diff",owner:"uranusjr"},django:{title:"Django/Jinja2",require:"markup-templating",alias:"jinja2",owner:"romanvm"},"dns-zone-file":{title:"DNS zone file",owner:"RunDevelopment",alias:"dns-zone"},docker:{title:"Docker",alias:"dockerfile",owner:"JustinBeckwith"},dot:{title:"DOT (Graphviz)",alias:"gv",optional:"markup",owner:"RunDevelopment"},ebnf:{title:"EBNF",owner:"RunDevelopment"},editorconfig:{title:"EditorConfig",owner:"osipxd"},eiffel:{title:"Eiffel",owner:"Conaclos"},ejs:{title:"EJS",require:["javascript","markup-templating"],owner:"RunDevelopment",alias:"eta",aliasTitles:{eta:"Eta"}},elixir:{title:"Elixir",owner:"Golmote"},elm:{title:"Elm",owner:"zwilias"},etlua:{title:"Embedded Lua templating",require:["lua","markup-templating"],owner:"RunDevelopment"},erb:{title:"ERB",require:["ruby","markup-templating"],owner:"Golmote"},erlang:{title:"Erlang",owner:"Golmote"},"excel-formula":{title:"Excel Formula",alias:["xlsx","xls"],owner:"RunDevelopment"},fsharp:{title:"F#",require:"clike",owner:"simonreynolds7"},factor:{title:"Factor",owner:"catb0t"},false:{title:"False",owner:"edukisto"},"firestore-security-rules":{title:"Firestore security rules",require:"clike",owner:"RunDevelopment"},flow:{title:"Flow",require:"javascript",owner:"Golmote"},fortran:{title:"Fortran",owner:"Golmote"},ftl:{title:"FreeMarker Template Language",require:"markup-templating",owner:"RunDevelopment"},gml:{title:"GameMaker Language",alias:"gamemakerlanguage",require:"clike",owner:"LiarOnce"},gap:{title:"GAP (CAS)",owner:"RunDevelopment"},gcode:{title:"G-code",owner:"RunDevelopment"},gdscript:{title:"GDScript",owner:"RunDevelopment"},gedcom:{title:"GEDCOM",owner:"Golmote"},gettext:{title:"gettext",alias:"po",owner:"RunDevelopment"},gherkin:{title:"Gherkin",owner:"hason"},git:{title:"Git",owner:"lgiraudel"},glsl:{title:"GLSL",require:"c",owner:"Golmote"},gn:{title:"GN",alias:"gni",owner:"RunDevelopment"},"linker-script":{title:"GNU Linker Script",alias:"ld",owner:"RunDevelopment"},go:{title:"Go",require:"clike",owner:"arnehormann"},"go-module":{title:"Go module",alias:"go-mod",owner:"RunDevelopment"},gradle:{title:"Gradle",require:"clike",owner:"zeabdelkhalek-badido18"},graphql:{title:"GraphQL",optional:"markdown",owner:"Golmote"},groovy:{title:"Groovy",require:"clike",owner:"robfletcher"},haml:{title:"Haml",require:"ruby",optional:["css","css-extras","coffeescript","erb","javascript","less","markdown","scss","textile"],owner:"Golmote"},handlebars:{title:"Handlebars",require:"markup-templating",alias:["hbs","mustache"],aliasTitles:{mustache:"Mustache"},owner:"Golmote"},haskell:{title:"Haskell",alias:"hs",owner:"bholst"},haxe:{title:"Haxe",require:"clike",optional:"regex",owner:"Golmote"},hcl:{title:"HCL",owner:"outsideris"},hlsl:{title:"HLSL",require:"c",owner:"RunDevelopment"},hoon:{title:"Hoon",owner:"matildepark"},http:{title:"HTTP",optional:["csp","css","hpkp","hsts","javascript","json","markup","uri"],owner:"danielgtaylor"},hpkp:{title:"HTTP Public-Key-Pins",owner:"ScottHelme"},hsts:{title:"HTTP Strict-Transport-Security",owner:"ScottHelme"},ichigojam:{title:"IchigoJam",owner:"BlueCocoa"},icon:{title:"Icon",owner:"Golmote"},"icu-message-format":{title:"ICU Message Format",owner:"RunDevelopment"},idris:{title:"Idris",alias:"idr",owner:"KeenS",require:"haskell"},ignore:{title:".ignore",owner:"osipxd",alias:["gitignore","hgignore","npmignore"],aliasTitles:{gitignore:".gitignore",hgignore:".hgignore",npmignore:".npmignore"}},inform7:{title:"Inform 7",owner:"Golmote"},ini:{title:"Ini",owner:"aviaryan"},io:{title:"Io",owner:"AlesTsurko"},j:{title:"J",owner:"Golmote"},java:{title:"Java",require:"clike",owner:"sherblot"},javadoc:{title:"JavaDoc",require:["markup","java","javadoclike"],modify:"java",optional:"scala",owner:"RunDevelopment"},javadoclike:{title:"JavaDoc-like",modify:["java","javascript","php"],owner:"RunDevelopment"},javastacktrace:{title:"Java stack trace",owner:"RunDevelopment"},jexl:{title:"Jexl",owner:"czosel"},jolie:{title:"Jolie",require:"clike",owner:"thesave"},jq:{title:"JQ",owner:"RunDevelopment"},jsdoc:{title:"JSDoc",require:["javascript","javadoclike","typescript"],modify:"javascript",optional:["actionscript","coffeescript"],owner:"RunDevelopment"},"js-extras":{title:"JS Extras",require:"javascript",modify:"javascript",optional:["actionscript","coffeescript","flow","n4js","typescript"],owner:"RunDevelopment"},json:{title:"JSON",alias:"webmanifest",aliasTitles:{webmanifest:"Web App Manifest"},owner:"CupOfTea696"},json5:{title:"JSON5",require:"json",owner:"RunDevelopment"},jsonp:{title:"JSONP",require:"json",owner:"RunDevelopment"},jsstacktrace:{title:"JS stack trace",owner:"sbrl"},"js-templates":{title:"JS Templates",require:"javascript",modify:"javascript",optional:["css","css-extras","graphql","markdown","markup","sql"],owner:"RunDevelopment"},julia:{title:"Julia",owner:"cdagnino"},keepalived:{title:"Keepalived Configure",owner:"dev-itsheng"},keyman:{title:"Keyman",owner:"mcdurdin"},kotlin:{title:"Kotlin",alias:["kt","kts"],aliasTitles:{kts:"Kotlin Script"},require:"clike",owner:"Golmote"},kumir:{title:"KuMir (\u041a\u0443\u041c\u0438\u0440)",alias:"kum",owner:"edukisto"},kusto:{title:"Kusto",owner:"RunDevelopment"},latex:{title:"LaTeX",alias:["tex","context"],aliasTitles:{tex:"TeX",context:"ConTeXt"},owner:"japborst"},latte:{title:"Latte",require:["clike","markup-templating","php"],owner:"nette"},less:{title:"Less",require:"css",optional:"css-extras",owner:"Golmote"},lilypond:{title:"LilyPond",require:"scheme",alias:"ly",owner:"RunDevelopment"},liquid:{title:"Liquid",require:"markup-templating",owner:"cinhtau"},lisp:{title:"Lisp",alias:["emacs","elisp","emacs-lisp"],owner:"JuanCaicedo"},livescript:{title:"LiveScript",owner:"Golmote"},llvm:{title:"LLVM IR",owner:"porglezomp"},log:{title:"Log file",optional:"javastacktrace",owner:"RunDevelopment"},lolcode:{title:"LOLCODE",owner:"Golmote"},lua:{title:"Lua",owner:"Golmote"},magma:{title:"Magma (CAS)",owner:"RunDevelopment"},makefile:{title:"Makefile",owner:"Golmote"},markdown:{title:"Markdown",require:"markup",optional:"yaml",alias:"md",owner:"Golmote"},"markup-templating":{title:"Markup templating",require:"markup",owner:"Golmote"},mata:{title:"Mata",owner:"RunDevelopment"},matlab:{title:"MATLAB",owner:"Golmote"},maxscript:{title:"MAXScript",owner:"RunDevelopment"},mel:{title:"MEL",owner:"Golmote"},mermaid:{title:"Mermaid",owner:"RunDevelopment"},metafont:{title:"METAFONT",owner:"LaeriExNihilo"},mizar:{title:"Mizar",owner:"Golmote"},mongodb:{title:"MongoDB",owner:"airs0urce",require:"javascript"},monkey:{title:"Monkey",owner:"Golmote"},moonscript:{title:"MoonScript",alias:"moon",owner:"RunDevelopment"},n1ql:{title:"N1QL",owner:"TMWilds"},n4js:{title:"N4JS",require:"javascript",optional:"jsdoc",alias:"n4jsd",owner:"bsmith-n4"},"nand2tetris-hdl":{title:"Nand To Tetris HDL",owner:"stephanmax"},naniscript:{title:"Naninovel Script",owner:"Elringus",alias:"nani"},nasm:{title:"NASM",owner:"rbmj"},neon:{title:"NEON",owner:"nette"},nevod:{title:"Nevod",owner:"nezaboodka"},nginx:{title:"nginx",owner:"volado"},nim:{title:"Nim",owner:"Golmote"},nix:{title:"Nix",owner:"Golmote"},nsis:{title:"NSIS",owner:"idleberg"},objectivec:{title:"Objective-C",require:"c",alias:"objc",owner:"uranusjr"},ocaml:{title:"OCaml",owner:"Golmote"},odin:{title:"Odin",owner:"edukisto"},opencl:{title:"OpenCL",require:"c",modify:["c","cpp"],owner:"Milania1"},openqasm:{title:"OpenQasm",alias:"qasm",owner:"RunDevelopment"},oz:{title:"Oz",owner:"Golmote"},parigp:{title:"PARI/GP",owner:"Golmote"},parser:{title:"Parser",require:"markup",owner:"Golmote"},pascal:{title:"Pascal",alias:"objectpascal",aliasTitles:{objectpascal:"Object Pascal"},owner:"Golmote"},pascaligo:{title:"Pascaligo",owner:"DefinitelyNotAGoat"},psl:{title:"PATROL Scripting Language",owner:"bertysentry"},pcaxis:{title:"PC-Axis",alias:"px",owner:"RunDevelopment"},peoplecode:{title:"PeopleCode",alias:"pcode",owner:"RunDevelopment"},perl:{title:"Perl",owner:"Golmote"},php:{title:"PHP",require:"markup-templating",owner:"milesj"},phpdoc:{title:"PHPDoc",require:["php","javadoclike"],modify:"php",owner:"RunDevelopment"},"php-extras":{title:"PHP Extras",require:"php",modify:"php",owner:"milesj"},"plant-uml":{title:"PlantUML",alias:"plantuml",owner:"RunDevelopment"},plsql:{title:"PL/SQL",require:"sql",owner:"Golmote"},powerquery:{title:"PowerQuery",alias:["pq","mscript"],owner:"peterbud"},powershell:{title:"PowerShell",owner:"nauzilus"},processing:{title:"Processing",require:"clike",owner:"Golmote"},prolog:{title:"Prolog",owner:"Golmote"},promql:{title:"PromQL",owner:"arendjr"},properties:{title:".properties",owner:"Golmote"},protobuf:{title:"Protocol Buffers",require:"clike",owner:"just-boris"},pug:{title:"Pug",require:["markup","javascript"],optional:["coffeescript","ejs","handlebars","less","livescript","markdown","scss","stylus","twig"],owner:"Golmote"},puppet:{title:"Puppet",owner:"Golmote"},pure:{title:"Pure",optional:["c","cpp","fortran"],owner:"Golmote"},purebasic:{title:"PureBasic",require:"clike",alias:"pbfasm",owner:"HeX0R101"},purescript:{title:"PureScript",require:"haskell",alias:"purs",owner:"sriharshachilakapati"},python:{title:"Python",alias:"py",owner:"multipetros"},qsharp:{title:"Q#",require:"clike",alias:"qs",owner:"fedonman"},q:{title:"Q (kdb+ database)",owner:"Golmote"},qml:{title:"QML",require:"javascript",owner:"RunDevelopment"},qore:{title:"Qore",require:"clike",owner:"temnroegg"},r:{title:"R",owner:"Golmote"},racket:{title:"Racket",require:"scheme",alias:"rkt",owner:"RunDevelopment"},cshtml:{title:"Razor C#",alias:"razor",require:["markup","csharp"],optional:["css","css-extras","javascript","js-extras"],owner:"RunDevelopment"},jsx:{title:"React JSX",require:["markup","javascript"],optional:["jsdoc","js-extras","js-templates"],owner:"vkbansal"},tsx:{title:"React TSX",require:["jsx","typescript"]},reason:{title:"Reason",require:"clike",owner:"Golmote"},regex:{title:"Regex",owner:"RunDevelopment"},rego:{title:"Rego",owner:"JordanSh"},renpy:{title:"Ren'py",alias:"rpy",owner:"HyuchiaDiego"},rescript:{title:"ReScript",alias:"res",owner:"vmarcosp"},rest:{title:"reST (reStructuredText)",owner:"Golmote"},rip:{title:"Rip",owner:"ravinggenius"},roboconf:{title:"Roboconf",owner:"Golmote"},robotframework:{title:"Robot Framework",alias:"robot",owner:"RunDevelopment"},ruby:{title:"Ruby",require:"clike",alias:"rb",owner:"samflores"},rust:{title:"Rust",owner:"Golmote"},sas:{title:"SAS",optional:["groovy","lua","sql"],owner:"Golmote"},sass:{title:"Sass (Sass)",require:"css",optional:"css-extras",owner:"Golmote"},scss:{title:"Sass (SCSS)",require:"css",optional:"css-extras",owner:"MoOx"},scala:{title:"Scala",require:"java",owner:"jozic"},scheme:{title:"Scheme",owner:"bacchus123"},"shell-session":{title:"Shell session",require:"bash",alias:["sh-session","shellsession"],owner:"RunDevelopment"},smali:{title:"Smali",owner:"RunDevelopment"},smalltalk:{title:"Smalltalk",owner:"Golmote"},smarty:{title:"Smarty",require:"markup-templating",optional:"php",owner:"Golmote"},sml:{title:"SML",alias:"smlnj",aliasTitles:{smlnj:"SML/NJ"},owner:"RunDevelopment"},solidity:{title:"Solidity (Ethereum)",alias:"sol",require:"clike",owner:"glachaud"},"solution-file":{title:"Solution file",alias:"sln",owner:"RunDevelopment"},soy:{title:"Soy (Closure Template)",require:"markup-templating",owner:"Golmote"},sparql:{title:"SPARQL",require:"turtle",owner:"Triply-Dev",alias:"rq"},"splunk-spl":{title:"Splunk SPL",owner:"RunDevelopment"},sqf:{title:"SQF: Status Quo Function (Arma 3)",require:"clike",owner:"RunDevelopment"},sql:{title:"SQL",owner:"multipetros"},squirrel:{title:"Squirrel",require:"clike",owner:"RunDevelopment"},stan:{title:"Stan",owner:"RunDevelopment"},stata:{title:"Stata Ado",require:["mata","java","python"],owner:"RunDevelopment"},iecst:{title:"Structured Text (IEC 61131-3)",owner:"serhioromano"},stylus:{title:"Stylus",owner:"vkbansal"},supercollider:{title:"SuperCollider",alias:"sclang",owner:"RunDevelopment"},swift:{title:"Swift",owner:"chrischares"},systemd:{title:"Systemd configuration file",owner:"RunDevelopment"},"t4-templating":{title:"T4 templating",owner:"RunDevelopment"},"t4-cs":{title:"T4 Text Templates (C#)",require:["t4-templating","csharp"],alias:"t4",owner:"RunDevelopment"},"t4-vb":{title:"T4 Text Templates (VB)",require:["t4-templating","vbnet"],owner:"RunDevelopment"},tap:{title:"TAP",owner:"isaacs",require:"yaml"},tcl:{title:"Tcl",owner:"PeterChaplin"},tt2:{title:"Template Toolkit 2",require:["clike","markup-templating"],owner:"gflohr"},textile:{title:"Textile",require:"markup",optional:"css",owner:"Golmote"},toml:{title:"TOML",owner:"RunDevelopment"},tremor:{title:"Tremor",alias:["trickle","troy"],owner:"darach",aliasTitles:{trickle:"trickle",troy:"troy"}},turtle:{title:"Turtle",alias:"trig",aliasTitles:{trig:"TriG"},owner:"jakubklimek"},twig:{title:"Twig",require:"markup-templating",owner:"brandonkelly"},typescript:{title:"TypeScript",require:"javascript",optional:"js-templates",alias:"ts",owner:"vkbansal"},typoscript:{title:"TypoScript",alias:"tsconfig",aliasTitles:{tsconfig:"TSConfig"},owner:"dkern"},unrealscript:{title:"UnrealScript",alias:["uscript","uc"],owner:"RunDevelopment"},uorazor:{title:"UO Razor Script",owner:"jaseowns"},uri:{title:"URI",alias:"url",aliasTitles:{url:"URL"},owner:"RunDevelopment"},v:{title:"V",require:"clike",owner:"taggon"},vala:{title:"Vala",require:"clike",optional:"regex",owner:"TemplarVolk"},vbnet:{title:"VB.Net",require:"basic",owner:"Bigsby"},velocity:{title:"Velocity",require:"markup",owner:"Golmote"},verilog:{title:"Verilog",owner:"a-rey"},vhdl:{title:"VHDL",owner:"a-rey"},vim:{title:"vim",owner:"westonganger"},"visual-basic":{title:"Visual Basic",alias:["vb","vba"],aliasTitles:{vba:"VBA"},owner:"Golmote"},warpscript:{title:"WarpScript",owner:"RunDevelopment"},wasm:{title:"WebAssembly",owner:"Golmote"},"web-idl":{title:"Web IDL",alias:"webidl",owner:"RunDevelopment"},wgsl:{title:"WGSL",owner:"Dr4gonthree"},wiki:{title:"Wiki markup",require:"markup",owner:"Golmote"},wolfram:{title:"Wolfram language",alias:["mathematica","nb","wl"],aliasTitles:{mathematica:"Mathematica",nb:"Mathematica Notebook"},owner:"msollami"},wren:{title:"Wren",owner:"clsource"},xeora:{title:"Xeora",require:"markup",alias:"xeoracube",aliasTitles:{xeoracube:"XeoraCube"},owner:"freakmaxi"},"xml-doc":{title:"XML doc (.net)",require:"markup",modify:["csharp","fsharp","vbnet"],owner:"RunDevelopment"},xojo:{title:"Xojo (REALbasic)",owner:"Golmote"},xquery:{title:"XQuery",require:"markup",owner:"Golmote"},yaml:{title:"YAML",alias:"yml",owner:"hason"},yang:{title:"YANG",owner:"RunDevelopment"},zig:{title:"Zig",owner:"RunDevelopment"}},plugins:{meta:{path:"plugins/{id}/prism-{id}",link:"plugins/{id}/"},"line-highlight":{title:"Line Highlight",description:"Highlights specific lines and/or line ranges."},"line-numbers":{title:"Line Numbers",description:"Line number at the beginning of code lines.",owner:"kuba-kubula"},"show-invisibles":{title:"Show Invisibles",description:"Show hidden characters such as tabs and line breaks.",optional:["autolinker","data-uri-highlight"]},autolinker:{title:"Autolinker",description:"Converts URLs and emails in code to clickable links. Parses Markdown links in comments."},wpd:{title:"WebPlatform Docs",description:'Makes tokens link to WebPlatform.org documentation. The links open in a new tab.'},"custom-class":{title:"Custom Class",description:"This plugin allows you to prefix Prism's default classes (.comment can become .namespace--comment) or replace them with your defined ones (like .editor__comment). You can even add new classes.",owner:"dvkndn",noCSS:!0},"file-highlight":{title:"File Highlight",description:"Fetch external files and highlight them with Prism. Used on the Prism website itself.",noCSS:!0},"show-language":{title:"Show Language",description:"Display the highlighted language in code blocks (inline code does not show the label).",owner:"nauzilus",noCSS:!0,require:"toolbar"},"jsonp-highlight":{title:"JSONP Highlight",description:"Fetch content with JSONP and highlight some interesting content (e.g. GitHub/Gists or Bitbucket API).",noCSS:!0,owner:"nauzilus"},"highlight-keywords":{title:"Highlight Keywords",description:"Adds special CSS classes for each keyword for fine-grained highlighting.",owner:"vkbansal",noCSS:!0},"remove-initial-line-feed":{title:"Remove initial line feed",description:"Removes the initial line feed in code blocks.",owner:"Golmote",noCSS:!0},"inline-color":{title:"Inline color",description:"Adds a small inline preview for colors in style sheets.",require:"css-extras",owner:"RunDevelopment"},previewers:{title:"Previewers",description:"Previewers for angles, colors, gradients, easing and time.",require:"css-extras",owner:"Golmote"},autoloader:{title:"Autoloader",description:"Automatically loads the needed languages to highlight the code blocks.",owner:"Golmote",noCSS:!0},"keep-markup":{title:"Keep Markup",description:"Prevents custom markup from being dropped out during highlighting.",owner:"Golmote",optional:"normalize-whitespace",noCSS:!0},"command-line":{title:"Command Line",description:"Display a command line with a prompt and, optionally, the output/response from the commands.",owner:"chriswells0"},"unescaped-markup":{title:"Unescaped Markup",description:"Write markup without having to escape anything."},"normalize-whitespace":{title:"Normalize Whitespace",description:"Supports multiple operations to normalize whitespace in code blocks.",owner:"zeitgeist87",optional:"unescaped-markup",noCSS:!0},"data-uri-highlight":{title:"Data-URI Highlight",description:"Highlights data-URI contents.",owner:"Golmote",noCSS:!0},toolbar:{title:"Toolbar",description:"Attach a toolbar for plugins to easily register buttons on the top of a code block.",owner:"mAAdhaTTah"},"copy-to-clipboard":{title:"Copy to Clipboard Button",description:"Add a button that copies the code block to the clipboard when clicked.",owner:"mAAdhaTTah",require:"toolbar",noCSS:!0},"download-button":{title:"Download Button",description:"A button in the toolbar of a code block adding a convenient way to download a code file.",owner:"Golmote",require:"toolbar",noCSS:!0},"match-braces":{title:"Match braces",description:"Highlights matching braces.",owner:"RunDevelopment"},"diff-highlight":{title:"Diff Highlight",description:"Highlights the code inside diff blocks.",owner:"RunDevelopment",require:"diff"},"filter-highlight-all":{title:"Filter highlightAll",description:"Filters the elements the highlightAll and highlightAllUnder methods actually highlight.",owner:"RunDevelopment",noCSS:!0},treeview:{title:"Treeview",description:"A language with special styles to highlight file system tree structures.",owner:"Golmote"}}})},2885:(e,t,n)=>{const r=n(9901),a=n(9642),o=new Set;function i(e){void 0===e?e=Object.keys(r.languages).filter((e=>"meta"!=e)):Array.isArray(e)||(e=[e]);const t=[...o,...Object.keys(Prism.languages)];a(r,e,t).load((e=>{if(!(e in r.languages))return void(i.silent||console.warn("Language does not exist: "+e));const t="./prism-"+e;delete n.c[n(6500).resolve(t)],delete Prism.languages[e],n(6500)(t),o.add(e)}))}i.silent=!1,e.exports=i},6726:(e,t,n)=>{var r={"./":2885};function a(e){var t=o(e);return n(t)}function o(e){if(!n.o(r,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return r[e]}a.keys=function(){return Object.keys(r)},a.resolve=o,e.exports=a,a.id=6726},6500:(e,t,n)=>{var r={"./":2885};function a(e){var t=o(e);return n(t)}function o(e){if(!n.o(r,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return r[e]}a.keys=function(){return Object.keys(r)},a.resolve=o,e.exports=a,a.id=6500},9642:e=>{"use strict";var t=function(){var e=function(){};function t(e,t){Array.isArray(e)?e.forEach(t):null!=e&&t(e,0)}function n(e){for(var t={},n=0,r=e.length;n "));var l={},s=e[r];if(s){function c(t){if(!(t in e))throw new Error(r+" depends on an unknown component "+t);if(!(t in l))for(var i in a(t,o),l[t]=!0,n[t])l[i]=!0}t(s.require,c),t(s.optional,c),t(s.modify,c)}n[r]=l,o.pop()}}return function(e){var t=n[e];return t||(a(e,r),t=n[e]),t}}function a(e){for(var t in e)return!0;return!1}return function(o,i,l){var s=function(e){var t={};for(var n in e){var r=e[n];for(var a in r)if("meta"!=a){var o=r[a];t[a]="string"==typeof o?{title:o}:o}}return t}(o),c=function(e){var n;return function(r){if(r in e)return r;if(!n)for(var a in n={},e){var o=e[a];t(o&&o.alias,(function(t){if(t in n)throw new Error(t+" cannot be alias for both "+a+" and "+n[t]);if(t in e)throw new Error(t+" cannot be alias of "+a+" because it is a component.");n[t]=a}))}return n[r]||r}}(s);i=i.map(c),l=(l||[]).map(c);var u=n(i),d=n(l);i.forEach((function e(n){var r=s[n];t(r&&r.require,(function(t){t in d||(u[t]=!0,e(t))}))}));for(var p,f=r(s),m=u;a(m);){for(var h in p={},m){var g=s[h];t(g&&g.modify,(function(e){e in d&&(p[e]=!0)}))}for(var b in d)if(!(b in u))for(var v in f(b))if(v in u){p[b]=!0;break}for(var y in m=p)u[y]=!0}var w={getIds:function(){var e=[];return w.load((function(t){e.push(t)})),e},load:function(t,n){return function(t,n,r,a){var o=a?a.series:void 0,i=a?a.parallel:e,l={},s={};function c(e){if(e in l)return l[e];s[e]=!0;var a,u=[];for(var d in t(e))d in n&&u.push(d);if(0===u.length)a=r(e);else{var p=i(u.map((function(e){var t=c(e);return delete s[e],t})));o?a=o(p,(function(){return r(e)})):r(e)}return l[e]=a}for(var u in n)c(u);var d=[];for(var p in s)d.push(l[p]);return i(d)}(f,u,t,n)}};return w}}();e.exports=t},2703:(e,t,n)=>{"use strict";var r=n(414);function a(){}function o(){}o.resetWarningCache=a,e.exports=function(){function e(e,t,n,a,o,i){if(i!==r){var l=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw l.name="Invariant Violation",l}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:o,resetWarningCache:a};return n.PropTypes=n,n}},5697:(e,t,n)=>{e.exports=n(2703)()},414:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},4448:(e,t,n)=>{"use strict";var r=n(7294),a=n(7418),o=n(3840);function i(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n